cozy-ui 62.9.1 → 62.12.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/CHANGELOG.md +29 -0
- package/CODEOWNERS +2 -0
- package/package.json +8 -5
- package/react/ActionMenu/index.jsx +2 -1
- package/react/BottomSheet/BottomSheet.jsx +53 -45
- package/react/Dialog/index.jsx +7 -3
- package/react/DropdownText/Readme.md +53 -0
- package/react/DropdownText/index.jsx +79 -0
- package/react/PieChart/Readme.md +53 -0
- package/react/PieChart/index.jsx +141 -0
- package/react/PieChart/index.spec.jsx +123 -0
- package/react/SelectionBar/index.jsx +8 -4
- package/react/Sidebar/index.jsx +2 -1
- package/react/Viewer/Viewer.jsx +131 -0
- package/react/Viewer/ViewerContainer.jsx +88 -0
- package/react/Viewer/ViewerInformationsWrapper.jsx +61 -0
- package/react/Viewer/ViewerWithCustomPanelAndFooter.jsx +52 -0
- package/react/Viewer/index.jsx +8 -310
- package/react/Viewer/proptypes.js +9 -0
- package/react/__snapshots__/examples.spec.jsx.snap +351 -230
- package/react/examples.spec.jsx +2 -1
- package/react/hooks/useSetFlagshipUi/useSetFlagshipUI.spec.ts +122 -31
- package/react/hooks/useSetFlagshipUi/useSetFlagshipUI.ts +7 -5
- package/react/index.js +2 -0
- package/transpiled/react/ActionMenu/index.js +1 -1
- package/transpiled/react/BottomSheet/BottomSheet.js +16 -6
- package/transpiled/react/Dialog/index.js +4 -3
- package/transpiled/react/DropdownText/index.js +80 -0
- package/transpiled/react/PieChart/index.js +164 -0
- package/transpiled/react/SelectionBar/index.js +1 -1
- package/transpiled/react/Sidebar/index.js +1 -1
- package/transpiled/react/Viewer/Viewer.js +169 -0
- package/transpiled/react/Viewer/ViewerContainer.js +99 -0
- package/transpiled/react/Viewer/ViewerInformationsWrapper.js +41 -0
- package/transpiled/react/Viewer/ViewerWithCustomPanelAndFooter.js +48 -0
- package/transpiled/react/Viewer/index.js +5 -337
- package/transpiled/react/Viewer/proptypes.js +9 -0
- package/transpiled/react/hooks/useSetFlagshipUi/useSetFlagshipUI.js +5 -5
- package/transpiled/react/index.js +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
# [62.12.0](https://github.com/cozy/cozy-ui/compare/v62.11.0...v62.12.0) (2022-04-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Hide bottom of screen in immersive mode ([65fcc5f](https://github.com/cozy/cozy-ui/commit/65fcc5f))
|
|
7
|
+
* Revert icons to white in immersive mode ([43bc925](https://github.com/cozy/cozy-ui/commit/43bc925))
|
|
8
|
+
* Upgrade cozy-intent and cozy-device-helper ([44904b4](https://github.com/cozy/cozy-ui/commit/44904b4))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* Use new caller API in components ([10742b0](https://github.com/cozy/cozy-ui/commit/10742b0))
|
|
14
|
+
|
|
15
|
+
# [62.11.0](https://github.com/cozy/cozy-ui/compare/v62.10.0...v62.11.0) (2022-04-22)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* Add dropdown ([ee214f8](https://github.com/cozy/cozy-ui/commit/ee214f8))
|
|
21
|
+
|
|
22
|
+
# [62.10.0](https://github.com/cozy/cozy-ui/compare/v62.9.1...v62.10.0) (2022-04-21)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* Add chart.js and react-chartjs-2 packages ([16df033](https://github.com/cozy/cozy-ui/commit/16df033))
|
|
28
|
+
* Add PieChart component ([b7ce49f](https://github.com/cozy/cozy-ui/commit/b7ce49f))
|
|
29
|
+
|
|
1
30
|
## [62.9.1](https://github.com/cozy/cozy-ui/compare/v62.9.0...v62.9.1) (2022-04-21)
|
|
2
31
|
|
|
3
32
|
|
package/CODEOWNERS
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-ui",
|
|
3
|
-
"version": "62.
|
|
3
|
+
"version": "62.12.0",
|
|
4
4
|
"description": "Cozy apps UI SDK",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"prebuild:css:kss": "mkdir -p build/styleguide && stylus -C node_modules/normalize.css/normalize.css node_modules/normalize.css/normalize.styl",
|
|
44
44
|
"prebuild:doc:kss": "run-s clean:doc:kss build:css:kss",
|
|
45
45
|
"prepare": "yarn release",
|
|
46
|
-
"prepush": "[[ $(git rev-parse --abbrev-ref HEAD) != 'gh-pages' ]] && yarn lint || true",
|
|
47
46
|
"release": "npm-run-all --parallel sprite palette && yarn build",
|
|
48
47
|
"semantic-release": "semantic-release",
|
|
49
48
|
"sprite": "scripts/make-icon-sprite.sh",
|
|
@@ -92,10 +91,10 @@
|
|
|
92
91
|
"commitlint-config-cozy": "0.6.0",
|
|
93
92
|
"copyfiles": "2.4.1",
|
|
94
93
|
"cozy-client": "27.19.1",
|
|
95
|
-
"cozy-device-helper": "
|
|
94
|
+
"cozy-device-helper": "1.18.0",
|
|
96
95
|
"cozy-doctypes": "^1.69.0",
|
|
97
96
|
"cozy-harvest-lib": "^6.7.3",
|
|
98
|
-
"cozy-intent": "1.
|
|
97
|
+
"cozy-intent": "1.16.1",
|
|
99
98
|
"cozy-sharing": "^3.10.0",
|
|
100
99
|
"cozy-stack-client": "27.19.1",
|
|
101
100
|
"css-loader": "0.28.11",
|
|
@@ -113,6 +112,7 @@
|
|
|
113
112
|
"http-server": "0.13.0",
|
|
114
113
|
"husky": "0.14.3",
|
|
115
114
|
"identity-obj-proxy": "3.0.0",
|
|
115
|
+
"jest-canvas-mock": "2.3.1",
|
|
116
116
|
"jest-cli": "^26.6.3",
|
|
117
117
|
"kss": "3.0.1",
|
|
118
118
|
"kss-webpack-plugin": "1.5.0",
|
|
@@ -153,6 +153,7 @@
|
|
|
153
153
|
"dependencies": {
|
|
154
154
|
"@babel/runtime": "^7.3.4",
|
|
155
155
|
"@popperjs/core": "^2.4.4",
|
|
156
|
+
"chart.js": "3.7.1",
|
|
156
157
|
"classnames": "^2.2.5",
|
|
157
158
|
"cozy-interapp": "^0.5.4",
|
|
158
159
|
"date-fns": "^1.28.5",
|
|
@@ -164,6 +165,7 @@
|
|
|
164
165
|
"node-polyglot": "^2.2.2",
|
|
165
166
|
"normalize.css": "^8.0.0",
|
|
166
167
|
"piwik-react-router": "0.12.1",
|
|
168
|
+
"react-chartjs-2": "4.1.0",
|
|
167
169
|
"react-markdown": "^4.0.8",
|
|
168
170
|
"react-pdf": "^4.0.5",
|
|
169
171
|
"react-popper": "^2.2.3",
|
|
@@ -200,7 +202,8 @@
|
|
|
200
202
|
},
|
|
201
203
|
"jest": {
|
|
202
204
|
"setupFilesAfterEnv": [
|
|
203
|
-
"./test/jestsetup.js"
|
|
205
|
+
"./test/jestsetup.js",
|
|
206
|
+
"jest-canvas-mock"
|
|
204
207
|
],
|
|
205
208
|
"moduleFileExtensions": [
|
|
206
209
|
"js",
|
|
@@ -2,6 +2,8 @@ import React, { useState, useEffect, useRef, useMemo } from 'react'
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import { BottomSheet as MuiBottomSheet } from 'mui-bottom-sheet'
|
|
4
4
|
|
|
5
|
+
import { flagshipMetadata } from 'cozy-device-helper'
|
|
6
|
+
|
|
5
7
|
import Stack from 'cozy-ui/transpiled/react/Stack'
|
|
6
8
|
import Paper from 'cozy-ui/transpiled/react/Paper'
|
|
7
9
|
|
|
@@ -27,6 +29,15 @@ const makeStyles = ({ isTopPosition }) => ({
|
|
|
27
29
|
},
|
|
28
30
|
stack: {
|
|
29
31
|
backgroundColor: 'var(--defaultBackgroundColor)'
|
|
32
|
+
},
|
|
33
|
+
flagshipImmersive: {
|
|
34
|
+
backgroundColor: 'var(--paperBackgroundColor)',
|
|
35
|
+
bottom: 0,
|
|
36
|
+
content: '',
|
|
37
|
+
height: 'var(--flagship-bottom-height)',
|
|
38
|
+
position: 'fixed',
|
|
39
|
+
width: '100%',
|
|
40
|
+
zIndex: 'var(--zIndex-modal)'
|
|
30
41
|
}
|
|
31
42
|
})
|
|
32
43
|
|
|
@@ -97,18 +108,11 @@ const BottomSheet = ({ toolbarProps, settings, children }) => {
|
|
|
97
108
|
)
|
|
98
109
|
: 0
|
|
99
110
|
|
|
100
|
-
// Will return 0 if the variable is not set
|
|
101
|
-
const flagshipBottomOffset = Number(
|
|
102
|
-
getComputedStyle(document.body)
|
|
103
|
-
.getPropertyValue('--flagship-bottom-height')
|
|
104
|
-
.replace('px', '')
|
|
105
|
-
)
|
|
106
|
-
|
|
107
111
|
const minHeight =
|
|
108
112
|
headerRef.current.offsetHeight +
|
|
109
113
|
actionButtonsHeight +
|
|
110
114
|
actionButtonsBottomMargin +
|
|
111
|
-
|
|
115
|
+
(flagshipMetadata.navbarHeight || 0)
|
|
112
116
|
|
|
113
117
|
// Used so that the bottomSheet can be opened to the top,
|
|
114
118
|
// without stopping at the content height
|
|
@@ -149,43 +153,47 @@ const BottomSheet = ({ toolbarProps, settings, children }) => {
|
|
|
149
153
|
})
|
|
150
154
|
|
|
151
155
|
return (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
156
|
+
<>
|
|
157
|
+
{flagshipMetadata.immersive && <span style={styles.flagshipImmersive} />}
|
|
158
|
+
|
|
159
|
+
<MuiBottomSheet
|
|
160
|
+
peekHeights={peekHeights}
|
|
161
|
+
defaultHeight={initPos}
|
|
162
|
+
backdrop={false}
|
|
163
|
+
fullHeight={false}
|
|
164
|
+
onIndexChange={snapIndex => handleOnIndexChange(snapIndex)}
|
|
165
|
+
styles={{ root: styles.root }}
|
|
166
|
+
threshold={0}
|
|
167
|
+
// springConfig doc : https://docs.pmnd.rs/react-spring/common/configs
|
|
168
|
+
springConfig={{
|
|
169
|
+
tension: defaultBottomSheetSpringConfig.tension,
|
|
170
|
+
friction: defaultBottomSheetSpringConfig.friction,
|
|
171
|
+
clamp: defaultBottomSheetSpringConfig.clamp
|
|
172
|
+
}}
|
|
173
|
+
disabledClosing={true}
|
|
174
|
+
snapPointSeekerMode="next"
|
|
175
|
+
>
|
|
176
|
+
<div ref={innerContentRef}>
|
|
177
|
+
<Paper
|
|
178
|
+
data-testid="bottomSheet-header"
|
|
179
|
+
className="u-w-100 u-h-2-half u-pos-relative u-flex u-flex-items-center u-flex-justify-center"
|
|
180
|
+
ref={headerRef}
|
|
181
|
+
elevation={0}
|
|
182
|
+
square
|
|
183
|
+
>
|
|
184
|
+
<div style={styles.indicator} />
|
|
185
|
+
</Paper>
|
|
186
|
+
<Stack
|
|
187
|
+
style={styles.stack}
|
|
188
|
+
className="u-flex u-flex-column u-ov-hidden"
|
|
189
|
+
spacing="s"
|
|
190
|
+
>
|
|
191
|
+
{overriddenChildren}
|
|
192
|
+
</Stack>
|
|
193
|
+
</div>
|
|
194
|
+
<div style={{ height: bottomSpacerHeight }} />
|
|
195
|
+
</MuiBottomSheet>
|
|
196
|
+
</>
|
|
189
197
|
)
|
|
190
198
|
}
|
|
191
199
|
|
package/react/Dialog/index.jsx
CHANGED
|
@@ -3,6 +3,8 @@ import { RemoveScroll } from 'react-remove-scroll'
|
|
|
3
3
|
import { default as MUIDialog } from '@material-ui/core/Dialog'
|
|
4
4
|
import { useTheme } from '@material-ui/core'
|
|
5
5
|
|
|
6
|
+
import { flagshipMetadata } from 'cozy-device-helper'
|
|
7
|
+
|
|
6
8
|
import useBreakpoints from '../hooks/useBreakpoints'
|
|
7
9
|
import { useCozyTheme } from '../CozyTheme'
|
|
8
10
|
import themesStyles from '../../stylus/settings/palette.styl'
|
|
@@ -47,16 +49,18 @@ const Dialog = props => {
|
|
|
47
49
|
},
|
|
48
50
|
{
|
|
49
51
|
bottomBackground: theme.palette.background[sidebar ? 'default' : 'paper'],
|
|
50
|
-
bottomTheme: 'dark',
|
|
52
|
+
bottomTheme: flagshipMetadata.immersive ? 'light' : 'dark',
|
|
51
53
|
bottomOverlay: 'transparent',
|
|
52
54
|
topOverlay: 'transparent',
|
|
53
55
|
topBackground:
|
|
54
56
|
cozBar && getComputedStyle(cozBar).getPropertyValue('background-color'),
|
|
55
57
|
topTheme:
|
|
56
|
-
|
|
58
|
+
flagshipMetadata.immersive ||
|
|
59
|
+
(cozBar && cozBar.classList.contains('coz-theme-primary'))
|
|
57
60
|
? 'light'
|
|
58
61
|
: 'dark'
|
|
59
|
-
}
|
|
62
|
+
},
|
|
63
|
+
'cozy-ui/Dialog'
|
|
60
64
|
)
|
|
61
65
|
|
|
62
66
|
return (
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
This component can be used as a trigger to open menus, for example an ActionMenu component. There is also `DropdownButton` which offers the same possibilities, but with the added button wrapper.
|
|
2
|
+
|
|
3
|
+
```jsx
|
|
4
|
+
import DropdownText from 'cozy-ui/transpiled/react/DropdownText'
|
|
5
|
+
import Typography from 'cozy-ui/transpiled/react/Typography'
|
|
6
|
+
import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
|
|
7
|
+
|
|
8
|
+
const variants = [
|
|
9
|
+
'h1',
|
|
10
|
+
'h2',
|
|
11
|
+
'h3',
|
|
12
|
+
'h4',
|
|
13
|
+
'h5',
|
|
14
|
+
'subtitle1',
|
|
15
|
+
'subtitle2',
|
|
16
|
+
'body1',
|
|
17
|
+
'body2',
|
|
18
|
+
'caption'
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
;
|
|
22
|
+
|
|
23
|
+
<>
|
|
24
|
+
<Grid container>
|
|
25
|
+
<Grid item xs={6}>
|
|
26
|
+
Default
|
|
27
|
+
{variants.map((variant, index) => (
|
|
28
|
+
<div key={index} className='u-mb-1'>
|
|
29
|
+
<DropdownText variant={variant}>
|
|
30
|
+
{variant}
|
|
31
|
+
</DropdownText>
|
|
32
|
+
</div>
|
|
33
|
+
))}
|
|
34
|
+
</Grid>
|
|
35
|
+
<Grid item xs={6}>
|
|
36
|
+
Disabled
|
|
37
|
+
{variants.map((variant, index) => (
|
|
38
|
+
<div key={index} className='u-mb-1'>
|
|
39
|
+
<DropdownText variant={variant} disabled>
|
|
40
|
+
{variant}
|
|
41
|
+
</DropdownText>
|
|
42
|
+
</div>
|
|
43
|
+
))}
|
|
44
|
+
</Grid>
|
|
45
|
+
</Grid>
|
|
46
|
+
<DropdownText spaceBetween style={{ border: '1px solid var(--borderMainColor)', width: '100%', marginBottom: '1rem' }}>
|
|
47
|
+
Space between text and icon
|
|
48
|
+
</DropdownText>
|
|
49
|
+
<DropdownText style={{ border: '1px solid var(--borderMainColor)' }}>
|
|
50
|
+
Text with<br />breaking spaces<br />inside content
|
|
51
|
+
</DropdownText>
|
|
52
|
+
</>
|
|
53
|
+
```
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { makeStyles } from '@material-ui/core/styles'
|
|
4
|
+
|
|
5
|
+
import Typography from '../Typography'
|
|
6
|
+
import Icon from '../Icon'
|
|
7
|
+
import BottomIcon from '../Icons/Bottom'
|
|
8
|
+
|
|
9
|
+
const useStyles = makeStyles(theme => ({
|
|
10
|
+
endIcon: {
|
|
11
|
+
marginLeft: '5px'
|
|
12
|
+
},
|
|
13
|
+
typography: {
|
|
14
|
+
display: 'flex',
|
|
15
|
+
alignItems: 'center',
|
|
16
|
+
width: '100%',
|
|
17
|
+
justifyContent: ({ spaceBetween }) =>
|
|
18
|
+
spaceBetween ? 'space-between' : 'left',
|
|
19
|
+
color: ({ disabled }) =>
|
|
20
|
+
theme.palette.text[disabled ? 'disabled' : 'primary']
|
|
21
|
+
}
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
const endIconSizeByVariant = {
|
|
25
|
+
h1: 24,
|
|
26
|
+
h2: 17,
|
|
27
|
+
h3: 15,
|
|
28
|
+
h4: 14,
|
|
29
|
+
h5: 13,
|
|
30
|
+
h6: 12,
|
|
31
|
+
body1: 12,
|
|
32
|
+
body2: 11,
|
|
33
|
+
caption: 10,
|
|
34
|
+
subtitle1: 11,
|
|
35
|
+
subtitle2: 10
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const DropdownText = forwardRef(
|
|
39
|
+
(
|
|
40
|
+
{
|
|
41
|
+
spaceBetween = false,
|
|
42
|
+
variant = 'body1',
|
|
43
|
+
disabled = false,
|
|
44
|
+
children,
|
|
45
|
+
...props
|
|
46
|
+
},
|
|
47
|
+
ref
|
|
48
|
+
) => {
|
|
49
|
+
const styles = useStyles({ spaceBetween, disabled })
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Typography
|
|
53
|
+
ref={ref}
|
|
54
|
+
classes={{ root: styles.typography }}
|
|
55
|
+
variant={variant}
|
|
56
|
+
{...props}
|
|
57
|
+
>
|
|
58
|
+
{children}
|
|
59
|
+
<Icon
|
|
60
|
+
className={styles.endIcon}
|
|
61
|
+
icon={BottomIcon}
|
|
62
|
+
size={endIconSizeByVariant[variant]}
|
|
63
|
+
/>
|
|
64
|
+
</Typography>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
DropdownText.propTypes = {
|
|
70
|
+
/** Whether there is a space between the label and the icon */
|
|
71
|
+
spaceBetween: PropTypes.bool,
|
|
72
|
+
/** Variant used by Typography component */
|
|
73
|
+
variant: PropTypes.string,
|
|
74
|
+
/** Whether the component is disabled */
|
|
75
|
+
disabled: PropTypes.bool,
|
|
76
|
+
children: PropTypes.node
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default DropdownText
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#### PieChart
|
|
2
|
+
|
|
3
|
+
```jsx
|
|
4
|
+
import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
|
|
5
|
+
import PieChart from 'cozy-ui/transpiled/react/PieChart'
|
|
6
|
+
|
|
7
|
+
;
|
|
8
|
+
|
|
9
|
+
<Grid container>
|
|
10
|
+
<Grid item xs={12} sm={6}>
|
|
11
|
+
<PieChart
|
|
12
|
+
single={true}
|
|
13
|
+
primaryText="60 %"
|
|
14
|
+
secondaryText="of the total"
|
|
15
|
+
data={{
|
|
16
|
+
labels: ['Health'],
|
|
17
|
+
datasets: [{ data: [60, 40] }]
|
|
18
|
+
}}
|
|
19
|
+
options={{
|
|
20
|
+
plugins: {
|
|
21
|
+
tooltip: {
|
|
22
|
+
callbacks: {
|
|
23
|
+
label: tooltipItems => `${tooltipItems.label}: ${tooltipItems.raw}%`
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}}
|
|
28
|
+
/>
|
|
29
|
+
</Grid>
|
|
30
|
+
<Grid item xs={12} sm={6}>
|
|
31
|
+
<PieChart
|
|
32
|
+
primaryText="105 €"
|
|
33
|
+
secondaryText="on the period"
|
|
34
|
+
data={{
|
|
35
|
+
labels: ['Earnings', 'Children', 'Sports', 'Housing', 'Health'],
|
|
36
|
+
datasets: [{
|
|
37
|
+
data: [40, 30, 20, 10, 5],
|
|
38
|
+
backgroundColor: ['#8978FF', '#FF7B5E', '#F85AA8', '#F1B61E', '#15CACD']
|
|
39
|
+
}]
|
|
40
|
+
}}
|
|
41
|
+
options={{
|
|
42
|
+
plugins: {
|
|
43
|
+
tooltip: {
|
|
44
|
+
callbacks: {
|
|
45
|
+
label: tooltipItems => `${tooltipItems.label}: ${tooltipItems.raw}€`
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
</Grid>
|
|
52
|
+
</Grid>
|
|
53
|
+
```
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import cx from 'classnames'
|
|
4
|
+
import { Chart as ChartJS, ArcElement, Tooltip } from 'chart.js'
|
|
5
|
+
import { Doughnut } from 'react-chartjs-2'
|
|
6
|
+
import { useTheme } from '@material-ui/core'
|
|
7
|
+
import { makeStyles } from '@material-ui/core/styles'
|
|
8
|
+
import set from 'lodash/set'
|
|
9
|
+
import cloneDeep from 'lodash/cloneDeep'
|
|
10
|
+
|
|
11
|
+
import Typography from '../Typography'
|
|
12
|
+
import isTesting from '../helpers/isTesting'
|
|
13
|
+
|
|
14
|
+
ChartJS.register(ArcElement, Tooltip)
|
|
15
|
+
|
|
16
|
+
const useStyles = makeStyles(theme => ({
|
|
17
|
+
container: {
|
|
18
|
+
position: 'relative',
|
|
19
|
+
zIndex: '1',
|
|
20
|
+
width: '192px',
|
|
21
|
+
height: '192px'
|
|
22
|
+
},
|
|
23
|
+
background: {
|
|
24
|
+
position: 'absolute',
|
|
25
|
+
boxSizing: 'border-box',
|
|
26
|
+
top: 0,
|
|
27
|
+
bottom: 0,
|
|
28
|
+
left: 0,
|
|
29
|
+
right: 0,
|
|
30
|
+
border: '24px solid var(--actionColorGhost)',
|
|
31
|
+
borderRadius: '100%',
|
|
32
|
+
zIndex: -1,
|
|
33
|
+
backgroundColor: ({ single }) =>
|
|
34
|
+
!single && theme.palette.type === 'dark'
|
|
35
|
+
? theme.palette.primary.main
|
|
36
|
+
: 'none',
|
|
37
|
+
boxShadow: ({ single }) =>
|
|
38
|
+
!single && theme.palette.type === 'dark'
|
|
39
|
+
? `0 0 0 2px ${theme.palette.primary.main}`
|
|
40
|
+
: 'none'
|
|
41
|
+
},
|
|
42
|
+
centerText: {
|
|
43
|
+
display: 'flex',
|
|
44
|
+
flexDirection: 'column',
|
|
45
|
+
position: 'absolute',
|
|
46
|
+
alignItems: 'center',
|
|
47
|
+
justifyContent: 'center',
|
|
48
|
+
textAlign: 'center',
|
|
49
|
+
top: '25px',
|
|
50
|
+
left: '25px',
|
|
51
|
+
right: '25px',
|
|
52
|
+
bottom: '25px',
|
|
53
|
+
borderRadius: '50%',
|
|
54
|
+
zIndex: '-1'
|
|
55
|
+
},
|
|
56
|
+
typography: {
|
|
57
|
+
color: ({ single }) =>
|
|
58
|
+
!single && theme.palette.type === 'dark'
|
|
59
|
+
? theme.palette.primary.contrastText
|
|
60
|
+
: theme.palette.text.primary
|
|
61
|
+
}
|
|
62
|
+
}))
|
|
63
|
+
|
|
64
|
+
export const makeOptions = ({ options, single }) => {
|
|
65
|
+
const madeOptions = {
|
|
66
|
+
cutout: '75%',
|
|
67
|
+
elements: {
|
|
68
|
+
arc: {
|
|
69
|
+
borderWidth: 0
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
animation: isTesting() ? false : { duration: 1000 },
|
|
73
|
+
...options
|
|
74
|
+
}
|
|
75
|
+
if (single) set(madeOptions, 'plugins.tooltip.filter', item => item.label)
|
|
76
|
+
|
|
77
|
+
return madeOptions
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const makeData = ({ data, single, theme }) => {
|
|
81
|
+
const madeData = cloneDeep(data)
|
|
82
|
+
if (single)
|
|
83
|
+
set(madeData, 'datasets[0].backgroundColor', [
|
|
84
|
+
theme.palette.primary.main,
|
|
85
|
+
'transparent'
|
|
86
|
+
])
|
|
87
|
+
|
|
88
|
+
return madeData
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const PieChart = ({
|
|
92
|
+
data,
|
|
93
|
+
options = {},
|
|
94
|
+
primaryText,
|
|
95
|
+
secondaryText,
|
|
96
|
+
single = false,
|
|
97
|
+
className,
|
|
98
|
+
...props
|
|
99
|
+
}) => {
|
|
100
|
+
const theme = useTheme()
|
|
101
|
+
const classes = useStyles({ single })
|
|
102
|
+
const madeOptions = makeOptions({ options, single })
|
|
103
|
+
const madeData = makeData({ data, single, theme })
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div className={cx(classes.container, className)} {...props}>
|
|
107
|
+
<div className={classes.background} />
|
|
108
|
+
<Doughnut data={madeData} options={madeOptions} />
|
|
109
|
+
{(primaryText || secondaryText) && (
|
|
110
|
+
<div className={classes.centerText}>
|
|
111
|
+
{primaryText && (
|
|
112
|
+
<Typography classes={{ root: classes.typography }} variant="h3">
|
|
113
|
+
{primaryText}
|
|
114
|
+
</Typography>
|
|
115
|
+
)}
|
|
116
|
+
{secondaryText && (
|
|
117
|
+
<Typography classes={{ root: classes.typography }} variant="body2">
|
|
118
|
+
{secondaryText}
|
|
119
|
+
</Typography>
|
|
120
|
+
)}
|
|
121
|
+
</div>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
PieChart.propTypes = {
|
|
128
|
+
/** Data to be passed to chart.js graph */
|
|
129
|
+
data: PropTypes.object.isRequired,
|
|
130
|
+
/** Options to be passed to chart.js graph */
|
|
131
|
+
options: PropTypes.object,
|
|
132
|
+
/** Text to show as primary */
|
|
133
|
+
primaryText: PropTypes.string,
|
|
134
|
+
/** Text to show as secondary */
|
|
135
|
+
secondaryText: PropTypes.string,
|
|
136
|
+
/** Whether to use a single data */
|
|
137
|
+
single: PropTypes.bool,
|
|
138
|
+
className: PropTypes.string
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export default PieChart
|