Skip to content

Commit 57f9eb4

Browse files
author
Emily
authored
Merge pull request #439 from primer/release-12.1.0
Release Tracking PR 12.1.0
2 parents fd899b6 + bcdbb8b commit 57f9eb4

File tree

8 files changed

+112
-46
lines changed

8 files changed

+112
-46
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@primer/components",
3-
"version": "12.0.2",
3+
"version": "12.1.0",
44
"description": "Primer react components",
55
"main": "dist/index.umd.js",
66
"module": "dist/index.esm.js",

pages/components/docs/Box.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ The Box component serves as a wrapper component for most layout related needs. U
66

77
```.jsx
88
<Box>
9-
<Label m={1}>Box can be used to create block level elements & more</Label>
9+
Box can be used to create both <Box as="span" bg="green.1">inline</Box> and
10+
<Box bg="blue.1">block-level elements,</Box>
11+
<Box bg="purple.1" width={[1, 1, 1/2]}>elements with fixed or responsive width and height,</Box>
12+
<Box bg="yellow.0" p={4} mt={2}>and more!</Box>
1013
</Box>
11-
12-
<Label m={1}>Default label</Label>
1314
```
1415

1516
## System props

pages/components/index.mdx

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# Getting Started
1+
React components for the [Primer Design System](https://primer.style)
22

3-
Install Primer Components in your project with npm:
3+
## Installation
4+
5+
Install `@primer/components` in your project with npm:
46

57
```
68
npm install @primer/components
79
```
810

9-
# Usage
11+
## Usage
1012

1113
All of our components are exported by name from `@primer/components`, so you can import them with:
1214

@@ -21,7 +23,7 @@ import {
2123

2224
Primer Components come with all the necessary CSS built-in, so you don't need to worry about including [Primer CSS].
2325

24-
## Base styles
26+
#### Base styles
2527

2628
You can establish base Primer styles for your app by wrapping all of your Primer components in `<BaseStyles>`:
2729

@@ -38,6 +40,77 @@ export default () => (
3840
)
3941
```
4042

41-
This will set the `color`, `font-family`, and `line-height` CSS properties to the same ones used in [Primer CSS](https://github.com/primer/css/blob/master/src/base/base.scss#L15-L21).
43+
This will set the `color`, `font-family`, and `line-height` CSS properties to the same ones used in [primer-base](https://github.com/primer/primer/blob/master/modules/primer-base/lib/base.scss#L15).
44+
45+
#### Theming
46+
47+
Components are styled using Primer's [theme](https://github.com/primer/components/blob/master/src/theme.js) by default, but you can provide your own theme by using [styled-component's][styled-components] `<ThemeProvider>`. If you'd like to fully replace the Primer [theme](https://github.com/primer/components/blob/master/src/theme.js) with your custom theme, pass your theme to the `<ThemeProvider>` in the root of your application like so:
48+
49+
```jsx
50+
import {ThemeProvider} from 'styled-components'
51+
52+
const theme = { ... }
53+
54+
const App = (props) => {
55+
return (
56+
<div>
57+
<ThemeProvider theme={theme}>
58+
<div>your app here</div>
59+
</ThemeProvider>
60+
</div>
61+
)
62+
}
63+
64+
```
65+
66+
If you'd like to merge the Primer theme with your theme, you can do so importing the Primer theme and merging using Object.assign:
67+
68+
```jsx
69+
import {ThemeProvider} from 'styled-components'
70+
import {theme} from '@primer/components'
71+
72+
const customTheme = { ... }
73+
74+
75+
const App = (props) => {
76+
return (
77+
<div>
78+
<ThemeProvider theme={Object.assign({}, theme, customTheme)}> // matching keys in customTheme will override keys in the Primer theme
79+
<div>your app here</div>
80+
</ThemeProvider>
81+
</div>
82+
)
83+
}
84+
```
85+
86+
*Note that using `Object.assign` will only create a shallow merge. This means that if both themes have a `color` object, the _entire_ `color` object will be replaced with the new `color` object, instead of only replacing duplicate values from the original theme's color object.
87+
88+
#### Static CSS rendering
89+
90+
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].
91+
92+
## Local Development
93+
94+
To run `@primer/components` locally when adding or updating components:
95+
96+
1. Clone this repo: `git clone https://github.com/primer/components`
97+
1. Install dependencies: `npm install`
98+
1. Run the dev app: `npm start`
99+
100+
> 👉 See [the contributing docs](contributing.md) for more info on code style, testing, and coverage.
101+
102+
103+
## Principles
104+
105+
- Everything is a component.
106+
- Aim for total style encapsulation; don't rely on inheritance to provide default styles.
107+
- Build small building blocks with minimal props to keep complexity low.
108+
- Keep system constrained by only including props needed per component.
109+
- Favor extending or wrapping components for more complex operations.
110+
- Maintain design system consistency with utilities as props (for spacing, color, font-size, line-height, widths, and radii).
111+
42112

43-
[Primer CSS]: https://github.com/primer/css
113+
[styled-components]: https://www.styled-components.com/docs
114+
[Primer CSS]: https://github.com/primer/primer
115+
[flash of unstyled content]: https://en.wikipedia.org/wiki/Flash_of_unstyled_content
116+
[Next.js]: https://github.com/zeit/next.js

src/Flex.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import styled from 'styled-components'
22
import PropTypes from 'prop-types'
3-
import {display} from 'styled-system'
4-
import {COMMON, FLEX_CONTAINER, FLEX_ITEM} from './constants'
3+
import {FLEX_CONTAINER, FLEX_ITEM} from './constants'
54
import theme from './theme'
5+
import Box from './Box'
66

7-
const Flex = styled.div`
8-
${FLEX_CONTAINER}
9-
${COMMON}
10-
${display}
7+
const Flex = styled(Box)`
8+
${FLEX_CONTAINER};
119
`
1210

13-
Flex.Item = styled.div`
14-
${FLEX_ITEM} ${COMMON};
11+
Flex.Item = styled(Box)`
12+
${FLEX_ITEM};
1513
`
1614

1715
Flex.defaultProps = {
@@ -22,13 +20,11 @@ Flex.Item.defaultProps = {
2220
theme
2321
}
2422
Flex.propTypes = {
25-
...COMMON.propTypes,
26-
...FLEX_CONTAINER.propTypes,
27-
...display.propTypes
23+
...Box.propTypes,
24+
...FLEX_CONTAINER.propTypes
2825
}
2926

3027
Flex.Item.propTypes = {
31-
...COMMON.propTypes,
3228
...FLEX_ITEM.propTypes,
3329
theme: PropTypes.object
3430
}

src/__tests__/FlexContainer.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import React from 'react'
2-
import {display} from 'styled-system'
32
import Flex from '../Flex'
4-
import {FLEX_CONTAINER, COMMON} from '../constants'
3+
import {FLEX_CONTAINER} from '../constants'
54
import {render} from '../utils/testing'
65

76
describe('Flex', () => {
87
it('implements system props', () => {
98
expect(Flex).toImplementSystemProps(FLEX_CONTAINER)
10-
expect(Flex).toImplementSystemProps(COMMON)
11-
expect(Flex).toImplementSystemProps(display)
129
})
1310

1411
it('has default theme', () => {

src/__tests__/FlexItem.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from 'react'
22
import Flex from '../Flex'
3-
import {FLEX_ITEM, COMMON} from '../constants'
3+
import {FLEX_ITEM} from '../constants'
44
import {render} from '../utils/testing'
55

66
describe('Flex.Item', () => {
77
it('implements system props', () => {
88
expect(Flex.Item).toImplementSystemProps(FLEX_ITEM)
9-
expect(Flex.Item).toImplementSystemProps(COMMON)
109
})
1110

1211
it('has default theme', () => {

src/__tests__/__snapshots__/FlexContainer.js.snap

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
exports[`Flex respects alignContent 1`] = `
44
.c0 {
5-
-webkit-align-content: start;
6-
-ms-flex-line-pack: start;
7-
align-content: start;
85
display: -webkit-box;
96
display: -webkit-flex;
107
display: -ms-flexbox;
118
display: flex;
9+
-webkit-align-content: start;
10+
-ms-flex-line-pack: start;
11+
align-content: start;
1212
}
1313
1414
<div
@@ -19,14 +19,14 @@ exports[`Flex respects alignContent 1`] = `
1919

2020
exports[`Flex respects alignItems 1`] = `
2121
.c0 {
22-
-webkit-align-items: start;
23-
-webkit-box-align: start;
24-
-ms-flex-align: start;
25-
align-items: start;
2622
display: -webkit-box;
2723
display: -webkit-flex;
2824
display: -ms-flexbox;
2925
display: flex;
26+
-webkit-align-items: start;
27+
-webkit-box-align: start;
28+
-ms-flex-align: start;
29+
align-items: start;
3030
}
3131
3232
<div
@@ -37,13 +37,13 @@ exports[`Flex respects alignItems 1`] = `
3737

3838
exports[`Flex respects flexDirection 1`] = `
3939
.c0 {
40-
-webkit-flex-direction: row;
41-
-ms-flex-direction: row;
42-
flex-direction: row;
4340
display: -webkit-box;
4441
display: -webkit-flex;
4542
display: -ms-flexbox;
4643
display: flex;
44+
-webkit-flex-direction: row;
45+
-ms-flex-direction: row;
46+
flex-direction: row;
4747
}
4848
4949
<div
@@ -54,13 +54,13 @@ exports[`Flex respects flexDirection 1`] = `
5454

5555
exports[`Flex respects flexWrap 1`] = `
5656
.c0 {
57-
-webkit-flex-wrap: nowrap;
58-
-ms-flex-wrap: nowrap;
59-
flex-wrap: nowrap;
6057
display: -webkit-box;
6158
display: -webkit-flex;
6259
display: -ms-flexbox;
6360
display: flex;
61+
-webkit-flex-wrap: nowrap;
62+
-ms-flex-wrap: nowrap;
63+
flex-wrap: nowrap;
6464
}
6565
6666
<div
@@ -71,14 +71,14 @@ exports[`Flex respects flexWrap 1`] = `
7171

7272
exports[`Flex respects justifyContent 1`] = `
7373
.c0 {
74-
-webkit-box-pack: start;
75-
-webkit-justify-content: start;
76-
-ms-flex-pack: start;
77-
justify-content: start;
7874
display: -webkit-box;
7975
display: -webkit-flex;
8076
display: -ms-flexbox;
8177
display: flex;
78+
-webkit-box-pack: start;
79+
-webkit-justify-content: start;
80+
-ms-flex-pack: start;
81+
justify-content: start;
8282
}
8383
8484
<div

0 commit comments

Comments
 (0)