Skip to content

Commit 06f4a73

Browse files
author
Emily
authored
Merge pull request #377 from primer/release-q4-santa
Release Q4 🎅🏼
2 parents 3c4195f + a28993c commit 06f4a73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2353
-2001
lines changed

.eslintrc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"plugin:jsx-a11y/recommended"
66
],
77
"rules": {
8-
"import/no-namespace": 0
8+
"import/no-namespace": 0,
9+
"no-unused-vars": ["error", {
10+
"ignoreRestSiblings": true
11+
}]
912
}
1013
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ This will set the `color`, `font-family`, and `line-height` CSS properties to th
7878

7979
#### Static CSS rendering
8080

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].
8282

8383
## Local Development
8484

@@ -101,7 +101,7 @@ To run `@primer/components` locally when adding or updating components:
101101
- Maintain design system consistency with utilities as props (for spacing, color, font-size, line-height, widths, and radii).
102102

103103

104-
[emotion]: https://emotion.sh/
104+
[styled-components]: https://www.styled-components.com/docs
105105
[Primer CSS]: https://github.com/primer/primer
106106
[flash of unstyled content]: https://en.wikipedia.org/wiki/Flash_of_unstyled_content
107107
[Next.js]: https://github.com/zeit/next.js

contributing.md

Lines changed: 33 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -51,125 +51,52 @@ A code coverage report is included in the `npm test` output, and test coverage d
5151

5252
## Tools we use
5353

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.
5555
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.
5756

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:
61-
62-
```jsx
63-
import {withSystemProps, POSITION} from './system-props'
64-
65-
function Component(props) {
66-
/* implementation */
67-
}
68-
69-
export default withSystemProps(Component, POSITION)
70-
71-
// equivalent:
72-
export default withSystemProps({is: Component}, POSITION)
73-
74-
// with more default props:
75-
export default withSystemProps(
76-
{
77-
is: Component,
78-
m: 2
79-
},
80-
POSITION
81-
)
82-
```
83-
84-
Categories of system props are exported from `src/system-props`:
8557

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
9159

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.
9361

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`.
9563

96-
```jsx
97-
import {withSystemProps, LAYOUT} from './system-props'
64+
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).
9865

99-
const Block = 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.**
10167

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:
10468

10569
```jsx
106-
import Box from './Box'
107-
108-
function FancyBox({flashing, ...rest}) {
109-
return <Box className={flashing && 'Box--flashing'} {...rest} />
110-
}
111-
112-
FancyBox.propTypes = {
113-
flashing: PropTypes.bool,
114-
// be sure to spread Box's prop-types
115-
...Box.propTypes
70+
import {TYPOGRAPHY, COMMON} from './constants'
71+
import theme from './theme'
72+
73+
const Component = styled.div`
74+
${TYPOGRAPHY}
75+
${COMMON};
76+
`
77+
78+
Component.defaultProps = {
79+
theme, // make sure to always set the default theme!
80+
m: 0,
81+
fontSize: 5,
11682
}
11783

118-
FancyBox.defaultProps = {
119-
...Box.defaultProps
84+
Component.propTypes = {
85+
...COMMON.propTypes,
86+
...TYPOGRAPHY.propTypes
12087
}
12188

122-
// if you don't spread defaultProps from another system component,
123-
// you will need to wrap the export in withDefaultTheme()
124-
export default FancyBox
89+
export default Component
12590
```
12691

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`:
12893

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:
130-
131-
```jsx
132-
import classnames from 'classnames'
133-
import Box from './Box'
134-
135-
export default function FancyBox({flashing, className, ...rest}) {
136-
const classes = classnames(className, flashing && 'Box--flashing')
137-
return <Box className={classes} {...rest} />
138-
}
139-
140-
FancyBox.propTypes = {
141-
className: PropTypes.string,
142-
flashing: PropTypes.bool,
143-
...Box.propTypes
144-
}
145-
```
146-
147-
Alternatively, you can create the component from scratch using `withSystemProps()`, and pass it the same system props:
148-
149-
```jsx
150-
import classnames from 'classnames'
151-
import {withSystemProps, LAYOUT, COMMON} from './system-props'
152-
153-
function FancyBox({flashing, className, is: Tag, ...rest}) {
154-
return (
155-
<Tag
156-
className={classnames(className, flashing && 'Box--flashing')}
157-
{...rest}
158-
/>
159-
)
160-
}
161-
162-
FancyBox.propTypes = {
163-
flashing: PropTypes.bool
164-
}
165-
166-
export default withSystemProps(FancyBox, [...LAYOUT, ...COMMON])
167-
```
168-
169-
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
17099

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.
173100

174101
## Writing documentation
175102

@@ -204,12 +131,14 @@ This site is served as a subdirectory of [primer.style] using a [path alias](htt
204131
## Glossary
205132

206133
### 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:
208135

209136
```jsx
210-
import {styled} from 'react-emotion'
137+
import {styled} from 'styled-components'
211138
import {space} from 'styled-system'
212-
const SpaceDiv = styled('div')(space)
139+
const SpaceDiv = styled.div`
140+
${space}
141+
`
213142
```
214143

215144
System props come with `propTypes` that can be mixed into your own with ES6 [spread syntax]:
@@ -222,8 +151,6 @@ SpaceDiv.propTypes = {
222151
```
223152

224153
[classnames]: https://www.npmjs.com/package/classnames
225-
[emotion]: https://emotion.sh/
226-
[emotion-theming]: https://github.com/emotion-js/emotion/tree/master/packages/emotion-theming
227154
[spread syntax]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
228155
[styled-system]: https://jxnblk.com/styled-system/getting-started
229156
[system-components]: https://jxnblk.com/styled-system/system-components

0 commit comments

Comments
 (0)