@workday/canvas-kit-react 7.0.6 → 7.0.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/checkbox/lib/Checkbox.tsx +106 -54
- package/dist/commonjs/checkbox/lib/Checkbox.d.ts +4 -0
- package/dist/commonjs/checkbox/lib/Checkbox.d.ts.map +1 -1
- package/dist/commonjs/checkbox/lib/Checkbox.js +65 -34
- package/dist/commonjs/radio/lib/Radio.d.ts +1 -0
- package/dist/commonjs/radio/lib/Radio.d.ts.map +1 -1
- package/dist/commonjs/radio/lib/Radio.js +74 -26
- package/dist/es6/checkbox/lib/Checkbox.d.ts +4 -0
- package/dist/es6/checkbox/lib/Checkbox.d.ts.map +1 -1
- package/dist/es6/checkbox/lib/Checkbox.js +65 -34
- package/dist/es6/radio/lib/Radio.d.ts +1 -0
- package/dist/es6/radio/lib/Radio.d.ts.map +1 -1
- package/dist/es6/radio/lib/Radio.js +74 -26
- package/package.json +5 -5
- package/radio/lib/Radio.tsx +98 -29
package/radio/lib/Radio.tsx
CHANGED
|
@@ -48,6 +48,7 @@ export interface RadioProps extends Themeable {
|
|
|
48
48
|
* The value of the Radio button.
|
|
49
49
|
*/
|
|
50
50
|
value?: string;
|
|
51
|
+
variant?: 'inverse' | undefined;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
const radioBorderRadius = 9;
|
|
@@ -77,16 +78,20 @@ const RadioInputWrapper = styled('div')<Pick<RadioProps, 'disabled'>>({
|
|
|
77
78
|
width: radioWidth,
|
|
78
79
|
});
|
|
79
80
|
|
|
80
|
-
const RadioRipple = styled('span')<Pick<RadioProps, 'disabled'>>(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
81
|
+
const RadioRipple = styled('span')<Pick<RadioProps, 'disabled' | 'variant'>>(
|
|
82
|
+
{
|
|
83
|
+
borderRadius: borderRadius.circle,
|
|
84
|
+
boxShadow: `0 0 0 0 ${colors.soap200}`,
|
|
85
|
+
height: radioHeight,
|
|
86
|
+
transition: 'box-shadow 150ms ease-out',
|
|
87
|
+
width: radioWidth,
|
|
88
|
+
position: 'absolute',
|
|
89
|
+
pointerEvents: 'none', // This is a decorative element we don't want it to block clicks to input
|
|
90
|
+
},
|
|
91
|
+
({variant}) => ({
|
|
92
|
+
opacity: variant === 'inverse' ? '0.4' : '1',
|
|
93
|
+
})
|
|
94
|
+
);
|
|
90
95
|
|
|
91
96
|
const RadioInput = styled('input')<RadioProps & StyledType>(
|
|
92
97
|
{
|
|
@@ -105,6 +110,7 @@ const RadioInput = styled('input')<RadioProps & StyledType>(
|
|
|
105
110
|
({
|
|
106
111
|
checked,
|
|
107
112
|
disabled,
|
|
113
|
+
variant,
|
|
108
114
|
theme: {
|
|
109
115
|
canvas: {
|
|
110
116
|
palette: {
|
|
@@ -134,34 +140,68 @@ const RadioInput = styled('input')<RadioProps & StyledType>(
|
|
|
134
140
|
// input (which is visually hidden)
|
|
135
141
|
'&:hover ~ div:first-of-type': {
|
|
136
142
|
backgroundColor: checked
|
|
137
|
-
?
|
|
143
|
+
? variant === 'inverse'
|
|
144
|
+
? colors.frenchVanilla100
|
|
145
|
+
: themePrimary.main
|
|
138
146
|
: disabled
|
|
139
147
|
? inputColors.disabled.background
|
|
140
148
|
: 'white',
|
|
141
149
|
borderColor: checked
|
|
142
|
-
?
|
|
150
|
+
? variant === 'inverse'
|
|
151
|
+
? colors.soap300
|
|
152
|
+
: themePrimary.main
|
|
143
153
|
: disabled
|
|
144
154
|
? inputColors.disabled.border
|
|
155
|
+
: variant === 'inverse'
|
|
156
|
+
? colors.soap300
|
|
145
157
|
: inputColors.hoverBorder,
|
|
146
158
|
borderWidth: '1px',
|
|
147
159
|
},
|
|
148
160
|
'&:focus, &focus:hover': {
|
|
149
161
|
'& ~ div:first-of-type': {
|
|
150
|
-
borderColor: checked ? themePrimary.main : themeFocusOutline,
|
|
151
162
|
borderWidth: '2px',
|
|
163
|
+
borderColor: variant === 'inverse' ? colors.blackPepper400 : themeFocusOutline,
|
|
164
|
+
boxShadow: 'none',
|
|
165
|
+
...focusRing({
|
|
166
|
+
width: variant === 'inverse' ? 2 : 0,
|
|
167
|
+
separation: 0,
|
|
168
|
+
animate: false,
|
|
169
|
+
innerColor: variant === 'inverse' ? colors.blackPepper400 : undefined,
|
|
170
|
+
outerColor: variant === 'inverse' ? colors.frenchVanilla100 : undefined,
|
|
171
|
+
}),
|
|
152
172
|
},
|
|
153
173
|
},
|
|
154
174
|
'&:checked:focus ~ div:first-of-type': {
|
|
155
|
-
...focusRing({
|
|
175
|
+
...focusRing({
|
|
176
|
+
separation: 2,
|
|
177
|
+
width: 2,
|
|
178
|
+
innerColor: variant === 'inverse' ? colors.blackPepper400 : undefined,
|
|
179
|
+
outerColor: variant === 'inverse' ? colors.frenchVanilla100 : themeFocusOutline,
|
|
180
|
+
}),
|
|
181
|
+
borderColor: variant === 'inverse' ? colors.frenchVanilla100 : themePrimary.main,
|
|
182
|
+
borderWidth: '2px',
|
|
156
183
|
},
|
|
157
184
|
...mouseFocusBehavior({
|
|
158
185
|
'&:focus ~ div:first-of-type': {
|
|
159
|
-
...focusRing({
|
|
186
|
+
...focusRing({
|
|
187
|
+
width: 0,
|
|
188
|
+
outerColor: variant === 'inverse' ? colors.frenchVanilla100 : themeFocusOutline,
|
|
189
|
+
}),
|
|
160
190
|
borderWidth: '1px',
|
|
161
|
-
borderColor: checked
|
|
191
|
+
borderColor: checked
|
|
192
|
+
? variant === 'inverse'
|
|
193
|
+
? colors.soap300
|
|
194
|
+
: themePrimary.main
|
|
195
|
+
: inputColors.border,
|
|
162
196
|
},
|
|
163
197
|
'&:focus:hover ~ div:first-of-type, &:focus:active ~ div:first-of-type': {
|
|
164
|
-
borderColor: checked
|
|
198
|
+
borderColor: checked
|
|
199
|
+
? variant === 'inverse'
|
|
200
|
+
? colors.soap300
|
|
201
|
+
: themePrimary.main
|
|
202
|
+
: variant === 'inverse'
|
|
203
|
+
? colors.soap300
|
|
204
|
+
: inputColors.hoverBorder,
|
|
165
205
|
},
|
|
166
206
|
}),
|
|
167
207
|
})
|
|
@@ -187,6 +227,7 @@ const RadioBackground = styled('div')<RadioProps>(
|
|
|
187
227
|
({
|
|
188
228
|
checked,
|
|
189
229
|
disabled,
|
|
230
|
+
variant,
|
|
190
231
|
theme: {
|
|
191
232
|
canvas: {
|
|
192
233
|
palette: {primary: themePrimary},
|
|
@@ -194,19 +235,26 @@ const RadioBackground = styled('div')<RadioProps>(
|
|
|
194
235
|
},
|
|
195
236
|
}) => ({
|
|
196
237
|
borderColor: checked
|
|
197
|
-
?
|
|
238
|
+
? variant === 'inverse'
|
|
239
|
+
? colors.soap300
|
|
240
|
+
: themePrimary.main
|
|
198
241
|
: disabled
|
|
199
242
|
? inputColors.disabled.border
|
|
243
|
+
: variant === 'inverse'
|
|
244
|
+
? colors.soap300
|
|
200
245
|
: inputColors.border,
|
|
201
246
|
backgroundColor: checked
|
|
202
|
-
?
|
|
247
|
+
? variant === 'inverse'
|
|
248
|
+
? colors.frenchVanilla100
|
|
249
|
+
: themePrimary.main
|
|
203
250
|
: disabled
|
|
204
251
|
? inputColors.disabled.background
|
|
205
252
|
: 'white',
|
|
253
|
+
opacity: disabled && variant === 'inverse' ? '.4' : '1',
|
|
206
254
|
})
|
|
207
255
|
);
|
|
208
256
|
|
|
209
|
-
const RadioCheck = styled('div')<Pick<RadioProps, 'checked'>>(
|
|
257
|
+
const RadioCheck = styled('div')<Pick<RadioProps, 'checked' | 'variant'>>(
|
|
210
258
|
{
|
|
211
259
|
borderRadius: radioBorderRadius,
|
|
212
260
|
display: 'flex',
|
|
@@ -216,8 +264,11 @@ const RadioCheck = styled('div')<Pick<RadioProps, 'checked'>>(
|
|
|
216
264
|
transition: 'transform 200ms ease, opacity 200ms ease',
|
|
217
265
|
width: radioDot,
|
|
218
266
|
},
|
|
219
|
-
({theme}) => ({
|
|
220
|
-
backgroundColor:
|
|
267
|
+
({theme, variant}) => ({
|
|
268
|
+
backgroundColor:
|
|
269
|
+
variant === 'inverse'
|
|
270
|
+
? theme.canvas.palette.primary.main
|
|
271
|
+
: theme.canvas.palette.primary.contrast,
|
|
221
272
|
}),
|
|
222
273
|
({checked}) => ({
|
|
223
274
|
opacity: checked ? 1 : 0,
|
|
@@ -225,18 +276,35 @@ const RadioCheck = styled('div')<Pick<RadioProps, 'checked'>>(
|
|
|
225
276
|
})
|
|
226
277
|
);
|
|
227
278
|
|
|
228
|
-
const RadioLabel = styled('label')<{disabled?: boolean}>(
|
|
279
|
+
const RadioLabel = styled('label')<{disabled?: boolean; variant?: 'inverse' | undefined}>(
|
|
229
280
|
{
|
|
230
281
|
...canvas.type.levels.subtext.large,
|
|
231
282
|
paddingLeft: radioLabelDistance,
|
|
232
283
|
},
|
|
233
|
-
({
|
|
284
|
+
({variant}) => (variant === 'inverse' ? {color: colors.frenchVanilla100} : undefined),
|
|
285
|
+
({disabled, variant}) =>
|
|
286
|
+
disabled
|
|
287
|
+
? {
|
|
288
|
+
color: variant === 'inverse' ? colors.frenchVanilla100 : inputColors.disabled.text,
|
|
289
|
+
opacity: variant === 'inverse' ? '.4' : '1',
|
|
290
|
+
}
|
|
291
|
+
: {cursor: 'pointer'}
|
|
234
292
|
);
|
|
235
293
|
|
|
236
294
|
export const Radio = createComponent('input')({
|
|
237
295
|
displayName: 'Radio',
|
|
238
296
|
Component: (
|
|
239
|
-
{
|
|
297
|
+
{
|
|
298
|
+
checked = false,
|
|
299
|
+
id,
|
|
300
|
+
label = '',
|
|
301
|
+
disabled,
|
|
302
|
+
name,
|
|
303
|
+
onChange,
|
|
304
|
+
value,
|
|
305
|
+
variant,
|
|
306
|
+
...elemProps
|
|
307
|
+
}: RadioProps,
|
|
240
308
|
ref,
|
|
241
309
|
Element
|
|
242
310
|
) => {
|
|
@@ -255,15 +323,16 @@ export const Radio = createComponent('input')({
|
|
|
255
323
|
type="radio"
|
|
256
324
|
value={value}
|
|
257
325
|
aria-checked={checked}
|
|
326
|
+
variant={variant}
|
|
258
327
|
{...elemProps}
|
|
259
328
|
/>
|
|
260
|
-
<RadioRipple />
|
|
261
|
-
<RadioBackground checked={checked} disabled={disabled}>
|
|
262
|
-
<RadioCheck checked={checked} />
|
|
329
|
+
<RadioRipple variant={variant} />
|
|
330
|
+
<RadioBackground checked={checked} disabled={disabled} variant={variant}>
|
|
331
|
+
<RadioCheck checked={checked} variant={variant} />
|
|
263
332
|
</RadioBackground>
|
|
264
333
|
</RadioInputWrapper>
|
|
265
334
|
{label && (
|
|
266
|
-
<RadioLabel htmlFor={inputId} disabled={disabled}>
|
|
335
|
+
<RadioLabel htmlFor={inputId} disabled={disabled} variant={variant}>
|
|
267
336
|
{label}
|
|
268
337
|
</RadioLabel>
|
|
269
338
|
)}
|