UNPKG

@metamask/design-system-twrnc-preset

Version:
1 lines 1.79 kB
{"version":3,"file":"ThemeProvider.mjs","sourceRoot":"","sources":["../src/ThemeProvider.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,QAAO,EAAE,OAAO,EAAE,cAAc;;AACvC,OAAO,EAAE,MAAM,EAAE,cAAc;AAE/B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAG3D,OAAO,EAAE,YAAY,EAAE,2BAAuB;AAE9C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAC5B,QAAQ,EACR,KAAK,GAIN,EAAE,EAAE;IACH,MAAM,YAAY,GAAsB,OAAO,CAAC,GAAG,EAAE;QACnD,MAAM,cAAc,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;QACrD,MAAM,EAAE,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QAClC,OAAO;YACL,EAAE;YACF,KAAK;SACN,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,CACL,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CACzC;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,YAAY,CAAC,QAAQ,CAAC,CACzB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React, { useMemo } from 'react';\nimport { create } from 'twrnc';\n\nimport { generateTailwindConfig } from './tailwind.config';\nimport type { Theme } from './Theme.types';\nimport type { ThemeContextProps } from './ThemeContext';\nimport { ThemeContext } from './ThemeContext';\n\n/**\n * Theme provider component that wraps child components with theme context\n *\n * @param options - Component props\n * @param options.children - Child components to render\n * @param options.theme - Theme to apply (light or dark)\n * @returns React component that provides theme context to children\n */\nexport const ThemeProvider = ({\n children,\n theme,\n}: {\n children: React.ReactNode;\n theme: Theme;\n}) => {\n const contextValue: ThemeContextProps = useMemo(() => {\n const tailwindConfig = generateTailwindConfig(theme);\n const tw = create(tailwindConfig);\n return {\n tw,\n theme,\n };\n }, [theme]);\n\n return (\n <ThemeContext.Provider value={contextValue}>\n {children}\n </ThemeContext.Provider>\n );\n};\n"]}