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,KAAK;AAE3E,MAAa,6BAAA,GAAA,MAAA,KAAgC,oBAAoB,IAAIA,sBAAAA;AAErE,SAAgB,kBAAkB;CAChC,MAAM,OAAA,GAAA,MAAA,KAAU,oBAAoB;AACpC,KAAI,CAAC,IACH,OAAM,IAAI,MACR,oGACD;AAGH,QAAO;;AAcT,SAAgB,qBAAqB,EACnC,OACA,UACA,UAAU,QACkB;CAC5B,MAAM,cAAc,qBAAqB;AAMzC,QAAO,iBAAA,GAAA,kBAAA,KAAC,qBAAD;EAAqB,QAAA,GAAA,MAAA,eAJpBC,4BAAAA,kBAAkB,UAAU,cAAcD,sBAAAA,eAAe,MAAM,EACrE;GAAC;GAAO;GAAa;GAAQ,CAC9B;EAEgD;EAA+B,CAAA;;AAGlF,qBAAqB,cAAc"}