Skip to content

Commit e15e1fd

Browse files
authored
Merge branch 'dev' into master
2 parents b009972 + d0ff8cc commit e15e1fd

File tree

104 files changed

+2496
-123
lines changed

Some content is hidden

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

104 files changed

+2496
-123
lines changed

.storybook/Octicon.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react'
2+
import {storiesOf} from '@storybook/react'
3+
import octicons from 'octicons'
4+
import SVGInline from 'react-svg-inline'
5+
6+
const Octicon = (props) => {
7+
const {name} = props
8+
if (name in octicons) {
9+
return <SVGInline svg={octicons[name].toSVG(props)} />
10+
} else {
11+
throw new Error(`No such octicon: "${name}"!`)
12+
}
13+
}
14+
15+
const story = storiesOf('Octicons', module)
16+
const sizes = [64, 32, 16]
17+
18+
Object.keys(octicons).forEach(name => {
19+
story.add(name, () => (
20+
<div>{sizes.map((size, i) => (
21+
<Octicon name={name} width={size} height={size} key={i} />
22+
))}</div>
23+
))
24+
})

.storybook/addons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@storybook/addon-options/register'

.storybook/config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react'
2+
import { configure, addDecorator } from '@storybook/react'
3+
import { setOptions } from '@storybook/addon-options'
4+
import '../modules/primer-css/index.scss'
5+
6+
setOptions({
7+
name: 'Primer',
8+
url: 'http://primercss.io/',
9+
showDownPanel: false,
10+
})
11+
12+
addDecorator(story => (
13+
<div className='p-4'>
14+
{story()}
15+
</div>
16+
))
17+
18+
const contexts = [
19+
require.context('.', true, /\.js$/),
20+
require.context('../modules', true, /stories.*\.js$/),
21+
]
22+
23+
configure(() => {
24+
contexts.forEach(context => {
25+
context.keys()
26+
.filter(key => !key.includes('node_modules'))
27+
.forEach(context)
28+
})
29+
}, module)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import remark from 'remark'
2+
import parents from 'unist-util-parents'
3+
import select from 'unist-util-select'
4+
import findBefore from 'unist-util-find-before'
5+
import htmlToReact from 'html-to-react'
6+
import parsePairs from 'parse-pairs'
7+
8+
const htmlParser = new htmlToReact.Parser()
9+
10+
const nodeToStory = (node, file) => {
11+
const html = node.value
12+
const element = htmlParser.parse(html)
13+
const pairs = node.lang.replace(/^html\s*/, '')
14+
const attrs = pairs.length ? parsePairs(pairs) : {}
15+
const title = attrs.title || getPreviousHeading(node) ||
16+
`story @ ${file}:${node.position.start.line}`
17+
return {
18+
title,
19+
story: () => element,
20+
attrs,
21+
html,
22+
file,
23+
node,
24+
}
25+
}
26+
27+
const getPreviousHeading = node => {
28+
const heading = findBefore(node.parent, node, 'heading')
29+
return (heading && !heading.used)
30+
? (heading.used = true, heading.children.map(c => c.value).join(''))
31+
: undefined
32+
}
33+
34+
export default req => {
35+
return req.keys().reduce((stories, file) => {
36+
const content = req(file)
37+
const ast = parents(remark.parse(content))
38+
const path = file.replace(/^\.\//, '')
39+
return stories.concat(
40+
select(ast, 'code[lang^=html]')
41+
.map(node => nodeToStory(node, path))
42+
.filter(({attrs}) => attrs.story !== "false")
43+
)
44+
}, [])
45+
}

.storybook/postcss.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// FIXME this should go away when we merge and release:
2+
// <https://github.com/primer/primer-module-build/pull/19>
3+
const plugins = require("primer-module-build/lib/.postcss.json")
4+
delete plugins.use
5+
6+
module.exports = {
7+
plugins,
8+
}

.storybook/preview-head.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<link rel="stylesheet" href="https://unpkg.com/primer-css@9.2.0/build/build.css">
2+
<script src="https://github.com/site/assets/styleguide.js" async></script>

.storybook/webpack.config.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const path = require("path");
2+
3+
const modulesPath = path.resolve(__dirname, "../modules")
4+
5+
module.exports = {
6+
module: {
7+
rules: [
8+
{
9+
test: /\.md$/,
10+
use: "raw-loader",
11+
},
12+
{
13+
test: /\.scss$/,
14+
loaders: [
15+
"style-loader",
16+
"css-loader",
17+
{
18+
loader: "postcss-loader",
19+
options: {
20+
config: {
21+
path: require.resolve("./postcss.config.js"),
22+
},
23+
},
24+
},
25+
{
26+
loader: "sass-loader",
27+
options: {
28+
includePaths: [
29+
modulesPath,
30+
],
31+
}
32+
},
33+
],
34+
include: modulesPath,
35+
},
36+
],
37+
},
38+
}

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ env:
99
# github
1010
- secure: "J+1oWjvvXjyrwkY/4IFWKdN/weFmQcPwlRuFG4R0Gb3rYe4nqtC9l68sJvmS8asc8dQMhOhcUZCH6sjvo7l2WD4NuK4umPSbs+rJNUsfbvH4pZjStQIj/3ll1OfQelGDWAYQWhIfciYY4F3Bp0ZWTfKOppLQ2AVIYu1fPVXDdlo="
1111

12-
before_script:
13-
- lerna bootstrap
14-
1512
script:
1613
- npm test
1714

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Primer CSS Module Generator
2+
3+
[![npm version](http://img.shields.io/npm/v/generator-primer-module.svg)](https://www.npmjs.org/package/generator-primer-module)
4+
[![Build Status](https://travis-ci.org/primer/primer-css.svg?branch=master)](https://travis-ci.org/primer/primer-css)
5+
6+
Primer is the CSS framework that powers GitHub's front-end design. This is a
7+
[Yeoman] generator that we use to scaffold new Primer modules.
8+
9+
## Usage
10+
11+
### In the Monorepo
12+
13+
1. `cd` to the top level directory of the `primer-css` repository
14+
1. Run:
15+
16+
```sh
17+
npm run new-module
18+
```
19+
20+
You can also pass the module name as a positional argument like this:
21+
22+
```sh
23+
npm run new-module -- primer-module-name
24+
```
25+
26+
1. Answer the interactive prompts.
27+
28+
> If you don't know some of the answers (aside from the module name, which
29+
> is required), it's okay to press <kbd>enter</kbd> or <kbd>return</kbd>.
30+
31+
1. If all goes well, the new module will be bootstrapped and ready to use. You
32+
should see a directory with this structure:
33+
34+
```
35+
modules/primer-module-name/
36+
├── LICENSE
37+
├── README.md
38+
├── index.scss
39+
├── lib
40+
│   └── module-name.scss
41+
└── package.json
42+
```
43+
44+
1. If you have any TODOs left from unanswered prompts, fill them out! You can
45+
list them again with:
46+
47+
```sh
48+
ack TODO modules/primer-module-name
49+
```
50+
51+
(Note: you can use `grep` if you don't have `ack` installed.)
52+
53+
54+
### Standalone installation
55+
56+
This repository is distributed with [npm][npm]. After [installing
57+
npm][install-npm], you can install `generator-primer-module` with this command.
58+
59+
```sh
60+
npm install --save generator-primer-module
61+
```
62+
63+
You'll also need to install the [`yo` CLI](https://github.com/yeoman/yo):
64+
65+
```sh
66+
npm install -g yo
67+
```
68+
69+
### Standalone usage
70+
71+
It's possible to use this generator to create "standalone" Primer modules that
72+
live outside of the Primer CSS monorepo, with the following caveats:
73+
74+
* When prompted to add the new module to existing meta-packages, you will need
75+
to un-select them all.
76+
* You will also need to manually install all of the monorepo's top-level dev
77+
dependencies to get tools like `primer-module-build` and `ava`.
78+
* The `npm test` command will not work, because it references a test spec in
79+
the monorepo.
80+
81+
To run the generator, just pass `primer-module` to the `yo` CLI:
82+
83+
```sh
84+
yo primer-module
85+
```
86+
87+
Then answer the interactiv prompts. **Note that, unlike most other generators,
88+
this one creates a new directory with the provided module name in the current
89+
working directory.**
90+
91+
You can also pass the module name as a positional argument, as in:
92+
93+
```sh
94+
yo primer-module primer-foo-bar
95+
```
96+
97+
98+
## License
99+
100+
[MIT](./LICENSE) &copy; [GitHub](https://github.com/)
101+
102+
[primer]: https://github.com/primer/primer
103+
[docs]: http://primercss.io/
104+
[npm]: https://www.npmjs.com/
105+
[install-npm]: https://docs.npmjs.com/getting-started/installing-node
106+
[sass]: http://sass-lang.com/
107+
[yeoman]: http://yeoman.io

0 commit comments

Comments
 (0)