@metamask/design-system-twrnc-preset
Version:
33 lines • 1.08 kB
JavaScript
function $importDefault(module) {
if (module?.__esModule) {
return module.default;
}
return module;
}
import $React, { useMemo } from "react";
const React = $importDefault($React);
import { create } from "twrnc";
import { generateTailwindConfig } from "./tailwind.config.mjs";
import { ThemeContext } from "./ThemeContext.mjs";
/**
* Theme provider component that wraps child components with theme context
*
* @param options - Component props
* @param options.children - Child components to render
* @param options.theme - Theme to apply (light or dark)
* @returns React component that provides theme context to children
*/
export const ThemeProvider = ({ children, theme, }) => {
const contextValue = useMemo(() => {
const tailwindConfig = generateTailwindConfig(theme);
const tw = create(tailwindConfig);
return {
tw,
theme,
};
}, [theme]);
return (<ThemeContext.Provider value={contextValue}>
{children}
</ThemeContext.Provider>);
};
//# sourceMappingURL=ThemeProvider.mjs.map