You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Components no longer have a default `theme` prop. To ensure components still render correctly, you'll need pass the Primer theme to a [styled-components](https://styled-components.com/)`<ThemeProvider>` at the root of your application:
Copy file name to clipboardExpand all lines: contributor-docs/CONTRIBUTING.md
+1-19Lines changed: 1 addition & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,6 @@
6
6
4.[Developing Components](#developing-components)
7
7
-[Tools we use](#tools-we-use)
8
8
-[Component patterns](#component-patterns)
9
-
-[Adding default theme](#adding-default-theme)
10
9
-[Adding system props](#adding-system-props)
11
10
-[Adding the sx prop](#adding-the-sx-prop)
12
11
-[Linting](#linting)
@@ -72,15 +71,14 @@ With a couple of exceptions, all components should be created with the `styled`
72
71
73
72
Default values for system props can be set in `Component.defaultProps`.
74
73
75
-
⚠️ **Make sure to always set the default `theme` prop to our [theme](https://github.com/primer/components/blob/main/src/theme-preval.js)! This allows consumers of our components to access our theme values without a ThemeProvider.**
74
+
⚠️ **Do not set the default `theme` prop! This can sometimes override the theme provided by the ThemeProvider and cause unexpected theming issues.**
76
75
77
76
Additionally, every component should support [the `sx` prop](https://primer.style/components/overriding-styles); remember to add `${sx}` to the style literal.
78
77
79
78
Here's an example of a basic component written in the style of Primer Components:
80
79
81
80
```jsx
82
81
import {TYPOGRAPHY, COMMON} from'./constants'
83
-
importthemefrom'./theme'
84
82
importsxfrom'./sx
85
83
86
84
const Component = styled.div`
@@ -92,28 +90,13 @@ const Component = styled.div`
92
90
`
93
91
94
92
Component.defaultProps = {
95
-
theme, // make sure to always set the default theme!
96
93
m: 0,
97
94
fontSize: 5,
98
95
}
99
96
100
97
export default Component
101
98
```
102
99
103
-
### Adding default theme
104
-
105
-
Each component needs access to our default Primer Theme, so that users of the component can access theme values easily in their consuming applications.
106
-
107
-
To add the default theme to a component, import the theme and assign it to the component's defaultProps object:
108
-
109
-
```jsx
110
-
import theme from './theme'
111
-
112
-
Component.defaultProps = {
113
-
theme // make sure to always set the default theme!
114
-
}
115
-
```
116
-
117
100
### Adding system props
118
101
119
102
Each component should have access to the appropriate system props. Every component has access to `COMMON`. For **most** components added, you'll only need to give the component to `COMMON`. If you are unsure, ping a DS team member on your PR.
@@ -223,7 +206,6 @@ After opening a pull request, a member of the design systems team will add the a
223
206
- If it's a new component, does the component make sense to add to Primer Components? (Ideally this is discussed before the pull request stage, please reach out to a DS member if you aren't sure if a component should be added to Primer Components!)
224
207
- Does the component follow our [Primer Components code style](#component-patterns)?
225
208
- Does the component use theme values for most CSS values?
226
-
- Does the component have access to the [default theme](#adding-default-theme)?
227
209
- Does the component have the [correct system props implemented](#adding-system-props)?
228
210
- Is the component API intuitive?
229
211
- Does the component have the appropriate [type definitions in`index.d.ts`](#typescript-support)?
Copy file name to clipboardExpand all lines: docs/content/getting-started.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,11 +79,27 @@ This will apply the same `color`, `font-family`, and `line-height` styles to the
79
79
80
80
## Theming
81
81
82
-
Components are styled using Primer's [theme](https://github.com/primer/components/blob/main/src/theme-preval.js) by default, but you can provide your own theme by using[styled-component's](https://styled-components.com/)`<ThemeProvider>`. If you'd like to fully replace the Primer [theme](https://github.com/primer/components/blob/main/src/theme-preval.js) with your custom theme, pass your theme to the `<ThemeProvider>`in the root of your application like so:
82
+
For Primer Components to render correcly, you must pass the Primer theme to a[styled-components](<(https://styled-components.com/)>)`<ThemeProvider>`at the root of your application:
83
83
84
84
```jsx
85
85
import {ThemeProvider} from'styled-components'
86
+
import {theme} from'@primer/components'
87
+
88
+
constApp=props=> {
89
+
return (
90
+
<div>
91
+
<ThemeProvider theme={theme}>
92
+
<div>your app here</div>
93
+
</ThemeProvider>
94
+
</div>
95
+
)
96
+
}
97
+
```
86
98
99
+
If you'd like to fully replace the Primer [theme](https://github.com/primer/components/blob/main/src/theme-preval.js) with your custom theme, pass your theme to the `<ThemeProvider>` instead:
0 commit comments