Guide
Step-by-step guide to updating your code from Carbon v10 to v11.
- Overview
- Migrating a React app or library
- Migrating an app or library using just styles
- Migrating carbon-icons
- Migrating Carbon elements
Overview
This guide helps you update your project to Carbon v11. It is broken into sections based on how you are using Carbon in your project today. For most teams using Carbon, you’ll want to use the Migrating a React app section.
One of the biggest changes to Carbon in v11 is that we moved to dedicated packages under the
@carbon
- carbon-components
- carbon-components-react
- carbon-icons
- @carbon/icons-react
You can access all of this work under one single package:
@carbon/react
If you were previously using
carbon-components
@carbon/styles
@carbon/react
Both the
carbon-components
carbon-components-react
@carbon/styles
@carbon/react
Migrating a React app or library
Starting in v11, the React components for Carbon live in the
@carbon/react
The
@carbon/react
Step 1: Install @carbon/react
To get started, uninstall the following packages if they exist in your project:
- carbon-components
- carbon-components-react
- carbon-icons
- @carbon/icons-react
npm uninstall carbon-components carbon-components-react carbon-icons @carbon/icons-react
Or, with Yarn:
yarn remove carbon-components carbon-components-react carbon-icons @carbon/icons-react
Next, install the
@carbon/react
npm install @carbon/react
Or, with Yarn:
yarn add @carbon/react
Now that you’ve removed the old packages and brought in the new ones, run the codemod below to fix your pathing.
npx @carbon/upgrade migrate update-carbon-components-react-import-to-scoped --write
After running the command, your code should start looking like this:
// Beforeimport { Accordion, AccordionItem } from 'carbon-components-react';// Afterimport { Accordion, AccordionItem } from '@carbon/react';
Step 2: Install Dart Sass
If you were previously importing styles from
carbon-components
@carbon/react
@carbon/react/scss
Before you’re able to bring in these styles, you’ll need to make sure your project is setup to use Dart Sass. Starting in v11, Carbon styles requires Dart Sass through the
sass
First, let’s remove
node-sass
node-sass
sass
npm uninstall node-sass
Or, with Yarn:
yarn remove node-sass
Now, let’s install
sass
npm install sass --save-dev
Or, with Yarn:
yarn add sass --dev
Once you have Dart Sass installed, it’s important that you configure your project to support resolving imports in Sass from
node_modules
node_modules
includePaths
To learn more about how to configure your specific toolchain to support this, read the documentation for configuration here. We also have published a guide over on Medium to help out with common problems that come from this migration.
Step 3: Update style import paths
Now, open your project’s root stylesheet to make the following changes:
- @import 'carbon-components/scss/globals/scss/styles.scss';+ @use '@carbon/react';
If you were providing any configuration options before you imported Carbon you can now provide them using the
with
@use '@carbon/react' with ($css--default-type: true,$css--reset: true);
If you were using any feature flags in v10, you can safely remove them in v11.
You can also use @import to bring in Carbon, if you prefer, although @use is recommended.
For cases where your projects does’t need to include everything via
@use '@carbon/react'
// Configure feature flags if needed, if not these// lines can be removed@use '@carbon/react/scss/config' with ($font-path: '@ibm/plex',$use-flexbox-grid: 'true');// Emit the css reset@use '@carbon/react/scss/reset';
When migrating your custom components, some of our most used sass assets are included below, along with what you would need to have at the top of your file to use it. Essentially, all we are doing is including the path where we would find these styles in our package.
Carbon sass I’m using | Sass modules to include |
---|---|
Type tokens |
|
Theme tokens |
|
Theme mixins |
|
Design language color tokens |
|
Spacing tokens |
|
Breakpoint mixins |
|
Motion tokens and functions |
|
Rem and other convert functions |
|
Z-index helper |
|
Focus outline helper |
|
Transform rotate helper |
|
Skeleton animation helper |
|
Now that you’ve migrated all of your imports, do a find/replace using your favorite code editor. The prefix
carbon--
carbon--
- @include carbon--breakpoint(lg) {+ @include breakpoint(lg) {width: 42%;}
Once you’ve removed the prefix, your styles should all be set using the old, v10 tokens. We recommend teams install the community supported stylelint-plugin-carbon-tokens to further assist in migrating your tokens to v11 tokens as the old v10 tokens will be removed in our next major release.
Step 4: Updating component size props
Components with size variants have been updated to use the same API options. Previously, the size options were inconsistent:
field
medium
short
Prop value | Size |
---|---|
| 24px |
| 32px |
| 40px |
| 48px |
| 64px |
| 80px |
Note: the default size in v11 is
md
40px
Run the following codemods to update the size prop across the effected components in your project.
npx @carbon/upgrade migrate small-to-size-prop --writenpx @carbon/upgrade migrate size-prop-update --write
By running the series of codemods, they will do the following, in order:
- Removes the deprecated boolean prop and replaces it withsmall.size="sm"
- Removes v10 size props and replaces them with v11 sizes props.
It’s important to run the npx commands in the order that they are presented above. Doing them out of order might result in the codemod not working as intended.
The following components all have size variants that may be affected in your code. To update, you will need to switch to one of the size options listed above. The codemod will make short work of these changes.
- Accordion
- Button
- ComboBox
- Dropdown
- Multiselect
- Filterable multiselect
- ContentSwitcher
- DataTable
- DatePicker
- FileUploader
- FileUploaderItem
- FileUploaderDropContainer
- FileUploaderButton
- Link
- Modal
- ComposedModal
- NumberInput
- OverflowMenu
- Search
- Select
- Tag
- TextInput
- TimePicker
- Toggle
Step 5: Update icon sizes and imports
The
@carbon/icons-react
@carbon/react/icons
This update includes a change to the API of the icon components that come from this package. Previously, we would export icons that included the size of the asset. This update allows you to bring the icon directly and specify the size using the
size
Run the following codemods to update your project’s icons.
npx @carbon/upgrade migrate icons-react-size-prop --writenpx @carbon/upgrade migrate update-carbon-icons-react-import-to-carbon-react --write
By running the series of codemods, they will do the following, in order:
- Removes the size from the import and places it on the icon directly.
- Remove the pathing and replace it with@carbon/icons-react.@carbon/react/icons
It’s important to run the npx commands in the order that they are presented above. Doing them out of order might result in the codemod not working as intended.
After running the command, instead of your icons imports looking like this:
Before
import { Add32, Add24, Add20, Add16 } from '@carbon/icons-react';function MyComponent() {return (<><Add32 /><Add24 /><Add20 /><Add16 />
They should start looking like this:
After
import { Add } from '@carbon/react/icons';function MyComponent() {return (<><Add size={32} /><Add size={24} /><Add size={20} /><Add />
Removed icons
The following deprecated icons have been removed. Use the table below to find their replacement, if available, in v11.
Asset | v10 | v11 |
---|---|---|
app-switcher | AppSwitcher | Switcher |
arrows | Arrows | ArrowsVertical |
back-to-top | BackToTop | UpToTop |
checkbox—undeterminate | CheckboxUndeterminate | CheckboxIndeterminate |
checkbox—undeterminate—filled | CheckboxUndeterminateFilled | CheckboxIndeterminateFilled |
cloud—lightning | CloudLightning | Removed |
cloud—rain | CloudRain | Removed |
cloud—snow | CloudSnow | Removed |
delete | Delete | TrashCan |
edit-filter | EditFilter | FilterEdit |
sunny | Sunny | Removed |
research—bloch-sphere | ResearchBlockSphere | BlochSphere |
research—hinton-plot | ResearchHintonPlot | HintonPlot |
research—matrix | ResearchMatrix | Matrix |
misuse—alt | MisuseAlt | MisuseOutline |
logo—google | LogoGoogle | Removed |
mammogram—stacked | MammogramStacked | Removed |
logo—delicious | LogoDelicious | Removed |
logo—stumbleupon | LogoStumbleUpon | Removed |
letter—Aa—large | LetterAaLarge | TextFont |
glyph—caution-inverted | GlyphCautionInverted | CautionInverted |
glyph—caution | GlyphCaution | Caution |
glyph—circle-fill | GlyphCircleFill | CircleFill |
glyph—circle-stroke | GlyphCircleStroke | CircleStroke |
glyph—critical | GlyphCritical | Critical |
glyph—incomplete | GlyphIncomplete | Incomplete |
glyph—square-fill | GlyphSquareFill | SquareFill |
glyph—undefined | GlyphUndefined | Undefined |
However, in certain situations, we will be unable to infer what the correct update should be for a certain usage of the icon component. We have written the codemod to work for most situations, but you will see console warnings for files that will require you to manually review them to make sure the transforms were applied correctly.
The most common manual update that teams will need to make is if a
prop
ref
function MyComponent({ renderIcon: Icon }) {const ref = useRef(null);return <Icon ref={ref} />;}// Before<MyComponent renderIcon={Search16} />// After the codemod
In this situation, you will need to update your code to use
React.forwardRef
<MyComponentrenderIcon={React.forwardRef((props, ref) => (<Search ref={ref} size={16} {...props} />))}/>;// Or, alternatively:const Search16 = React.forwardRef((props, ref) => {return <Search ref={ref} size={16} {...props} />;
Manual migration
In addition to the automated codemods above, there are several patterns in your codebase that you will need to update manually:
- If you use the name in a test you will need to manually change this. Prefer to use the component directly if using enzymeForwardRef(IconName16)
- If you use snapshot tests, the structure will change and include a prop. Make sure that thesizeprop value matches what your icon name used to be. For example,sizeshould become<Add16 /><Add size={16} />
Step 6: Update components that have changed
In v11, we have updated the APIs of certain components in one of the following ways:
- Update usage to be applied to the outermost element of a componentclassName
- Remove props that have been deprecated in v10
- Refactor the API to ship an accessible component
For a full list of changes to components, check out our Migration Docs. Below are some common changes that may impact you and your usage of Carbon.
Changes to className
className
The usage of
className
The following components previously were not applying the
className
className
className
- Checkbox
- ComboBox
- Table
- TableToolbar
- DataTableSkeleton
- DatePicker
- DatePickerSkeleton
- DatePickerInput
- Dropdown
- FileUploaderDropContainer
- FileUploaderItem
- FormGroup
- FilterableMultiSelect
- MultiSelect
- NotificationTextDetails
- NotificationIcon
- NumberInput
- OverflowMenuItem
- RadioButtonGroup
- RadioTile
- Select
- Slider
- Switch
- TextArea
- ControlledPasswordInput
- PasswordInput
- TextInput
- TimePicker
- Tooltip
- HeaderContainer
Notification
We have updated the notification components to be more accessible out of the box.
ToastNotification
InlineNotification
role="status"
role
log
alert
For notifications requiring an action, a new
ActionableNotifiation
role="alertdialog"
hasFocus
All notifications have a new optional
closeOnEscape
escape
Update ToastNotification
usage
ToastNotification
- can no longer contain interactive elements. Achildrencontaining an action or interactive children should be replaced withToastNotification.ActionableNotification
- The prop is no longer needed and can be removed.notificationType
- The default is nowrole.statusandlogcan also be used.alert
- The prop toggles the closing of notifications via thecloseOnEscapekey.escape
Update InlineNotification
usage
InlineNotification
- The prop has been removed. Anactionscontaining an action or interactive children should be replaced withInlineNotificationconfigured with theActionableNotificationprop.inline
- can no longer contain interactive elements.children
- The prop is no longer needed and can be removed.notificationType
- The default is nowrole.statusandlogcan also be used.alert
- The prop toggles the closing of notifications via thecloseOnEscapekey.escape
When using ActionableNotification
:
ActionableNotification
- The prop enables a styling variation resulting in a similar visual design toinline.InlineNotification
- The prop configures the action button text.actionButtonLabel
- The prop toggles the automatic placement of focus.hasFocus
- The prop toggles the closing of notifications via thecloseOnEscapekey.escape
Tabs
Tabs have been updated to be more composable so that you have the flexibity and control to make them look and act how you want.
In v10, you may have code that looks like the following:
<Tabs><Tab label="Tab label 1"><p>Content for first tab goes here.</p></Tab><Tab label="Tab label 2"><p>Content for second tab goes here.</p></Tab><Tab label="Tab label 3" disabled><p>Content for third tab goes here.</p>
Those same Tabs, migrated to v11:
<Tabs><TabList><Tab>Tab Label 1</Tab><Tab>Tab Label 2</Tab><Tab disabled>Tab Label 3</Tab><Tab title="Tab Label 4 shows truncation">Tab Label 4 shows truncation</Tab></TabList><TabPanels><TabPanel>Content for first tab goes here.</TabPanel>
Update Tabs
and Tab
usage
Tabs
Tab
All the same functionality for Tabs is available in v11 and more! However, some props have been deprecated because they have either been renamed or are no longer needed. Below are the minor tweaks in naming or implementation.
- the prop is deprecated. Both “contained” and “default” tabs still exist but now can be called by adding the proptypeto thecontained.TabList
- Default tabs are now referred to as line tabs in our documentation here and in our storybook.
- prop is no longer needed with the new composable Tabs. You have control over tab content and when it is hidden through thehiddenandTabPanelcomponents.TabPanels
- prop is now namedselected.selectedIndex
- is no longer needed.tabContentClassName(equivalent to tab content) takes in a className prop on its outermost node.TabPanel
- For ,Tabis no longer needed.labelofchildrenare now the label.Tab
- Due to its composability, ,renderAnchor,renderButtonare no longer needed onrenderContent. You now have full control over what is rendered inside ofTabandTab.TabPanel
- Because is no longer needed, the associatedrenderButtonprop has also been deprecated.tabIndex
- onselectedis deprecated in favor orTab, now placed onselectedIndexinstead.Tabs
For more details about the changes to Tabs, see our storybook documentation here.
Step 7: Done with @carbon/react!
And that’s it! You’re done. At this point you have migrated to use Carbon v11 using the
@carbon/react
If you run into any problems after this point, please feel free to reach out to us over on Slack or open up a discussion on GitHub. We want to make this migration experience as seamless as possible and will be monitoring both areas to help out.
Migrating an app or library using just styles
Starting in v11, the styles for Carbon live in the
@carbon/styles
carbon-components
For teams using Svelte, Angular, Vue, LWC, or Web Components, please review the documention, for those respective frameworks before making the migration to v11.
Step 1: Install @carbon/styles
To get started, uninstall
carbon-components
npm uninstall carbon-components
Or, with Yarn:
yarn remove carbon-components
Next, install the
@carbon/styles
npm install @carbon/styles
Or, with Yarn:
yarn add @carbon/styles
Step 2: Install and configure Dart Sass
Previously,
carbon-components
@carbon/styles
sass
If you don’t have this dependency already in your project, you can install it:
npm install sass
Or, with Yarn:
yarn add sass
Similarly, if you currently use
node-sass
node-sass
One you have Dart Sass installed, it’s important that you configure your project to support resolving imports in Sass from
node_modules
node_modules
includePaths
To learn more about how to configure your specific toolchain to support this, read the documentation for configuration here. We also have published a guide over on Medium to help out with common problems that come from this migration.
Step 3: Update import paths and tokens
Now, open your project’s root stylesheet to make the following changes:
- @import 'carbon-components/scss/globals/scss/styles.scss';+ @use '@carbon/styles';
If you were providing any configuration options before you imported Carbon you can now provide them using the
with
@use '@carbon/styles' with ($css--default-type: true,$css--reset: true);
For cases where your projects does’t need to include everything via
@use '@carbon/styles'
// configure feature flags if needed, if not this line can be removed@use '@carbon/styles/scss/config' with ($font-path: '@ibm/plex');// ensure the css reset is included@use '@carbon/styles/scss/reset';// add styles for components individually
When migrating your custom components, some of our most used sass assets are included below, along with what you would need to have at the top of your file to use it. Essentially, all we are doing is including the path where we would find these styles in our package.
Carbon sass I’m using | Sass modules to include |
---|---|
Theme tokens |
|
Theme mixins |
|
Design language color tokens |
|
Spacing tokens |
|
Breakpoint mixins |
|
Motion tokens and functions |
|
Rem and other convert functions |
|
Z-index helper |
|
Focus outline helper |
|
Transform rotate helper |
|
Skeleton animation helper |
|
Now that you’ve migrated all of your imports, do a find/replace using your favorite code editor. The prefix
carbon--
carbon--
- @include carbon--breakpoint(lg) {+ @include breakpoint(lg) {width: 42%;}
Once you’ve removed the prefix, your styles should all be set using the old, v10 tokens. We recommend teams install the community supported stylelint-plugin-carbon-tokens to further assist in migrating your tokens to v11 tokens as the old v10 tokens will be removed in our next major release.
Step 4: Update bx to cds
If you are targeting specific selectors that use the
bx
cds
bx
// Option A@use '@carbon/styles' with ($prefix: 'bx');// Option B@use '@carbon/styles/scss/config' with ($prefix: 'bx');
Step 5: Enable flexbox grid
If you are using the flexbox-based grid in your project, you can continue to use this feature in v11 by importing the following:
@use '@carbon/styles/scss/grid/flexbox';
This is important due to the fact that the CSS Grid implementation is used by default in v11. However, bringing in the flexbox grid styles in this way means that your layouts will continue to work the same as in v10.
Step 6: Done with @carbon/styles!
And that’s it! You’re done. At this point you have migrated to use Carbon v11 using the
@carbon/styles
If you run into any problems after this point, please feel free to reach out to us over on Slack or open up a discussion on GitHub. We want to make this migration experience as seamless as possible and will be monitoring both areas to help out.
Migrating carbon-icons
The
carbon-icons
If you are using
@carbon/react
@carbon/react/icons
Migrating Carbon elements
The packages that we ship for the IBM Design Language have been updated in v11. The most notable change is that these packages now require Dart Sass in order to compile as they now use Sass Modules to improve compilation times.
If you were directly importing from one of these element packages, consider importing from either
@carbon/styles
@carbon/react
For teams using these packages directly, you will need to update each of the elements packages you’re using to the latest version.
npm install @carbon/<package-name>@latest
Or, with Yarn:
yarn upgrade @carbon/<package-name>@latest
Afterwards, you will need to update the import paths and import names themselves that you bring in. In general, each package now supports importing from the package directly and all
carbon--
For full details fo the changes to each elements package, check out the links below.
If you were previously using the
@carbon/import-once