Skip to content

Commit d944e3c

Browse files
author
Emily
authored
Merge pull request #262 from primer/q3-lochness-monster
Q3 Lochness Monster Tracking PR
2 parents c95b2d2 + 6080ded commit d944e3c

34 files changed

+3280
-5124
lines changed

README.md

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,51 +10,104 @@ Currently we link to the latest build of [Primer CSS] so that we may use current
1010

1111
## Installation
1212

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

1515
```
16-
npm install primer-react
16+
npm install @primer/components
1717
```
1818

1919
## Usage
2020

2121
**If you are upgrading from a version before `1.0.0-beta`, please read the [migration docs](migrating.md).**
2222

23-
All of our components are exported by name from `primer-react`, so you can import them with:
23+
All of our components are exported by name from `@primer/components`, so you can import them with:
2424

2525
```js
2626
import {
2727
Box,
2828
Button,
2929
Heading,
3030
Text
31-
} from 'primer-react'
31+
} from '@primer/components'
3232
```
3333

3434
### Styling
3535

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.
36+
This project uses [emotion] to generate static CSS for most component styles, but still relies on [Primer CSS] for some classname-based styles that haven't yet been ported over.
3737

38-
To ensure proper styling, you'll need to link to the most recent build of [Primer CSS] in one of the following ways:
38+
To ensure proper styling of all Primer components, you'll need to include some static CSS that's distributed with the `@primer/components` npm package in `dist/primer-components.css`.
3939

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:
40+
#### JavaScript bundlers
41+
If you're using a JavaScript bundler that supports CSS imports, you can import it in your bundles directly:
4142

42-
```js
43-
{
44-
test: /\.css$/,
45-
use: ['style-loader', 'css-loader']
46-
}
47-
```
43+
```js
44+
import '@primer/components/dist/css/build.css'
45+
```
46+
47+
If you're using webpack, you will need to install [style-loader](https://github.com/webpack-contrib/style-loader) and configure webpack to use it for imports ending in '.css', e.g.
48+
49+
```js
50+
{
51+
module: {
52+
rules: [
53+
{
54+
test: /\.css$/,
55+
use: 'style-loader'
56+
}
57+
]
58+
}
59+
}
60+
```
61+
62+
#### Server inlining
63+
If you run a Node server, you can read the file from disk at startup:
64+
65+
```jsx
66+
const {readFileSync} = require('fs')
67+
const cssPath = require.resolve('@primer/components/dist/primer-components.css')
68+
const css = readFileSync(cssPath, 'utf8')
69+
```
70+
71+
Then, inline it into the `<head>` of your HTML template(s) or render it server-side in React like so:
72+
73+
```jsx
74+
// assuming the `css` variable is set as above
75+
export default () => (
76+
<html>
77+
<head>
78+
<style>{css}</style>
79+
</head>
80+
<body>
81+
...
82+
</body>
83+
</html>
84+
)
85+
```
86+
87+
#### Static apps
88+
For fully static or statically generated (Jekyll, Hugo, etc.) apps, you may need to manually copy `node_modules/@primer/components/dist/css/build.css` (after `npm install --save @primer/components`) to one of your site's public directories, i.e. `/assets`:
89+
90+
```sh
91+
cp node_modules/@primer/components/dist/css/build.css assets/primer-components.css
92+
```
93+
94+
Then link to it in the `<head>` of your HTML document(s):
95+
96+
```html
97+
<link rel="stylesheet" href="/assets/primer-components.css">
98+
```
99+
100+
### Static CSS rendering
48101

49-
1. **For pre-production applications**, you can link directly to [the build on unpkg.com](https://unpkg.com/primer/build/build.css).
102+
Some Primer components rendered client-side may produce a [flash of unstyled content]. You can avoid most jarring flashes by ensuring that `primer-components.css` is either inlined or linked in the `<head>` of your document with one of the techniques described above.
50103

51-
1. Otherwise, you can `npm install --save primer` and either or link `node_modules/primer/build/build.css` to your source directory.
104+
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].
52105

53106
## Local Development
54107

55-
To run `primer-react` locally when adding or updating components:
108+
To run `@primer/components` locally when adding or updating components:
56109

57-
1. Clone this repo: `git clone https://github.com/primer/primer-react`
110+
1. Clone this repo: `git clone https://github.com/primer/components`
58111
1. Install dependencies: `npm install`
59112
1. Run the dev app: `npm run dev`
60113

@@ -73,3 +126,5 @@ To run `primer-react` locally when adding or updating components:
73126

74127
[emotion]: https://emotion.sh/
75128
[Primer CSS]: https://github.com/primer/primer
129+
[flash of unstyled content]: https://en.wikipedia.org/wiki/Flash_of_unstyled_content
130+
[Next.js]: https://github.com/zeit/next.js

