UNPKG

@metamask/design-system-twrnc-preset

Version:
1 lines 1.76 kB
{"version":3,"file":"ThemeProvider.cjs","sourceRoot":"","sources":["../src/ThemeProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAuC;AACvC,iCAA+B;AAE/B,2DAA2D;AAG3D,qDAA8C;AAE9C;;;;;;;GAOG;AACI,MAAM,aAAa,GAAG,CAAC,EAC5B,QAAQ,EACR,KAAK,GAIN,EAAE,EAAE;IACH,MAAM,YAAY,GAAsB,IAAA,eAAO,EAAC,GAAG,EAAE;QACnD,MAAM,cAAc,GAAG,IAAA,wCAAsB,EAAC,KAAK,CAAC,CAAC;QACrD,MAAM,EAAE,GAAG,IAAA,cAAM,EAAC,cAAc,CAAC,CAAC;QAClC,OAAO;YACL,EAAE;YACF,KAAK;SACN,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,CACL,CAAC,2BAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CACzC;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,2BAAY,CAAC,QAAQ,CAAC,CACzB,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,aAAa,iBAqBxB","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"]}