cozy-ui 95.3.0 → 95.4.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,18 @@
1
+ # [95.4.0](https://github.com/cozy/cozy-ui/compare/v95.3.0...v95.4.0) (2023-10-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **ActionsMenu:** ActionsMenuMobileHeader was unnecessarily in DOM on desktop ([805a030](https://github.com/cozy/cozy-ui/commit/805a030))
7
+ * **Menu, ActionsMenu:** The margins between elements were not as expected ([e021fdc](https://github.com/cozy/cozy-ui/commit/e021fdc))
8
+
9
+
10
+ ### Features
11
+
12
+ * **ActionsMenuItem:** Add `cozyActionsMenuItem` class to be able to target it ([fcd6dfa](https://github.com/cozy/cozy-ui/commit/fcd6dfa))
13
+ * **ListItem:** Add min heights ([ceaba86](https://github.com/cozy/cozy-ui/commit/ceaba86))
14
+ * **ListItemIcon:** Add `cozyListItemIcon` class to be able to target it ([f0b218f](https://github.com/cozy/cozy-ui/commit/f0b218f))
15
+
1
16
  # [95.3.0](https://github.com/cozy/cozy-ui/compare/v95.2.0...v95.3.0) (2023-10-18)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "95.3.0",
3
+ "version": "95.4.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -1,6 +1,7 @@
1
1
  import React, { forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import omit from 'lodash/omit'
4
+ import cx from 'classnames'
4
5
 
5
6
  import MenuItem from '../MenuItem'
6
7
  import ListItem from '../ListItem'
@@ -11,16 +12,27 @@ const cleanPropsForDOM = props => {
11
12
  return omit(props, nonDOMProps)
12
13
  }
13
14
 
14
- const ActionsMenuItem = forwardRef(({ isListItem, ...props }, ref) => {
15
- const Component = isListItem ? ListItem : MenuItem
16
- const compProps = cleanPropsForDOM(props)
17
-
18
- return <Component {...compProps} ref={ref} button ellipsis={false} />
19
- })
15
+ const ActionsMenuItem = forwardRef(
16
+ ({ isListItem, className, ...props }, ref) => {
17
+ const Component = isListItem ? ListItem : MenuItem
18
+ const compProps = cleanPropsForDOM(props)
19
+
20
+ return (
21
+ <Component
22
+ {...compProps}
23
+ className={cx(className, { ['cozyActionsMenuItem']: !isListItem })}
24
+ ref={ref}
25
+ button
26
+ ellipsis={false}
27
+ />
28
+ )
29
+ }
30
+ )
20
31
 
21
32
  ActionsMenuItem.displayName = 'ActionsMenuItem'
22
33
 
23
34
  ActionsMenuItem.propTypes = {
35
+ className: PropTypes.string,
24
36
  /** Whether the ActionsMenuItem will return a ListItem or MenuItem */
25
37
  isListItem: PropTypes.bool
26
38
  }
@@ -8,12 +8,8 @@ import useBreakpoints from '../providers/Breakpoints'
8
8
  const ActionsMenuMobileHeader = forwardRef(({ children, ...props }, ref) => {
9
9
  const { isMobile } = useBreakpoints()
10
10
 
11
- // To make accessibility work, we need to return a displayed item.
12
- // The trick is to return an empty one with no padding to simulate a display none.
13
- // Otherwise it will be impossible to use keyboard navigation for example
14
- // probably due to the inner workings of Mui
15
11
  if (!isMobile) {
16
- return <ActionsMenuItem {...props} ref={ref} className="u-p-0" />
12
+ return null
17
13
  }
18
14
 
19
15
  return (
@@ -26,6 +22,8 @@ const ActionsMenuMobileHeader = forwardRef(({ children, ...props }, ref) => {
26
22
  )
27
23
  })
28
24
 
25
+ ActionsMenuMobileHeader.displayName = 'ActionsMenuMobileHeader'
26
+
29
27
  ActionsMenuMobileHeader.propTypes = {
30
28
  children: PropTypes.node
31
29
  }
@@ -44,13 +44,24 @@ const ActionsMenuWrapper = ({
44
44
 
45
45
  return (
46
46
  <Menu {...props} open={open} onClose={onClose}>
47
- {React.Children.map(children, child =>
48
- React.isValidElement(child)
47
+ {React.Children.map(children, (child, idx) => {
48
+ // To keep accessibility, we spread the autofocus on the second child
49
+ // if the first one is ActionsMenuMobileHeader
50
+ const firstChild = React.Children.toArray(children)[0]
51
+ const firstChildComponentName =
52
+ firstChild?.type?.name || firstChild?.type?.displayName
53
+ const isFirstChildActionsMenuMobileHeader =
54
+ firstChildComponentName === 'ActionsMenuMobileHeader'
55
+ const autoFocus =
56
+ isFirstChildActionsMenuMobileHeader && idx === 1 ? true : undefined
57
+
58
+ return React.isValidElement(child)
49
59
  ? React.cloneElement(child, {
60
+ autoFocus,
50
61
  onClick: overrideClick(child.props)
51
62
  })
52
63
  : null
53
- )}
64
+ })}
54
65
  </Menu>
55
66
  )
56
67
  }
@@ -209,6 +209,9 @@ const toggleMenu = () => setState(state => ({ showMenu: !state.showMenu }))
209
209
  </ListItemIcon>
210
210
  <ListItemText primary="Attachment" />
211
211
  </ActionsMenuItem>
212
+ <ActionsMenuItem>
213
+ <ListItemText primary="Item without icon" />
214
+ </ActionsMenuItem>
212
215
 
213
216
  <Divider className="u-mv-half" />
214
217
 
@@ -1,9 +1,23 @@
1
- import ListItemIcon from '@material-ui/core/ListItemIcon'
1
+ import React, { forwardRef } from 'react'
2
+ import MuiListItemIcon from '@material-ui/core/ListItemIcon'
3
+
4
+ import cx from 'classnames'
2
5
 
3
6
  export const smallSize = 16
4
7
  export const mediumSize = 24
5
8
  export const largeSize = 32
6
9
 
10
+ // We add a specific class to be able to override the style in makeOverride when used in an other component
11
+ const ListItemIcon = forwardRef(({ className, ...props }, ref) => {
12
+ return (
13
+ <MuiListItemIcon
14
+ {...props}
15
+ ref={ref}
16
+ className={cx(className, 'cozyListItemIcon')}
17
+ />
18
+ )
19
+ })
20
+
7
21
  ListItemIcon.displayName = 'ListItemIcon'
8
22
 
9
23
  export default ListItemIcon
@@ -76,6 +76,9 @@ const hideMenu = () => setState({ showMenu: false })
76
76
  </ListItemIcon>
77
77
  <ListItemText primary="Attachment" />
78
78
  </MenuItem>
79
+ <MenuItem onClick={hideMenu}>
80
+ <ListItemText primary="Item without icon" />
81
+ </MenuItem>
79
82
 
80
83
  <Divider className="u-mv-half" />
81
84
 
@@ -293,25 +293,31 @@ export const makeOverrides = theme => ({
293
293
  gap: 16,
294
294
  paddingTop: 12,
295
295
  paddingBottom: 12,
296
+ minHeight: 56,
296
297
  '&.small': {
297
298
  paddingTop: 8,
298
- paddingBottom: 8
299
+ paddingBottom: 8,
300
+ minHeight: 48
299
301
  },
300
302
  '&.large': {
301
303
  paddingTop: 16,
302
- paddingBottom: 16
304
+ paddingBottom: 16,
305
+ minHeight: 64
303
306
  }
304
307
  },
305
308
  dense: {
306
309
  paddingTop: 8,
307
310
  paddingBottom: 8,
311
+ minHeight: 48,
308
312
  '&.small': {
309
313
  paddingTop: 4,
310
- paddingBottom: 4
314
+ paddingBottom: 4,
315
+ minHeight: 40
311
316
  },
312
317
  '&.large': {
313
318
  paddingTop: 12,
314
- paddingBottom: 12
319
+ paddingBottom: 12,
320
+ minHeight: 56
315
321
  }
316
322
  }
317
323
  },
@@ -347,16 +353,25 @@ export const makeOverrides = theme => ({
347
353
  },
348
354
  MuiMenuItem: {
349
355
  root: {
350
- gap: 8,
351
356
  maxWidth: 320,
352
357
  whiteSpace: 'normal',
353
358
  overflow: 'auto',
354
359
  paddingTop: 4,
355
- paddingBottom: 4
360
+ paddingBottom: 4,
361
+ [theme.breakpoints.up('sm')]: {
362
+ minHeight: 40
363
+ },
364
+ '&.cozyActionsMenuItem': {
365
+ minWidth: 256
366
+ },
367
+ '& .cozyListItemIcon': {
368
+ width: 16,
369
+ height: 16
370
+ }
356
371
  },
357
372
  gutters: {
358
- paddingLeft: 8,
359
- paddingRight: 8
373
+ paddingLeft: 16,
374
+ paddingRight: 16
360
375
  }
361
376
  },
362
377
  MuiFormLabel: {
@@ -1,9 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["isListItem"];
4
+ var _excluded = ["isListItem", "className"];
4
5
  import React, { forwardRef } from 'react';
5
6
  import PropTypes from 'prop-types';
6
7
  import omit from 'lodash/omit';
8
+ import cx from 'classnames';
7
9
  import MenuItem from "cozy-ui/transpiled/react/MenuItem";
8
10
  import ListItem from "cozy-ui/transpiled/react/ListItem";
9
11
 
@@ -14,11 +16,13 @@ var cleanPropsForDOM = function cleanPropsForDOM(props) {
14
16
 
15
17
  var ActionsMenuItem = /*#__PURE__*/forwardRef(function (_ref, ref) {
16
18
  var isListItem = _ref.isListItem,
19
+ className = _ref.className,
17
20
  props = _objectWithoutProperties(_ref, _excluded);
18
21
 
19
22
  var Component = isListItem ? ListItem : MenuItem;
20
23
  var compProps = cleanPropsForDOM(props);
21
24
  return /*#__PURE__*/React.createElement(Component, _extends({}, compProps, {
25
+ className: cx(className, _defineProperty({}, 'cozyActionsMenuItem', !isListItem)),
22
26
  ref: ref,
23
27
  button: true,
24
28
  ellipsis: false
@@ -26,6 +30,8 @@ var ActionsMenuItem = /*#__PURE__*/forwardRef(function (_ref, ref) {
26
30
  });
27
31
  ActionsMenuItem.displayName = 'ActionsMenuItem';
28
32
  ActionsMenuItem.propTypes = {
33
+ className: PropTypes.string,
34
+
29
35
  /** Whether the ActionsMenuItem will return a ListItem or MenuItem */
30
36
  isListItem: PropTypes.bool
31
37
  };
@@ -11,17 +11,10 @@ var ActionsMenuMobileHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
11
11
  props = _objectWithoutProperties(_ref, _excluded);
12
12
 
13
13
  var _useBreakpoints = useBreakpoints(),
14
- isMobile = _useBreakpoints.isMobile; // To make accessibility work, we need to return a displayed item.
15
- // The trick is to return an empty one with no padding to simulate a display none.
16
- // Otherwise it will be impossible to use keyboard navigation for example
17
- // probably due to the inner workings of Mui
18
-
14
+ isMobile = _useBreakpoints.isMobile;
19
15
 
20
16
  if (!isMobile) {
21
- return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
22
- ref: ref,
23
- className: "u-p-0"
24
- }));
17
+ return null;
25
18
  }
26
19
 
27
20
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
@@ -31,6 +24,7 @@ var ActionsMenuMobileHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
31
24
  className: "u-mv-half"
32
25
  }));
33
26
  });
27
+ ActionsMenuMobileHeader.displayName = 'ActionsMenuMobileHeader';
34
28
  ActionsMenuMobileHeader.propTypes = {
35
29
  children: PropTypes.node
36
30
  };
@@ -51,8 +51,17 @@ var ActionsMenuWrapper = function ActionsMenuWrapper(_ref) {
51
51
  return /*#__PURE__*/React.createElement(Menu, _extends({}, props, {
52
52
  open: open,
53
53
  onClose: onClose
54
- }), React.Children.map(children, function (child) {
54
+ }), React.Children.map(children, function (child, idx) {
55
+ var _firstChild$type, _firstChild$type2;
56
+
57
+ // To keep accessibility, we spread the autofocus on the second child
58
+ // if the first one is ActionsMenuMobileHeader
59
+ var firstChild = React.Children.toArray(children)[0];
60
+ var firstChildComponentName = (firstChild === null || firstChild === void 0 ? void 0 : (_firstChild$type = firstChild.type) === null || _firstChild$type === void 0 ? void 0 : _firstChild$type.name) || (firstChild === null || firstChild === void 0 ? void 0 : (_firstChild$type2 = firstChild.type) === null || _firstChild$type2 === void 0 ? void 0 : _firstChild$type2.displayName);
61
+ var isFirstChildActionsMenuMobileHeader = firstChildComponentName === 'ActionsMenuMobileHeader';
62
+ var autoFocus = isFirstChildActionsMenuMobileHeader && idx === 1 ? true : undefined;
55
63
  return /*#__PURE__*/React.isValidElement(child) ? /*#__PURE__*/React.cloneElement(child, {
64
+ autoFocus: autoFocus,
56
65
  onClick: overrideClick(child.props)
57
66
  }) : null;
58
67
  }));
@@ -1,6 +1,21 @@
1
- import ListItemIcon from '@material-ui/core/ListItemIcon';
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["className"];
4
+ import React, { forwardRef } from 'react';
5
+ import MuiListItemIcon from '@material-ui/core/ListItemIcon';
6
+ import cx from 'classnames';
2
7
  export var smallSize = 16;
3
8
  export var mediumSize = 24;
4
- export var largeSize = 32;
9
+ export var largeSize = 32; // We add a specific class to be able to override the style in makeOverride when used in an other component
10
+
11
+ var ListItemIcon = /*#__PURE__*/forwardRef(function (_ref, ref) {
12
+ var className = _ref.className,
13
+ props = _objectWithoutProperties(_ref, _excluded);
14
+
15
+ return /*#__PURE__*/React.createElement(MuiListItemIcon, _extends({}, props, {
16
+ ref: ref,
17
+ className: cx(className, 'cozyListItemIcon')
18
+ }));
19
+ });
5
20
  ListItemIcon.displayName = 'ListItemIcon';
6
21
  export default ListItemIcon;
@@ -8,7 +8,7 @@ import { alpha, darken } from "cozy-ui/transpiled/react/styles";
8
8
  import { makeAlertColor, makeChipStyleByColor, makeSecondaryButtonStyle, makeTextButtonStyle, makeContainedButtonStyle } from "cozy-ui/transpiled/react/MuiCozyTheme/helpers";
9
9
  var SWITCH_BAR_WIDTH = 25;
10
10
  export var makeOverrides = function makeOverrides(theme) {
11
- var _objectSpread2, _root, _root2;
11
+ var _root, _objectSpread2, _root2, _root3;
12
12
 
13
13
  return {
14
14
  MuiOutlinedInput: {
@@ -276,25 +276,31 @@ export var makeOverrides = function makeOverrides(theme) {
276
276
  gap: 16,
277
277
  paddingTop: 12,
278
278
  paddingBottom: 12,
279
+ minHeight: 56,
279
280
  '&.small': {
280
281
  paddingTop: 8,
281
- paddingBottom: 8
282
+ paddingBottom: 8,
283
+ minHeight: 48
282
284
  },
283
285
  '&.large': {
284
286
  paddingTop: 16,
285
- paddingBottom: 16
287
+ paddingBottom: 16,
288
+ minHeight: 64
286
289
  }
287
290
  },
288
291
  dense: {
289
292
  paddingTop: 8,
290
293
  paddingBottom: 8,
294
+ minHeight: 48,
291
295
  '&.small': {
292
296
  paddingTop: 4,
293
- paddingBottom: 4
297
+ paddingBottom: 4,
298
+ minHeight: 40
294
299
  },
295
300
  '&.large': {
296
301
  paddingTop: 12,
297
- paddingBottom: 12
302
+ paddingBottom: 12,
303
+ minHeight: 56
298
304
  }
299
305
  }
300
306
  },
@@ -328,17 +334,23 @@ export var makeOverrides = function makeOverrides(theme) {
328
334
  }
329
335
  },
330
336
  MuiMenuItem: {
331
- root: {
332
- gap: 8,
337
+ root: (_root = {
333
338
  maxWidth: 320,
334
339
  whiteSpace: 'normal',
335
340
  overflow: 'auto',
336
341
  paddingTop: 4,
337
342
  paddingBottom: 4
338
- },
343
+ }, _defineProperty(_root, theme.breakpoints.up('sm'), {
344
+ minHeight: 40
345
+ }), _defineProperty(_root, '&.cozyActionsMenuItem', {
346
+ minWidth: 256
347
+ }), _defineProperty(_root, '& .cozyListItemIcon', {
348
+ width: 16,
349
+ height: 16
350
+ }), _root),
339
351
  gutters: {
340
- paddingLeft: 8,
341
- paddingRight: 8
352
+ paddingLeft: 16,
353
+ paddingRight: 16
342
354
  }
343
355
  },
344
356
  MuiFormLabel: {
@@ -435,11 +447,11 @@ export var makeOverrides = function makeOverrides(theme) {
435
447
  }), _objectSpread2))
436
448
  },
437
449
  MuiDialogContent: {
438
- root: (_root = {
450
+ root: (_root2 = {
439
451
  padding: '24px 32px 0'
440
- }, _defineProperty(_root, theme.breakpoints.down('sm'), {
452
+ }, _defineProperty(_root2, theme.breakpoints.down('sm'), {
441
453
  padding: '24px 16px 0'
442
- }), _defineProperty(_root, '&.disableGutters', {
454
+ }), _defineProperty(_root2, '&.disableGutters', {
443
455
  padding: 0,
444
456
  '& .dialogContentInner': {
445
457
  marginBottom: 0
@@ -449,7 +461,7 @@ export var makeOverrides = function makeOverrides(theme) {
449
461
  marginRight: 0,
450
462
  marginTop: 0
451
463
  }
452
- }), _defineProperty(_root, '& .dialogContentInner', {
464
+ }), _defineProperty(_root2, '& .dialogContentInner', {
453
465
  marginBottom: '24px',
454
466
  '&.withFluidActions': _defineProperty({}, theme.breakpoints.down('sm'), {
455
467
  marginBottom: 0,
@@ -474,20 +486,20 @@ export var makeOverrides = function makeOverrides(theme) {
474
486
  marginRight: '-1rem',
475
487
  marginTop: '-0.75rem'
476
488
  })
477
- }), _root)
489
+ }), _root2)
478
490
  },
479
491
  MuiDialogActions: {
480
- root: (_root2 = {
492
+ root: (_root3 = {
481
493
  margin: '16px 32px',
482
494
  padding: 0
483
- }, _defineProperty(_root2, theme.breakpoints.down('sm'), {
495
+ }, _defineProperty(_root3, theme.breakpoints.down('sm'), {
484
496
  margin: '8px 16px',
485
497
  '& button': {
486
498
  flexGrow: 1
487
499
  }
488
- }), _defineProperty(_root2, '&.dialogActionsFluid', {
500
+ }), _defineProperty(_root3, '&.dialogActionsFluid', {
489
501
  margin: '24px 0 0'
490
- }), _defineProperty(_root2, '&.columnLayout', {
502
+ }), _defineProperty(_root3, '&.columnLayout', {
491
503
  display: 'flex',
492
504
  flexDirection: 'column-reverse',
493
505
  '& button': {
@@ -497,9 +509,9 @@ export var makeOverrides = function makeOverrides(theme) {
497
509
  marginBottom: '8px'
498
510
  }
499
511
  }
500
- }), _defineProperty(_root2, '&:not(.columnLayout) > :not(:first-child):not(:first-child)', {
512
+ }), _defineProperty(_root3, '&:not(.columnLayout) > :not(:first-child):not(:first-child)', {
501
513
  marginLeft: 4
502
- }), _root2)
514
+ }), _root3)
503
515
  },
504
516
  MuiDivider: {
505
517
  inset: {