Skip to content

Commit ddf774c

Browse files
authored
Merge pull request #427 from primer/markdown_stories
Adding stories from markdown for the other modules that didn't have any stories
2 parents 01f84f9 + b860097 commit ddf774c

File tree

18 files changed

+142
-55
lines changed

18 files changed

+142
-55
lines changed

.storybook/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import React from 'react'
22
import { configure, addDecorator } from '@storybook/react'
33
import { setOptions } from '@storybook/addon-options'
44
import '../modules/primer/index.scss'
5+
import { version } from '../modules/primer/package.json'
56

67
setOptions({
7-
name: 'Primer',
8+
name: `Primer v${version}`,
89
url: 'http://primer.github.io/',
910
showDownPanel: false,
1011
})

.storybook/lib/storiesFromMarkdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const htmlParser = new htmlToReact.Parser()
1212

1313
const railsOcticonToReact = (html) => {
1414
// <%= octicon "tools" %> to <Octicon name="tools" />
15-
const octre = /<%= octicon ["']([a-z\-]+)["'][^%]*%>/gi
15+
const octre = /<%= octicon[\(\s]["']([a-z\-]+)["'][^%]*%>/gi
1616
html = html.replace(octre, (match, name) => {
1717
return ReactDOMServer.renderToStaticMarkup(<Octicon name={name} />)
1818
})

modules/primer-branch-name/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,19 @@ status: Stable
4242

4343
Branch names can be a link name or not:
4444

45-
```html
45+
```html title="Branch name"
4646
<span class="branch-name">a_new_feature_branch</span>
47+
```
48+
49+
```html title="Branch name with link"
4750
<a href="#url" class="branch-name">a_new_feature_branch</a>
4851
```
4952

5053
You may also include an octicon before the branch name text:
5154

52-
```html
55+
```html title="Branch name with icon"
5356
<span class="branch-name">
54-
<%= octicon("git-branch") width:16 height:16 %>
57+
<%= octicon("git-branch", width:16, height:16) %>
5558
a_new_feature_branch
5659
</span>
5760
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import { storiesOf } from '@storybook/react'
3+
import storiesFromMarkdown from '../../.storybook/lib/storiesFromMarkdown'
4+
5+
const stories = storiesOf('Branch Name', module)
6+
7+
storiesFromMarkdown(require.context('.', true, /\.md$/))
8+
.forEach(({title, story}) => {
9+
stories.add(title, story)
10+
})

modules/primer-labels/README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ GitHub also programmatically generates and applies a background color for labels
5454

5555
The base `Label` style does not apply a background color, here's an example using the `bg-blue` utility to apply a blue background:
5656

57-
```html
57+
```html title="Label"
5858
<span title="Label: default label" class="Label bg-blue">default label</span>
5959
```
6060

6161
**Note:** Be sure to include a title attribute on labels, it's helpful for people using screen-readers to differentiate a label from other text. I.e. without the title attribute, the following example would read as _"New select component design"_, rather than identifying `design` as a label.
6262

63-
```html
63+
```html title="Label without title"
64+
<!-- Don't do this -->
6465
<a href="#url">New select component</a><span class="Label bg-blue ml-1">design</span>
6566
```
6667

@@ -70,31 +71,31 @@ Labels come in a few different themes. Use a theme that helps communicate the co
7071

7172
Use `Label--gray` to create a label with a light gray background and gray text. This label is neutral in color and can be used in contexts where all you need to communicate is metadata, or whe you want a label to feel less prominent compared with labels with stronger colors.
7273

73-
```html
74+
```html title="Label theme gray"
7475
<span title="Label: gray label" class="Label Label--gray">gray label</span>
7576
```
7677

7778
Use `Label--gray-darker` to create a label with a dark-gray background color. This label is also neutral in color, however, since it's background is darker it can stand out more compared to `Label--gray`.
7879

79-
```html
80+
```html title="Label theme dark gray"
8081
<span title="Label: dark gray label" class="Label Label--gray-darker">dark gray label</span>
8182
```
8283

8384
Use `Label--orange` to communicate "warning". The orange background color is very close to red, so avoid using next to labels with a red background color since most people will find it hard to tell the difference.
8485

85-
```html
86+
```html title="Label theme orange"
8687
<span title="Label: orange label" class="Label Label--orange">orange label</span>
8788
```
8889

8990
Use `Label--outline` to create a label with gray text, a gray border, and a transparent background. The outline reduces the contrast of this label in combination with filled labels. Use this in contexts where you need it to stand out less than other labels and communicate a neutral message.
9091

91-
```html
92+
```html title="Label outline"
9293
<span title="Label: outline label" class="Label Label--outline">outlined label</span>
9394
```
9495

9596
Use `Label--outline-green` in combination with `Label--outline` to communicate a positive message.
9697

97-
```html
98+
```html title="Label outline green"
9899
<span title="Label: green outline label" class="Label Label--outline Label--outline-green">green outlined label</span>
99100
```
100101

@@ -103,14 +104,14 @@ Use `Label--outline-green` in combination with `Label--outline` to communicate a
103104

104105
Use state labels to inform users of an items status. States are large labels with bolded text. The default state has a gray background.
105106

106-
```html
107+
```html title="State"
107108
<span class="State">Default</span>
108109
```
109110

110111
### State themes
111112
States come in a few variations that apply different colors. Use the state that best communicates the status or function.
112113

113-
```html
114+
```html title="State themes"
114115
<span title="Status: open" class="State State--green"><%= octicon "git-pull-request" %> Open</span>
115116
<span title="Status: closed" class="State State--red"><%= octicon "git-pull-request" %> Closed</span>
116117
<span title="Status: merged" class="State State--purple"><%= octicon "git-merge" %> Merged</span>
@@ -121,7 +122,7 @@ States come in a few variations that apply different colors. Use the state that
121122
### Small states
122123
Use `State--small` for a state label with reduced padding a smaller font size. This is useful in denser areas of content.
123124

124-
```html
125+
```html title="Small states"
125126
<span title="Status: open" class="State State--green State--small"><%= octicon "issue-opened" %> Open</span>
126127
<span title="Status: closed" class="State State--red State--small"><%= octicon "issue-closed" %> Closed</span>
127128
```
@@ -130,15 +131,15 @@ Use `State--small` for a state label with reduced padding a smaller font size. T
130131

131132
Use the `Counter` component to add a count to navigational elements and buttons. Counters come in 3 variations: the default `Counter` with a light gray background, `Counter--gray` with a dark-gray background and inverse white text, and `Counter--gray-light` with a light-gray background and dark gray text.
132133

133-
```html
134+
```html title="Counter"
134135
<span class="Counter">16</span>
135136
<span class="Counter Counter--gray">32</span>
136137
<span class="Counter Counter--gray-light">64</span>
137138
```
138139

139140
Use the `Counter` in navigation to indicate the number of items without the user having to click through or count the items, such as open issues in a GitHub repo. See more options in [navigation](../../core/components/navigation).
140141

141-
```html
142+
```html title="Counter in tabs"
142143
<div class="tabnav">
143144
<nav class="tabnav-tabs" aria-label="Foo bar">
144145
<a href="#url" class="tabnav-tab selected" aria-current="page">Foo tab <span class="Counter">23</a>
@@ -149,7 +150,7 @@ Use the `Counter` in navigation to indicate the number of items without the user
149150

150151
Counters can also be used in `Box` headers to indicate the number of items in a list. See more on the [box component](../../core/components/box).
151152

152-
```html
153+
```html title="Counter in Box headers"
153154
<div class="Box">
154155
<div class="Box-header">
155156
<h3 class="Box-title">

modules/primer-labels/stories.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import { storiesOf } from '@storybook/react'
3+
import storiesFromMarkdown from '../../.storybook/lib/storiesFromMarkdown'
4+
5+
const stories = storiesOf('Labels', module)
6+
7+
storiesFromMarkdown(require.context('.', true, /\.md$/))
8+
.forEach(({title, story}) => {
9+
stories.add(title, story)
10+
})

modules/primer-layout/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ You can find all the below styles in `_layout.scss`.
5050

5151
Center your page's contents with a `.container`.
5252

53-
```html+erb
54-
<div class="container">
55-
<!-- contents here -->
53+
```html title="Container"
54+
<div class="container border">
55+
Container
5656
</div>
5757
```
5858

@@ -73,7 +73,7 @@ The grid is pretty standard—you create rows with `.columns` and individual col
7373

7474
In practice, your columns will look like the example below.
7575

76-
```html
76+
```html title="Grid columns"
7777
<div class="container">
7878
<div class="columns mb-1">
7979
<div class="one-fifth column block-blue p-3 border">
@@ -117,9 +117,9 @@ In practice, your columns will look like the example below.
117117

118118
Columns can be [centered](/utilities/#centering-content) by adding `.centered` to the `.column` class.
119119

120-
```html
120+
```html title="Grid centered"
121121
<div class="columns">
122-
<div class="one-half column centered block-blue p-3">
122+
<div class="one-half column centered block-blue border p-3">
123123
.one-half
124124
</div>
125125
</div>

modules/primer-layout/docs/grid.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The grid is 12 columns and percentage-based. The number of columns a container s
1313

1414
Use `.clearfix` on the container and float utilities with columns for a floated grid layout.
1515

16-
```html
16+
```html title="Float based grid"
1717
<div class="container-lg clearfix">
1818
<div class="col-4 float-left border p-4">
1919
My column
@@ -31,7 +31,7 @@ Use `.clearfix` on the container and float utilities with columns for a floated
3131

3232
To reverse the order of columns, use `float-right` to float columns to the right.
3333

34-
```html
34+
```html title="Float grid reversed"
3535
<div class="container-lg clearfix">
3636
<div class="col-4 float-right border p-4">
3737
One
@@ -48,7 +48,7 @@ To reverse the order of columns, use `float-right` to float columns to the right
4848
## Nesting
4949
You can infinitely nest grid layouts within other columns since the column widths are percentage based. With great flexibility comes great responsibility - be sensible with how far you nest!
5050

51-
```html
51+
```html title="Nesting grids"
5252
<div class="clearfix">
5353
<div class="col-6 float-left px-1">
5454
<div class="border p-1">Unnested</div>
@@ -74,7 +74,8 @@ You can infinitely nest grid layouts within other columns since the column width
7474
## Centering a column
7575

7676
Use `.mx-auto` to center columns within a container.
77-
```html
77+
78+
```html title="Centering a column"
7879
<div class="border">
7980
<div class="col-6 p-2 mx-auto border">
8081
This column is the center of my world.
@@ -85,7 +86,8 @@ Use `.mx-auto` to center columns within a container.
8586

8687
## Column widths
8788
Column widths can be used with any other block or inline-block elements to add percentage-based widths.
88-
```html
89+
90+
```html title="Column widths"
8991
<div>
9092
<div class="col-4 float-right p-2 border text-red">
9193
<%= octicon "heart" %> Don't go bacon my heart.
@@ -98,7 +100,7 @@ Column widths can be used with any other block or inline-block elements to add p
98100

99101
Using column offset classes can push a div over X number of columns. They work responsively using the [breakpoints outlined below](/styleguide/css/modules/grid#responsive-grids).
100102

101-
```html
103+
```html title="Offset columns"
102104
<div class="clearfix">
103105
<div class="offset-1 col-3 border p-3">.offset-1</div>
104106
<div class="offset-2 col-3 border p-3">.offset-2</div>
@@ -108,7 +110,7 @@ Using column offset classes can push a div over X number of columns. They work r
108110
## Gutters
109111
Use gutter styles or padding utilities to create gutters. You can use the default gutter style, `gutter`, or either of its modifiers, `gutter-condensed` or `gutter-spacious`. Gutter styles also support responsive breakpoint modifiers. Gutter styles add padding to the left and right side of each column and apply a negative margin to the container to ensure content inside each column lines up with content outside of the grid.
110112

111-
```html
113+
```html title="Gutters"
112114
<div class="clearfix gutter-md-spacious border">
113115
<div class="col-3 float-left">
114116
<div class="border p-3">.col-md-3</div>
@@ -127,7 +129,7 @@ Use gutter styles or padding utilities to create gutters. You can use the defaul
127129

128130
Use padding utilities to create gutters for more customized layouts.
129131

130-
```html
132+
```html title="Gutters with padding"
131133
<div class="container-lg clearfix">
132134
<div class="col-3 float-left pr-2 mb-3">
133135
<div class="border bg-gray-light">.pr-2</div>
@@ -156,7 +158,7 @@ Use padding utilities to create gutters for more customized layouts.
156158
## Inline-block grids
157159
Use column widths with `d-inline-block` as an alternative to floated grids.
158160

159-
```html
161+
```html title="Inline-block grid"
160162
<div>
161163
<div class="col-4 d-inline-block border">
162164
.col-4 .d-inline-block
@@ -171,7 +173,7 @@ Use column widths with `d-inline-block` as an alternative to floated grids.
171173
```
172174

173175
You can use column widths and other utilities on elements such as lists to create the layout you need while keeping the markup semantically correct.
174-
```html
176+
```html title="Inline-block grid list"
175177
<ul class="list-style-none">
176178
<li class="d-inline-block col-2 p-2"><img class="width-full avatar" src="/broccolini.png" alt="broccolini" /></li><!--
177179
--><li class="d-inline-block col-2 p-2"><img class="width-full avatar" src="/jonrohan.png" alt="jonrohan" /></li><!--
@@ -190,7 +192,7 @@ Using [display table utilities](/styleguide/css/utilities/layout#display) with c
190192

191193
A useful example is being able to keep the height of the container equal across a row when the length of content may differ.
192194

193-
```html
195+
```html title="Table grid"
194196
<div class="d-table col-12">
195197
<div class="col-4 d-table-cell border p-2">
196198
Bacon ipsum dolor amet leberkas pork pig kielbasa shankle ribeye meatball, salami alcatra venison.
@@ -205,7 +207,7 @@ A useful example is being able to keep the height of the container equal across
205207
```
206208
You can also create an alternative [media object](/styleguide/css/utilities/layout#the-media-object) layout with `.display-table` and column widths.
207209

208-
```html
210+
```html title="Table grid alternative"
209211
<div class="d-table col-12">
210212
<div class="col-2 d-table-cell v-align-middle">
211213
<img class="width-full avatar" src="/github.png" alt="github" />
@@ -220,7 +222,7 @@ You can also create an alternative [media object](/styleguide/css/utilities/layo
220222

221223
Note that table cells will fill the width of their container even when the total columns doesn't add up to 12.
222224

223-
```html
225+
```html title="Table grid cells"
224226
<div class="d-table col-12">
225227
<div class="col-4 d-table-cell border">
226228
.col-4 .d-table-cell
@@ -240,7 +242,7 @@ You can use [flex utilities](/styleguide/css/utilities/flexbox) on the container
240242

241243
This can be useful for keeping columns the same height, justifying content and vertically aligning items. The flexbox grid is also great for working with responsive layouts.
242244

243-
```html
245+
```html title="Flexbox grid"
244246
<div class="d-flex flex-column flex-md-row flex-items-center flex-md-items-center">
245247
<div class="col-2 d-flex flex-items-center flex-items-center flex-md-items-start">
246248
<img class="width-full avatar mb-2 mb-md-0" src="/github.png" alt="github" />
@@ -273,7 +275,7 @@ We use abbreviations for each breakpoint to keep the class names concise.
273275

274276
In this example at the `sm` breakpoint 2 columns will show, at the `md` breakpoint 4 columns will show, and at the `lg` breakpoint 6 columns will show.
275277

276-
```html
278+
```html title="Responsive grid"
277279
<div class="container-lg clearfix">
278280
<div class="col-sm-6 col-md-3 col-lg-2 float-left p-2 border">
279281
.col-sm-6 .col-md-3 .col-lg-2
@@ -298,7 +300,7 @@ In this example at the `sm` breakpoint 2 columns will show, at the `md` breakpoi
298300

299301
For demonstration, this is how the above example would look at the `sm` breakpoint.
300302

301-
```html
303+
```html title="Responsive grid small"
302304
<div class="container-lg clearfix">
303305
<div class="col-sm-6 float-left p-2 border">
304306
.col-sm-6
@@ -322,7 +324,7 @@ For demonstration, this is how the above example would look at the `sm` breakpoi
322324
```
323325
This is how that same example would look at the `md` breakpoint.
324326

325-
```html
327+
```html title="Responsive grid medium"
326328
<div class="container-lg clearfix">
327329
<div class="col-md-3 float-left p-2 border">
328330
.col-md-3
@@ -347,7 +349,7 @@ This is how that same example would look at the `md` breakpoint.
347349

348350
This is how that example would look at the `lg` breakpoint.
349351

350-
```html
352+
```html title="Responsive grid large"
351353
<div class="container-lg clearfix">
352354
<div class="col-lg-2 float-left p-2 border">
353355
.col-lg-2
@@ -373,7 +375,7 @@ This is how that example would look at the `lg` breakpoint.
373375
## Containers
374376
Container widths match our breakpoints and are available at a `md`, `lg`, and `xl` size. Containers apply a max-width rather than a fixed width for responsive layouts, and they center the container.
375377

376-
```html
378+
```html title="Containers sized"
377379
<div class="container-md border">
378380
.container-md, max-width 768px
379381
</div>

modules/primer-layout/stories.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import { storiesOf } from '@storybook/react'
3+
import storiesFromMarkdown from '../../.storybook/lib/storiesFromMarkdown'
4+
5+
const stories = storiesOf('Layout', module)
6+
7+
storiesFromMarkdown(require.context('.', true, /\.md$/))
8+
.forEach(({title, story}) => {
9+
stories.add(title, story)
10+
})

0 commit comments

Comments
 (0)