mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-13 20:27:22 +00:00
0cb5fae947
Install motion + animate-ui, overhaul design tokens with brand cyan accent, and replace CSS keyframe animations in Dialog, Tabs, Switch, and Tooltip with spring-physics and blur-fade transitions via animate-ui Radix primitives.
37 lines
749 B
TypeScript
37 lines
749 B
TypeScript
import * as React from 'react';
|
|
|
|
function getStrictContext<T>(
|
|
name?: string,
|
|
): readonly [
|
|
({
|
|
value,
|
|
children,
|
|
}: {
|
|
value: T;
|
|
children?: React.ReactNode;
|
|
}) => React.JSX.Element,
|
|
() => T,
|
|
] {
|
|
const Context = React.createContext<T | undefined>(undefined);
|
|
|
|
const Provider = ({
|
|
value,
|
|
children,
|
|
}: {
|
|
value: T;
|
|
children?: React.ReactNode;
|
|
}) => <Context.Provider value={value}>{children}</Context.Provider>;
|
|
|
|
const useSafeContext = () => {
|
|
const ctx = React.useContext(Context);
|
|
if (ctx === undefined) {
|
|
throw new Error(`useContext must be used within ${name ?? 'a Provider'}`);
|
|
}
|
|
return ctx;
|
|
};
|
|
|
|
return [Provider, useSafeContext] as const;
|
|
}
|
|
|
|
export { getStrictContext };
|