@workday/canvas-kit-preview-react 11.1.6 → 11.1.7
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/color-picker/lib/ColorPicker.tsx +10 -4
- package/color-picker/lib/parts/SwatchBook.tsx +34 -22
- package/dist/commonjs/color-picker/lib/ColorPicker.d.ts +2 -1
- package/dist/commonjs/color-picker/lib/ColorPicker.d.ts.map +1 -1
- package/dist/commonjs/color-picker/lib/ColorPicker.js +8 -1
- package/dist/commonjs/color-picker/lib/parts/SwatchBook.d.ts +5 -1
- package/dist/commonjs/color-picker/lib/parts/SwatchBook.d.ts.map +1 -1
- package/dist/commonjs/color-picker/lib/parts/SwatchBook.js +11 -7
- package/dist/es6/color-picker/lib/ColorPicker.d.ts +2 -1
- package/dist/es6/color-picker/lib/ColorPicker.d.ts.map +1 -1
- package/dist/es6/color-picker/lib/ColorPicker.js +8 -1
- package/dist/es6/color-picker/lib/parts/SwatchBook.d.ts +5 -1
- package/dist/es6/color-picker/lib/parts/SwatchBook.d.ts.map +1 -1
- package/dist/es6/color-picker/lib/parts/SwatchBook.js +11 -7
- package/package.json +4 -4
|
@@ -7,7 +7,7 @@ import {FormField} from '@workday/canvas-kit-preview-react/form-field';
|
|
|
7
7
|
import styled from '@emotion/styled';
|
|
8
8
|
|
|
9
9
|
import {ResetButton} from './parts/ColorReset';
|
|
10
|
-
import {SwatchBook} from './parts/SwatchBook';
|
|
10
|
+
import {SwatchBook, SwatchBookColorObject} from './parts/SwatchBook';
|
|
11
11
|
|
|
12
12
|
export interface ColorPickerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
13
13
|
/**
|
|
@@ -21,7 +21,7 @@ export interface ColorPickerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
21
21
|
/**
|
|
22
22
|
* The array of colors to be rendered in the swatchbook.
|
|
23
23
|
*/
|
|
24
|
-
colorSet?: string[];
|
|
24
|
+
colorSet?: string[] | SwatchBookColorObject[];
|
|
25
25
|
/**
|
|
26
26
|
* If true, render an input for entering a custom hex color.
|
|
27
27
|
* @default false
|
|
@@ -149,13 +149,19 @@ const HexColorInput = styled(ColorInput)({
|
|
|
149
149
|
width: '168px',
|
|
150
150
|
});
|
|
151
151
|
|
|
152
|
-
const isCustomColor = (colors: string[], hexCode?: string) => {
|
|
152
|
+
const isCustomColor = (colors: (string | SwatchBookColorObject)[], hexCode?: string) => {
|
|
153
153
|
if (!hexCode) {
|
|
154
154
|
return false;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
const lowercaseHex = hexCode.toLowerCase();
|
|
158
|
-
return !colors.
|
|
158
|
+
return !colors.some((color: string | SwatchBookColorObject) => {
|
|
159
|
+
if (typeof color === 'string') {
|
|
160
|
+
return color.toLowerCase() === lowercaseHex;
|
|
161
|
+
} else {
|
|
162
|
+
return color.value.toLowerCase() === lowercaseHex;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
159
165
|
};
|
|
160
166
|
|
|
161
167
|
export const ColorPicker = ({
|
|
@@ -4,8 +4,13 @@ import {borderRadius, colors, space} from '@workday/canvas-kit-react/tokens';
|
|
|
4
4
|
import {focusRing, mouseFocusBehavior} from '@workday/canvas-kit-react/common';
|
|
5
5
|
import {ColorSwatch} from '@workday/canvas-kit-react/color-picker';
|
|
6
6
|
|
|
7
|
+
export interface SwatchBookColorObject {
|
|
8
|
+
value: string;
|
|
9
|
+
label: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
export interface SwatchBookProps {
|
|
8
|
-
colors: string[];
|
|
13
|
+
colors: (string | SwatchBookColorObject)[];
|
|
9
14
|
value?: string;
|
|
10
15
|
onSelect: (color: string) => void;
|
|
11
16
|
}
|
|
@@ -58,26 +63,33 @@ const Container = styled('div')({
|
|
|
58
63
|
margin: `0px -${space.xxs} -${space.xxs} 0px`,
|
|
59
64
|
});
|
|
60
65
|
|
|
61
|
-
export const SwatchBook = ({colors, value, onSelect}: SwatchBookProps) =>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
export const SwatchBook = ({colors, value, onSelect}: SwatchBookProps) => {
|
|
67
|
+
return (
|
|
68
|
+
<Container>
|
|
69
|
+
{colors.map((color: string | SwatchBookColorObject, index: number) => {
|
|
70
|
+
const hexCode = typeof color === 'object' ? color.value : color;
|
|
71
|
+
const label = typeof color === 'object' ? color.label : color;
|
|
72
|
+
const isSelected = value ? hexCode.toLowerCase() === value.toLowerCase() : false;
|
|
65
73
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
const handleClick = () => onSelect(hexCode);
|
|
75
|
+
const handleKeyDown = (event: React.KeyboardEvent) =>
|
|
76
|
+
(event.key === 'Enter' || event.key === ' ') && onSelect(hexCode);
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
78
|
+
return (
|
|
79
|
+
<SwatchContainer
|
|
80
|
+
key={index + '-' + color}
|
|
81
|
+
onClick={handleClick}
|
|
82
|
+
onKeyDown={handleKeyDown}
|
|
83
|
+
tabIndex={0}
|
|
84
|
+
isSelected={isSelected}
|
|
85
|
+
role="button"
|
|
86
|
+
aria-label={label}
|
|
87
|
+
aria-selected={isSelected}
|
|
88
|
+
>
|
|
89
|
+
<ColorSwatch color={hexCode} showCheck={isSelected} />
|
|
90
|
+
</SwatchContainer>
|
|
91
|
+
);
|
|
92
|
+
})}
|
|
93
|
+
</Container>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { SwatchBookColorObject } from './parts/SwatchBook';
|
|
2
3
|
export interface ColorPickerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
4
|
/**
|
|
4
5
|
* The function called when the ColorPicker state changes.
|
|
@@ -11,7 +12,7 @@ export interface ColorPickerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
11
12
|
/**
|
|
12
13
|
* The array of colors to be rendered in the swatchbook.
|
|
13
14
|
*/
|
|
14
|
-
colorSet?: string[];
|
|
15
|
+
colorSet?: string[] | SwatchBookColorObject[];
|
|
15
16
|
/**
|
|
16
17
|
* If true, render an input for entering a custom hex color.
|
|
17
18
|
* @default false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorPicker.d.ts","sourceRoot":"","sources":["../../../../color-picker/lib/ColorPicker.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ColorPicker.d.ts","sourceRoot":"","sources":["../../../../color-picker/lib/ColorPicker.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,EAAa,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AAErE,MAAM,WAAW,gBAAiB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC5E;;OAEG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,qBAAqB,EAAE,CAAC;IAC9C;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;IACjD;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA4GD,eAAO,MAAM,WAAW;kKAYrB,gBAAgB;;CAsDlB,CAAC"}
|
|
@@ -116,7 +116,14 @@ const isCustomColor = (colors, hexCode) => {
|
|
|
116
116
|
return false;
|
|
117
117
|
}
|
|
118
118
|
const lowercaseHex = hexCode.toLowerCase();
|
|
119
|
-
return !colors.
|
|
119
|
+
return !colors.some((color) => {
|
|
120
|
+
if (typeof color === 'string') {
|
|
121
|
+
return color.toLowerCase() === lowercaseHex;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
return color.value.toLowerCase() === lowercaseHex;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
120
127
|
};
|
|
121
128
|
const ColorPicker = ({ colorSet = defaultColorSet, customHexInputLabel = 'Custom Hex Color', submitLabel = 'Submit', onColorChange, onColorReset, onSubmitClick, resetLabel = 'Reset', resetColor, value = '', showCustomHexInput = false, ...elemProps }) => {
|
|
122
129
|
const [validHexValue, setValidHexValue] = React.useState('');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwatchBook.d.ts","sourceRoot":"","sources":["../../../../../color-picker/lib/parts/SwatchBook.tsx"],"names":[],"mappings":"AAMA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"SwatchBook.d.ts","sourceRoot":"","sources":["../../../../../color-picker/lib/parts/SwatchBook.tsx"],"names":[],"mappings":"AAMA,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,CAAC,MAAM,GAAG,qBAAqB,CAAC,EAAE,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAkDD,eAAO,MAAM,UAAU,gCAA+B,eAAe,gBA6BpE,CAAC"}
|
|
@@ -64,11 +64,15 @@ const Container = styled_1.default('div')({
|
|
|
64
64
|
flexWrap: 'wrap',
|
|
65
65
|
margin: `0px -${tokens_1.space.xxs} -${tokens_1.space.xxs} 0px`,
|
|
66
66
|
});
|
|
67
|
-
const SwatchBook = ({ colors, value, onSelect }) =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
const SwatchBook = ({ colors, value, onSelect }) => {
|
|
68
|
+
return (React.createElement(Container, null, colors.map((color, index) => {
|
|
69
|
+
const hexCode = typeof color === 'object' ? color.value : color;
|
|
70
|
+
const label = typeof color === 'object' ? color.label : color;
|
|
71
|
+
const isSelected = value ? hexCode.toLowerCase() === value.toLowerCase() : false;
|
|
72
|
+
const handleClick = () => onSelect(hexCode);
|
|
73
|
+
const handleKeyDown = (event) => (event.key === 'Enter' || event.key === ' ') && onSelect(hexCode);
|
|
74
|
+
return (React.createElement(SwatchContainer, { key: index + '-' + color, onClick: handleClick, onKeyDown: handleKeyDown, tabIndex: 0, isSelected: isSelected, role: "button", "aria-label": label, "aria-selected": isSelected },
|
|
75
|
+
React.createElement(color_picker_1.ColorSwatch, { color: hexCode, showCheck: isSelected })));
|
|
76
|
+
})));
|
|
77
|
+
};
|
|
74
78
|
exports.SwatchBook = SwatchBook;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { SwatchBookColorObject } from './parts/SwatchBook';
|
|
2
3
|
export interface ColorPickerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
4
|
/**
|
|
4
5
|
* The function called when the ColorPicker state changes.
|
|
@@ -11,7 +12,7 @@ export interface ColorPickerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
11
12
|
/**
|
|
12
13
|
* The array of colors to be rendered in the swatchbook.
|
|
13
14
|
*/
|
|
14
|
-
colorSet?: string[];
|
|
15
|
+
colorSet?: string[] | SwatchBookColorObject[];
|
|
15
16
|
/**
|
|
16
17
|
* If true, render an input for entering a custom hex color.
|
|
17
18
|
* @default false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorPicker.d.ts","sourceRoot":"","sources":["../../../../color-picker/lib/ColorPicker.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ColorPicker.d.ts","sourceRoot":"","sources":["../../../../color-picker/lib/ColorPicker.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,EAAa,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AAErE,MAAM,WAAW,gBAAiB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC5E;;OAEG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,qBAAqB,EAAE,CAAC;IAC9C;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;IACjD;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA4GD,eAAO,MAAM,WAAW;kKAYrB,gBAAgB;;CAsDlB,CAAC"}
|
|
@@ -91,7 +91,14 @@ const isCustomColor = (colors, hexCode) => {
|
|
|
91
91
|
return false;
|
|
92
92
|
}
|
|
93
93
|
const lowercaseHex = hexCode.toLowerCase();
|
|
94
|
-
return !colors.
|
|
94
|
+
return !colors.some((color) => {
|
|
95
|
+
if (typeof color === 'string') {
|
|
96
|
+
return color.toLowerCase() === lowercaseHex;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return color.value.toLowerCase() === lowercaseHex;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
95
102
|
};
|
|
96
103
|
export const ColorPicker = ({ colorSet = defaultColorSet, customHexInputLabel = 'Custom Hex Color', submitLabel = 'Submit', onColorChange, onColorReset, onSubmitClick, resetLabel = 'Reset', resetColor, value = '', showCustomHexInput = false, ...elemProps }) => {
|
|
97
104
|
const [validHexValue, setValidHexValue] = React.useState('');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwatchBook.d.ts","sourceRoot":"","sources":["../../../../../color-picker/lib/parts/SwatchBook.tsx"],"names":[],"mappings":"AAMA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"SwatchBook.d.ts","sourceRoot":"","sources":["../../../../../color-picker/lib/parts/SwatchBook.tsx"],"names":[],"mappings":"AAMA,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,CAAC,MAAM,GAAG,qBAAqB,CAAC,EAAE,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAkDD,eAAO,MAAM,UAAU,gCAA+B,eAAe,gBA6BpE,CAAC"}
|
|
@@ -39,10 +39,14 @@ const Container = styled('div')({
|
|
|
39
39
|
flexWrap: 'wrap',
|
|
40
40
|
margin: `0px -${space.xxs} -${space.xxs} 0px`,
|
|
41
41
|
});
|
|
42
|
-
export const SwatchBook = ({ colors, value, onSelect }) =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
export const SwatchBook = ({ colors, value, onSelect }) => {
|
|
43
|
+
return (React.createElement(Container, null, colors.map((color, index) => {
|
|
44
|
+
const hexCode = typeof color === 'object' ? color.value : color;
|
|
45
|
+
const label = typeof color === 'object' ? color.label : color;
|
|
46
|
+
const isSelected = value ? hexCode.toLowerCase() === value.toLowerCase() : false;
|
|
47
|
+
const handleClick = () => onSelect(hexCode);
|
|
48
|
+
const handleKeyDown = (event) => (event.key === 'Enter' || event.key === ' ') && onSelect(hexCode);
|
|
49
|
+
return (React.createElement(SwatchContainer, { key: index + '-' + color, onClick: handleClick, onKeyDown: handleKeyDown, tabIndex: 0, isSelected: isSelected, role: "button", "aria-label": label, "aria-selected": isSelected },
|
|
50
|
+
React.createElement(ColorSwatch, { color: hexCode, showCheck: isSelected })));
|
|
51
|
+
})));
|
|
52
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-preview-react",
|
|
3
|
-
"version": "11.1.
|
|
3
|
+
"version": "11.1.7",
|
|
4
4
|
"description": "Canvas Kit Preview is made up of components that have the full design and a11y review, are part of the DS ecosystem and are approved for use in product. The API's could be subject to change, but not without strong communication and migration strategies.",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@emotion/react": "^11.7.1",
|
|
48
48
|
"@emotion/styled": "^11.6.0",
|
|
49
|
-
"@workday/canvas-kit-react": "^11.1.
|
|
50
|
-
"@workday/canvas-kit-styling": "^11.1.
|
|
49
|
+
"@workday/canvas-kit-react": "^11.1.7",
|
|
50
|
+
"@workday/canvas-kit-styling": "^11.1.7",
|
|
51
51
|
"@workday/canvas-system-icons-web": "^3.0.0",
|
|
52
52
|
"@workday/canvas-tokens-web": "^2.0.0",
|
|
53
53
|
"@workday/design-assets-types": "^0.2.8"
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"react-hook-form": "7.36.1",
|
|
59
59
|
"yup": "^0.32.11"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "f2f16c84455ece760c07e75631480f0ec65b9ada"
|
|
62
62
|
}
|