Skip to content

Commit 91115e8

Browse files
authored
Merge pull request #182 from primer/release-1.0.0-beta
Release Tracking 1.0.0-beta
2 parents 8f62bed + fa32055 commit 91115e8

File tree

132 files changed

+5183
-1957
lines changed

Some content is hidden

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

132 files changed

+5183
-1957
lines changed

.babelrc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2-
"presets": ["env", "stage-0", "react"]
2+
"presets": [
3+
"env",
4+
"stage-0",
5+
"react"
6+
],
7+
"plugins": [
8+
"add-react-displayname"
9+
]
310
}

.eslintrc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"plugin:github/es6",
44
"plugin:github/react",
55
"plugin:jsx-a11y/recommended"
6-
]
6+
],
7+
"rules": {
8+
"import/no-namespace": "warn"
9+
}
710
}

.github/pull_request_template.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Describe your changes
2+
3+
Closes #:
4+
5+
6+
#### If development process was changed:
7+
Description of changes:
8+
- [ ] Updated README?
9+
10+
11+
#### Merge Checklist:
12+
- [ ] Changed base branch to release branch
13+
- [ ] Updated Kit (`npm run build:docs)
14+
- [ ] Enabled GH Pages for testing
15+
- [ ] Tested in Chrome [(BrowserStack)](https://www.browserstack.com/)
16+
- [ ] Tested in Firefox [(BrowserStack)](https://www.browserstack.com/)
17+
- [ ] Tested in Safari [(BrowserStack)](https://www.browserstack.com/)
18+
- [ ] Tested in Edge [(BrowserStack)](https://www.browserstack.com/)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.*.swp
12
.DS_Store
23
coverage/
34
dist/

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.tgz
2+
.*
3+
*.config.js
4+
coverage/
5+
docs/
6+
script/
7+
src/__tests__/

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
save=true
22
save-exact=true
3+
# we create our tags in Releases now
4+
git-tag-version=false

README.md

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,51 @@
44

55
## Status
66

7-
⚠️ This project is WIP and not ready for production use yet!
7+
**⚠️ This project is WIP and not ready for production use yet!**
88

9-
Currently we link to the latest built Primer CSS so that we may use current Primer styles to start to build components. This does not include `primer-base` so as to avoid unwanted base overrides.
9+
Currently we link to the latest build of [Primer CSS] so that we may use current Primer styles to start to build components. This does not include `primer-base` so as to avoid unwanted base overrides.
1010

1111
## Installation
1212

13-
Install primer-react in your project with:
13+
Install primer-react in your project with npm:
1414

15-
`npm install primer-react`
15+
```
16+
npm install primer-react
17+
```
18+
19+
## Usage
20+
21+
**If you are upgrading from a version before `1.0.0-beta`, please read the [migration docs](migrating.md).**
22+
23+
All of our components are exported by name from `primer-react`, so you can import them with:
24+
25+
```js
26+
import {
27+
Block,
28+
Button,
29+
Heading,
30+
Text
31+
} from 'primer-react'
32+
```
33+
34+
### Styling
35+
36+
This project uses [emotion] under the hood to generate static CSS from _some_ component styles, but still relies on [Primer CSS] for some component styles that haven't yet been ported over.
37+
38+
To ensure proper styling, you'll need to link to the most recent build of [Primer CSS] in one of the following ways:
39+
40+
1. If you're using webpack, you can install [style-loader](https://github.com/webpack-contrib/style-loader) and [css-loader](), `import 'primer/build/build.css'` in your bundle, and include the following in your webpack config's `module.rules` list:
41+
42+
```js
43+
{
44+
test: /\.css$/,
45+
use: ['style-loader', 'css-loader']
46+
}
47+
```
48+
49+
1. **For pre-production applications**, you can link directly to [the build on unpkg.com](https://unpkg.com/primer/build/build.css).
50+
51+
1. Otherwise, you can `npm install --save primer` and either or link `node_modules/primer/build/build.css` to your source directory.
1652

1753
## Local Development
1854

@@ -76,11 +112,12 @@ test coverage data is generated in the `coverage/` directory.
76112
## Principles
77113

78114
- Everything is a component.
79-
- Aim for total style encapsulation, don't rely on inheritance to provide default styles.
115+
- Aim for total style encapsulation; don't rely on inheritance to provide default styles.
80116
- Build small building blocks with minimal props to keep complexity low.
81117
- Keep system constrained by only including props needed per component.
82118
- Favor extending or wrapping components for more complex operations.
83119
- Maintain design system consistency with utilities as props (for spacing, color, font-size, line-height, widths, and radii).
84120
85121
86122
[npx]: https://www.npmjs.com/package/npx
123+
[Primer CSS]: https://github.com/primer/primer

contributing.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Contribution guidelines
2+
3+
## Tools we use
4+
5+
### Components
6+
1. We use [emotion] to style our components, and [emotion-theming] as the theme provider.
7+
1. We use style functions from [styled-system] whenever possible, and styled-systems' `style()` function to create new ones.
8+
1. We use [system-components] to reduce the amount of boilerplate needed to implement styled-system functions.
9+
10+
## Component patterns
11+
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:
12+
13+
```jsx
14+
import {withSystemProps, POSITION} from './system-props'
15+
16+
function Component(props) {
17+
/* implementation */
18+
}
19+
20+
export default withSystemProps(Component, POSITION)
21+
22+
// equivalent:
23+
export default withSystemProps({is: Component}, POSITION)
24+
25+
// with more default props:
26+
export default withSystemProps(
27+
{
28+
is: Component,
29+
m: 2
30+
},
31+
POSITION
32+
)
33+
```
34+
35+
Categories of system props are exported from `src/system-props`:
36+
37+
* `COMMON` includes color and spacing (margin and padding) props
38+
* `TYPOGRAPHY` includes `COMMON` and font family, font weight, and line-height
39+
* `POSITION` includes `COMMON` and positioning props
40+
* `FLEX_CONTAINER` includes `COMMON` and flexbox props for containers
41+
* `FLEX_ITEM` includes `COMMON` and flexbox props for items in a flex container
42+
43+
### Components with only system props
44+
Components with only system props should be created by passing the default tag to `withSystemProps()`:
45+
46+
```jsx
47+
import {withSystemProps, LAYOUT} from './system-props'
48+
49+
const Block = withSystemProps('div', LAYOUT)
50+
```
51+
52+
### Primer CSS components
53+
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:
54+
55+
```jsx
56+
import Box from './Box'
57+
58+
function FancyBox({flashing, ...rest}) {
59+
return <Box className={flashing && 'Box--flashing'} {...rest} />
60+
}
61+
62+
FancyBox.propTypes = {
63+
flashing: PropTypes.bool,
64+
// be sure to spread Box's prop-types
65+
...Box.propTypes
66+
}
67+
68+
FancyBox.defaultProps = {
69+
...Box.defaultProps
70+
}
71+
72+
// if you don't spread defaultProps from another system component,
73+
// you will need to wrap the export in withDefaultTheme()
74+
export default FancyBox
75+
```
76+
77+
> **⚠️ 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.**
78+
79+
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:
80+
81+
```jsx
82+
import classnames from 'classnames'
83+
import Box from './Box'
84+
85+
export default function FancyBox({flashing, className, ...rest}) {
86+
const classes = classnames(className, flashing && 'Box--flashing')
87+
return <Box className={classes} {...rest} />
88+
}
89+
90+
FancyBox.propTypes = {
91+
className: PropTypes.string,
92+
flashing: PropTypes.bool,
93+
...Box.propTypes
94+
}
95+
```
96+
97+
Alternatively, you can create the component from scratch using `withSystemProps()`, and pass it the same system props:
98+
99+
```jsx
100+
import classnames from 'classnames'
101+
import {withSystemProps, LAYOUT} from './system-props'
102+
103+
function FancyBox({flashing, className, is: Tag, ...rest}) {
104+
return (
105+
<Tag
106+
className={classnames(className, flashing && 'Box--flashing')}
107+
{...rest}
108+
/>
109+
)
110+
}
111+
112+
FancyBox.propTypes = {
113+
flashing: PropTypes.bool
114+
}
115+
116+
export default withSystemProps(FancyBox, LAYOUT)
117+
```
118+
119+
In this case, you will need to deal explicitly with two props passed down from [emotion] and [system-components], respectively:
120+
121+
* `className`: You _must_ render this prop, otherwise **your component will not be styled.**
122+
* `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.
123+
124+
## Glossary
125+
126+
### System props
127+
System props are style functions that provide on or more props, and can be passed directly the return value of [emotion]'s `styled()` function:
128+
129+
```jsx
130+
import {styled} from 'react-emotion'
131+
import {space} from 'styled-system'
132+
const SpaceDiv = styled('div')(space)
133+
```
134+
135+
System props come with `propTypes` that can be mixed into your own with ES6 [spread syntax]:
136+
137+
```jsx
138+
SpaceDiv.propTypes = {
139+
stellar: PropTypes.bool,
140+
...space.propTypes
141+
}
142+
```
143+
144+
[classnames]: https://www.npmjs.com/package/classnames
145+
[emotion]: https://emotion.sh/
146+
[emotion-theming]: https://github.com/emotion-js/emotion/tree/master/packages/emotion-theming
147+
[spread syntax]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
148+
[styled-system]: https://jxnblk.com/styled-system/getting-started
149+
[system-components]: https://jxnblk.com/styled-system/system-components
150+
[table]: https://jxnblk.com/styled-system/table

docs/bundle.js

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/components/index.html

Lines changed: 92 additions & 168 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)