UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 2.17 kB
{"version":3,"file":"MantineThemeProvider.cjs","names":["DEFAULT_THEME","mergeMantineTheme"],"sources":["../../../../src/core/MantineProvider/MantineThemeProvider/MantineThemeProvider.tsx"],"sourcesContent":["import { createContext, use, useMemo } from 'react';\nimport { DEFAULT_THEME } from '../default-theme';\nimport { mergeMantineTheme } from '../merge-mantine-theme';\nimport { MantineTheme, MantineThemeOverride } from '../theme.types';\n\nexport const MantineThemeContext = createContext<MantineTheme | null>(null);\n\nexport const useSafeMantineTheme = () => use(MantineThemeContext) || DEFAULT_THEME;\n\nexport function useMantineTheme() {\n const ctx = use(MantineThemeContext);\n if (!ctx) {\n throw new Error(\n '@mantine/core: MantineProvider was not found in component tree, make sure you have it in your app'\n );\n }\n\n return ctx;\n}\n\nexport interface MantineThemeProviderProps {\n /** Determines whether theme should be inherited from parent MantineProvider @default true */\n inherit?: boolean;\n\n /** Theme override object */\n theme?: MantineThemeOverride;\n\n /** Your application or part of the application that requires different theme */\n children?: React.ReactNode;\n}\n\nexport function MantineThemeProvider({\n theme,\n children,\n inherit = true,\n}: MantineThemeProviderProps) {\n const parentTheme = useSafeMantineTheme();\n const mergedTheme = useMemo(\n () => mergeMantineTheme(inherit ? parentTheme : DEFAULT_THEME, theme),\n [theme, parentTheme, inherit]\n );\n\n return <MantineThemeContext value={mergedTheme}>{children}</MantineThemeContext>;\n}\n\nMantineThemeProvider.displayName = '@mantine/core/MantineThemeProvider';\n"],"mappings":";;;;;;;AAKA,MAAa,uBAAA,GAAA,MAAA,eAAyD,IAAI;AAE1E,MAAa,6BAAA,GAAA,MAAA,KAAgC,mBAAmB,KAAKA,sBAAAA;AAErE,SAAgB,kBAAkB;CAChC,MAAM,OAAA,GAAA,MAAA,KAAU,mBAAmB;CACnC,IAAI,CAAC,KACH,MAAM,IAAI,MACR,mGACF;CAGF,OAAO;AACT;AAaA,SAAgB,qBAAqB,EACnC,OACA,UACA,UAAU,QACkB;CAC5B,MAAM,cAAc,oBAAoB;CAMxC,OAAO,iBAAA,GAAA,kBAAA,KAAC,qBAAD;EAAqB,QAAA,GAAA,MAAA,eAJpBC,4BAAAA,kBAAkB,UAAU,cAAcD,sBAAAA,eAAe,KAAK,GACpE;GAAC;GAAO;GAAa;EAAO,CAGe;EAAI;CAA8B,CAAA;AACjF;AAEA,qBAAqB,cAAc"}