/
do-dont.js
62 lines (57 loc) · 1.61 KB
/
do-dont.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {Box, Text} from '@primer/react'
import React from 'react'
export function DoDontContainer({stacked, children}) {
return (
<Box sx={{display: 'grid', gridTemplateColumns: ['1fr', null, stacked ? '1fr' : '1fr 1fr'], gridGap: 4, mb: 4}}>
{children}
</Box>
)
}
DoDontContainer.defaultProps = {
stacked: false,
}
export function Do(props) {
return <DoDontBase {...props} title="Do" bg="success.fg" borderColor="success.muted" />
}
export function Dont(props) {
return <DoDontBase {...props} title="Don’t" bg="danger.fg" borderColor="danger.muted" />
}
function DoDontBase({children, title, bg, borderColor, indented}) {
return (
<Box sx={{display: 'flex', flexDirection: 'column'}}>
<Box
sx={{
display: 'flex',
alignSelf: 'start',
flexDirection: 'row',
alignItems: 'center',
mb: '2',
backgroundColor: bg,
borderRadius: '2',
color: 'fg.onEmphasis',
paddingX: '2',
}}
>
<Text sx={{fontWeight: 'bold', fontSize: '1', color: 'fg.onEmphasis'}}>{title}</Text>
</Box>
<Box sx={{'& *:last-child': {mb: 0}, img: {maxWidth: '100%'}, display: 'flex', flexDirection: 'column'}}>
{indented ? (
<Box
as="blockquote"
sx={{
margin: '0',
borderLeftWidth: '4px',
borderLeftStyle: 'solid',
borderLeftColor: borderColor,
paddingLeft: '3',
}}
>
{children}
</Box>
) : (
children
)}
</Box>
</Box>
)
}