Skip to content

Commit a4c0cfd

Browse files
committed
Create a DoDont wrapper component (#69)
* Create a DoDont wrapper component * Use apostrophe
1 parent bdaf24d commit a4c0cfd

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

docs/content/components/do-dont.mdx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Do/Dont
2+
title: Do/Don't
33
---
44

55
The `Do` and `Dont` components are used for providing good and bad examples within documentation.
@@ -9,38 +9,37 @@ The `Do` and `Dont` components are used for providing good and bad examples with
99
To use these components in your MDX files, import them like so:
1010

1111
```js
12-
import {Do, Dont} from '@primer/gatsby-theme-doctocat'
13-
```
14-
15-
If you plan to create side-by-side Do/Don't examples, you'll also want to import the `Grid` component from `@primer/components`:
16-
17-
```js
18-
import {Grid} from '@primer/components'
12+
import {DoDont, Do, Dont} from '@primer/gatsby-theme-doctocat'
1913
```
2014

2115
### Side-by-side
2216

23-
To create a side-by-side Do/Don't example, you can wrap the `Do` and `Dont` components with the `Grid` component:
17+
To create a side-by-side Do/Don't example, wrap the `Do` and `Dont` components with the `DoDont` component:
2418

2519
```jsx live
26-
<Grid gridTemplateColumns={['1fr', '1fr', '1fr 1fr']} gridGap={3}>
20+
<DoDont>
2721
<Do src="https://user-images.githubusercontent.com/586552/63106528-06de5100-bf51-11e9-8a5e-98583ed74874.png">
2822
Use brief and direct communication
2923
</Do>
3024
<Dont src="https://user-images.githubusercontent.com/586552/63106527-06de5100-bf51-11e9-858c-72de6a5c728a.png">
3125
Don't use wordy and redundant copy
3226
</Dont>
33-
</Grid>
27+
</DoDont>
3428
```
3529
3630
_Note: Caption text should describe the image and be able to stand on its own._
3731
38-
### Isolation
32+
### Stacked
3933
40-
The `Do` and `Dont` components don't always have to be used together. Here's an example of how you might use the `Do` component in isolation:
34+
The `DoDont` component also accepts a `stacked` prop to create stacked Do/Don't examples:
4135

4236
```jsx live
43-
<Do src="https://user-images.githubusercontent.com/586552/63046880-46e5fb00-bea1-11e9-836d-be1b1c7d963f.png">
44-
Use a container class to give the text a max-width
45-
</Do>
37+
<DoDont stacked>
38+
<Do src="https://user-images.githubusercontent.com/586552/63046880-46e5fb00-bea1-11e9-836d-be1b1c7d963f.png">
39+
Use a container class to give the text a max-width
40+
</Do>
41+
<Dont src="https://user-images.githubusercontent.com/586552/63046881-46e5fb00-bea1-11e9-87ee-80dbeb0bea1c.png">
42+
Don't let the text span the entire width of the window
43+
</Dont>
44+
</DoDont>
4645
```
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as components from '@primer/components'
2-
import {Hero, Caption, Do, Dont} from '@primer/gatsby-theme-doctocat'
1+
import * as primerComponents from '@primer/components'
2+
import * as doctocatComponents from '@primer/gatsby-theme-doctocat'
33

4-
export default {...components, Hero, Caption, Do, Dont}
4+
export default {...primerComponents, ...doctocatComponents}

docs/src/@primer/gatsby-theme-doctocat/nav.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
children:
2020
- title: Caption
2121
url: /components/caption
22-
- title: Do/Dont
22+
- title: Do/Don't
2323
url: /components/do-dont
2424
- title: Contributing
2525
url: /contributing

theme/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export {default as Caption} from './src/components/caption'
2-
export {Do, Dont} from './src/components/do-dont'
2+
export {DoDont, Do, Dont} from './src/components/do-dont'
33
export {default as Container} from './src/components/container'
44
export {default as Head} from './src/components/head'
55
export {default as Header} from './src/components/header'

theme/src/components/do-dont.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
import {CircleOcticon, Flex, Text} from '@primer/components'
1+
import {CircleOcticon, Flex, Text, Grid} from '@primer/components'
22
import {Check, X} from '@primer/octicons-react'
33
import React from 'react'
44
import Caption from './caption'
55

6+
export function DoDont({stacked, children}) {
7+
return (
8+
<Grid
9+
gridTemplateColumns={['1fr', null, stacked ? '1fr' : '1fr 1fr']}
10+
gridGap={3}
11+
mb={3}
12+
>
13+
{children}
14+
</Grid>
15+
)
16+
}
17+
18+
DoDont.defaultProps = {
19+
stacked: false,
20+
}
21+
622
export function Do({src, children}) {
723
return (
824
<Flex flexDirection="column">
@@ -20,7 +36,7 @@ export function Do({src, children}) {
2036
</Text>
2137
</Flex>
2238
<img src={src} width="100%" />
23-
<Caption>{children}</Caption>
39+
<Caption mb={0}>{children}</Caption>
2440
</Flex>
2541
)
2642
}
@@ -42,7 +58,7 @@ export function Dont({src, children}) {
4258
</Text>
4359
</Flex>
4460
<img src={src} width="100%" />
45-
<Caption>{children}</Caption>
61+
<Caption mb={0}>{children}</Caption>
4662
</Flex>
4763
)
4864
}

0 commit comments

Comments
 (0)