@automattic/vip-design-system 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslines.json +10 -0
- package/.eslintignore +7 -0
- package/.eslintrc.json +23 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +22 -0
- package/.github/workflows/codeql-analysis.yml +71 -0
- package/.github/workflows/nodejs.yaml +29 -0
- package/.prettierrc +9 -0
- package/.storybook/preview.js +8 -7
- package/README.md +52 -2
- package/babel.config.js +10 -10
- package/build/system/Avatar/Avatar.js +6 -2
- package/build/system/Avatar/Avatar.test.js +54 -0
- package/build/system/Badge/Badge.js +2 -2
- package/build/system/BlankState/BlankState.js +5 -4
- package/build/system/Button/Button.js +5 -1
- package/build/system/Card/Card.js +8 -5
- package/build/system/Code/Code.js +4 -4
- package/build/system/ConfirmationDialog/ConfirmationDialog.js +2 -2
- package/build/system/Dialog/Dialog.js +3 -0
- package/build/system/Dialog/DialogButton.js +2 -4
- package/build/system/Dialog/DialogContent.js +5 -5
- package/build/system/Form/Checkbox.js +52 -5
- package/build/system/Form/InlineSelect.js +32 -16
- package/build/system/Form/Input.js +9 -6
- package/build/system/Form/Label.js +2 -2
- package/build/system/Form/RadioBoxGroup.js +101 -0
- package/build/system/Form/SearchSelect.js +36 -56
- package/build/system/Form/Select.js +3 -3
- package/build/system/Form/Textarea.js +9 -6
- package/build/system/Form/Toggle.js +1 -1
- package/build/system/Form/ToggleGroup.js +78 -0
- package/build/system/Form/ToggleRow.js +6 -5
- package/build/system/Form/Validation.js +4 -4
- package/build/system/Form/index.js +8 -0
- package/build/system/Notice/Notice.js +58 -54
- package/build/system/Notification/Notification.js +4 -4
- package/build/system/OptionRow/OptionRow.js +12 -11
- package/build/system/ResourceList/ResourceItem.js +89 -0
- package/build/system/ResourceList/ResourceList.js +121 -0
- package/build/system/ResourceList/index.js +11 -0
- package/build/system/Table/TableRow.js +2 -2
- package/build/system/Tabs/TabItem.js +3 -3
- package/build/system/Tabs/Tabs.js +1 -1
- package/build/system/Time/index.js +91 -0
- package/build/system/Tooltip/Tooltip.js +49 -47
- package/build/system/Wizard/WizardStep.js +5 -5
- package/build/system/Wizard/WizardStepHorizontal.js +2 -2
- package/build/system/index.js +9 -2
- package/build/system/theme/colors.js +235 -131
- package/build/system/theme/index.js +140 -107
- package/package.json +48 -11
- package/src/system/Avatar/Avatar.js +6 -2
- package/src/system/Avatar/Avatar.stories.js +0 -5
- package/src/system/Avatar/Avatar.test.js +31 -0
- package/src/system/Badge/Badge.js +3 -3
- package/src/system/Badge/Badge.stories.js +0 -5
- package/src/system/BlankState/BlankState.js +5 -5
- package/src/system/BlankState/BlankState.stories.js +0 -5
- package/src/system/Box/Box.stories.js +0 -5
- package/src/system/Button/Button.js +6 -2
- package/src/system/Card/Card.js +6 -4
- package/src/system/Card/Card.stories.js +0 -5
- package/src/system/Code/Code.js +4 -4
- package/src/system/Code/Code.stories.js +4 -1
- package/src/system/ConfirmationDialog/ConfirmationDialog.js +2 -2
- package/src/system/ConfirmationDialog/ConfirmationDialog.stories.js +0 -5
- package/src/system/Dialog/Dialog.js +1 -1
- package/src/system/Dialog/Dialog.stories.js +0 -5
- package/src/system/Dialog/DialogButton.js +2 -3
- package/src/system/Dialog/DialogContent.js +17 -4
- package/src/system/Flex/Flex.stories.js +0 -5
- package/src/system/Form/Checkbox.js +44 -2
- package/src/system/Form/InlineSelect.js +30 -15
- package/src/system/Form/Input.js +6 -4
- package/src/system/Form/Input.stories.js +0 -5
- package/src/system/Form/Label.js +2 -2
- package/src/system/Form/RadioBoxGroup.js +68 -0
- package/src/system/Form/RadioBoxGroup.stories.js +37 -0
- package/src/system/Form/SearchSelect.js +35 -42
- package/src/system/Form/Select.js +18 -18
- package/src/system/Form/Select.stories.js +1 -1
- package/src/system/Form/Textarea.js +6 -4
- package/src/system/Form/Toggle.js +1 -1
- package/src/system/Form/ToggleGroup.js +63 -0
- package/src/system/Form/ToggleGroup.stories.js +34 -0
- package/src/system/Form/ToggleRow.js +5 -5
- package/src/system/Form/Validation.js +2 -2
- package/src/system/Form/index.js +3 -1
- package/src/system/Grid/Grid.stories.js +0 -5
- package/src/system/Heading/Heading.stories.js +0 -5
- package/src/system/Link/Link.stories.js +0 -5
- package/src/system/Notice/Notice.js +33 -28
- package/src/system/Notification/Notification.js +6 -6
- package/src/system/Notification/Notification.stories.js +0 -5
- package/src/system/OptionRow/OptionRow.js +37 -32
- package/src/system/OptionRow/OptionRow.stories.js +0 -5
- package/src/system/Progress/Progress.stories.js +0 -5
- package/src/system/ResourceList/ResourceItem.js +66 -0
- package/src/system/ResourceList/ResourceList.js +96 -0
- package/src/system/ResourceList/ResourceList.stories.js +300 -0
- package/src/system/ResourceList/index.js +7 -0
- package/src/system/Spinner/Spinner.stories.js +0 -5
- package/src/system/Table/Table.stories.js +0 -5
- package/src/system/Table/TableRow.js +3 -3
- package/src/system/Tabs/TabItem.js +3 -3
- package/src/system/Tabs/Tabs.js +1 -1
- package/src/system/Tabs/Tabs.stories.js +0 -5
- package/src/system/Text/Text.stories.js +0 -5
- package/src/system/{Timeline/Timeline.stories.js → Time/Time.stories.js} +5 -5
- package/src/system/Time/index.js +62 -0
- package/src/system/Tooltip/Tooltip.js +40 -35
- package/src/system/Tooltip/Tooltip.stories.js +0 -5
- package/src/system/Wizard/Wizard.js +7 -7
- package/src/system/Wizard/WizardStep.js +10 -10
- package/src/system/Wizard/WizardStepHorizontal.js +3 -3
- package/src/system/index.js +29 -4
- package/src/system/theme/colors.js +233 -129
- package/src/system/theme/index.js +298 -256
- package/test/setupAfterEnv.js +13 -0
- package/test/setupTests.js +4 -0
- package/src/system/Timeline/index.js +0 -40
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { BiGlobe, BiCheckCircle, BiRevision } from 'react-icons/bi';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
Avatar,
|
|
14
|
+
Badge,
|
|
15
|
+
Box,
|
|
16
|
+
Card,
|
|
17
|
+
Flex,
|
|
18
|
+
Button,
|
|
19
|
+
ResourceList,
|
|
20
|
+
ResourceItem,
|
|
21
|
+
Text,
|
|
22
|
+
Heading,
|
|
23
|
+
} from '..';
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
title: 'ResourceList',
|
|
27
|
+
component: ResourceList,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const logs = [
|
|
31
|
+
{
|
|
32
|
+
actor: 'Saxon Fletcher',
|
|
33
|
+
action: 'switched primary domain to',
|
|
34
|
+
object: 'mydomain.com',
|
|
35
|
+
date: new Date(),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
actor: 'Saxon Fletcher',
|
|
39
|
+
action: 'switched primary domain to',
|
|
40
|
+
object: 'mydomain.com',
|
|
41
|
+
date: new Date( new Date().setHours( 11 ) ),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
actor: 'Simon Wheatley',
|
|
45
|
+
action: 'deployed to',
|
|
46
|
+
object: 'Production',
|
|
47
|
+
showObject: true,
|
|
48
|
+
date: new Date( new Date().setDate( 15 ) ),
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
actor: 'Saxon Fletcher',
|
|
52
|
+
action: 'created a backup on',
|
|
53
|
+
object: 'Production',
|
|
54
|
+
date: new Date( new Date().setDate( 13 ) ),
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
export const Grouped = () => (
|
|
59
|
+
<Box sx={{ p: 5, pt: 2 }}>
|
|
60
|
+
<Heading sx={{ mb: 2 }}>Audit Log</Heading>
|
|
61
|
+
<Text sx={{ mb: 4 }}>A live trail of system and human events.</Text>
|
|
62
|
+
<ResourceList
|
|
63
|
+
items={logs}
|
|
64
|
+
dateKey="date"
|
|
65
|
+
groupedByDay={true}
|
|
66
|
+
renderItem={item => (
|
|
67
|
+
<ResourceItem
|
|
68
|
+
item={item}
|
|
69
|
+
icon={<BiGlobe sx={{ color: 'red' }} />}
|
|
70
|
+
dateKey={'date'}
|
|
71
|
+
relativeTime={true}
|
|
72
|
+
timeOnly={true}
|
|
73
|
+
>
|
|
74
|
+
<Flex sx={{ alignItems: 'center', gap: 3 }}>
|
|
75
|
+
<Avatar
|
|
76
|
+
name={item.actor}
|
|
77
|
+
src="https://uifaces.co/our-content/donated/1H_7AxP0.jpg"
|
|
78
|
+
size={16}
|
|
79
|
+
/>
|
|
80
|
+
<Heading variant="h4" as="p" sx={{ mb: 0, fontWeight: 'normal' }}>
|
|
81
|
+
{item.actor}{' '}
|
|
82
|
+
<Text as="span" sx={{ color: 'muted', mb: 0 }}>
|
|
83
|
+
{item.action}
|
|
84
|
+
</Text>{' '}
|
|
85
|
+
{item.object}
|
|
86
|
+
</Heading>
|
|
87
|
+
</Flex>
|
|
88
|
+
{item.showObject && (
|
|
89
|
+
<Box
|
|
90
|
+
variant="indent"
|
|
91
|
+
sx={{ mt: 2, display: 'flex', flexWrap: 'wrap', gap: 3, alignItems: 'center' }}
|
|
92
|
+
>
|
|
93
|
+
<Heading variant="h5" as="div" sx={{ mb: 0 }}>
|
|
94
|
+
Merge pull request{' '}
|
|
95
|
+
<Text as="span" sx={{ color: 'muted' }}>
|
|
96
|
+
#443
|
|
97
|
+
</Text>
|
|
98
|
+
</Heading>
|
|
99
|
+
<Text sx={{ mb: 0, fontSize: 1, display: 'flex', alignItems: 'center', gap: 1 }}>
|
|
100
|
+
<Avatar
|
|
101
|
+
name={item.actor}
|
|
102
|
+
src="https://uifaces.co/our-content/donated/n4Ngwvi7.jpg"
|
|
103
|
+
size={16}
|
|
104
|
+
/>
|
|
105
|
+
{item.actor}
|
|
106
|
+
</Text>
|
|
107
|
+
<Text sx={{ mb: 0, fontSize: 1, display: 'flex', alignItems: 'center', gap: 1 }}>
|
|
108
|
+
<BiCheckCircle size={16} />
|
|
109
|
+
Deployed in 31s
|
|
110
|
+
</Text>
|
|
111
|
+
</Box>
|
|
112
|
+
)}
|
|
113
|
+
</ResourceItem>
|
|
114
|
+
)}
|
|
115
|
+
/>
|
|
116
|
+
</Box>
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const deploys = [
|
|
120
|
+
{
|
|
121
|
+
title: 'Merge pull request',
|
|
122
|
+
id: '#773',
|
|
123
|
+
author: 'Saxon Fletcher',
|
|
124
|
+
date: new Date( new Date().setHours( 11 ) ),
|
|
125
|
+
status: 'running',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
title: 'Update homepage',
|
|
129
|
+
id: '#772',
|
|
130
|
+
author: 'Saxon Fletcher',
|
|
131
|
+
date: new Date( new Date().setHours( 9 ) ),
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
title: 'Improve overall performance',
|
|
135
|
+
id: '#771',
|
|
136
|
+
author: 'Saxon Fletcher',
|
|
137
|
+
date: new Date( new Date().setHours( 8 ) ),
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
title: 'Merge pull request',
|
|
141
|
+
id: '#770',
|
|
142
|
+
author: 'Saxon Fletcher',
|
|
143
|
+
date: new Date( new Date().setHours( 5 ) ),
|
|
144
|
+
status: 'failed',
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
title: 'Merge pull request',
|
|
148
|
+
id: '#773',
|
|
149
|
+
author: 'Saxon Fletcher',
|
|
150
|
+
date: new Date( new Date().setHours( 11 ) ),
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
title: 'Update homepage',
|
|
154
|
+
id: '#772',
|
|
155
|
+
author: 'Saxon Fletcher',
|
|
156
|
+
date: new Date( new Date().setHours( 9 ) ),
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
title: 'Improve overall performance',
|
|
160
|
+
id: '#771',
|
|
161
|
+
author: 'Saxon Fletcher',
|
|
162
|
+
date: new Date( new Date().setHours( 8 ) ),
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
title: 'Merge pull request',
|
|
166
|
+
id: '#770',
|
|
167
|
+
author: 'Saxon Fletcher',
|
|
168
|
+
date: new Date( new Date().setHours( 5 ) ),
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
title: 'Merge pull request',
|
|
172
|
+
id: '#773',
|
|
173
|
+
author: 'Saxon Fletcher',
|
|
174
|
+
date: new Date( new Date().setHours( 11 ) ),
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
title: 'Update homepage',
|
|
178
|
+
id: '#772',
|
|
179
|
+
author: 'Saxon Fletcher',
|
|
180
|
+
date: new Date( new Date().setHours( 9 ) ),
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
title: 'Improve overall performance',
|
|
184
|
+
id: '#771',
|
|
185
|
+
author: 'Saxon Fletcher',
|
|
186
|
+
date: new Date( new Date().setHours( 8 ) ),
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
title: 'Merge pull request',
|
|
190
|
+
id: '#770',
|
|
191
|
+
author: 'Saxon Fletcher',
|
|
192
|
+
date: new Date( new Date().setHours( 5 ) ),
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
title: 'Merge pull request',
|
|
196
|
+
id: '#773',
|
|
197
|
+
author: 'Saxon Fletcher',
|
|
198
|
+
date: new Date( new Date().setHours( 11 ) ),
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
title: 'Update homepage',
|
|
202
|
+
id: '#772',
|
|
203
|
+
author: 'Saxon Fletcher',
|
|
204
|
+
date: new Date( new Date().setHours( 9 ) ),
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
title: 'Improve overall performance',
|
|
208
|
+
id: '#771',
|
|
209
|
+
author: 'Saxon Fletcher',
|
|
210
|
+
date: new Date( new Date().setHours( 8 ) ),
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
title: 'Merge pull request',
|
|
214
|
+
id: '#770',
|
|
215
|
+
author: 'Saxon Fletcher',
|
|
216
|
+
date: new Date( new Date().setHours( 5 ) ),
|
|
217
|
+
},
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
export const Relative = () => (
|
|
221
|
+
<Box sx={{ p: 5, pt: 2 }}>
|
|
222
|
+
<Heading sx={{ mb: 2 }}>Deploys</Heading>
|
|
223
|
+
<Text sx={{ mb: 4 }}>View and manage application deployments.</Text>
|
|
224
|
+
<Card variant="indent" sx={{ mb: 4, display: 'flex', flexDirection: 'row-reverse', gap: 1 }}>
|
|
225
|
+
{deploys.map( ( deploy, index ) => (
|
|
226
|
+
<Box
|
|
227
|
+
key={index}
|
|
228
|
+
sx={{
|
|
229
|
+
flex: '1 1 auto',
|
|
230
|
+
width: 10,
|
|
231
|
+
height: 4,
|
|
232
|
+
backgroundColor: deploy.status === 'running' ? 'blue.50' : 'green.50',
|
|
233
|
+
borderRadius: 1,
|
|
234
|
+
}}
|
|
235
|
+
></Box>
|
|
236
|
+
) )}
|
|
237
|
+
</Card>
|
|
238
|
+
<ResourceList
|
|
239
|
+
items={deploys}
|
|
240
|
+
dateKey="date"
|
|
241
|
+
groupedByDay={false}
|
|
242
|
+
renderItem={item => (
|
|
243
|
+
<ResourceItem
|
|
244
|
+
item={item}
|
|
245
|
+
dateKey={'date'}
|
|
246
|
+
relativeTime={true}
|
|
247
|
+
timeOnly={true}
|
|
248
|
+
renderActions={() => (
|
|
249
|
+
<Flex sx={{ alignItems: 'center' }}>
|
|
250
|
+
<Button variant="secondary" sx={{ fontSize: 1 }}>
|
|
251
|
+
Rollback
|
|
252
|
+
</Button>
|
|
253
|
+
</Flex>
|
|
254
|
+
)}
|
|
255
|
+
>
|
|
256
|
+
<Flex sx={{ alignItems: 'center', gap: 4 }}>
|
|
257
|
+
<Flex sx={{ alignItems: 'center', gap: 3, minWidth: 300 }}>
|
|
258
|
+
<Heading variant="h4" as="p" sx={{ mb: 0, fontWeight: 'normal' }}>
|
|
259
|
+
{item.title}{' '}
|
|
260
|
+
<Text as="span" sx={{ color: 'muted', mb: 0 }}>
|
|
261
|
+
{item.id}
|
|
262
|
+
</Text>
|
|
263
|
+
</Heading>
|
|
264
|
+
{item.status === 'running' && <Badge sx={{ mb: 0 }}>Running</Badge>}
|
|
265
|
+
</Flex>
|
|
266
|
+
<Text sx={{ mb: 0, color: 'muted', display: 'flex', alignItems: 'center', gap: 2 }}>
|
|
267
|
+
<Avatar
|
|
268
|
+
name={item.author}
|
|
269
|
+
size={16}
|
|
270
|
+
src="https://randomuser.me/api/portraits/men/46.jpg"
|
|
271
|
+
/>
|
|
272
|
+
{item.author}
|
|
273
|
+
</Text>
|
|
274
|
+
<Text
|
|
275
|
+
sx={{
|
|
276
|
+
mb: 0,
|
|
277
|
+
color: item.status === 'running' ? 'blue.60' : 'muted',
|
|
278
|
+
display: 'flex',
|
|
279
|
+
alignItems: 'center',
|
|
280
|
+
gap: 1,
|
|
281
|
+
}}
|
|
282
|
+
>
|
|
283
|
+
{item.status === 'running' ? (
|
|
284
|
+
<React.Fragment>
|
|
285
|
+
<BiRevision size={16} />
|
|
286
|
+
Running for 31s
|
|
287
|
+
</React.Fragment>
|
|
288
|
+
) : (
|
|
289
|
+
<React.Fragment>
|
|
290
|
+
<BiCheckCircle size={16} />
|
|
291
|
+
Deployed in 31s
|
|
292
|
+
</React.Fragment>
|
|
293
|
+
)}
|
|
294
|
+
</Text>
|
|
295
|
+
</Flex>
|
|
296
|
+
</ResourceItem>
|
|
297
|
+
)}
|
|
298
|
+
/>
|
|
299
|
+
</Box>
|
|
300
|
+
);
|
|
@@ -55,7 +55,7 @@ const TableCell = ( { head, isRowHead, cell } ) => {
|
|
|
55
55
|
fontWeight: 'body',
|
|
56
56
|
borderTop: head ? '1px solid' : 'none',
|
|
57
57
|
borderColor: 'border',
|
|
58
|
-
'&:first-
|
|
58
|
+
'&:first-of-type': {
|
|
59
59
|
pl: 5,
|
|
60
60
|
},
|
|
61
61
|
} }
|
|
@@ -74,7 +74,7 @@ const TableCell = ( { head, isRowHead, cell } ) => {
|
|
|
74
74
|
TableCell.propTypes = {
|
|
75
75
|
head: PropTypes.bool,
|
|
76
76
|
isRowHead: PropTypes.bool,
|
|
77
|
-
cell: PropTypes.
|
|
77
|
+
cell: PropTypes.node,
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
TableRow.propTypes = {
|
|
@@ -84,4 +84,4 @@ TableRow.propTypes = {
|
|
|
84
84
|
rowHead: PropTypes.bool,
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
export { TableRow };
|
|
87
|
+
export { TableRow };
|
|
@@ -27,9 +27,9 @@ const TabItem = ( { active = false, sx, ...props } ) => (
|
|
|
27
27
|
borderTop: 'none',
|
|
28
28
|
borderLeft: 'none',
|
|
29
29
|
borderRight: 'none',
|
|
30
|
-
borderBottom: '
|
|
30
|
+
borderBottom: '1px solid',
|
|
31
31
|
borderColor: active ? 'link' : 'transparent',
|
|
32
|
-
transform: 'translateY(
|
|
32
|
+
transform: 'translateY(1px)',
|
|
33
33
|
'&:visited': {
|
|
34
34
|
color: active ? 'heading' : 'muted',
|
|
35
35
|
},
|
|
@@ -45,7 +45,7 @@ const TabItem = ( { active = false, sx, ...props } ) => (
|
|
|
45
45
|
|
|
46
46
|
TabItem.propTypes = {
|
|
47
47
|
active: PropTypes.bool,
|
|
48
|
-
sx: PropTypes.
|
|
48
|
+
sx: PropTypes.object,
|
|
49
49
|
variant: PropTypes.string,
|
|
50
50
|
};
|
|
51
51
|
|
package/src/system/Tabs/Tabs.js
CHANGED
|
@@ -6,24 +6,24 @@ import React from 'react';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { Time, Grid, Box } from '..';
|
|
10
10
|
|
|
11
11
|
export default {
|
|
12
|
-
title: '
|
|
13
|
-
component:
|
|
12
|
+
title: 'Time',
|
|
13
|
+
component: Time,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export const Default = () => (
|
|
17
17
|
<React.Fragment>
|
|
18
18
|
<Grid gap={ 2 } columns={ [ 2, '100px 300px' ] } sx={ { mb: '20px' } }>
|
|
19
|
-
<
|
|
19
|
+
<Time time="7pm" />
|
|
20
20
|
<Box>
|
|
21
21
|
It looks like everything is recovered now. You can forget about the last event.
|
|
22
22
|
</Box>
|
|
23
23
|
</Grid>
|
|
24
24
|
|
|
25
25
|
<Grid gap={ 2 } columns={ [ 2, '100px 200px' ] }>
|
|
26
|
-
<
|
|
26
|
+
<Time time="6pm" />
|
|
27
27
|
<Box>
|
|
28
28
|
At this particular moment in the day, something happened with your environment.
|
|
29
29
|
</Box>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { Text } from 'theme-ui';
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
|
|
9
|
+
const formatter = new Intl.RelativeTimeFormat( undefined, {
|
|
10
|
+
numeric: 'auto',
|
|
11
|
+
} );
|
|
12
|
+
|
|
13
|
+
const DIVISIONS = [
|
|
14
|
+
{ amount: 60, name: 'seconds' },
|
|
15
|
+
{ amount: 60, name: 'minutes' },
|
|
16
|
+
{ amount: 24, name: 'hours' },
|
|
17
|
+
{ amount: 7, name: 'days' },
|
|
18
|
+
{ amount: 12, name: 'months' },
|
|
19
|
+
{ amount: Number.POSITIVE_INFINITY, name: 'years' },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
function formatTimeAgo( date ) {
|
|
23
|
+
let duration = ( date - new Date() ) / 1000;
|
|
24
|
+
|
|
25
|
+
for ( let i = 0; i <= DIVISIONS.length; i++ ) {
|
|
26
|
+
const division = DIVISIONS[ i ];
|
|
27
|
+
if ( Math.abs( duration ) < division.amount ) {
|
|
28
|
+
return formatter.format( Math.round( duration ), division.name );
|
|
29
|
+
}
|
|
30
|
+
duration /= division.amount;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const Time = ( { time, relativeTime = false, timeOnly = false, ...props } ) => {
|
|
35
|
+
let formattedTime;
|
|
36
|
+
if ( relativeTime ) {
|
|
37
|
+
formattedTime = formatTimeAgo( time );
|
|
38
|
+
} else if ( timeOnly ) {
|
|
39
|
+
formattedTime = time.toLocaleTimeString();
|
|
40
|
+
} else {
|
|
41
|
+
formattedTime = time.toLocaleString();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Text
|
|
46
|
+
title={time.toLocaleString( 'sv', { timeZoneName: 'short' } )}
|
|
47
|
+
datetime={time}
|
|
48
|
+
as="time"
|
|
49
|
+
{...props}
|
|
50
|
+
>
|
|
51
|
+
{formattedTime}
|
|
52
|
+
</Text>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
Time.propTypes = {
|
|
57
|
+
time: PropTypes.string,
|
|
58
|
+
timeOnly: PropTypes.bool,
|
|
59
|
+
relativeTime: PropTypes.bool,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { Time };
|
|
@@ -5,31 +5,26 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { MdHelp } from 'react-icons/md';
|
|
8
|
-
import
|
|
8
|
+
import * as TTip from '@radix-ui/react-tooltip';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
const Tooltip = ( { trigger = <MdHelp />, text = '', width = 200, children, ...props } ) => {
|
|
16
|
-
const [ position, setPosition ] = useState( { left: 0, top: '100%' } );
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { Card, Text } from '..';
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
if ( node !== null ) {
|
|
20
|
-
const outerX = window.innerWidth;
|
|
21
|
-
const outerY = window.innerHeight;
|
|
22
|
-
const bounds = node.getBoundingClientRect();
|
|
23
|
-
console.log( 'bounds:', bounds );
|
|
24
|
-
setPosition( {
|
|
25
|
-
left: bounds.x + bounds.width > outerX ? -bounds.width : 0,
|
|
26
|
-
top: bounds.y + bounds.height > outerY ? -bounds.height : '100%',
|
|
27
|
-
} );
|
|
28
|
-
}
|
|
29
|
-
}, [] );
|
|
15
|
+
const StyledArrow = props => <TTip.Arrow sx={{ fill: 'white' }} { ...props } />;
|
|
30
16
|
|
|
17
|
+
const Tooltip = ( {
|
|
18
|
+
trigger = <MdHelp />,
|
|
19
|
+
text = '',
|
|
20
|
+
width = 200,
|
|
21
|
+
children,
|
|
22
|
+
tooltipProps,
|
|
23
|
+
...props
|
|
24
|
+
} ) => {
|
|
31
25
|
return (
|
|
32
|
-
<
|
|
26
|
+
<TTip.Root
|
|
27
|
+
skipDelayDuration={ 700 }
|
|
33
28
|
sx={ {
|
|
34
29
|
display: 'inline-block',
|
|
35
30
|
position: 'relative',
|
|
@@ -45,31 +40,41 @@ const Tooltip = ( { trigger = <MdHelp />, text = '', width = 200, children, ...p
|
|
|
45
40
|
},
|
|
46
41
|
},
|
|
47
42
|
} }
|
|
43
|
+
{ ...tooltipProps }
|
|
48
44
|
>
|
|
49
|
-
<
|
|
50
|
-
<Card
|
|
51
|
-
ref={ contentRef }
|
|
52
|
-
className="tooltip-content"
|
|
45
|
+
<TTip.Trigger
|
|
53
46
|
sx={ {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
background: 'transparent',
|
|
48
|
+
border: 'none',
|
|
49
|
+
display: 'inline-flex',
|
|
50
|
+
outline: 'none',
|
|
51
|
+
p: 0,
|
|
52
|
+
m: 0,
|
|
59
53
|
} }
|
|
60
|
-
{ ...props }
|
|
61
54
|
>
|
|
62
|
-
{
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
{ trigger }
|
|
56
|
+
|
|
57
|
+
<TTip.Content>
|
|
58
|
+
<Card
|
|
59
|
+
className="tooltip-content"
|
|
60
|
+
sx={ { width: width } }
|
|
61
|
+
{ ...props }
|
|
62
|
+
>
|
|
63
|
+
{ children ? children : <Text sx={ { fontSize: 1 } }>{ text }</Text> }
|
|
64
|
+
</Card>
|
|
65
|
+
<StyledArrow />
|
|
66
|
+
</TTip.Content>
|
|
67
|
+
</TTip.Trigger>
|
|
68
|
+
</TTip.Root>
|
|
65
69
|
);
|
|
66
70
|
};
|
|
67
71
|
|
|
68
72
|
Tooltip.propTypes = {
|
|
73
|
+
children: PropTypes.object,
|
|
74
|
+
text: PropTypes.string,
|
|
75
|
+
tooltipProps: PropTypes.object,
|
|
69
76
|
trigger: PropTypes.string,
|
|
70
77
|
width: PropTypes.number,
|
|
71
|
-
text: PropTypes.string,
|
|
72
|
-
children: PropTypes.object,
|
|
73
78
|
};
|
|
74
79
|
|
|
75
80
|
export { Tooltip };
|
|
@@ -12,7 +12,7 @@ import { MdArrowForward } from 'react-icons/md';
|
|
|
12
12
|
*/
|
|
13
13
|
import { Box, WizardStep, Flex, WizardStepHorizontal } from '..';
|
|
14
14
|
|
|
15
|
-
const Wizard = ({ steps, activeStep, variant, completed = [], ...props }) => {
|
|
15
|
+
const Wizard = ( { steps, activeStep, variant, completed = [], ...props } ) => {
|
|
16
16
|
return (
|
|
17
17
|
<Box>
|
|
18
18
|
{variant === 'horizontal' ? (
|
|
@@ -23,7 +23,7 @@ const Wizard = ({ steps, activeStep, variant, completed = [], ...props }) => {
|
|
|
23
23
|
}}
|
|
24
24
|
{...props}
|
|
25
25
|
>
|
|
26
|
-
{steps.map(({ title, subTitle }, index) => (
|
|
26
|
+
{steps.map( ( { title, subTitle }, index ) => (
|
|
27
27
|
<React.Fragment key={index}>
|
|
28
28
|
<WizardStepHorizontal
|
|
29
29
|
active={index === activeStep}
|
|
@@ -32,22 +32,22 @@ const Wizard = ({ steps, activeStep, variant, completed = [], ...props }) => {
|
|
|
32
32
|
/>
|
|
33
33
|
{index < steps.length - 1 && <MdArrowForward sx={{ mx: 2, color: 'grey.80' }} />}
|
|
34
34
|
</React.Fragment>
|
|
35
|
-
))}
|
|
35
|
+
) )}
|
|
36
36
|
</Flex>
|
|
37
|
-
{steps[activeStep].children}
|
|
37
|
+
{steps[ activeStep ].children}
|
|
38
38
|
</Box>
|
|
39
39
|
) : (
|
|
40
|
-
steps.map(({ title, subTitle, children }, index) => (
|
|
40
|
+
steps.map( ( { title, subTitle, children }, index ) => (
|
|
41
41
|
<WizardStep
|
|
42
42
|
active={index === activeStep}
|
|
43
43
|
title={title}
|
|
44
44
|
subTitle={subTitle}
|
|
45
|
-
complete={completed.includes(index)}
|
|
45
|
+
complete={completed.includes( index )}
|
|
46
46
|
key={index}
|
|
47
47
|
>
|
|
48
48
|
{children}
|
|
49
49
|
</WizardStep>
|
|
50
|
-
))
|
|
50
|
+
) )
|
|
51
51
|
)}
|
|
52
52
|
</Box>
|
|
53
53
|
);
|