cozy-ui 146.3.1 → 146.5.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 +14 -0
- package/package.json +1 -1
- package/react/ColorList/Readme.md +2 -0
- package/react/ColorList/index.jsx +19 -4
- package/react/ColorList/index.spec.jsx +56 -0
- package/react/EditBadge/Readme.md +1 -0
- package/react/EditBadge/index.jsx +12 -2
- package/transpiled/react/ColorList/index.d.ts +6 -1
- package/transpiled/react/ColorList/index.js +23 -8
- package/transpiled/react/ColorList/index.spec.d.ts +1 -0
- package/transpiled/react/EditBadge/index.d.ts +6 -1
- package/transpiled/react/EditBadge/index.js +13 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [146.5.0](https://github.com/cozy/cozy-ui/compare/v146.4.0...v146.5.0) (2026-11-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **ColorList:** Name the colors ([886abac](https://github.com/cozy/cozy-ui/commit/886abac))
|
|
7
|
+
|
|
8
|
+
# [146.4.0](https://github.com/cozy/cozy-ui/compare/v146.3.1...v146.4.0) (2026-11-04)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **EditBadge:** Add componentsProps to customize the badge button ([8248bc7](https://github.com/cozy/cozy-ui/commit/8248bc7))
|
|
14
|
+
|
|
1
15
|
## [146.3.1](https://github.com/cozy/cozy-ui/compare/v146.3.0...v146.3.1) (2026-11-03)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -15,8 +15,10 @@ const ColorPickerDemo = ({ variant }) => {
|
|
|
15
15
|
<div style={{ width: (variant.medium || isMobile) ? '100%' : 200 }}>
|
|
16
16
|
<ColorList
|
|
17
17
|
size={variant.medium ? 'medium' : undefined}
|
|
18
|
+
getColorLabel={color => `Color ${color}`}
|
|
18
19
|
customColorProps={{
|
|
19
20
|
enabled: true,
|
|
21
|
+
'aria-label': 'Custom color',
|
|
20
22
|
onClick: () => {}
|
|
21
23
|
}}
|
|
22
24
|
selectedColor={selectedColor}
|
|
@@ -15,7 +15,15 @@ const sizeToPx = {
|
|
|
15
15
|
medium: 41
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const ColorList = ({
|
|
18
|
+
const ColorList = ({
|
|
19
|
+
size,
|
|
20
|
+
selectedColor,
|
|
21
|
+
getColorLabel,
|
|
22
|
+
customColorProps,
|
|
23
|
+
onClick
|
|
24
|
+
}) => {
|
|
25
|
+
const { enabled: isCustomEnabled, ...customButtonProps } =
|
|
26
|
+
customColorProps ?? {}
|
|
19
27
|
const { isMobile } = useBreakpoints()
|
|
20
28
|
|
|
21
29
|
const _size = size || (isMobile ? 'medium' : 'small')
|
|
@@ -37,6 +45,8 @@ const ColorList = ({ size, selectedColor, customColorProps, onClick }) => {
|
|
|
37
45
|
<ButtonBase
|
|
38
46
|
className="u-bdrs-circle"
|
|
39
47
|
component="div"
|
|
48
|
+
aria-label={getColorLabel?.(color) ?? color}
|
|
49
|
+
aria-pressed={selectedColor?.toUpperCase() === color}
|
|
40
50
|
onClick={() => onClick?.(color)}
|
|
41
51
|
>
|
|
42
52
|
<Avatar color={color} size={avatarSize}>
|
|
@@ -49,12 +59,13 @@ const ColorList = ({ size, selectedColor, customColorProps, onClick }) => {
|
|
|
49
59
|
</ButtonBase>
|
|
50
60
|
</ImageListItem>
|
|
51
61
|
))}
|
|
52
|
-
{
|
|
62
|
+
{isCustomEnabled && (
|
|
53
63
|
<ImageListItem
|
|
54
64
|
className="u-ta-center"
|
|
55
65
|
classes={{ item: 'u-ov-visible' }}
|
|
56
66
|
>
|
|
57
67
|
<Button
|
|
68
|
+
{...customButtonProps}
|
|
58
69
|
className="u-miw-auto u-mih-auto u-p-0 u-bdrs-circle"
|
|
59
70
|
variant="ghost"
|
|
60
71
|
style={{
|
|
@@ -68,7 +79,6 @@ const ColorList = ({ size, selectedColor, customColorProps, onClick }) => {
|
|
|
68
79
|
}}
|
|
69
80
|
classes={{ label: 'u-flex u-w-auto' }}
|
|
70
81
|
label={<Icon icon={Palette} size={iconSize} color="#000" />}
|
|
71
|
-
onClick={ev => customColorProps?.onClick(ev)}
|
|
72
82
|
/>
|
|
73
83
|
</ImageListItem>
|
|
74
84
|
)}
|
|
@@ -79,9 +89,14 @@ const ColorList = ({ size, selectedColor, customColorProps, onClick }) => {
|
|
|
79
89
|
ColorList.propTypes = {
|
|
80
90
|
size: propTypes.oneOf(['small', 'medium']),
|
|
81
91
|
selectedColor: propTypes.string,
|
|
92
|
+
/** Accessible name of a color. Defaults to its hexadecimal code */
|
|
93
|
+
getColorLabel: propTypes.func,
|
|
82
94
|
customColorProps: propTypes.shape({
|
|
83
95
|
enabled: propTypes.bool,
|
|
84
|
-
onClick: propTypes.func
|
|
96
|
+
onClick: propTypes.func,
|
|
97
|
+
'aria-label': propTypes.string,
|
|
98
|
+
'aria-pressed': propTypes.bool,
|
|
99
|
+
'data-testid': propTypes.string
|
|
85
100
|
}),
|
|
86
101
|
onClick: propTypes.func
|
|
87
102
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import ColorList from '.'
|
|
5
|
+
import { BreakpointsProvider } from '../providers/Breakpoints'
|
|
6
|
+
|
|
7
|
+
const setup = props =>
|
|
8
|
+
render(
|
|
9
|
+
<BreakpointsProvider>
|
|
10
|
+
<ColorList {...props} />
|
|
11
|
+
</BreakpointsProvider>
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
describe('ColorList', () => {
|
|
15
|
+
it('lets a keyboard reach and pick a color', () => {
|
|
16
|
+
const onClick = jest.fn()
|
|
17
|
+
setup({ onClick })
|
|
18
|
+
|
|
19
|
+
const color = screen.getByRole('button', { name: '#273891' })
|
|
20
|
+
expect(color.tabIndex).toBe(0)
|
|
21
|
+
fireEvent.keyDown(color, { key: 'Enter' })
|
|
22
|
+
expect(onClick).toHaveBeenCalledWith('#273891')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('names its colors and tells the selected one, whatever its case', () => {
|
|
26
|
+
setup({
|
|
27
|
+
selectedColor: '#7e57e3',
|
|
28
|
+
getColorLabel: color => (color === '#7E57E3' ? 'Purple' : color)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
expect(screen.getByRole('button', { name: 'Purple' })).toHaveAttribute(
|
|
32
|
+
'aria-pressed',
|
|
33
|
+
'true'
|
|
34
|
+
)
|
|
35
|
+
expect(screen.getByRole('button', { name: '#273891' })).toHaveAttribute(
|
|
36
|
+
'aria-pressed',
|
|
37
|
+
'false'
|
|
38
|
+
)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('passes its props to the custom color button', () => {
|
|
42
|
+
const onClick = jest.fn()
|
|
43
|
+
setup({
|
|
44
|
+
customColorProps: {
|
|
45
|
+
enabled: true,
|
|
46
|
+
onClick,
|
|
47
|
+
'aria-label': 'Custom color',
|
|
48
|
+
'data-testid': 'custom'
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
fireEvent.click(screen.getByRole('button', { name: 'Custom color' }))
|
|
53
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
54
|
+
expect(screen.queryByTestId('custom')).toBeInTheDocument()
|
|
55
|
+
})
|
|
56
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Icon, Pen } from '@linagora/twake-icons'
|
|
2
|
+
import cx from 'classnames'
|
|
2
3
|
import PropTypes from 'prop-types'
|
|
3
4
|
import React, { useState, useRef } from 'react'
|
|
4
5
|
|
|
@@ -12,6 +13,7 @@ const EditBadge = ({
|
|
|
12
13
|
onUpload,
|
|
13
14
|
onDelete,
|
|
14
15
|
anchorOrigin,
|
|
16
|
+
componentsProps,
|
|
15
17
|
children,
|
|
16
18
|
...props
|
|
17
19
|
}) => {
|
|
@@ -28,9 +30,13 @@ const EditBadge = ({
|
|
|
28
30
|
badgeContent={
|
|
29
31
|
<>
|
|
30
32
|
<Button
|
|
33
|
+
{...componentsProps?.button}
|
|
31
34
|
ref={menuAnchorRef}
|
|
32
35
|
component="div"
|
|
33
|
-
className=
|
|
36
|
+
className={cx(
|
|
37
|
+
'u-miw-auto u-w-2-half u-h-2-half u-bdrs-circle',
|
|
38
|
+
componentsProps?.button?.className
|
|
39
|
+
)}
|
|
34
40
|
classes={{ label: 'u-flex u-w-auto' }}
|
|
35
41
|
style={{
|
|
36
42
|
outline: '4px solid var(--paperBackgroundColor)'
|
|
@@ -74,7 +80,11 @@ EditBadge.defaultProps = {
|
|
|
74
80
|
EditBadge.propTypes = {
|
|
75
81
|
src: PropTypes.func.isRequired,
|
|
76
82
|
onUpload: PropTypes.func.isRequired,
|
|
77
|
-
onDelete: PropTypes.func.isRequired
|
|
83
|
+
onDelete: PropTypes.func.isRequired,
|
|
84
|
+
componentsProps: PropTypes.shape({
|
|
85
|
+
/** Props spread to the badge button */
|
|
86
|
+
button: PropTypes.object
|
|
87
|
+
})
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
export default EditBadge
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { COLORS };
|
|
2
2
|
export default ColorList;
|
|
3
3
|
import { COLORS } from "./helpers";
|
|
4
|
-
declare function ColorList({ size, selectedColor, customColorProps, onClick }: {
|
|
4
|
+
declare function ColorList({ size, selectedColor, getColorLabel, customColorProps, onClick }: {
|
|
5
5
|
size: any;
|
|
6
6
|
selectedColor: any;
|
|
7
|
+
getColorLabel: any;
|
|
7
8
|
customColorProps: any;
|
|
8
9
|
onClick: any;
|
|
9
10
|
}): JSX.Element;
|
|
@@ -11,9 +12,13 @@ declare namespace ColorList {
|
|
|
11
12
|
namespace propTypes {
|
|
12
13
|
const size: propTypes.Requireable<string>;
|
|
13
14
|
const selectedColor: propTypes.Requireable<string>;
|
|
15
|
+
const getColorLabel: propTypes.Requireable<(...args: any[]) => any>;
|
|
14
16
|
const customColorProps: propTypes.Requireable<propTypes.InferProps<{
|
|
15
17
|
enabled: propTypes.Requireable<boolean>;
|
|
16
18
|
onClick: propTypes.Requireable<(...args: any[]) => any>;
|
|
19
|
+
'aria-label': propTypes.Requireable<string>;
|
|
20
|
+
'aria-pressed': propTypes.Requireable<boolean>;
|
|
21
|
+
'data-testid': propTypes.Requireable<string>;
|
|
17
22
|
}>>;
|
|
18
23
|
const onClick: propTypes.Requireable<(...args: any[]) => any>;
|
|
19
24
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["enabled"];
|
|
1
4
|
import { Icon, Check, Palette } from '@linagora/twake-icons';
|
|
2
5
|
import propTypes from 'prop-types';
|
|
3
6
|
import React from 'react';
|
|
@@ -16,9 +19,14 @@ var sizeToPx = {
|
|
|
16
19
|
var ColorList = function ColorList(_ref) {
|
|
17
20
|
var size = _ref.size,
|
|
18
21
|
selectedColor = _ref.selectedColor,
|
|
22
|
+
getColorLabel = _ref.getColorLabel,
|
|
19
23
|
customColorProps = _ref.customColorProps,
|
|
20
24
|
_onClick = _ref.onClick;
|
|
21
25
|
|
|
26
|
+
var _ref2 = customColorProps !== null && customColorProps !== void 0 ? customColorProps : {},
|
|
27
|
+
isCustomEnabled = _ref2.enabled,
|
|
28
|
+
customButtonProps = _objectWithoutProperties(_ref2, _excluded);
|
|
29
|
+
|
|
22
30
|
var _useBreakpoints = useBreakpoints(),
|
|
23
31
|
isMobile = _useBreakpoints.isMobile;
|
|
24
32
|
|
|
@@ -31,6 +39,8 @@ var ColorList = function ColorList(_ref) {
|
|
|
31
39
|
rowHeight: avatarSize,
|
|
32
40
|
gap: _size === 'medium' ? 16 : 5
|
|
33
41
|
}, COLORS.map(function (color) {
|
|
42
|
+
var _getColorLabel;
|
|
43
|
+
|
|
34
44
|
return /*#__PURE__*/React.createElement(ImageListItem, {
|
|
35
45
|
key: color,
|
|
36
46
|
className: "u-ta-center",
|
|
@@ -40,6 +50,8 @@ var ColorList = function ColorList(_ref) {
|
|
|
40
50
|
}, /*#__PURE__*/React.createElement(ButtonBase, {
|
|
41
51
|
className: "u-bdrs-circle",
|
|
42
52
|
component: "div",
|
|
53
|
+
"aria-label": (_getColorLabel = getColorLabel === null || getColorLabel === void 0 ? void 0 : getColorLabel(color)) !== null && _getColorLabel !== void 0 ? _getColorLabel : color,
|
|
54
|
+
"aria-pressed": (selectedColor === null || selectedColor === void 0 ? void 0 : selectedColor.toUpperCase()) === color,
|
|
43
55
|
onClick: function onClick() {
|
|
44
56
|
return _onClick === null || _onClick === void 0 ? void 0 : _onClick(color);
|
|
45
57
|
}
|
|
@@ -50,12 +62,12 @@ var ColorList = function ColorList(_ref) {
|
|
|
50
62
|
icon: Check,
|
|
51
63
|
size: iconSize
|
|
52
64
|
}) : ' ')));
|
|
53
|
-
}),
|
|
65
|
+
}), isCustomEnabled && /*#__PURE__*/React.createElement(ImageListItem, {
|
|
54
66
|
className: "u-ta-center",
|
|
55
67
|
classes: {
|
|
56
68
|
item: 'u-ov-visible'
|
|
57
69
|
}
|
|
58
|
-
}, /*#__PURE__*/React.createElement(Button, {
|
|
70
|
+
}, /*#__PURE__*/React.createElement(Button, _extends({}, customButtonProps, {
|
|
59
71
|
className: "u-miw-auto u-mih-auto u-p-0 u-bdrs-circle",
|
|
60
72
|
variant: "ghost",
|
|
61
73
|
style: {
|
|
@@ -73,19 +85,22 @@ var ColorList = function ColorList(_ref) {
|
|
|
73
85
|
icon: Palette,
|
|
74
86
|
size: iconSize,
|
|
75
87
|
color: "#000"
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
return customColorProps === null || customColorProps === void 0 ? void 0 : customColorProps.onClick(ev);
|
|
79
|
-
}
|
|
80
|
-
})));
|
|
88
|
+
})
|
|
89
|
+
}))));
|
|
81
90
|
};
|
|
82
91
|
|
|
83
92
|
ColorList.propTypes = {
|
|
84
93
|
size: propTypes.oneOf(['small', 'medium']),
|
|
85
94
|
selectedColor: propTypes.string,
|
|
95
|
+
|
|
96
|
+
/** Accessible name of a color. Defaults to its hexadecimal code */
|
|
97
|
+
getColorLabel: propTypes.func,
|
|
86
98
|
customColorProps: propTypes.shape({
|
|
87
99
|
enabled: propTypes.bool,
|
|
88
|
-
onClick: propTypes.func
|
|
100
|
+
onClick: propTypes.func,
|
|
101
|
+
'aria-label': propTypes.string,
|
|
102
|
+
'aria-pressed': propTypes.bool,
|
|
103
|
+
'data-testid': propTypes.string
|
|
89
104
|
}),
|
|
90
105
|
onClick: propTypes.func
|
|
91
106
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export default EditBadge;
|
|
2
|
-
declare function EditBadge({ src, onUpload, onDelete, anchorOrigin, children, ...props }: {
|
|
2
|
+
declare function EditBadge({ src, onUpload, onDelete, anchorOrigin, componentsProps, children, ...props }: {
|
|
3
3
|
[x: string]: any;
|
|
4
4
|
src: any;
|
|
5
5
|
onUpload: any;
|
|
6
6
|
onDelete: any;
|
|
7
7
|
anchorOrigin: any;
|
|
8
|
+
componentsProps: any;
|
|
8
9
|
children: any;
|
|
9
10
|
}): JSX.Element;
|
|
10
11
|
declare namespace EditBadge {
|
|
@@ -18,6 +19,10 @@ declare namespace EditBadge {
|
|
|
18
19
|
const src: PropTypes.Validator<(...args: any[]) => any>;
|
|
19
20
|
const onUpload: PropTypes.Validator<(...args: any[]) => any>;
|
|
20
21
|
const onDelete: PropTypes.Validator<(...args: any[]) => any>;
|
|
22
|
+
const componentsProps: PropTypes.Requireable<PropTypes.InferProps<{
|
|
23
|
+
/** Props spread to the badge button */
|
|
24
|
+
button: PropTypes.Requireable<object>;
|
|
25
|
+
}>>;
|
|
21
26
|
}
|
|
22
27
|
}
|
|
23
28
|
import PropTypes from "prop-types";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["src", "onUpload", "onDelete", "anchorOrigin", "children"];
|
|
4
|
+
var _excluded = ["src", "onUpload", "onDelete", "anchorOrigin", "componentsProps", "children"];
|
|
5
5
|
import { Icon, Pen } from '@linagora/twake-icons';
|
|
6
|
+
import cx from 'classnames';
|
|
6
7
|
import PropTypes from 'prop-types';
|
|
7
8
|
import React, { useState, useRef } from 'react';
|
|
8
9
|
import EditMenu from "cozy-ui/transpiled/react/EditBadge/EditMenu";
|
|
@@ -11,10 +12,13 @@ import Badge from "cozy-ui/transpiled/react/Badge";
|
|
|
11
12
|
import Button from "cozy-ui/transpiled/react/Buttons";
|
|
12
13
|
|
|
13
14
|
var EditBadge = function EditBadge(_ref) {
|
|
15
|
+
var _componentsProps$butt;
|
|
16
|
+
|
|
14
17
|
var src = _ref.src,
|
|
15
18
|
onUpload = _ref.onUpload,
|
|
16
19
|
onDelete = _ref.onDelete,
|
|
17
20
|
anchorOrigin = _ref.anchorOrigin,
|
|
21
|
+
componentsProps = _ref.componentsProps,
|
|
18
22
|
children = _ref.children,
|
|
19
23
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
20
24
|
|
|
@@ -37,10 +41,10 @@ var EditBadge = function EditBadge(_ref) {
|
|
|
37
41
|
var menuAnchorRef = useRef(null);
|
|
38
42
|
return /*#__PURE__*/React.createElement(Badge, _extends({}, props, {
|
|
39
43
|
anchorOrigin: anchorOrigin,
|
|
40
|
-
badgeContent: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
|
|
44
|
+
badgeContent: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, _extends({}, componentsProps === null || componentsProps === void 0 ? void 0 : componentsProps.button, {
|
|
41
45
|
ref: menuAnchorRef,
|
|
42
46
|
component: "div",
|
|
43
|
-
className:
|
|
47
|
+
className: cx('u-miw-auto u-w-2-half u-h-2-half u-bdrs-circle', componentsProps === null || componentsProps === void 0 ? void 0 : (_componentsProps$butt = componentsProps.button) === null || _componentsProps$butt === void 0 ? void 0 : _componentsProps$butt.className),
|
|
44
48
|
classes: {
|
|
45
49
|
label: 'u-flex u-w-auto'
|
|
46
50
|
},
|
|
@@ -56,7 +60,7 @@ var EditBadge = function EditBadge(_ref) {
|
|
|
56
60
|
return !v;
|
|
57
61
|
});
|
|
58
62
|
}
|
|
59
|
-
}), /*#__PURE__*/React.createElement(EditMenu, {
|
|
63
|
+
})), /*#__PURE__*/React.createElement(EditMenu, {
|
|
60
64
|
anchorRef: menuAnchorRef.current,
|
|
61
65
|
status: status,
|
|
62
66
|
showMenu: showMenu,
|
|
@@ -83,6 +87,10 @@ EditBadge.defaultProps = {
|
|
|
83
87
|
EditBadge.propTypes = {
|
|
84
88
|
src: PropTypes.func.isRequired,
|
|
85
89
|
onUpload: PropTypes.func.isRequired,
|
|
86
|
-
onDelete: PropTypes.func.isRequired
|
|
90
|
+
onDelete: PropTypes.func.isRequired,
|
|
91
|
+
componentsProps: PropTypes.shape({
|
|
92
|
+
/** Props spread to the badge button */
|
|
93
|
+
button: PropTypes.object
|
|
94
|
+
})
|
|
87
95
|
};
|
|
88
96
|
export default EditBadge;
|