@workday/canvas-kit-react 11.0.0-alpha.671-next.0 → 11.0.0-alpha.682-next.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/checkbox/lib/CheckBackground.tsx +48 -0
- package/checkbox/lib/Checkbox.tsx +18 -355
- package/checkbox/lib/CheckboxCheck.tsx +81 -0
- package/checkbox/lib/CheckboxContainer.tsx +58 -0
- package/checkbox/lib/CheckboxInput.tsx +279 -0
- package/checkbox/lib/CheckboxRipple.tsx +21 -0
- package/common/lib/styles/focusRing.ts +4 -17
- package/dist/commonjs/avatar/lib/Avatar.js +1 -1
- package/dist/commonjs/badge/lib/CountBadge.js +7 -7
- package/dist/commonjs/banner/lib/Banner.js +1 -1
- package/dist/commonjs/button/lib/BaseButton.js +22 -22
- package/dist/commonjs/button/lib/DeleteButton.js +1 -1
- package/dist/commonjs/button/lib/PrimaryButton.js +2 -2
- package/dist/commonjs/button/lib/SecondaryButton.js +2 -2
- package/dist/commonjs/button/lib/TertiaryButton.js +15 -15
- package/dist/commonjs/button/lib/ToolbarDropdownButton.js +6 -1
- package/dist/commonjs/button/lib/ToolbarIconButton.js +6 -1
- package/dist/commonjs/button/lib/deprecated_Button.js +2 -2
- package/dist/commonjs/card/lib/Card.js +1 -1
- package/dist/commonjs/card/lib/CardHeading.js +1 -1
- package/dist/commonjs/checkbox/lib/CheckBackground.d.ts +10 -0
- package/dist/commonjs/checkbox/lib/CheckBackground.d.ts.map +1 -0
- package/dist/commonjs/checkbox/lib/CheckBackground.js +42 -0
- package/dist/commonjs/checkbox/lib/Checkbox.d.ts +3 -45
- package/dist/commonjs/checkbox/lib/Checkbox.d.ts.map +1 -1
- package/dist/commonjs/checkbox/lib/Checkbox.js +10 -204
- package/dist/commonjs/checkbox/lib/CheckboxCheck.d.ts +10 -0
- package/dist/commonjs/checkbox/lib/CheckboxCheck.d.ts.map +1 -0
- package/dist/commonjs/checkbox/lib/CheckboxCheck.js +51 -0
- package/dist/commonjs/checkbox/lib/CheckboxContainer.d.ts +13 -0
- package/dist/commonjs/checkbox/lib/CheckboxContainer.d.ts.map +1 -0
- package/dist/commonjs/checkbox/lib/CheckboxContainer.js +37 -0
- package/dist/commonjs/checkbox/lib/CheckboxInput.d.ts +48 -0
- package/dist/commonjs/checkbox/lib/CheckboxInput.d.ts.map +1 -0
- package/dist/commonjs/checkbox/lib/CheckboxInput.js +59 -0
- package/dist/commonjs/checkbox/lib/CheckboxRipple.d.ts +2 -0
- package/dist/commonjs/checkbox/lib/CheckboxRipple.d.ts.map +1 -0
- package/dist/commonjs/checkbox/lib/CheckboxRipple.js +33 -0
- package/dist/commonjs/common/lib/AccessibleHide.js +1 -1
- package/dist/commonjs/common/lib/CanvasProvider.js +1 -1
- package/dist/commonjs/common/lib/styles/focusRing.d.ts.map +1 -1
- package/dist/commonjs/common/lib/styles/focusRing.js +5 -16
- package/dist/commonjs/loading-dots/lib/LoadingDots.js +2 -2
- package/dist/commonjs/radio/lib/Radio.js +17 -3
- package/dist/commonjs/select/lib/Select.js +1 -1
- package/dist/commonjs/switch/lib/Switch.js +2 -2
- package/dist/commonjs/tabs/lib/TabsItem.js +1 -1
- package/dist/commonjs/text/lib/LabelText.js +24 -24
- package/dist/commonjs/text/lib/Text.js +15 -15
- package/dist/es6/avatar/lib/Avatar.js +1 -1
- package/dist/es6/badge/lib/CountBadge.js +7 -7
- package/dist/es6/banner/lib/Banner.js +1 -1
- package/dist/es6/button/lib/BaseButton.js +22 -22
- package/dist/es6/button/lib/DeleteButton.js +1 -1
- package/dist/es6/button/lib/PrimaryButton.js +2 -2
- package/dist/es6/button/lib/SecondaryButton.js +2 -2
- package/dist/es6/button/lib/TertiaryButton.js +15 -15
- package/dist/es6/button/lib/ToolbarDropdownButton.js +6 -1
- package/dist/es6/button/lib/ToolbarIconButton.js +6 -1
- package/dist/es6/button/lib/deprecated_Button.js +2 -2
- package/dist/es6/card/lib/Card.js +1 -1
- package/dist/es6/card/lib/CardHeading.js +1 -1
- package/dist/es6/checkbox/lib/CheckBackground.d.ts +10 -0
- package/dist/es6/checkbox/lib/CheckBackground.d.ts.map +1 -0
- package/dist/es6/checkbox/lib/CheckBackground.js +20 -0
- package/dist/es6/checkbox/lib/Checkbox.d.ts +3 -45
- package/dist/es6/checkbox/lib/Checkbox.d.ts.map +1 -1
- package/dist/es6/checkbox/lib/Checkbox.js +11 -205
- package/dist/es6/checkbox/lib/CheckboxCheck.d.ts +10 -0
- package/dist/es6/checkbox/lib/CheckboxCheck.d.ts.map +1 -0
- package/dist/es6/checkbox/lib/CheckboxCheck.js +29 -0
- package/dist/es6/checkbox/lib/CheckboxContainer.d.ts +13 -0
- package/dist/es6/checkbox/lib/CheckboxContainer.d.ts.map +1 -0
- package/dist/es6/checkbox/lib/CheckboxContainer.js +15 -0
- package/dist/es6/checkbox/lib/CheckboxInput.d.ts +48 -0
- package/dist/es6/checkbox/lib/CheckboxInput.d.ts.map +1 -0
- package/dist/es6/checkbox/lib/CheckboxInput.js +37 -0
- package/dist/es6/checkbox/lib/CheckboxRipple.d.ts +2 -0
- package/dist/es6/checkbox/lib/CheckboxRipple.d.ts.map +1 -0
- package/dist/es6/checkbox/lib/CheckboxRipple.js +11 -0
- package/dist/es6/common/lib/AccessibleHide.js +1 -1
- package/dist/es6/common/lib/CanvasProvider.js +1 -1
- package/dist/es6/common/lib/styles/focusRing.d.ts.map +1 -1
- package/dist/es6/common/lib/styles/focusRing.js +5 -16
- package/dist/es6/loading-dots/lib/LoadingDots.js +2 -2
- package/dist/es6/radio/lib/Radio.js +17 -3
- package/dist/es6/select/lib/Select.js +1 -1
- package/dist/es6/switch/lib/Switch.js +2 -2
- package/dist/es6/tabs/lib/TabsItem.js +1 -1
- package/dist/es6/text/lib/LabelText.js +24 -24
- package/dist/es6/text/lib/Text.js +15 -15
- package/package.json +4 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {createComponent, ErrorType} from '@workday/canvas-kit-react/common';
|
|
3
|
+
import {calc, createStencil, createVars, px2rem, cssVar} from '@workday/canvas-kit-styling';
|
|
4
|
+
import {base, brand, system} from '@workday/canvas-tokens-web';
|
|
5
|
+
|
|
6
|
+
interface CheckBackgroundProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
error?: ErrorType;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const backgroundVars = createVars('inner', 'outer');
|
|
12
|
+
|
|
13
|
+
const checkboxBackgroundStencil = createStencil({
|
|
14
|
+
base: {
|
|
15
|
+
alignItems: 'center',
|
|
16
|
+
backgroundColor: base.frenchVanilla100,
|
|
17
|
+
borderRadius: system.shape.half,
|
|
18
|
+
boxSizing: 'border-box',
|
|
19
|
+
display: 'flex',
|
|
20
|
+
height: calc.add(system.space.x4, px2rem(2)),
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
padding: `${system.space.zero} ${calc.divide(system.space.x1, 2)}`,
|
|
23
|
+
pointerEvents: 'none',
|
|
24
|
+
position: 'absolute',
|
|
25
|
+
transition: 'border 200ms ease, background 200ms',
|
|
26
|
+
width: calc.add(system.space.x4, px2rem(2)),
|
|
27
|
+
border: `${px2rem(1)} solid ${base.licorice200}`,
|
|
28
|
+
},
|
|
29
|
+
modifiers: {
|
|
30
|
+
error: {
|
|
31
|
+
error: {
|
|
32
|
+
[backgroundVars.inner]: cssVar(brand.error.base, base.cinnamon500),
|
|
33
|
+
[backgroundVars.outer]: 'transparent',
|
|
34
|
+
},
|
|
35
|
+
alert: {
|
|
36
|
+
[backgroundVars.inner]: cssVar(brand.alert.base, base.cantaloupe600),
|
|
37
|
+
[backgroundVars.outer]: cssVar(brand.alert.darkest, base.cantaloupe400),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const CheckBackground = createComponent('div')({
|
|
44
|
+
displayName: 'CheckBackground',
|
|
45
|
+
Component: ({error, children}: CheckBackgroundProps) => {
|
|
46
|
+
return <div {...checkboxBackgroundStencil({error})}>{children}</div>;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -1,328 +1,22 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import {
|
|
3
3
|
createComponent,
|
|
4
|
-
StyledType,
|
|
5
4
|
ErrorType,
|
|
6
5
|
useUniqueId,
|
|
7
|
-
focusRing,
|
|
8
|
-
mouseFocusBehavior,
|
|
9
|
-
getErrorColors,
|
|
10
|
-
styled,
|
|
11
|
-
useTheme,
|
|
12
|
-
Themeable,
|
|
13
6
|
useLocalRef,
|
|
14
7
|
} from '@workday/canvas-kit-react/common';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {base} from '@workday/canvas-tokens-web';
|
|
20
|
-
import {cssVar} from '@workday/canvas-kit-styling';
|
|
21
|
-
|
|
22
|
-
export interface CheckboxProps extends Themeable {
|
|
23
|
-
/**
|
|
24
|
-
* If true, set the Checkbox to the checked state.
|
|
25
|
-
* @default false
|
|
26
|
-
*/
|
|
27
|
-
checked?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* If true, set the Checkbox to the disabled state.
|
|
30
|
-
* @default false
|
|
31
|
-
*/
|
|
32
|
-
disabled?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* The HTML `id` of the underlying checkbox input element. This is required if `label` is defined as a non-empty string.
|
|
35
|
-
* @default {useUniqueId}
|
|
36
|
-
*/
|
|
37
|
-
id?: string;
|
|
38
|
-
/**
|
|
39
|
-
* The text of the Checkbox label.
|
|
40
|
-
* @default ''
|
|
41
|
-
*/
|
|
42
|
-
label?: string;
|
|
43
|
-
/**
|
|
44
|
-
* The function called when the Checkbox state changes.
|
|
45
|
-
*/
|
|
46
|
-
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
47
|
-
/**
|
|
48
|
-
* The value of the Checkbox.
|
|
49
|
-
*/
|
|
50
|
-
value?: string;
|
|
51
|
-
/**
|
|
52
|
-
* The type of error associated with the Checkbox (if applicable).
|
|
53
|
-
*/
|
|
54
|
-
error?: ErrorType;
|
|
55
|
-
/**
|
|
56
|
-
* If true, set the Checkbox to an indeterminate state. Use this on a Checkbox with nested child Checkboxes to denote that some (but not all) child Checkboxes are checked.
|
|
57
|
-
* @default false
|
|
58
|
-
*/
|
|
59
|
-
indeterminate?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* The variant for the checkbox
|
|
62
|
-
*/
|
|
63
|
-
variant?: 'inverse' | undefined;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const CheckboxContainer = styled('div')({
|
|
67
|
-
display: 'flex',
|
|
68
|
-
alignItems: 'center',
|
|
69
|
-
minHeight: space.m,
|
|
70
|
-
position: 'relative',
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Using a wrapper prevents the browser default behavior of trigging
|
|
75
|
-
* :hover on the checkbox when you hover on it's corresponding label.
|
|
76
|
-
* This stops the ripple from showing when you hover on the label.
|
|
77
|
-
*/
|
|
78
|
-
const CheckboxInputWrapper = styled('div')<Pick<CheckboxProps, 'disabled'>>({
|
|
79
|
-
display: 'flex',
|
|
80
|
-
height: `calc(${space.s} + 2px)`,
|
|
81
|
-
minWidth: `calc(${space.s} + 2px)`,
|
|
82
|
-
marginTop: '3px',
|
|
83
|
-
alignSelf: 'flex-start',
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const CheckboxRipple = styled('span')<Pick<CheckboxProps, 'disabled' | 'variant'>>(
|
|
87
|
-
{
|
|
88
|
-
borderRadius: borderRadius.circle,
|
|
89
|
-
boxShadow: `0 0 0 0 ${colors.soap200}`,
|
|
90
|
-
height: `calc(${space.s} + 2px)`,
|
|
91
|
-
transition: 'box-shadow 150ms ease-out',
|
|
92
|
-
width: `calc(${space.s} + 2px)`,
|
|
93
|
-
position: 'absolute',
|
|
94
|
-
pointerEvents: 'none', // This is a decorative element we don't want it to block clicks to input
|
|
95
|
-
},
|
|
96
|
-
({variant}) => ({
|
|
97
|
-
opacity: variant === 'inverse' ? '0.4' : '1',
|
|
98
|
-
})
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Note: `~ div:first-of-type` refers to `CheckboxBackground`
|
|
103
|
-
* and was easier to use than a component selector in this case.
|
|
104
|
-
*/
|
|
105
|
-
const CheckboxInput = styled('input')<CheckboxProps & StyledType>(
|
|
106
|
-
({
|
|
107
|
-
theme: {
|
|
108
|
-
canvas: {
|
|
109
|
-
palette: {
|
|
110
|
-
primary: themePrimary,
|
|
111
|
-
common: {focusOutline: themeFocusOutline},
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
variant,
|
|
116
|
-
}) => ({
|
|
117
|
-
borderRadius: borderRadius.s,
|
|
118
|
-
width: space.m,
|
|
119
|
-
height: space.m,
|
|
120
|
-
margin: 0,
|
|
121
|
-
marginTop: '-3px',
|
|
122
|
-
marginLeft: '-3px',
|
|
123
|
-
position: 'absolute',
|
|
124
|
-
opacity: 0,
|
|
125
|
-
|
|
126
|
-
'&:not(:disabled)': {
|
|
127
|
-
cursor: 'pointer',
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
// States
|
|
131
|
-
'&:not(:checked):not(:indeterminate):not(:disabled):not(:focus):hover, &:not(:checked):not(:indeterminate):not(:disabled):active':
|
|
132
|
-
{
|
|
133
|
-
'~ div:first-of-type': {
|
|
134
|
-
borderColor: variant === 'inverse' ? colors.soap300 : inputColors.hoverBorder,
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
'&:checked ~ div:first-of-type, &:indeterminate ~ div:first-of-type': {
|
|
138
|
-
borderColor: variant === 'inverse' ? colors.soap300 : themePrimary.main,
|
|
139
|
-
backgroundColor: variant === 'inverse' ? colors.frenchVanilla100 : themePrimary.main,
|
|
140
|
-
},
|
|
141
|
-
'&:disabled ~ div:first-of-type': {
|
|
142
|
-
borderColor: cssVar(base.licorice100),
|
|
143
|
-
backgroundColor: variant === 'inverse' ? colors.soap300 : inputColors.disabled.background,
|
|
144
|
-
opacity: variant === 'inverse' ? '.4' : '1',
|
|
145
|
-
},
|
|
146
|
-
'&:disabled:checked ~ div:first-of-type, &:disabled:indeterminate ~ div:first-of-type': {
|
|
147
|
-
borderColor: variant === 'inverse' ? colors.soap300 : themePrimary.light,
|
|
148
|
-
backgroundColor: variant === 'inverse' ? colors.frenchVanilla100 : themePrimary.light,
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
// Focus
|
|
152
|
-
'&:focus, &:active': {
|
|
153
|
-
outline: 'none',
|
|
154
|
-
},
|
|
155
|
-
'&:focus ~ div:first-of-type': {
|
|
156
|
-
borderColor: variant === 'inverse' ? colors.blackPepper400 : themePrimary.main,
|
|
157
|
-
borderWidth: '2px',
|
|
158
|
-
boxShadow: 'none',
|
|
159
|
-
...focusRing({
|
|
160
|
-
width: variant === 'inverse' ? 2 : 0,
|
|
161
|
-
separation: 0,
|
|
162
|
-
animate: false,
|
|
163
|
-
innerColor: variant === 'inverse' ? colors.blackPepper400 : undefined,
|
|
164
|
-
outerColor: variant === 'inverse' ? colors.frenchVanilla100 : undefined,
|
|
165
|
-
}),
|
|
166
|
-
},
|
|
167
|
-
'&:checked:focus ~ div:first-of-type, &:indeterminate:focus ~ div:first-of-type': {
|
|
168
|
-
...focusRing({
|
|
169
|
-
width: 2,
|
|
170
|
-
separation: 2,
|
|
171
|
-
animate: false,
|
|
172
|
-
innerColor: variant === 'inverse' ? colors.blackPepper400 : undefined,
|
|
173
|
-
outerColor: variant === 'inverse' ? colors.frenchVanilla100 : themeFocusOutline,
|
|
174
|
-
}),
|
|
175
|
-
borderColor: variant === 'inverse' ? colors.frenchVanilla100 : themePrimary.main,
|
|
176
|
-
borderWidth: '2px',
|
|
177
|
-
'& span': {
|
|
178
|
-
marginLeft: '-7px',
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
...mouseFocusBehavior({
|
|
182
|
-
'&:focus ~ div:first-of-type': {
|
|
183
|
-
border:
|
|
184
|
-
variant === 'inverse'
|
|
185
|
-
? `1px solid ${colors.soap300}`
|
|
186
|
-
: `1px solid ${inputColors.hoverBorder}`,
|
|
187
|
-
boxShadow: 'none',
|
|
188
|
-
'& span': {
|
|
189
|
-
marginLeft: '-6px',
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
'&:checked ~ div:first-of-type, &:indeterminate ~ div:first-of-type': {
|
|
193
|
-
borderColor: variant === 'inverse' ? colors.soap300 : themePrimary.main,
|
|
194
|
-
},
|
|
195
|
-
'&:disabled:checked ~ div:first-of-type, &:disabled:indeterminate ~ div:first-of-type': {
|
|
196
|
-
borderColor: themePrimary.light,
|
|
197
|
-
backgroundColor: variant === 'inverse' ? colors.frenchVanilla100 : themePrimary.light,
|
|
198
|
-
},
|
|
199
|
-
}),
|
|
200
|
-
}),
|
|
201
|
-
({disabled}) => ({
|
|
202
|
-
'&:hover ~ span:first-of-type': {
|
|
203
|
-
boxShadow: disabled
|
|
204
|
-
? undefined
|
|
205
|
-
: `0 0 0 calc((${space.l} - (${space.s} + 2px)) / 2) ${colors.soap200}`,
|
|
206
|
-
},
|
|
207
|
-
}),
|
|
208
|
-
({theme, error, variant}) => {
|
|
209
|
-
const errorColors = getErrorColors(error, theme);
|
|
210
|
-
|
|
211
|
-
if (errorColors.outer === errorColors.inner) {
|
|
212
|
-
errorColors.outer = 'transparent';
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const errorStyles = {
|
|
216
|
-
'& ~ div:first-of-type': {
|
|
217
|
-
border:
|
|
218
|
-
variant === 'inverse' ? `1px solid ${colors.soap300}` : `1px solid ${errorColors.inner}`,
|
|
219
|
-
boxShadow: `0 0 0 1px ${errorColors.inner}, 0 0 0 2px ${errorColors.outer}`,
|
|
220
|
-
},
|
|
221
|
-
'&:not(:checked):not(:indeterminate):not(:disabled):not(:focus):hover, &:not(:checked):not(:indeterminate):not(:disabled):active':
|
|
222
|
-
{
|
|
223
|
-
'~ div:first-of-type': {
|
|
224
|
-
borderColor: variant === 'inverse' ? `1px solid ${colors.soap300}` : errorColors.inner,
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
'&:checked ~ div:first-of-type, &:indeterminate ~ div:first-of-type': {
|
|
228
|
-
borderColor: variant === 'inverse' ? colors.soap300 : theme.canvas.palette.primary.main,
|
|
229
|
-
boxShadow: `
|
|
230
|
-
0 0 0 2px ${colors.frenchVanilla100},
|
|
231
|
-
0 0 0 4px ${errorColors.inner},
|
|
232
|
-
0 0 0 5px ${errorColors.outer}`,
|
|
233
|
-
},
|
|
234
|
-
};
|
|
235
|
-
return {
|
|
236
|
-
// Error rings take precedence over focus
|
|
237
|
-
...mouseFocusBehavior({
|
|
238
|
-
...errorStyles,
|
|
239
|
-
'&:not(:checked):not(:indeterminate):focus ~ div:first-of-type': {
|
|
240
|
-
border: `1px solid ${errorColors.inner}`,
|
|
241
|
-
boxShadow: `0 0 0 1px ${errorColors.inner}, 0 0 0 2px ${errorColors.outer}`,
|
|
242
|
-
},
|
|
243
|
-
}),
|
|
244
|
-
...errorStyles,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
const CheckboxBackground = styled('div')<CheckboxProps>(
|
|
250
|
-
{
|
|
251
|
-
alignItems: 'center',
|
|
252
|
-
backgroundColor: colors.frenchVanilla100,
|
|
253
|
-
borderRadius: borderRadius.s,
|
|
254
|
-
boxSizing: 'border-box',
|
|
255
|
-
display: 'flex',
|
|
256
|
-
height: `calc(${space.s} + 2px)`,
|
|
257
|
-
justifyContent: 'center',
|
|
258
|
-
padding: '0px 2px',
|
|
259
|
-
pointerEvents: 'none',
|
|
260
|
-
position: 'absolute',
|
|
261
|
-
transition: 'border 200ms ease, background 200ms',
|
|
262
|
-
width: `calc(${space.s} + 2px)`,
|
|
263
|
-
},
|
|
264
|
-
({variant}) => ({
|
|
265
|
-
border: `1px solid ${variant === 'inverse' ? colors.soap300 : inputColors.border}`,
|
|
266
|
-
})
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
const CheckboxCheck = styled('div')<Pick<CheckboxProps, 'checked' | 'indeterminate'>>(
|
|
270
|
-
{
|
|
271
|
-
display: 'flex',
|
|
272
|
-
flexDirection: 'column',
|
|
273
|
-
// When using align-items: center on a flex container in the column direction,
|
|
274
|
-
// the contents of flex item, if too big, will overflow their container in IE 10-11.
|
|
275
|
-
// max-width: 100%; is a workaround
|
|
276
|
-
// https://github.com/philipwalton/flexbugs#flexbug-2
|
|
277
|
-
maxWidth: '100%',
|
|
278
|
-
pointerEvents: 'none',
|
|
279
|
-
transition: 'transform 200ms ease, opacity 200ms ease',
|
|
280
|
-
span: {
|
|
281
|
-
// This is necessary because we're using max-width: 100% in the CheckboxCheck container
|
|
282
|
-
// in order for the Checkbox to render properly on IE 11
|
|
283
|
-
marginLeft: '-6px',
|
|
284
|
-
transition: 'margin 200ms ease',
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
({checked, indeterminate}) => ({
|
|
288
|
-
opacity: checked || indeterminate ? 1 : 0,
|
|
289
|
-
transform: checked || indeterminate ? 'scale(1)' : 'scale(0.5)',
|
|
290
|
-
})
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
const IndeterminateBox = styled('div')<CheckboxProps>(
|
|
294
|
-
{
|
|
295
|
-
width: '10px',
|
|
296
|
-
height: '2px',
|
|
297
|
-
},
|
|
298
|
-
({theme, variant}) => ({
|
|
299
|
-
backgroundColor:
|
|
300
|
-
variant === 'inverse'
|
|
301
|
-
? theme.canvas.palette.primary.main
|
|
302
|
-
: theme.canvas.palette.primary.contrast,
|
|
303
|
-
})
|
|
304
|
-
);
|
|
8
|
+
import {CheckboxRipple} from './CheckboxRipple';
|
|
9
|
+
import {CheckboxContainer} from './CheckboxContainer';
|
|
10
|
+
import {CheckboxCheck} from './CheckboxCheck';
|
|
11
|
+
import {CheckboxInput, CheckboxProps} from './CheckboxInput';
|
|
305
12
|
|
|
306
13
|
export const Checkbox = createComponent('input')({
|
|
307
14
|
displayName: 'Checkbox',
|
|
308
|
-
Component: (
|
|
309
|
-
{
|
|
310
|
-
checked = false,
|
|
311
|
-
label = '',
|
|
312
|
-
// TODO: Fix useTheme and make it a real hook
|
|
313
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
314
|
-
theme = useTheme(),
|
|
315
|
-
id,
|
|
316
|
-
disabled,
|
|
317
|
-
indeterminate,
|
|
318
|
-
variant,
|
|
319
|
-
...elemProps
|
|
320
|
-
}: CheckboxProps,
|
|
321
|
-
ref,
|
|
322
|
-
Element
|
|
323
|
-
) => {
|
|
15
|
+
Component: ({id, label = '', ...elemProps}: CheckboxProps, ref, Element) => {
|
|
16
|
+
const {checked = false, disabled, error, indeterminate, variant} = elemProps;
|
|
324
17
|
const inputId = useUniqueId(id);
|
|
325
18
|
const {localRef, elementRef} = useLocalRef(ref);
|
|
19
|
+
|
|
326
20
|
React.useEffect(() => {
|
|
327
21
|
if (typeof indeterminate === 'boolean' && localRef.current) {
|
|
328
22
|
localRef.current.indeterminate = indeterminate;
|
|
@@ -330,48 +24,15 @@ export const Checkbox = createComponent('input')({
|
|
|
330
24
|
}, [indeterminate, localRef]);
|
|
331
25
|
|
|
332
26
|
return (
|
|
333
|
-
<CheckboxContainer>
|
|
334
|
-
<
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
variant={variant}
|
|
343
|
-
aria-checked={indeterminate ? 'mixed' : checked}
|
|
344
|
-
{...elemProps}
|
|
345
|
-
/>
|
|
346
|
-
<CheckboxRipple variant={variant} />
|
|
347
|
-
<CheckboxBackground variant={variant} checked={checked} disabled={disabled}>
|
|
348
|
-
<CheckboxCheck checked={checked} indeterminate={indeterminate}>
|
|
349
|
-
{indeterminate ? (
|
|
350
|
-
<IndeterminateBox variant={variant} />
|
|
351
|
-
) : checked ? (
|
|
352
|
-
<SystemIcon
|
|
353
|
-
icon={checkSmallIcon}
|
|
354
|
-
color={
|
|
355
|
-
variant === 'inverse'
|
|
356
|
-
? theme.canvas.palette.primary.main
|
|
357
|
-
: theme.canvas.palette.primary.contrast
|
|
358
|
-
}
|
|
359
|
-
/>
|
|
360
|
-
) : null}
|
|
361
|
-
</CheckboxCheck>
|
|
362
|
-
</CheckboxBackground>
|
|
363
|
-
</CheckboxInputWrapper>
|
|
364
|
-
{label && (
|
|
365
|
-
<LabelText
|
|
366
|
-
htmlFor={inputId}
|
|
367
|
-
disabled={disabled}
|
|
368
|
-
variant={variant}
|
|
369
|
-
paddingInlineStart={space.xs}
|
|
370
|
-
cursor="pointer"
|
|
371
|
-
>
|
|
372
|
-
{label}
|
|
373
|
-
</LabelText>
|
|
374
|
-
)}
|
|
27
|
+
<CheckboxContainer label={label} disabled={disabled} id={inputId} variant={variant}>
|
|
28
|
+
<CheckboxInput as={Element} id={inputId} ref={elementRef} {...elemProps} />
|
|
29
|
+
<CheckboxRipple />
|
|
30
|
+
<CheckboxCheck
|
|
31
|
+
variant={variant}
|
|
32
|
+
checked={checked}
|
|
33
|
+
indeterminate={indeterminate}
|
|
34
|
+
error={error}
|
|
35
|
+
/>
|
|
375
36
|
</CheckboxContainer>
|
|
376
37
|
);
|
|
377
38
|
},
|
|
@@ -379,3 +40,5 @@ export const Checkbox = createComponent('input')({
|
|
|
379
40
|
ErrorType,
|
|
380
41
|
},
|
|
381
42
|
});
|
|
43
|
+
|
|
44
|
+
export {CheckboxProps};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {ErrorType, createComponent} from '@workday/canvas-kit-react/common';
|
|
3
|
+
import {createStencil, createStyles, cssVar, calc, px2rem} from '@workday/canvas-kit-styling';
|
|
4
|
+
import {brand, system} from '@workday/canvas-tokens-web';
|
|
5
|
+
import {SystemIcon} from '@workday/canvas-kit-react/icon';
|
|
6
|
+
import {checkSmallIcon} from '@workday/canvas-system-icons-web';
|
|
7
|
+
import {CheckBackground} from './CheckBackground';
|
|
8
|
+
|
|
9
|
+
interface CheckboxCheckProps {
|
|
10
|
+
checked: boolean;
|
|
11
|
+
error?: ErrorType;
|
|
12
|
+
indeterminate?: boolean;
|
|
13
|
+
variant?: 'inverse';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const checkboxCheckStencil = createStencil({
|
|
17
|
+
base: {
|
|
18
|
+
display: 'flex',
|
|
19
|
+
flexDirection: 'column',
|
|
20
|
+
maxWidth: '100%',
|
|
21
|
+
pointerEvents: 'none',
|
|
22
|
+
transition: 'transform 200ms ease, opacity 200ms ease',
|
|
23
|
+
span: {
|
|
24
|
+
marginInlineStart: calc.negate(px2rem(6)),
|
|
25
|
+
transition: 'margin 200ms ease',
|
|
26
|
+
},
|
|
27
|
+
opacity: 0,
|
|
28
|
+
transform: 'scale(0.5)',
|
|
29
|
+
},
|
|
30
|
+
modifiers: {
|
|
31
|
+
checked: {
|
|
32
|
+
true: {
|
|
33
|
+
opacity: 1,
|
|
34
|
+
transform: 'scale(1)',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
indeterminate: {
|
|
38
|
+
true: {
|
|
39
|
+
opacity: 1,
|
|
40
|
+
transform: 'scale(1)',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
variant: {
|
|
44
|
+
inverse: {
|
|
45
|
+
'& > div': {
|
|
46
|
+
backgroundColor: brand.primary.base,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const indeterminateBoxStyles = createStyles({
|
|
54
|
+
width: calc.add(system.space.x2, px2rem(2)),
|
|
55
|
+
height: calc.divide(system.space.x1, 2),
|
|
56
|
+
backgroundColor: brand.primary.accent,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const CheckboxCheck = createComponent('div')({
|
|
60
|
+
displayName: 'CheckboxCheck',
|
|
61
|
+
Component: ({checked, error, indeterminate, variant}: CheckboxCheckProps) => {
|
|
62
|
+
return (
|
|
63
|
+
<CheckBackground error={error}>
|
|
64
|
+
<div {...checkboxCheckStencil({checked, indeterminate, variant})}>
|
|
65
|
+
{indeterminate ? (
|
|
66
|
+
<div className={indeterminateBoxStyles} />
|
|
67
|
+
) : (
|
|
68
|
+
checked && (
|
|
69
|
+
<SystemIcon
|
|
70
|
+
icon={checkSmallIcon}
|
|
71
|
+
color={
|
|
72
|
+
variant === 'inverse' ? cssVar(brand.primary.base) : cssVar(brand.primary.accent)
|
|
73
|
+
}
|
|
74
|
+
/>
|
|
75
|
+
)
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
</CheckBackground>
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {createComponent} from '@workday/canvas-kit-react/common';
|
|
3
|
+
import {CSProps, calc, createStyles, cssVar, px2rem, createVars} from '@workday/canvas-kit-styling';
|
|
4
|
+
import {system} from '@workday/canvas-tokens-web';
|
|
5
|
+
import {LabelText} from '@workday/canvas-kit-react/text';
|
|
6
|
+
|
|
7
|
+
interface CheckboxContainerProps extends CSProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
variant?: 'inverse';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const inputVars = createVars('errorInner', 'errorOuter', 'alertInner', 'alertOuter');
|
|
16
|
+
|
|
17
|
+
const checkboxContainerStyles = createStyles({
|
|
18
|
+
display: 'flex',
|
|
19
|
+
alignItems: 'center',
|
|
20
|
+
minHeight: system.space.x6,
|
|
21
|
+
position: 'relative',
|
|
22
|
+
/**
|
|
23
|
+
* Using a wrapper prevents the browser default behavior of trigging
|
|
24
|
+
* :hover on the checkbox when you hover on it's corresponding label.
|
|
25
|
+
* This stops the ripple from showing when you hover on the label.
|
|
26
|
+
*/
|
|
27
|
+
'&>div': {
|
|
28
|
+
display: 'flex',
|
|
29
|
+
height: calc.add(system.space.x4, px2rem(2)),
|
|
30
|
+
minWidth: calc.add(system.space.x4, px2rem(2)),
|
|
31
|
+
marginTop: px2rem(3),
|
|
32
|
+
alignSelf: 'flex-start',
|
|
33
|
+
},
|
|
34
|
+
'& > label': {
|
|
35
|
+
paddingInlineStart: cssVar(system.space.x3),
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const CheckboxContainer = createComponent('div')({
|
|
40
|
+
displayName: 'CheckboxContainer',
|
|
41
|
+
Component: ({children, disabled, id, label, variant}: CheckboxContainerProps) => {
|
|
42
|
+
return (
|
|
43
|
+
<div className={checkboxContainerStyles}>
|
|
44
|
+
<div>{children}</div>
|
|
45
|
+
{label && (
|
|
46
|
+
<LabelText
|
|
47
|
+
htmlFor={id}
|
|
48
|
+
disabled={disabled}
|
|
49
|
+
variant={variant}
|
|
50
|
+
style={{cursor: disabled ? 'default' : 'pointer'}}
|
|
51
|
+
>
|
|
52
|
+
{label}
|
|
53
|
+
</LabelText>
|
|
54
|
+
)}
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
});
|