MantineProvider
MantineProvider
provides a theme object context value, manages color scheme
changes and injects CSS variables. It must be rendered at the root of your
application and should be used only once.
Usage
MantineProvider props
MantineProvider
supports the following props:
theme
Pass theme object override to theme
prop. It will be merged with the default
theme and used in all components.
colorSchemeManager
colorSchemeManager
is used to retrieve and set color scheme value in external storage. By default,
MantineProvider
uses window.localStorage
to store color scheme value, but you can pass your own
implementation to colorSchemeManager
prop. You can learn more about color scheme management in the
color schemes guide.
defaultColorScheme
defaultColorScheme
value is used when colorSchemeManager
cannot retrieve the value from external
storage, for example during server side rendering or when the user hasn't selected a preferred color scheme.
Possible values are light
, dark
and auto
. By default, color scheme value is light
.
You can learn more about color scheme management in the color schemes guide.
cssVariablesSelector
cssVariablesSelector
is a CSS selector to which CSS variables should be added.
By default, it is :root
. MantineProvider
generates CSS variables based on given theme override
and cssVariablesResolver
, then these variables are rendered into <style />
tag next to your application.
You can learn more about Mantine CSS variables in the CSS variables guide.
withCssVariables
withCssVariables
determines whether theme CSS variables should be added to given cssVariablesSelector
.
By default, it is set to true
, you should not change it unless you want to manage CSS variables
via .css
file (Note that in this case you will need to generate all theme tokens
that are not a part of the default theme on your side).
deduplicateCssVariables
deduplicateCssVariables
determines whether CSS variables should be deduplicated: if CSS variable has the same value as in default theme, it is not added in the runtime.
By default, it is set to true
. If set to false
, all Mantine CSS variables will be added in <style />
tag
even if they have the same value as in the default theme.
getRootElement
getRootElement
is a function that returns the root application (usually html
) element to set data-mantine-color-scheme
attribute.
Default value is () => document.documentElement
which means that data-mantine-color-scheme
attribute will be added to <html />
tag. You can learn more about color scheme management in the
color schemes guide.
classNamesPrefix
classNamesPrefix
is a prefix for components static classes (for example {selector}-Text-root
).
Default value is mantine
– all components will have mantine-
prefix in their static classes.
In this case (default classNamesPrefix
), Text component will have the following classes:
mantine-focus-auto
– global utility classm-3nrA4eL
– component class, usually a random string, with this class library styles are appliedmantine-Text-root
– component static class, part of Styles API
With classNamesPrefix
you can change only static class:
Now Text component will have the following classes:
mantine-focus-auto
–classNamesPrefix
does not impact global utility classes – it is static and cannot be changedm-3nrA4eL
–classNamesPrefix
does not impact library class – it is static and cannot be changedapp-Text-root
– component static class hasclassNamesPrefix
instead ofmantine
withStaticClasses
withStaticClasses
determines whether components should have static classes, for example, mantine-Button-root
.
By default, static classes are enabled, to disable them set withStaticClasses
to false
:
withGlobalClasses
withGlobalClasses
determines whether global classes should be added with <style />
tag.
Global classes are required for hiddenFrom
/visibleFrom
and lightHidden
/darkHidden
props to work.
By default, global classes are enabled, to disable them set withGlobalClasses
to false
. Note that
disabling global classes may break styles of some components.
getStyleNonce
getStyleNonce
is a function to generate nonce attribute added to dynamic generated <style />
tags.
cssVariablesResolver
cssVariablesResolver
is a function to generate CSS variables styles based on the theme object.
You can learn more about Mantine CSS variables in the CSS variables guide.