Migrating from Material UI
The first step is to install @volvo-cars/css and @volvo-cars/edls-css. During the transition period, you can use both MUI and EDLS components in the same project.
The migration process varies depending on the type of component.
Core and layout components
Section titled “Core and layout components”Examples: Box, Stack, Grid, Typography, Button
The design system provides utility classes as alternatives to these MUI components. If you’re not familiar with utility classes, read the CSS architecture page first.
For general layouts and Grid components, follow the layout guidelines.
For Box, Stack, Typography, and Button, we provide codemods.
The codemods perform the following steps:
- Replace JSX markup to use HTML elements instead of MUI components.
- Replace
sxattributes withstyleattributes. - Transform margin, padding, and flex properties into Volvo CSS classes, removing them from the
styleobject. - Transform
variantattributes into Volvo CSS classes.
If any properties are not supported by Volvo CSS, they are kept in the style object.
-
Install the tooling
Terminal window yarn add jscodeshift @volvo-cars/edls-cli -D -
Run the codemods
Replace
.with the path to the folder you want to migrate. We recommend creating one PR per component to keep changes reviewable.Terminal window npx jscodeshift --transform ./node_modules/@volvo-cars/edls-cli/codemods/box-transform.cjs --parser tsx --ignore-pattern="*.ts" --ignore-pattern="*.d.ts" --ignore-pattern="node_modules" .npx jscodeshift --transform ./node_modules/@volvo-cars/edls-cli/codemods/stack-transform.cjs --parser tsx --ignore-pattern="*.ts" --ignore-pattern="*.d.ts" --ignore-pattern="node_modules" .npx jscodeshift --transform ./node_modules/@volvo-cars/edls-cli/codemods/button-transform.cjs --parser tsx --ignore-pattern="*.ts" --ignore-pattern="*.d.ts" --ignore-pattern="node_modules" .npx jscodeshift --transform ./node_modules/@volvo-cars/edls-cli/codemods/typography-transform.cjs --parser tsx --ignore-pattern="*.ts" --ignore-pattern="*.d.ts" --ignore-pattern="node_modules" . -
Remove MUI imports. This is not included in the codemods due to the different ways MUI components can be imported. A find-and-replace in your editor will do the trick.
-
Run Prettier and ESLint to format the migrated code.
Component mapping
Section titled “Component mapping”| Material UI | EDLS Alternative |
|---|---|
| Button | Button |
| Icon | Icon |
| IconButton | IconButton |
| Input | TextInput |
| TextArea | TextArea |
| Checkbox | Checkbox |
| Radio | Radio |
| Select | Select |
| Switch | Switch |
| Slider | RangeSlider |
| Dialog | Dialog |
| Sidebar | Sheet |
| Tooltip | Tooltip |
| Breadcrumbs | Breadcrumbs |
| Accordion | Accordion |
| DataGrid | Table |
| TablePagination | TablePagination |
| Pagination | PagePagination |
| DatePicker | DropdownCalendar |
| DateRangePicker | DropdownCalendarRange |
| MultiSelect | DropdownMultiSelect |
| FilterSelect | DropdownSelect |
| Skeleton | Skeleton |
| Progress | Spinner |
| Snackbar | Work in progress |
Refer to the component documentation for usage details and examples of each alternative.