-
Notifications
You must be signed in to change notification settings - Fork 119
/
palette.js
172 lines (153 loc) · 3.53 KB
/
palette.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import React from 'react'
import styled from 'styled-components'
import {
Box,
Card,
Flex,
Heading,
Text,
Divider,
createTheme
} from 'pcln-design-system'
import select from 'select'
import { PageTitle, Description, Code } from '../src/components'
class CopyButton extends React.Component {
constructor() {
super()
this.handleClick = e => {
select(this.ghost)
document.execCommand('copy')
}
}
render() {
const child = React.Children.only(this.props.children)
const clone = React.cloneElement(child, {
onClick: this.handleClick
})
return [
clone,
<div
ref={ref => (this.ghost = ref)}
children={this.props.text}
style={{
position: 'absolute',
zIndex: -1,
opacity: 0
}}
/>
]
}
}
const flattenObject = obj =>
Object.keys(obj).map(key => ({
name: key,
value: obj[key]
}))
const ColorChip = styled(Box)`
height: 100px;
width: 100%;
border-radius: 2px 2px 0 0;
transition: all 0.1s ease;
`
const HexButton = styled.button`
width: 100%;
display: inline-block;
position: relative;
font-family: inherit;
font-size: 12px;
margin: 0;
padding: 0;
color: inherit;
text-align: left;
background-color: transparent;
border: 0;
border-radius: 0;
appearance: none;
transition: all 0.125s ease;
box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.08);
&:hover {
box-shadow: 0 8px 8px 0 rgba(0, 0, 0, 0.08),
0 16px 16px 0 rgba(0, 0, 0, 0.08);
}
&:active {
transform: scale(0.9);
}
& > span {
top: 0;
left: 0;
position: absolute;
font-size: 12px;
padding: 8px 0;
width: 100%;
color: #fff;
border-radius: 2px 2px 0 0;
background-color: #001833;
text-align: center;
opacity: 0;
transition-property: opacity;
transition-duration: 0.125s;
transition-timing-function: ease-out;
}
&:hover > span {
opacity: 1;
}
`
const ColorCard = ({ name, value }) => (
<Card borderWidth={0} m={0}>
<CopyButton text={value}>
<HexButton>
<ColorChip bg={value} />
<span>Press to copy</span>
<Box p={2}>
<Text fontSize={0} mb={1} align="left">
{name}
</Text>
<Code fontSize={0} align="left" color="gray">
{value}
</Code>
</Box>
</HexButton>
</CopyButton>
</Card>
)
const Column = props => (
<Box {...props} width={[1 / 2, null, 1 / 3, 1 / 4, 1 / 5]} mb={4} px={2} />
)
const ColorList = props =>
props.colors.map(color => (
<Column key={color.key}>
<ColorCard {...color} />
</Column>
))
export const SectionTitle = props => (
<Heading.h3 fontSize={[2, 3]} bold mt={[2, 4]} {...props} />
)
const defaultPalette = createTheme().palette
const rest = {}
const Palette = props => (
<Box>
<PageTitle>Palette</PageTitle>
<Description>
The design system includes a palette that can be used to theme components.
</Description>
{Object.keys(defaultPalette).map(key => {
if (typeof defaultPalette[key] === 'object') {
return (
<React.Fragment>
<SectionTitle>{key}</SectionTitle>
<Flex wrap mx={-2} pt={4}>
<ColorList colors={flattenObject(defaultPalette[key])} />
</Flex>
<Divider />
</React.Fragment>
)
} else {
rest[key] = defaultPalette[key]
}
})}
<Flex wrap mx={-2} pt={4}>
<ColorList colors={flattenObject(rest)} />
</Flex>
</Box>
)
export default Palette