6.x → 7.x migration guide
This guide is intended to help you migrate your project styles from 6.x to 7.x. It is not intended to be a comprehensive guide to all the changes in 7.x. For that, please see the 7.0.0 changelog.
Migration to @mantine/emotion
@mantine/emotion
package is available starting from version 7.9. If you do not want
to use CSS modules, have a lot of styles created with createStyles
, sx
and styles
props, or just prefer CSS-in-JS syntax, you can migrate to @mantine/emotion
. To view
the full documentation for @mantine/emotion
package, visit this page.
createStyles and Global component
createStyles
function and Global
component are no longer available in @mantine/core
package. Change imports
to @mantine/emotion
:
sx and styles props
sx
and styles props available in 7.x the same way as in 6.x after setup:
theme.colorScheme
In v7 color scheme value is managed by MantineProvider,
theme object no longer includes colorScheme
property.
Although it is still possible to access color scheme value in components with
useMantineColorScheme hook,
it is not recommended to base your styles on its value. Instead, use light
/dark
utilities.
Example of 6.x createStyles
with theme.colorScheme
migration to 7.0:
Migration to CSS modules
Before getting started, it is recommended to go through styles documentation. Most notable parts:
Note that this guide assumes that you have postcss-preset-mantine installed and configured in your project.
createStyles
createStyles
function is no longer available in 7.0. Use CSS Modules instead.
sx prop
sx
and prop is no longer available in 7.0. Use className
or style prop instead.
Nested selectors are not supported in style prop, use className
instead:
styles prop
styles
prop no longer supports nested selectors. Use
classNames
instead to apply styles to nested elements.
Regular selectors are still supported:
Global styles
Global
component and global styles on theme are not available in 7.0. Instead,
create a global stylesheet (.css
file) and import it in your application entry point.
theme referencing
All theme properties are now available as CSS variables. It is recommended to use CSS variables instead of referencing theme object in styles.
theme.colorScheme
Color scheme value is managed by MantineProvider,
theme object no longer includes colorScheme
property.
Although it is still possible to access color scheme value in components with
useMantineColorScheme hook,
it is not recommended to base your styles on its value. Instead, use light
/dark
mixins or light-dark
CSS function.
Example of 6.x createStyles
with theme.colorScheme
migration to 7.0:
Note that if your application has server-side rendering, you should not render any
elements based on its value (more info).
Instead, use light
/dark
mixins or light-dark
function to hide/display elements based
on color scheme value.
Color scheme toggle example: