forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSummaryCard.js
More file actions
81 lines (77 loc) · 1.88 KB
/
SummaryCard.js
File metadata and controls
81 lines (77 loc) · 1.88 KB
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
import React from 'react'
import { Text, Box } from '@chakra-ui/core'
import { objectOf, number, string, shape, arrayOf } from 'prop-types'
import { Doughnut, Segment } from './Doughnut'
function SummaryCard({ title, categoryDisplay, description, data }) {
return (
<Box
bg="white"
rounded="lg"
overflow="hidden"
boxShadow="medium"
width="min-content"
height="min-content"
>
<Box bg="primary" px="8">
<Text
fontSize="xl"
fontWeight="semibold"
textAlign="center"
color="white"
>
{title}
</Text>
<Text
fontSize="md"
textAlign="center"
color="white"
wordBreak="break-word"
>
{description}
</Text>
</Box>
<Box width="boxes.2">
<Doughnut
title={title}
data={data.categories.map(({ name, count, percentage }) => ({
title: categoryDisplay[name].name,
count,
percentage,
total: data.total,
}))}
color="#2e2e40"
height={320}
width={320}
valueAccessor={(d) => d.count}
>
{(segmentProps, index) => (
<Segment key={`segment:${index}`} {...segmentProps} />
)}
</Doughnut>
</Box>
</Box>
)
}
SummaryCard.propTypes = {
title: string.isRequired,
description: string.isRequired,
// An object of keys whose values have a shape:
categoryDisplay: objectOf(
shape({
name: string.isRequired,
color: string.isRequired,
}),
),
// An object with the following keys & values:
data: shape({
total: number.isRequired,
categories: arrayOf(
shape({
name: string.isRequired,
count: number.isRequired,
percentage: number.isRequired,
}),
),
}),
}
export default SummaryCard