Skip to content

Commit 526ba38

Browse files
Emilycolebemis
authored andcommitted
Create Do and Dont components (#63)
1 parent b870189 commit 526ba38

File tree

6 files changed

+102
-4
lines changed

6 files changed

+102
-4
lines changed

docs/content/components/do-dont.mdx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Do/Dont
3+
---
4+
5+
The `Do` and `Dont` components are used for providing good and bad examples within documentation.
6+
7+
## Usage
8+
9+
To use these components in your MDX files, import them like so:
10+
11+
```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'
19+
```
20+
21+
### Side-by-side
22+
23+
To create a side-by-side Do/Don't example, you can wrap the `Do` and `Dont` components with the `Grid` component:
24+
25+
```jsx live
26+
<Grid gridTemplateColumns={['1fr', '1fr', '1fr 1fr']} gridGap={3}>
27+
<Do src="https://user-images.githubusercontent.com/586552/63106528-06de5100-bf51-11e9-8a5e-98583ed74874.png">
28+
Use brief and direct communication
29+
</Do>
30+
<Dont src="https://user-images.githubusercontent.com/586552/63106527-06de5100-bf51-11e9-858c-72de6a5c728a.png">
31+
Don't use wordy and redundant copy
32+
</Dont>
33+
</Grid>
34+
```
35+
36+
_Note: Caption text should describe the image and be able to stand on its own._
37+
38+
### Isolation
39+
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:
41+
42+
```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>
46+
```
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import * as components from '@primer/components'
2-
import {Hero, Caption} from '@primer/gatsby-theme-doctocat'
2+
import {Hero, Caption, Do, Dont} from '@primer/gatsby-theme-doctocat'
33

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
children:
2020
- title: Caption
2121
url: /components/caption
22-
22+
- title: Do/Dont
23+
url: /components/do-dont
2324
- title: Contributing
2425
url: /contributing

theme/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {default as Caption} from './src/components/caption'
2+
export {Do, Dont} from './src/components/do-dont'
23
export {default as Container} from './src/components/container'
34
export {default as Head} from './src/components/head'
45
export {default as Header} from './src/components/header'

theme/src/components/caption.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {Text} from '@primer/components'
22
import React from 'react'
33

4-
const Caption = (props) => <Text as='p' my={3} fontSize='1' color='gray.5' {...props}/>
4+
function Caption(props) {
5+
return <Text as="p" mt={2} mb={3} fontSize={1} color="gray.5" {...props} />
6+
}
57

68
export default Caption

theme/src/components/do-dont.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {CircleOcticon, Flex, Text} from '@primer/components'
2+
import {Check, X} from '@primer/octicons-react'
3+
import React from 'react'
4+
import Caption from './caption'
5+
6+
export function Do({src, children}) {
7+
return (
8+
<Flex flexDirection="column">
9+
<Flex alignSelf="start" flexDirection="row" alignItems="center" mb="2">
10+
<CircleOcticon
11+
icon={Check}
12+
size={16}
13+
bg="green.5"
14+
color="white"
15+
mr="2"
16+
p="1"
17+
/>
18+
<Text fontWeight="bold" color="gray.9" ml="1">
19+
Do
20+
</Text>
21+
</Flex>
22+
<img src={src} width="100%" />
23+
<Caption>{children}</Caption>
24+
</Flex>
25+
)
26+
}
27+
28+
export function Dont({src, children}) {
29+
return (
30+
<Flex flexDirection="column">
31+
<Flex alignSelf="start" flexDirection="row" alignItems="center" mb="2">
32+
<CircleOcticon
33+
icon={X}
34+
size={16}
35+
bg="red.5"
36+
color="white"
37+
mr="2"
38+
p="1"
39+
/>
40+
<Text fontWeight="bold" color="gray.9" ml="1">
41+
Don't
42+
</Text>
43+
</Flex>
44+
<img src={src} width="100%" />
45+
<Caption>{children}</Caption>
46+
</Flex>
47+
)
48+
}

0 commit comments

Comments
 (0)