The 4.0.0-beta release renames some components:
FlexContaineris now namedFlexFlexItemis nowFlex.ItemUnderlineNavItemis nowUnderlineNav.ItemFilterListItemis nowFilterList.Item
There is a codemod available to upgrade component identifiers from v3.x.x-beta:
npx jscodeshift -t node_modules/@primer/components/codemods/v4.js path/to/srcThe following breaking changes must be accounted for manually:
Labelno longer has aschemeprop, but now respectssizeanddropshadowprops.StateLabeldoes have aschemeprop (instead ofstate), and takes different values.
🚨 As of v3, the name of the package has changed from primer-react to @primer/components.
The 3.0.0-beta release contains the following breaking changes:
- The
MergeStatuscomponent is gone. Use aStateLabelinstead. - The
Linkcomponent no longer acceptsschemeormutedprops, and has no underline by default. DonutChartis now simplyDonut, andDonutSliceisDonut.Slice.
There is a codemod available to upgrade from 2.x.x-beta and updating the package name:
npx jscodeshift -t node_modules/@primer/components/codemods/v3.js path/to/srcThe 2.0.0-beta release is a major version bump because it renames several components:
Boxis nowBorderBoxBlockis nowBoxCaretBoxis nowPointerBox
We suggest that you rename your components in the above order, since renaming Block to Box before renaming the old Box component to BorderBox will cause problems.
There is a codemod available to upgrade from 1.x.x-beta:
npx jscodeshift -t node_modules/primer-react/codemods/v2.js path/to/srcThis release is a major version bump because it completely refactors the guts of all our components. Here's what you need to know:
There is a codemod available to upgrade from previous versions 0.x.x-beta:
npx jscodeshift -t node_modules/primer-react/codemods/v1.js path/to/srcThe big change in this release is the introduction of emotion and styled-system under the hood to speed up our migration from Primer CSS to complete style encapsulation in React. For now, you will need to continue serving up Primer CSS to support components that haven't yet been migrated to the new styling system. See the README for more information.
This release also introduces early support for theming.
-
The
tagprop has been renamed toisto match styled-system conventions. -
Color props will require refactoring:
-
The
fgprop has been renamed tocoloracross the board. -
Color prop (
bg,color, andborderColor) values are now object paths that represent nested fields in thecolorsobject of our default theme. Because all of our color gradations are expressed as arrays, thegray,blue,green,orange,purple,red, andyellowvalues need to be updated to include the.5suffix so that they receive the value closest to the middle of each hue gradation (red.5maps totheme.colors.red[5]).In other words,
color="red"becomescolor="red.5",bg="purple"becomesbg="purple.5", and so on. See the full list of changes below.
-
-
Some typography props will require refactoring.
-
Some
Blockprops have changed. -
Some
FlexContainerandFlexItemprops have changed.
Theming is an optional way to override the values that control color, spacing, typography, and other aspects of our components.
There are two ways to change the theme of @primer/components components:
-
You can override the theme for an entire tree of components using the
<ThemeProvider>from emotion-theming:import {Block, Button, Text, theme as primer} from '@primer/components' import {ThemeProvider} from 'emotion-theming' // a theme with custom spacing and font sizes const theme = { ...primer, space: [0, 8, 16, 32, 64], fontSizes: [10, 12, 16, 24, 48] } // override theme.colors.bodytext = '#111' export default () => ( <ThemeProvider theme={theme}> <Block color='bodytext' p={4}> <Text fontSize={4}>Hello, world!</Text> </Block> </ThemeProvider> )
⚠️ Note: emotion-theming's<ThemeProvider>only allows exactly one child. -
You can theme individual components by passing the
themeprop directly:import {Text} from '@primer/components' const theme = { colors: { magenta: '#f0f' } } export default () => ( <Text theme={theme} color='magenta'>Hi, I'm magenta!</Text> )
☝️ This is an intentionally convoluted example, since you can use
<Text color='#f0f'>out of the box.
Read the styled-system docs for more information on theming in styled-system.
The following table lists color prop values that have changed in 1.0.0-beta:
| Prop | Before | After | Notes |
|---|---|---|---|
bg |
blue-light |
blue.0 |
|
bg |
blue |
blue.5 |
|
bg |
gray-dark |
gray.9 |
|
bg |
gray-light |
gray.0 |
|
bg |
gray |
gray.1 |
|
bg |
green-light |
green.1 |
|
bg |
green |
green.5 |
|
bg |
orange |
orange.7 |
|
bg |
purple-light |
purple.0 |
|
bg |
purple |
purple.5 |
|
bg |
red-light |
red.1 |
|
bg |
red |
red.5 |
|
bg |
yellow-light |
yellow.2 |
|
bg |
yellow |
yellow.5 |
|
borderColor |
black-fade |
blackfade15 |
|
borderColor |
blue-light |
blue.2 |
|
borderColor |
blue |
blue.5 |
|
borderColor |
gray-dark |
gray.3 |
|
borderColor |
gray-darker |
gray.7 |
|
borderColor |
gray-light |
#eaecef |
Not yet migrated |
borderColor |
gray |
gray.2 |
|
borderColor |
green-light |
#a2cbac |
Not yet migrated |
borderColor |
green |
green.4 |
|
borderColor |
purple |
purple.5 |
|
borderColor |
red-light |
#cea0a5 |
Not yet migrated |
borderColor |
yellow |
#d9d0a5 |
Not yet migrated |
color |
blue |
blue.5 |
|
color |
gray-dark |
gray.9 |
|
color |
gray-light |
gray.5 |
|
color |
gray |
gray.6 |
|
color |
green |
green.5 |
|
color |
orange-light |
orange.6 |
|
color |
orange |
orange.9 |
|
color |
purple |
purple.5 |
|
color |
red |
red.6 |
Remember that all fg props must be renamed to color.
-
Typography props are still only available on the
TextandHeadingcomponents. -
The
fontSizeprop works as before, but now treats any value that doesn't represent an index oftheme.fontSizesas a literal CSS value. -
The
lineHeightprop now accepts one of the keys fromtheme.lineHeights:default,condensed, orcondensedUltra. Any other value will be passed along as a literal CSS value.
The following table lists typography-related prop substitutions:
| Prop | Value(s) | Substitute |
|---|---|---|
lineHeight |
condensed-ultra |
lineHeight="condensedUltra" |
mono |
(boolean) | fontFamily="mono" |
nowrap |
(boolean) | css="white-space: nowrap" |
The Block component supports most of the same props, but the following ones will need to be refactored:
| Prop | Value(s) | Substitute |
|---|---|---|
border |
true |
border={1} |
border |
'bottom' |
borderBottom={1} |
border |
'left' |
borderLeft={1} |
border |
'right' |
borderRight={1} |
border |
'top' |
borderTop={1} |
shadow |
all | boxShadow="value" |
Note: array values in border props represent responsive values.
The FlexContainer and FlexItem components have changed significantly in this version. The following props have been renamed or deprecated:
| Prop | Value(s) | Substitute |
|---|---|---|
direction |
all | flexDirection="css-value" |
wrap |
wrap, nowrap |
flexWrap="css-value" |
inline |
(boolean) | display="inline-flex" |
| Prop | Value(s) | Substitute |
|---|---|---|
flexAuto |
(boolean) | No longer supported |
Codemods are scripted transformations that you can run on your code to relieve you of most of the grunt work involved in upgrading from one major version to the next. The codemod instructions for each major release assume that your code has already been upgraded to the previous major release. If this is not the case, you should run the codemods for all previous major versions first.
Beware that codemods are not 100% fool-proof and may break your code, especially if you do unexpected things like alias Primer exports in strange ways (import {Box as box}...), or use component identifiers from other modules that conflict with Primer's. Before running a codemod, please either back up your work or commit it, then carefully inspect the diff.