cozy-ui 66.1.0 → 66.2.2

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,29 @@
1
+ ## [66.2.2](https://github.com/cozy/cozy-ui/compare/v66.2.1...v66.2.2) (2022-05-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **IconButton:** Implementation of forwardRef ([a6405ba](https://github.com/cozy/cozy-ui/commit/a6405ba))
7
+
8
+ ## [66.2.1](https://github.com/cozy/cozy-ui/compare/v66.2.0...v66.2.1) (2022-05-05)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * IconButton propagates ref ([0aba625](https://github.com/cozy/cozy-ui/commit/0aba625))
14
+
15
+ # [66.2.0](https://github.com/cozy/cozy-ui/compare/v66.1.0...v66.2.0) (2022-05-03)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * Small size for IconButton ([63b6f70](https://github.com/cozy/cozy-ui/commit/63b6f70))
21
+
22
+
23
+ ### Features
24
+
25
+ * Add CircleButton ([bd2692a](https://github.com/cozy/cozy-ui/commit/bd2692a))
26
+
1
27
  # [66.1.0](https://github.com/cozy/cozy-ui/compare/v66.0.0...v66.1.0) (2022-05-03)
2
28
 
3
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "66.1.0",
3
+ "version": "66.2.2",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -29,11 +29,9 @@
29
29
  "build:doc:react": "styleguidist build --config docs/styleguide.config.js",
30
30
  "build": "env BABEL_ENV=transpilation babel --extensions .ts,.tsx,.js,.jsx react/ --out-dir transpiled/react --verbose",
31
31
  "clean:doc:kss": "rm -rf build/styleguide",
32
- "commitmsg": "commitlint -e $GIT_PARAMS",
33
32
  "deploy:doc": "git-directory-deploy --directory build/ --branch gh-pages",
34
33
  "makeSvgr": "scripts/generate-svgr-icon.sh",
35
34
  "lint": "npm-run-all 'lint:*'",
36
- "lint:commit": "git merge-base HEAD master && commitlint --from=$(git merge-base HEAD master) --to=HEAD || true",
37
35
  "lint:js": "eslint 'react/**/*.jsx' 'react/**/*.js' 'react/**/*.ts' 'docs/styleguide.config.js'",
38
36
  "lint:stylus": "stylint stylus --config .stylintrc",
39
37
  "lint:md": "remark . -o -S",
@@ -49,6 +47,7 @@
49
47
  "jest": "yarn test:jest",
50
48
  "screenshots": "node scripts/screenshots.js --screenshot-dir ./screenshots --styleguide-url file://$(pwd)/build/react --kss-dir ./build/styleguide",
51
49
  "test": "yarn test:jest",
50
+ "test:update:expl": "yarn test react/examples.spec.jsx -u",
52
51
  "screenshots:server": "nodemon ./scripts/pixelmatch-server/server.js -e js,hbs",
53
52
  "test:jest": "jest",
54
53
  "postbuild": "postcss transpiled/react/stylesheet.css --replace",
@@ -87,8 +86,6 @@
87
86
  "babel-plugin-inline-json-import": "0.3.2",
88
87
  "babel-preset-cozy-app": "2.0.2",
89
88
  "browserslist-config-cozy": "0.4.0",
90
- "commitlint": "7.6.1",
91
- "commitlint-config-cozy": "0.6.0",
92
89
  "copyfiles": "2.4.1",
93
90
  "cozy-client": "28.2.0",
94
91
  "cozy-device-helper": "2.0.0",
@@ -110,7 +107,6 @@
110
107
  "git-directory-deploy": "1.5.1",
111
108
  "handlebars": "^4.7.6",
112
109
  "http-server": "0.13.0",
113
- "husky": "0.14.3",
114
110
  "identity-obj-proxy": "3.0.0",
115
111
  "jest-canvas-mock": "2.3.1",
116
112
  "jest-cli": "^26.6.3",
@@ -0,0 +1,120 @@
1
+ ```jsx
2
+ import CircleButton from 'cozy-ui/transpiled/react/CircleButton'
3
+ import Icon from 'cozy-ui/transpiled/react/Icon'
4
+ import HeartIcon from 'cozy-ui/transpiled/react/Icons/Heart'
5
+ import PeopleIcon from 'cozy-ui/transpiled/react/Icons/People'
6
+
7
+ // <-- only useful for the documentation
8
+ import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
9
+ import Stack from 'cozy-ui/transpiled/react/Stack'
10
+ import Typography from 'cozy-ui/transpiled/react/Typography'
11
+ import Variants from 'cozy-ui/docs/components/Variants'
12
+
13
+ const columns = [{ title: 'default', disabled: false }, { title: 'disabled', disabled: true }]
14
+ const initialVariants = [{ default: true, active: false }]
15
+ // -->
16
+
17
+ ;
18
+
19
+ <Variants initialVariants={initialVariants} radio={true} screenshotAllVariants>
20
+ {variant => (
21
+ <Grid container>
22
+ {columns.map(column =>
23
+ <Grid item xs={12} sm={6} className="u-mb-1" key={JSON.stringify(column)}>
24
+ <Stack spacing="s">
25
+ <Typography>{Object.values(column)[0]}</Typography>
26
+ <CircleButton
27
+ label="Button"
28
+ disabled={Object.values(column)[1]}
29
+ variant={Object.keys(variant).find(key => variant[key])}
30
+ >
31
+ <Icon icon={HeartIcon} />
32
+ </CircleButton>
33
+ <CircleButton
34
+ label="Long label button"
35
+ disabled={Object.values(column)[1]}
36
+ variant={Object.keys(variant).find(key => variant[key])}
37
+ >
38
+ <Icon icon={HeartIcon} />
39
+ </CircleButton>
40
+ <CircleButton
41
+ disabled={Object.values(column)[1]}
42
+ variant={Object.keys(variant).find(key => variant[key])}
43
+ >
44
+ <Icon icon={PeopleIcon} />
45
+ </CircleButton>
46
+ </Stack>
47
+ </Grid>
48
+ )}
49
+ </Grid>
50
+ )}
51
+ </Variants>
52
+ ```
53
+
54
+ ### Use case
55
+
56
+ Can be used in a responsive container to distribute the elements.
57
+
58
+ ```jsx
59
+ import CircleButton from 'cozy-ui/transpiled/react/CircleButton'
60
+ import Icon from 'cozy-ui/transpiled/react/Icon'
61
+ import HeartIcon from 'cozy-ui/transpiled/react/Icons/Heart'
62
+ import PeopleIcon from 'cozy-ui/transpiled/react/Icons/People'
63
+
64
+ // <-- only useful for the documentation
65
+ import Typography from 'cozy-ui/transpiled/react/Typography'
66
+ import Variants from 'cozy-ui/docs/components/Variants'
67
+
68
+ const initialVariants = [{ fullWidth: false }]
69
+ const styles = {
70
+ display: 'flex',
71
+ justifyContent: 'center',
72
+ flexWrap: 'wrap'
73
+ }
74
+ // -->
75
+
76
+ ;
77
+
78
+ <Variants initialVariants={initialVariants} screenshotAllVariants>
79
+ {variant => (
80
+ <div style={styles}>
81
+ <CircleButton
82
+ label="Label"
83
+ fullWidth={variant.fullWidth}
84
+ >
85
+ <Icon icon={HeartIcon} />
86
+ </CircleButton>
87
+ <CircleButton
88
+ label="Very long long label"
89
+ fullWidth={variant.fullWidth}
90
+ >
91
+ <Icon icon={HeartIcon} />
92
+ </CircleButton>
93
+ <CircleButton
94
+ label="Label"
95
+ fullWidth={variant.fullWidth}
96
+ >
97
+ <Icon icon={HeartIcon} />
98
+ </CircleButton>
99
+ <CircleButton
100
+ label="Label"
101
+ fullWidth={variant.fullWidth}
102
+ >
103
+ <Icon icon={HeartIcon} />
104
+ </CircleButton>
105
+ <CircleButton
106
+ label="Very long long label"
107
+ fullWidth={variant.fullWidth}
108
+ >
109
+ <Icon icon={HeartIcon} />
110
+ </CircleButton>
111
+ <CircleButton
112
+ label="Label"
113
+ fullWidth={variant.fullWidth}
114
+ >
115
+ <Icon icon={HeartIcon} />
116
+ </CircleButton>
117
+ </div>
118
+ )}
119
+ </Variants>
120
+ ```
@@ -0,0 +1,16 @@
1
+ export const makeTypoColor = ({ theme, active, disabled }) => {
2
+ if (disabled) {
3
+ return theme.palette.text.disabled
4
+ }
5
+ if (active) {
6
+ return theme.palette.primary.main
7
+ }
8
+ return theme.palette.text.primary
9
+ }
10
+
11
+ export const makeButtonShadow = ({ theme, active, disabled }) => {
12
+ if (disabled || !active) {
13
+ return `inset 0 0 0 1px ${theme.palette.border.main}`
14
+ }
15
+ return `none`
16
+ }
@@ -0,0 +1,61 @@
1
+ import { makeTypoColor, makeButtonShadow } from './helpers'
2
+
3
+ const theme = {
4
+ palette: {
5
+ primary: { main: 'white' },
6
+ text: { disabled: 'lightGrey', primary: 'grey' },
7
+ border: { main: 'paleGrey' }
8
+ }
9
+ }
10
+
11
+ describe('makeTypoColor', () => {
12
+ it('should be correct color by default', () => {
13
+ const res = makeTypoColor({ theme, active: false, disabled: false })
14
+
15
+ expect(res).toBe('grey')
16
+ })
17
+
18
+ it('should be correct color when disabled', () => {
19
+ const res = makeTypoColor({ theme, active: false, disabled: true })
20
+
21
+ expect(res).toBe('lightGrey')
22
+ })
23
+
24
+ it('should be correct color when active', () => {
25
+ const res = makeTypoColor({ theme, active: true, disabled: false })
26
+
27
+ expect(res).toBe('white')
28
+ })
29
+
30
+ it('should be correct color when active disabled', () => {
31
+ const res = makeTypoColor({ theme, active: true, disabled: true })
32
+
33
+ expect(res).toBe('lightGrey')
34
+ })
35
+ })
36
+
37
+ describe('makeButtonShadow', () => {
38
+ it('should be correct color by default', () => {
39
+ const res = makeButtonShadow({ theme, active: false, disabled: false })
40
+
41
+ expect(res).toBe('inset 0 0 0 1px paleGrey')
42
+ })
43
+
44
+ it('should be correct color when disabled', () => {
45
+ const res = makeButtonShadow({ theme, active: false, disabled: true })
46
+
47
+ expect(res).toBe('inset 0 0 0 1px paleGrey')
48
+ })
49
+
50
+ it('should be none when active', () => {
51
+ const res = makeButtonShadow({ theme, active: true, disabled: false })
52
+
53
+ expect(res).toBe('none')
54
+ })
55
+
56
+ it('should be correct color when active disabled', () => {
57
+ const res = makeButtonShadow({ theme, active: true, disabled: true })
58
+
59
+ expect(res).toBe('inset 0 0 0 1px paleGrey')
60
+ })
61
+ })
@@ -0,0 +1,82 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import { makeStyles } from '@material-ui/core/styles'
4
+
5
+ import Box from '../Box'
6
+ import IconButton from '../IconButton'
7
+ import Typography from '../Typography'
8
+ import { makeTypoColor, makeButtonShadow } from './helpers'
9
+
10
+ const useStyles = makeStyles(theme => ({
11
+ iconButton: {
12
+ margin: '0 auto',
13
+ boxShadow: ({ active, disabled }) =>
14
+ makeButtonShadow({ theme, active, disabled }),
15
+ backgroundColor: ({ active }) =>
16
+ active ? theme.palette.primary.main : 'transparent',
17
+ color: ({ active }) =>
18
+ active ? theme.palette.primary.contrastText : theme.palette.text.icon,
19
+ '&:hover': {
20
+ backgroundColor: ({ active }) =>
21
+ active ? theme.palette.primary.dark : theme.palette.action.hover
22
+ }
23
+ },
24
+ typography: {
25
+ marginTop: '0.25rem',
26
+ color: ({ active, disabled }) => makeTypoColor({ theme, active, disabled })
27
+ }
28
+ }))
29
+
30
+ const CircleButton = ({
31
+ className,
32
+ label,
33
+ variant = 'default',
34
+ disabled,
35
+ fullWidth = false,
36
+ children,
37
+ ...props
38
+ }) => {
39
+ const styles = useStyles({ active: variant === 'active', disabled })
40
+
41
+ return (
42
+ <Box
43
+ className={className}
44
+ display="inline-flex"
45
+ flexDirection="column"
46
+ flexGrow={fullWidth ? 1 : undefined}
47
+ minWidth="64px"
48
+ flexBasis="64px"
49
+ padding="8px 0 4px 0"
50
+ >
51
+ <IconButton
52
+ className={styles.iconButton}
53
+ size="large"
54
+ disabled={disabled}
55
+ {...props}
56
+ >
57
+ {children}
58
+ </IconButton>
59
+ {label && (
60
+ <Typography
61
+ component="div"
62
+ className={styles.typography}
63
+ variant="caption"
64
+ align="center"
65
+ noWrap
66
+ >
67
+ {label}
68
+ </Typography>
69
+ )}
70
+ </Box>
71
+ )
72
+ }
73
+
74
+ CircleButton.propTypes = {
75
+ className: PropTypes.string,
76
+ label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
77
+ variant: PropTypes.oneOf(['default', 'active']),
78
+ disabled: PropTypes.bool,
79
+ fullWidth: PropTypes.bool
80
+ }
81
+
82
+ export default CircleButton
@@ -1,15 +1,19 @@
1
- import React from 'react'
1
+ import React, { forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import cx from 'classnames'
4
4
  import MuiIconButton from '@material-ui/core/IconButton'
5
5
 
6
- const IconButton = ({ size = 'medium', className, children, ...props }) => {
7
- return (
8
- <MuiIconButton className={cx(className, size)} {...props}>
9
- {children}
10
- </MuiIconButton>
11
- )
12
- }
6
+ const IconButton = forwardRef(
7
+ ({ size = 'medium', className, children, ...props }, ref) => {
8
+ return (
9
+ <MuiIconButton ref={ref} className={cx(className, size)} {...props}>
10
+ {children}
11
+ </MuiIconButton>
12
+ )
13
+ }
14
+ )
15
+
16
+ IconButton.displayName = 'IconButton'
13
17
 
14
18
  IconButton.propTypes = {
15
19
  className: PropTypes.string,
@@ -666,6 +666,12 @@ const makeOverrides = theme => ({
666
666
  MuiIconButton: {
667
667
  root: {
668
668
  color: theme.palette.text.secondary,
669
+ '&.small': {
670
+ padding: 3
671
+ },
672
+ '&.medium': {
673
+ padding: 12
674
+ },
669
675
  '&.large': {
670
676
  padding: 16
671
677
  },
package/react/index.js CHANGED
@@ -105,3 +105,4 @@ export { default as FilePicker } from './FilePicker'
105
105
  export { default as Chips } from './Chips'
106
106
  export { default as PieChart } from './PieChart'
107
107
  export { default as DropdownText } from './DropdownText'
108
+ export { default as CircleButton } from './CircleButton'
@@ -0,0 +1,26 @@
1
+ export var makeTypoColor = function makeTypoColor(_ref) {
2
+ var theme = _ref.theme,
3
+ active = _ref.active,
4
+ disabled = _ref.disabled;
5
+
6
+ if (disabled) {
7
+ return theme.palette.text.disabled;
8
+ }
9
+
10
+ if (active) {
11
+ return theme.palette.primary.main;
12
+ }
13
+
14
+ return theme.palette.text.primary;
15
+ };
16
+ export var makeButtonShadow = function makeButtonShadow(_ref2) {
17
+ var theme = _ref2.theme,
18
+ active = _ref2.active,
19
+ disabled = _ref2.disabled;
20
+
21
+ if (disabled || !active) {
22
+ return "inset 0 0 0 1px ".concat(theme.palette.border.main);
23
+ }
24
+
25
+ return "none";
26
+ };
@@ -0,0 +1,97 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["className", "label", "variant", "disabled", "fullWidth", "children"];
4
+ import React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import { makeStyles } from '@material-ui/core/styles';
7
+ import Box from "cozy-ui/transpiled/react/Box";
8
+ import IconButton from "cozy-ui/transpiled/react/IconButton";
9
+ import Typography from "cozy-ui/transpiled/react/Typography";
10
+ import { makeTypoColor, makeButtonShadow } from "cozy-ui/transpiled/react/CircleButton/helpers";
11
+ var useStyles = makeStyles(function (theme) {
12
+ return {
13
+ iconButton: {
14
+ margin: '0 auto',
15
+ boxShadow: function boxShadow(_ref) {
16
+ var active = _ref.active,
17
+ disabled = _ref.disabled;
18
+ return makeButtonShadow({
19
+ theme: theme,
20
+ active: active,
21
+ disabled: disabled
22
+ });
23
+ },
24
+ backgroundColor: function backgroundColor(_ref2) {
25
+ var active = _ref2.active;
26
+ return active ? theme.palette.primary.main : 'transparent';
27
+ },
28
+ color: function color(_ref3) {
29
+ var active = _ref3.active;
30
+ return active ? theme.palette.primary.contrastText : theme.palette.text.icon;
31
+ },
32
+ '&:hover': {
33
+ backgroundColor: function backgroundColor(_ref4) {
34
+ var active = _ref4.active;
35
+ return active ? theme.palette.primary.dark : theme.palette.action.hover;
36
+ }
37
+ }
38
+ },
39
+ typography: {
40
+ marginTop: '0.25rem',
41
+ color: function color(_ref5) {
42
+ var active = _ref5.active,
43
+ disabled = _ref5.disabled;
44
+ return makeTypoColor({
45
+ theme: theme,
46
+ active: active,
47
+ disabled: disabled
48
+ });
49
+ }
50
+ }
51
+ };
52
+ });
53
+
54
+ var CircleButton = function CircleButton(_ref6) {
55
+ var className = _ref6.className,
56
+ label = _ref6.label,
57
+ _ref6$variant = _ref6.variant,
58
+ variant = _ref6$variant === void 0 ? 'default' : _ref6$variant,
59
+ disabled = _ref6.disabled,
60
+ _ref6$fullWidth = _ref6.fullWidth,
61
+ fullWidth = _ref6$fullWidth === void 0 ? false : _ref6$fullWidth,
62
+ children = _ref6.children,
63
+ props = _objectWithoutProperties(_ref6, _excluded);
64
+
65
+ var styles = useStyles({
66
+ active: variant === 'active',
67
+ disabled: disabled
68
+ });
69
+ return /*#__PURE__*/React.createElement(Box, {
70
+ className: className,
71
+ display: "inline-flex",
72
+ flexDirection: "column",
73
+ flexGrow: fullWidth ? 1 : undefined,
74
+ minWidth: "64px",
75
+ flexBasis: "64px",
76
+ padding: "8px 0 4px 0"
77
+ }, /*#__PURE__*/React.createElement(IconButton, _extends({
78
+ className: styles.iconButton,
79
+ size: "large",
80
+ disabled: disabled
81
+ }, props), children), label && /*#__PURE__*/React.createElement(Typography, {
82
+ component: "div",
83
+ className: styles.typography,
84
+ variant: "caption",
85
+ align: "center",
86
+ noWrap: true
87
+ }, label));
88
+ };
89
+
90
+ CircleButton.propTypes = {
91
+ className: PropTypes.string,
92
+ label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
93
+ variant: PropTypes.oneOf(['default', 'active']),
94
+ disabled: PropTypes.bool,
95
+ fullWidth: PropTypes.bool
96
+ };
97
+ export default CircleButton;
@@ -1,12 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["size", "className", "children"];
4
- import React from 'react';
4
+ import React, { forwardRef } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import cx from 'classnames';
7
7
  import MuiIconButton from '@material-ui/core/IconButton';
8
-
9
- var IconButton = function IconButton(_ref) {
8
+ var IconButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
10
9
  var _ref$size = _ref.size,
11
10
  size = _ref$size === void 0 ? 'medium' : _ref$size,
12
11
  className = _ref.className,
@@ -14,10 +13,11 @@ var IconButton = function IconButton(_ref) {
14
13
  props = _objectWithoutProperties(_ref, _excluded);
15
14
 
16
15
  return /*#__PURE__*/React.createElement(MuiIconButton, _extends({
16
+ ref: ref,
17
17
  className: cx(className, size)
18
18
  }, props), children);
19
- };
20
-
19
+ });
20
+ IconButton.displayName = 'IconButton';
21
21
  IconButton.propTypes = {
22
22
  className: PropTypes.string,
23
23
  size: PropTypes.oneOf(['small', 'medium', 'large'])
@@ -606,6 +606,12 @@ var makeOverrides = function makeOverrides(theme) {
606
606
  MuiIconButton: {
607
607
  root: {
608
608
  color: theme.palette.text.secondary,
609
+ '&.small': {
610
+ padding: 3
611
+ },
612
+ '&.medium': {
613
+ padding: 12
614
+ },
609
615
  '&.large': {
610
616
  padding: 16
611
617
  },
@@ -82,4 +82,5 @@ export { default as BottomSheet, BottomSheetItem } from './BottomSheet';
82
82
  export { default as FilePicker } from './FilePicker';
83
83
  export { default as Chips } from './Chips';
84
84
  export { default as PieChart } from './PieChart';
85
- export { default as DropdownText } from './DropdownText';
85
+ export { default as DropdownText } from './DropdownText';
86
+ export { default as CircleButton } from './CircleButton';