contributing.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
4. [Component patterns](#component-patterns)
88
* [Components with only system props](#components-with-only-system-props)
99
* [Primer CSS components](#primer-css-components)
10-
5. [Deployment](#deployment)
11-
6. [Glossary](#glossary)
10+
5. [Writing Documentation](#writing-documentation)
11+
6. [Deployment](#deployment)
12+
7. [Glossary](#glossary)
1213

1314
## Code Style
1415

@@ -61,7 +62,7 @@ With a couple of exceptions, all components should be created by the `withSystem
6162
```jsx
6263
import {withSystemProps, POSITION} from './system-props'
6364

64-
function Component(props) {
65+
function Component(props) {
6566
/* implementation */
6667
}
6768

@@ -170,6 +171,16 @@ In this case, you will need to deal explicitly with two props passed down from [
170171
* `className`: You _must_ render this prop, otherwise **your component will not be styled.**
171172
* `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.
172173

174+
## Writing documentation
175+
176+
We use [Next.js](https://github.com/zeit/next.js/) and [MDX Docs](https://github.com/jxnblk/mdx-docs/) to power our documentation site at [https://primer.style/components](https://primer.style/components/).
177+
178+
To add a new component to our documentation site:
179+
180+
1. Create a new file with the `.md` extension for your component in `pages/components/docs`.
181+
2. Copy & paste the template from `doc-template.md` & replace placeholder brackets with relevant information.
182+
3. Add the new file to the `index.js` in `pages/components/docs`
183+
173184
## Deployment
174185
We deploy the Primer Components site using [Now]. Install the Now CLI and log in with:
175186

@@ -184,10 +195,10 @@ Once you're logged in, sync your local git repo with the `master` branch and run
184195
script/deploy
185196
```
186197

187-
This will create a new deployment and alias it to its production URL, [primer-react.now.sh](https://primer-react.now.sh).
198+
This will create a new deployment and alias it to its production URL, [primer-components.now.sh](https://primer-components.now.sh).
188199

189200
### Path aliasing
190-
This site is served as a subdirectory of [primer.style] using a [path alias](https://zeit.co/docs/features/path-aliases) configured in that repo's [`rules.json`](https://github.com/primer/primer.style/tree/master/rules.json). If you change the production deployment URL for this app, you will also need to change it there and re-deploy that app; otherwise, Now will automatically route requests from [primer.style/components](https://primer.style/components/) to the new deployment whenever you deploy this one to `primer-react.now.sh`.
201+
This site is served as a subdirectory of [primer.style] using a [path alias](https://zeit.co/docs/features/path-aliases) configured in that repo's [`rules.json`](https://github.com/primer/primer.style/tree/master/rules.json). If you change the production deployment URL for this app, you will also need to change it there and re-deploy that app; otherwise, Now will automatically route requests from [primer.style/components](https://primer.style/components/) to the new deployment whenever you alias this one to `primer-components.now.sh`.
191202

192203

193204
## Glossary

migrating.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ This release also introduces early support for [theming](#theming).
2828
### Theming
2929
Theming is an optional way to override the values that control color, spacing, typography, and other aspects of our components.
3030

31-
There are two ways to change the theme of primer-react components:
31+
There are two ways to change the theme of @primer/components components:
3232

3333
1. You can override the theme for an entire tree of components using the `<ThemeProvider>` from [emotion-theming]:
3434

3535
```jsx
36-
import {Block, Button, Text, theme as primer} from 'primer-react'
36+
import {Block, Button, Text, theme as primer} from '@primer/components'
3737
import {ThemeProvider} from 'emotion-theming'
3838

3939
// a theme with custom spacing and font sizes
@@ -60,7 +60,7 @@ There are two ways to change the theme of primer-react components:
6060
1. You can theme individual components by passing the `theme` prop directly:
6161
6262
```jsx
63-
import {Text} from 'primer-react'
63+
import {Text} from '@primer/components'
6464
6565
const theme = {
6666
colors: {

next.config.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const withPlugins = require('next-compose-plugins')
2-
const sass = require('@zeit/next-sass')
3-
const mdx = require('@zeit/next-mdx')({extension: /\.mdx?$/})
2+
const mdx = require('@zeit/next-mdx')
43

5-
module.exports = withPlugins([sass, mdx], {
4+
module.exports = withPlugins([
5+
mdx({extension: /\.mdx?$/})
6+
], {
67
/*
78
* Note: Prefixing assets with the fully qualified deployment URL
89
* makes them available even when the site is served from a path alias, as in
@@ -14,20 +15,22 @@ module.exports = withPlugins([sass, mdx], {
1415
includePaths: ['node_modules']
1516
},
1617

17-
webpack(config, {dev}) {
18-
// we only care about disabling mangling in production
19-
if (dev) {
20-
return config
21-
}
22-
for (const plugin of config.plugins) {
23-
// duck type: is this an UglifyJS plugin?
24-
if (plugin.options && plugin.options.uglifyOptions) {
25-
/* eslint-disable camelcase, no-console */
26-
console.warn('*** disabling mangling in UglifyJS plugin ***')
27-
plugin.options.uglifyOptions.compress = {keep_fnames: true}
28-
plugin.options.uglifyOptions.mangle.keep_fnames = true
29-
/* eslint-enable camelcase, no-console */
18+
webpack(config) {
19+
// load primer-components.css as raw string
20+
config.module.rules.push({
21+
test: /\.css$/,
22+
use: 'raw-loader'
23+
})
24+
25+
const {optimization} = config
26+
if (optimization && Array.isArray(optimization.minimizer)) {
27+
const terserPlugin = optimization.minimizer[0]
28+
/* eslint-disable camelcase, no-console */
29+
console.warn('*** disabling function mangling in Terser plugin ***')
30+
terserPlugin.options.terserOptions = {
31+
keep_fnames: true
3032
}
33+
/* eslint-enable camelcase, no-console */
3134
}
3235
return config
3336
}

now.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
2+
"name": "primer-components",
23
"files": [
34
"next.config.js",
45
"pages",
5-
"src"
6+
"src",
7+
"static/assets"
68
]
79
}

0 commit comments

Comments
 (0)