cozy-ui 75.6.1 → 76.0.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 CHANGED
@@ -1,3 +1,22 @@
1
+ # [76.0.0](https://github.com/cozy/cozy-ui/compare/v75.6.1...v76.0.0) (2022-10-05)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **List:** Change default color and position of List element ([2f11d48](https://github.com/cozy/cozy-ui/commit/2f11d48))
7
+ * **NestedSelect:** Remove useless divider in header ([b4c4f46](https://github.com/cozy/cozy-ui/commit/b4c4f46))
8
+ * **NestedSelect:** Remove useless style override in ItemRow ([b9e347e](https://github.com/cozy/cozy-ui/commit/b9e347e))
9
+
10
+
11
+ ### Features
12
+
13
+ * Add CircularChart component ([d1b7283](https://github.com/cozy/cozy-ui/commit/d1b7283))
14
+
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ * **List:** Style, color and position of List elements have been readjusted. The result may not be appropriate for your use case, refer to the documentation to apply adjustments if necessary.
19
+
1
20
  ## [75.6.1](https://github.com/cozy/cozy-ui/compare/v75.6.0...v75.6.1) (2022-09-30)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "75.6.1",
3
+ "version": "76.0.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -0,0 +1,59 @@
1
+ import React, { forwardRef } from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ import { makeStyles } from '../styles'
5
+ import MuiCircularProgress from '../CircularProgress'
6
+
7
+ const useStyles = makeStyles({
8
+ root: {
9
+ position: ({ position }) => position ?? undefined
10
+ },
11
+ svg: {
12
+ transform: 'rotate(-117deg)'
13
+ },
14
+ circle: {
15
+ strokeLinecap: 'round'
16
+ },
17
+ colorPrimary: {
18
+ color: ({ color }) => color ?? undefined
19
+ }
20
+ })
21
+
22
+ const computeValue = value => (value * 65) / 100
23
+
24
+ const CircularChartProgress = forwardRef(
25
+ ({ value, position, color, size, thickness, ...props }, ref) => {
26
+ const styles = useStyles({ color, position })
27
+ const computedValue = computeValue(value)
28
+
29
+ return (
30
+ <MuiCircularProgress
31
+ ref={ref}
32
+ classes={styles}
33
+ value={computedValue}
34
+ thickness={thickness}
35
+ size={size}
36
+ {...props}
37
+ />
38
+ )
39
+ }
40
+ )
41
+
42
+ CircularChartProgress.displayName = 'CircularChartProgress'
43
+
44
+ CircularChartProgress.defaultProps = {
45
+ value: 0,
46
+ variant: 'determinate',
47
+ size: 150,
48
+ thickness: 2.3
49
+ }
50
+
51
+ CircularChartProgress.propTypes = {
52
+ value: PropTypes.number,
53
+ position: PropTypes.string,
54
+ color: PropTypes.string,
55
+ size: PropTypes.number,
56
+ thickness: PropTypes.number
57
+ }
58
+
59
+ export default CircularChartProgress
@@ -0,0 +1,43 @@
1
+ import React, { forwardRef } from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ import Box from '../Box'
5
+ import CircularChartProgress from './CircularChartProgress'
6
+
7
+ const CircularProgressWithBackground = forwardRef(
8
+ ({ value, color, backgroundColor, size, thickness, ...props }, ref) => {
9
+ return (
10
+ <Box ref={ref} position="relative" display="inline-flex" {...props}>
11
+ <CircularChartProgress
12
+ size={size}
13
+ color={backgroundColor}
14
+ thickness={thickness}
15
+ position="absolute"
16
+ value={100}
17
+ />
18
+ <CircularChartProgress
19
+ value={value}
20
+ color={color}
21
+ size={size}
22
+ thickness={thickness}
23
+ />
24
+ </Box>
25
+ )
26
+ }
27
+ )
28
+
29
+ CircularProgressWithBackground.displayName = 'CircularProgressWithBackground'
30
+
31
+ CircularProgressWithBackground.defaultProps = {
32
+ backgroundColor: 'var(--actionColorGhost)'
33
+ }
34
+
35
+ CircularProgressWithBackground.propTypes = {
36
+ value: PropTypes.number,
37
+ color: PropTypes.string,
38
+ backgroundColor: PropTypes.string,
39
+ size: PropTypes.number,
40
+ thickness: PropTypes.number
41
+ }
42
+
43
+ export default CircularProgressWithBackground
@@ -0,0 +1,130 @@
1
+ ### Basic usage
2
+
3
+ ```bash
4
+ import CircularChart from 'cozy-ui/transpiled/react/CircularChart'
5
+
6
+ <CircularChart primaryProps={{ value: 70 }} secondaryProps={{ value: 30 }}>
7
+ {children}
8
+ </CircularChart>
9
+ ```
10
+
11
+ ### Demo
12
+
13
+ ```jsx
14
+ import CircularChart from 'cozy-ui/transpiled/react/CircularChart'
15
+ import Typography from 'cozy-ui/transpiled/react/Typography'
16
+ import Box from 'cozy-ui/transpiled/react/Box'
17
+ import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
18
+ import Icon from 'cozy-ui/transpiled/react/Icon'
19
+ import BikeIcon from 'cozy-ui/transpiled/react/Icons/Bike'
20
+
21
+ ;
22
+
23
+ <Grid container>
24
+
25
+ <Grid item xs={12} sm={6} className="u-mb-1">
26
+ <div>
27
+ <CircularChart
28
+ primaryProps={{ value: 70 }}
29
+ >
30
+ {isTesting()
31
+ ? <Icon icon={BikeIcon} size={72} />
32
+ : <Box fontSize="4.5rem">🚴</Box>
33
+ }
34
+ </CircularChart>
35
+ </div>
36
+ <div>
37
+ <CircularChart
38
+ size="medium"
39
+ primaryProps={{ value: 70 }}
40
+ >
41
+ {isTesting()
42
+ ? <Icon icon={BikeIcon} size={48} />
43
+ : <Box fontSize="3rem">🚴</Box>
44
+ }
45
+ </CircularChart>
46
+ </div>
47
+ <div>
48
+ <CircularChart
49
+ size="small"
50
+ primaryProps={{ value: 70 }}
51
+ >
52
+ {isTesting()
53
+ ? <Icon icon={BikeIcon} size={40} />
54
+ : <Box fontSize="2.5rem">🚴</Box>
55
+ }
56
+ </CircularChart>
57
+ </div>
58
+ </Grid>
59
+
60
+ <Grid item xs={12} sm={6} className="u-mb-1">
61
+ <div>
62
+ <CircularChart
63
+ primaryProps={{ value: 70 }}
64
+ secondaryProps={{ value: 30 }}
65
+ >
66
+ {isTesting()
67
+ ? <Icon icon={BikeIcon} size={72} />
68
+ : <Box fontSize="4.5rem">🚴</Box>
69
+ }
70
+ </CircularChart>
71
+ </div>
72
+ <div>
73
+ <CircularChart
74
+ size="medium"
75
+ primaryProps={{ value: 70 }}
76
+ secondaryProps={{ value: 30 }}
77
+ >
78
+ {isTesting()
79
+ ? <Icon icon={BikeIcon} size={48} />
80
+ : <Box fontSize="3rem">🚴</Box>
81
+ }
82
+ </CircularChart>
83
+ </div>
84
+ <div>
85
+ <CircularChart
86
+ size="small"
87
+ primaryProps={{ value: 70 }}
88
+ secondaryProps={{ value: 30 }}
89
+ >
90
+ {isTesting()
91
+ ? <Icon icon={BikeIcon} size={40} />
92
+ : <Box fontSize="2.5rem">🚴</Box>
93
+ }
94
+ </CircularChart>
95
+ </div>
96
+ </Grid>
97
+
98
+ </Grid>
99
+ ```
100
+
101
+ ### Fully customised
102
+
103
+ ```jsx
104
+ import CircularChart from 'cozy-ui/transpiled/react/CircularChart'
105
+ import Typography from 'cozy-ui/transpiled/react/Typography'
106
+
107
+ ;
108
+
109
+ <>
110
+ <CircularChart
111
+ primaryProps={{
112
+ value: 70,
113
+ color: '#BA5AE8',
114
+ backgroundColor: '#BA5AE83D',
115
+ size: 200,
116
+ thickness: 3
117
+ }}
118
+ secondaryProps={{
119
+ value: 30,
120
+ color: '#F1B61E',
121
+ backgroundColor: '#F1B61E3D',
122
+ size: 165,
123
+ thickness: 0.75
124
+ }}
125
+ >
126
+ <Typography variant="h3">Main title</Typography>
127
+ <Typography>secondary text</Typography>
128
+ </CircularChart>
129
+ </>
130
+ ```
@@ -0,0 +1,97 @@
1
+ import { makeSizeAndThickness } from './helpers'
2
+
3
+ describe('makeSizeAndThickness', () => {
4
+ describe('with hasTwoBar false', () => {
5
+ it('small values', () => {
6
+ const res = makeSizeAndThickness('small', false)
7
+
8
+ expect(res).toStrictEqual({
9
+ primarySizeAndThickness: {
10
+ size: 85,
11
+ thickness: 2.66
12
+ },
13
+ secondarySizeAndThickness: {
14
+ size: 73,
15
+ thickness: 2.5
16
+ }
17
+ })
18
+ })
19
+
20
+ it('medium values', () => {
21
+ const res = makeSizeAndThickness('medium', false)
22
+
23
+ expect(res).toStrictEqual({
24
+ primarySizeAndThickness: {
25
+ size: 102,
26
+ thickness: 2.527
27
+ },
28
+ secondarySizeAndThickness: {
29
+ size: 88,
30
+ thickness: 2.2
31
+ }
32
+ })
33
+ })
34
+
35
+ it('large values', () => {
36
+ const res = makeSizeAndThickness('large', false)
37
+
38
+ expect(res).toStrictEqual({
39
+ primarySizeAndThickness: {
40
+ size: 150,
41
+ thickness: 2.261
42
+ },
43
+ secondarySizeAndThickness: {
44
+ size: 132,
45
+ thickness: 1.9
46
+ }
47
+ })
48
+ })
49
+ })
50
+
51
+ describe('with hasTwoBar true', () => {
52
+ it('small values', () => {
53
+ const res = makeSizeAndThickness('small', true)
54
+
55
+ expect(res).toStrictEqual({
56
+ primarySizeAndThickness: {
57
+ size: 85,
58
+ thickness: 2
59
+ },
60
+ secondarySizeAndThickness: {
61
+ size: 73,
62
+ thickness: 2.5
63
+ }
64
+ })
65
+ })
66
+
67
+ it('medium values', () => {
68
+ const res = makeSizeAndThickness('medium', true)
69
+
70
+ expect(res).toStrictEqual({
71
+ primarySizeAndThickness: {
72
+ size: 102,
73
+ thickness: 1.9
74
+ },
75
+ secondarySizeAndThickness: {
76
+ size: 88,
77
+ thickness: 2.2
78
+ }
79
+ })
80
+ })
81
+
82
+ it('large values', () => {
83
+ const res = makeSizeAndThickness('large', true)
84
+
85
+ expect(res).toStrictEqual({
86
+ primarySizeAndThickness: {
87
+ size: 150,
88
+ thickness: 1.7
89
+ },
90
+ secondarySizeAndThickness: {
91
+ size: 132,
92
+ thickness: 1.9
93
+ }
94
+ })
95
+ })
96
+ })
97
+ })
@@ -0,0 +1,46 @@
1
+ const makeThickness = (thickness: number, hasTwoBar: boolean): number => {
2
+ return hasTwoBar ? thickness : thickness * 1.33
3
+ }
4
+
5
+ export const makeSizeAndThickness = (
6
+ size: string,
7
+ hasTwoBar: boolean
8
+ ): object => {
9
+ switch (size) {
10
+ case 'small':
11
+ return {
12
+ primarySizeAndThickness: {
13
+ size: 85,
14
+ thickness: makeThickness(2, hasTwoBar)
15
+ },
16
+ secondarySizeAndThickness: {
17
+ size: 73,
18
+ thickness: 2.5
19
+ }
20
+ }
21
+
22
+ case 'medium':
23
+ return {
24
+ primarySizeAndThickness: {
25
+ size: 102,
26
+ thickness: makeThickness(1.9, hasTwoBar)
27
+ },
28
+ secondarySizeAndThickness: {
29
+ size: 88,
30
+ thickness: 2.2
31
+ }
32
+ }
33
+
34
+ default:
35
+ return {
36
+ primarySizeAndThickness: {
37
+ size: 150,
38
+ thickness: makeThickness(1.7, hasTwoBar)
39
+ },
40
+ secondarySizeAndThickness: {
41
+ size: 132,
42
+ thickness: 1.9
43
+ }
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,77 @@
1
+ import React, { forwardRef } from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ import Box from '../Box'
5
+ import CircularProgressWithBackground from './CircularProgressWithBackground'
6
+ import { makeSizeAndThickness } from './helpers'
7
+
8
+ const CircularChart = forwardRef(
9
+ ({ size, primaryProps, secondaryProps, children, ...props }, ref) => {
10
+ const {
11
+ primarySizeAndThickness,
12
+ secondarySizeAndThickness
13
+ } = makeSizeAndThickness(size, Boolean(secondaryProps))
14
+
15
+ return (
16
+ <Box
17
+ ref={ref}
18
+ position="relative"
19
+ display="inline-flex"
20
+ justifyContent="center"
21
+ alignItems="center"
22
+ {...props}
23
+ >
24
+ {Boolean(primaryProps) && (
25
+ <CircularProgressWithBackground
26
+ {...primarySizeAndThickness}
27
+ {...primaryProps}
28
+ />
29
+ )}
30
+ {Boolean(secondaryProps) && (
31
+ <CircularProgressWithBackground
32
+ {...secondarySizeAndThickness}
33
+ {...secondaryProps}
34
+ position="absolute"
35
+ />
36
+ )}
37
+ <Box
38
+ position="absolute"
39
+ display="flex"
40
+ flexDirection="column"
41
+ justifyContent="center"
42
+ alignItems="center"
43
+ paddingBottom="1rem"
44
+ >
45
+ {children}
46
+ </Box>
47
+ </Box>
48
+ )
49
+ }
50
+ )
51
+
52
+ CircularChart.displayName = 'CircularChart'
53
+
54
+ CircularChart.defaultProps = {
55
+ size: 'large'
56
+ }
57
+
58
+ CircularChart.propTypes = {
59
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
60
+ primaryProps: PropTypes.shape({
61
+ value: PropTypes.number,
62
+ color: PropTypes.string,
63
+ backgroundColor: PropTypes.string,
64
+ size: PropTypes.number,
65
+ thickness: PropTypes.number
66
+ }),
67
+ secondaryProps: PropTypes.shape({
68
+ value: PropTypes.number,
69
+ color: PropTypes.string,
70
+ backgroundColor: PropTypes.string,
71
+ size: PropTypes.number,
72
+ thickness: PropTypes.number
73
+ }),
74
+ children: PropTypes.node
75
+ }
76
+
77
+ export default CircularChart