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
Copy file name to clipboardExpand all lines: README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,7 +78,7 @@ This will set the `color`, `font-family`, and `line-height` CSS properties to th
78
78
79
79
#### Static CSS rendering
80
80
81
-
If you're rendering React components both server-side _and_ client-side, we suggest following [Emotion's server-side rendering instructions](https://emotion.sh/docs/ssr) to avoid the flash of unstyled content for server-rendered components. This repo's [documentation template component](https://github.com/primer/components/blob/master/pages/_document.js) demonstrates how to do this in [Next.js].
81
+
If you're rendering React components both server-side _and_ client-side, we suggest following [styled-component's server-side rendering instructions](https://www.styled-components.com/docs/advanced#server-side-rendering) to avoid the flash of unstyled content for server-rendered components. This repo's [documentation template component](https://github.com/primer/components/blob/master/pages/_document.js) demonstrates how to do this in [Next.js].
82
82
83
83
## Local Development
84
84
@@ -101,7 +101,7 @@ To run `@primer/components` locally when adding or updating components:
101
101
- Maintain design system consistency with utilities as props (for spacing, color, font-size, line-height, widths, and radii).
@@ -51,125 +51,52 @@ A code coverage report is included in the `npm test` output, and test coverage d
51
51
52
52
## Tools we use
53
53
54
-
1. We use [emotion] to style our components, and [emotion-theming] as the theme provider.
54
+
1. We use [styled-components] to style our components.
55
55
2. We use style functions from [styled-system] whenever possible, and styled-systems' `style()` function to create new ones.
56
-
3. We use [system-components] to reduce the amount of boilerplate needed to implement styled-system functions.
57
56
58
-
## Component patterns
59
-
60
-
With a couple of exceptions, all components should be created by the `withSystemProps()` function from `src/system-props.js`. This function takes a "component-ish" value as its first argument, and an array of [system props](#system-props) as the second:
Categories of system props are exported from `src/system-props`:
85
57
86
-
*`COMMON` includes color and spacing (margin and padding) props
87
-
*`TYPOGRAPHY` includes font family, font weight, and line-height props
88
-
*`POSITION` includes positioning props
89
-
*`FLEX_CONTAINER` includes flexbox props for containers
90
-
*`FLEX_ITEM` includes flexbox props for items in a flex container
58
+
## Component patterns
91
59
92
-
### Components with only system props
60
+
With a couple of exceptions, all components should be created with the `styled` function from [styled-components] and should have the appropriate groups of system props attached.
93
61
94
-
Components with only system props should be created by passing the default tag to `withSystemProps()`:
62
+
Default values for system props can be set in `Component.defaultProps`.
Prop Types from system props such as `COMMON` or `TYPOGRAPHY` as well as styled-system functions can be spread in the component's prop types declaration (see example below).
98
65
99
-
constBlock=withSystemProps('div', LAYOUT)
100
-
```
66
+
⚠️ **Make sure to always set the default `theme` prop to our theme! This allows consumers of our components to access our theme values without a ThemeProvider.**
101
67
102
-
### Primer CSS components
103
-
If you're just adding Primer CSS class names, you can pass the `className` prop to another component created with `withSystemProps()`, and it will be combined with any generated classes automatically:
theme, // make sure to always set the default theme!
80
+
m:0,
81
+
fontSize:5,
116
82
}
117
83
118
-
FancyBox.defaultProps= {
119
-
...Box.defaultProps
84
+
Component.propTypes= {
85
+
...COMMON.propTypes,
86
+
...TYPOGRAPHY.propTypes
120
87
}
121
88
122
-
// if you don't spread defaultProps from another system component,
123
-
// you will need to wrap the export in withDefaultTheme()
124
-
exportdefaultFancyBox
89
+
exportdefaultComponent
125
90
```
126
91
127
-
> **⚠️ If you use this pattern, passing the component to `withSystemProps()` should throw an error because system-components has an issue (_TODO: ref_) with calling the underlying component render function twice.**
92
+
Categories of system props are exported from `src/constants.js`:
128
93
129
-
With the above pattern, it's possible to control whether users may pass additional class names to your component. If you want to allow this, the `className` prop should be listed in `propTypes` and combined with your own classes using the [classnames] function:
In this case, you will need to deal explicitly with two props passed down from [emotion] and [system-components], respectively:
94
+
*`COMMON` includes color and spacing (margin and padding) props
95
+
*`TYPOGRAPHY` includes font family, font weight, and line-height props
96
+
*`POSITION` includes positioning props
97
+
*`FLEX_CONTAINER` includes flexbox props for containers
98
+
*`FLEX_ITEM` includes flexbox props for items in a flex container
170
99
171
-
*`className`: You _must_ render this prop, otherwise **your component will not be styled.**
172
-
*`is`: This is what allows your component to render with arbitrary elements, and even other components. If you don't respect this prop, you should `delete Component.propTypes.is` to signal that it's not available.
173
100
174
101
## Writing documentation
175
102
@@ -204,12 +131,14 @@ This site is served as a subdirectory of [primer.style] using a [path alias](htt
204
131
## Glossary
205
132
206
133
### System props
207
-
System props are style functions that provide on or more props, and can be passed directly the return value of [emotion]'s `styled()` function:
134
+
System props are style functions that provide one or more props, and can be passed directly the return value of [styled-components]'s `styled()` function:
208
135
209
136
```jsx
210
-
import {styled} from'react-emotion'
137
+
import {styled} from'styled-components'
211
138
import {space} from'styled-system'
212
-
constSpaceDiv=styled('div')(space)
139
+
constSpaceDiv=styled.div`
140
+
${space}
141
+
`
213
142
```
214
143
215
144
System props come with `propTypes` that can be mixed into your own with ES6 [spread syntax]:
0 commit comments