@workday/canvas-kit-preview-react 9.0.0-alpha.364-next.3 → 9.0.0-alpha.382-next.2
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/dist/commonjs/color-picker/lib/ColorPicker.js +24 -47
- package/dist/commonjs/color-picker/lib/parts/ColorReset.js +32 -23
- package/dist/commonjs/color-picker/lib/parts/SwatchBook.js +26 -39
- package/dist/commonjs/form-field/lib/FormField.js +10 -33
- package/dist/commonjs/form-field/lib/FormFieldHint.js +8 -31
- package/dist/commonjs/form-field/lib/FormFieldInput.js +6 -17
- package/dist/commonjs/form-field/lib/FormFieldLabel.js +8 -31
- package/dist/commonjs/form-field/lib/hooks/useFormFieldHint.js +4 -5
- package/dist/commonjs/form-field/lib/hooks/useFormFieldInput.js +5 -6
- package/dist/commonjs/form-field/lib/hooks/useFormFieldLabel.js +4 -5
- package/dist/commonjs/form-field/lib/hooks/useFormFieldModel.js +8 -16
- package/dist/commonjs/form-field/lib/hooks/useFormFieldOrientation.js +3 -3
- package/dist/commonjs/menu/lib/Menu.js +96 -129
- package/dist/commonjs/menu/lib/MenuItem.js +94 -109
- package/dist/commonjs/pill/lib/Pill.js +55 -60
- package/dist/commonjs/pill/lib/PillAvatar.js +6 -17
- package/dist/commonjs/pill/lib/PillCount.js +7 -30
- package/dist/commonjs/pill/lib/PillIcon.js +8 -31
- package/dist/commonjs/pill/lib/PillIconButton.js +13 -36
- package/dist/commonjs/pill/lib/PillLabel.js +10 -33
- package/dist/commonjs/pill/lib/usePillModel.js +8 -16
- package/dist/commonjs/segmented-control/lib/SegmentedControl.js +6 -7
- package/dist/commonjs/segmented-control/lib/SegmentedControlItem.js +24 -49
- package/dist/commonjs/segmented-control/lib/SegmentedControlList.js +13 -38
- package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlItem.js +8 -10
- package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlModel.js +31 -31
- package/dist/commonjs/select/lib/Select.js +147 -189
- package/dist/commonjs/select/lib/SelectBase.js +106 -101
- package/dist/commonjs/select/lib/SelectMenu.js +53 -84
- package/dist/commonjs/select/lib/SelectOption.js +33 -47
- package/dist/commonjs/select/lib/scrolling.js +6 -7
- package/dist/commonjs/select/lib/utils.js +4 -4
- package/dist/commonjs/side-panel/lib/SidePanel.js +36 -51
- package/dist/commonjs/side-panel/lib/SidePanelToggleButton.js +17 -40
- package/dist/commonjs/side-panel/lib/hooks.js +20 -20
- package/dist/commonjs/status-indicator/lib/StatusIndicator.js +10 -34
- package/dist/commonjs/status-indicator/lib/StatusIndicatorIcon.js +9 -21
- package/dist/commonjs/status-indicator/lib/StatusIndicatorLabel.js +5 -28
- package/dist/commonjs/status-indicator/lib/hooks/useStatusIndicatorModel.js +6 -15
- package/dist/commonjs/text-area/lib/TextArea.js +8 -31
- package/dist/commonjs/text-area/lib/TextAreaField.d.ts.map +1 -1
- package/dist/commonjs/text-area/lib/TextAreaField.js +12 -36
- package/dist/commonjs/text-input/lib/TextInput.js +8 -31
- package/dist/commonjs/text-input/lib/TextInputField.d.ts.map +1 -1
- package/dist/commonjs/text-input/lib/TextInputField.js +12 -24
- package/dist/commonjs/text-input/lib/hooks/useTextInputField.js +3 -3
- package/dist/commonjs/text-input/lib/hooks/useTextInputModel.js +1 -1
- package/dist/es6/color-picker/lib/ColorPicker.js +15 -38
- package/dist/es6/color-picker/lib/parts/ColorReset.js +27 -18
- package/dist/es6/color-picker/lib/parts/SwatchBook.js +21 -34
- package/dist/es6/form-field/lib/FormField.js +4 -27
- package/dist/es6/form-field/lib/FormFieldHint.js +4 -27
- package/dist/es6/form-field/lib/FormFieldInput.js +3 -14
- package/dist/es6/form-field/lib/FormFieldLabel.js +4 -27
- package/dist/es6/form-field/lib/hooks/useFormFieldHint.js +2 -3
- package/dist/es6/form-field/lib/hooks/useFormFieldInput.js +3 -4
- package/dist/es6/form-field/lib/hooks/useFormFieldLabel.js +2 -3
- package/dist/es6/form-field/lib/hooks/useFormFieldModel.js +8 -16
- package/dist/es6/form-field/lib/hooks/useFormFieldOrientation.js +2 -2
- package/dist/es6/menu/lib/Menu.js +91 -125
- package/dist/es6/menu/lib/MenuItem.js +90 -106
- package/dist/es6/pill/lib/Pill.js +45 -50
- package/dist/es6/pill/lib/PillAvatar.js +3 -14
- package/dist/es6/pill/lib/PillCount.js +4 -27
- package/dist/es6/pill/lib/PillIcon.js +3 -26
- package/dist/es6/pill/lib/PillIconButton.js +7 -30
- package/dist/es6/pill/lib/PillLabel.js +5 -28
- package/dist/es6/pill/lib/usePillModel.js +8 -16
- package/dist/es6/segmented-control/lib/SegmentedControl.js +2 -3
- package/dist/es6/segmented-control/lib/SegmentedControlItem.js +17 -42
- package/dist/es6/segmented-control/lib/SegmentedControlList.js +9 -34
- package/dist/es6/segmented-control/lib/hooks/useSegmentedControlItem.js +5 -7
- package/dist/es6/segmented-control/lib/hooks/useSegmentedControlModel.js +29 -29
- package/dist/es6/select/lib/Select.js +144 -186
- package/dist/es6/select/lib/SelectBase.js +99 -94
- package/dist/es6/select/lib/SelectMenu.js +49 -80
- package/dist/es6/select/lib/SelectOption.js +30 -44
- package/dist/es6/select/lib/scrolling.js +6 -7
- package/dist/es6/select/lib/utils.js +4 -4
- package/dist/es6/side-panel/lib/SidePanel.js +31 -46
- package/dist/es6/side-panel/lib/SidePanelToggleButton.js +10 -33
- package/dist/es6/side-panel/lib/hooks.js +19 -19
- package/dist/es6/status-indicator/lib/StatusIndicator.js +5 -29
- package/dist/es6/status-indicator/lib/StatusIndicatorIcon.js +6 -18
- package/dist/es6/status-indicator/lib/StatusIndicatorLabel.js +3 -26
- package/dist/es6/status-indicator/lib/hooks/useStatusIndicatorModel.js +6 -15
- package/dist/es6/text-area/lib/TextArea.js +4 -27
- package/dist/es6/text-area/lib/TextAreaField.d.ts.map +1 -1
- package/dist/es6/text-area/lib/TextAreaField.js +9 -33
- package/dist/es6/text-input/lib/TextInput.js +4 -27
- package/dist/es6/text-input/lib/TextInputField.d.ts.map +1 -1
- package/dist/es6/text-input/lib/TextInputField.js +9 -21
- package/dist/es6/text-input/lib/hooks/useTextInputField.js +1 -1
- package/dist/es6/text-input/lib/hooks/useTextInputModel.js +1 -1
- package/package.json +3 -4
- package/text-area/lib/TextAreaField.tsx +6 -2
- package/text-input/lib/TextInputField.tsx +6 -2
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
1
|
import React, { useLayoutEffect } from 'react';
|
|
24
2
|
import { errorRing, styled, useUniqueId, } from '@workday/canvas-kit-react/common';
|
|
25
3
|
import { colors, borderRadius, inputColors, spaceNumbers, type, space, } from '@workday/canvas-kit-react/tokens';
|
|
@@ -29,28 +7,46 @@ import { SelectMenu } from './SelectMenu';
|
|
|
29
7
|
import { SelectOption } from './SelectOption';
|
|
30
8
|
import { scrollIntoViewIfNeeded } from './scrolling';
|
|
31
9
|
import { getCorrectedIndexByValue } from './utils';
|
|
32
|
-
export
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
10
|
+
export const buttonBorderWidth = 1;
|
|
11
|
+
export const buttonDefaultWidth = 280;
|
|
12
|
+
const menuIconSize = 24;
|
|
13
|
+
const buttonPadding = spaceNumbers.xxs - buttonBorderWidth;
|
|
14
|
+
const SelectButton = styled('button')({
|
|
15
|
+
...type.levels.subtext.large,
|
|
16
|
+
border: `${buttonBorderWidth}px solid ${inputColors.border}`,
|
|
17
|
+
cursor: 'default',
|
|
18
|
+
display: 'block',
|
|
19
|
+
backgroundColor: inputColors.background,
|
|
20
|
+
borderRadius: borderRadius.m,
|
|
21
|
+
boxSizing: 'border-box',
|
|
22
|
+
height: space.xl,
|
|
23
|
+
outline: 'none',
|
|
24
|
+
overflow: 'hidden',
|
|
25
|
+
padding: buttonPadding,
|
|
26
|
+
paddingRight: spaceNumbers.xxs + menuIconSize + buttonPadding,
|
|
27
|
+
textAlign: 'left',
|
|
28
|
+
textOverflow: 'ellipsis',
|
|
29
|
+
transition: '0.2s box-shadow, 0.2s border-color',
|
|
30
|
+
whiteSpace: 'nowrap',
|
|
37
31
|
// width is required (instead of minWidth) in order for the button to
|
|
38
32
|
// be sized properly for lengthy options
|
|
39
|
-
width: buttonDefaultWidth,
|
|
33
|
+
width: buttonDefaultWidth,
|
|
34
|
+
'&::placeholder': {
|
|
40
35
|
color: inputColors.placeholder,
|
|
41
|
-
},
|
|
36
|
+
},
|
|
37
|
+
'&:disabled': {
|
|
42
38
|
backgroundColor: inputColors.disabled.background,
|
|
43
39
|
borderColor: inputColors.disabled.border,
|
|
44
40
|
color: inputColors.disabled.text,
|
|
45
41
|
'&::placeholder': {
|
|
46
42
|
color: inputColors.disabled.text,
|
|
47
43
|
},
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
},
|
|
45
|
+
}, ({ error, menuVisibility, theme }) => {
|
|
46
|
+
const themedFocusOutlineColor = theme.canvas.palette.common.focusOutline;
|
|
47
|
+
const buttonFocusStyles = {
|
|
52
48
|
borderColor: themedFocusOutlineColor,
|
|
53
|
-
boxShadow:
|
|
49
|
+
boxShadow: `inset 0 0 0 1px ${themedFocusOutlineColor}`,
|
|
54
50
|
};
|
|
55
51
|
if (error === undefined) {
|
|
56
52
|
// If there isn't an error, apply focus and hover styles if the menu is
|
|
@@ -58,21 +54,22 @@ var SelectButton = styled('button')(__assign(__assign({}, type.levels.subtext.la
|
|
|
58
54
|
// or in the process of opening: style the button as if it had focus)
|
|
59
55
|
return menuVisibility === 'closed' || menuVisibility === 'closing'
|
|
60
56
|
? {
|
|
61
|
-
'&:focus:not([disabled])':
|
|
57
|
+
'&:focus:not([disabled])': {
|
|
58
|
+
...buttonFocusStyles,
|
|
59
|
+
},
|
|
62
60
|
'&:hover:not([disabled]):not(:focus)': {
|
|
63
61
|
borderColor: inputColors.hoverBorder,
|
|
64
62
|
},
|
|
65
63
|
}
|
|
66
|
-
:
|
|
64
|
+
: { ...buttonFocusStyles };
|
|
67
65
|
}
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
var grow = _a.grow;
|
|
71
|
-
return grow && {
|
|
72
|
-
width: '100%',
|
|
66
|
+
return {
|
|
67
|
+
...errorRing(error, theme),
|
|
73
68
|
};
|
|
69
|
+
}, ({ grow }) => grow && {
|
|
70
|
+
width: '100%',
|
|
74
71
|
});
|
|
75
|
-
|
|
72
|
+
const SelectMenuIcon = styled(SystemIcon)({
|
|
76
73
|
position: 'absolute',
|
|
77
74
|
top: space.xxxs,
|
|
78
75
|
right: space.xxxs,
|
|
@@ -82,57 +79,65 @@ var SelectMenuIcon = styled(SystemIcon)({
|
|
|
82
79
|
transition: '100ms fill',
|
|
83
80
|
},
|
|
84
81
|
});
|
|
85
|
-
|
|
82
|
+
const SelectInput = styled('input')({
|
|
86
83
|
display: 'none',
|
|
87
84
|
});
|
|
88
|
-
|
|
85
|
+
const SelectWrapper = styled('div')({
|
|
89
86
|
position: 'relative',
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
'&:hover .menu-icon path': {
|
|
99
|
-
fill: disabled ? undefined : colors.licorice500,
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
var defaultRenderOption = function (option) {
|
|
87
|
+
}, ({ grow }) => ({
|
|
88
|
+
display: grow ? 'block' : 'inline-block',
|
|
89
|
+
}), ({ disabled }) => ({
|
|
90
|
+
'&:hover .menu-icon path': {
|
|
91
|
+
fill: disabled ? undefined : colors.licorice500,
|
|
92
|
+
},
|
|
93
|
+
}));
|
|
94
|
+
const defaultRenderOption = option => {
|
|
104
95
|
return React.createElement("div", null, defaultRenderSelected(option));
|
|
105
96
|
};
|
|
106
|
-
|
|
97
|
+
const defaultRenderSelected = option => {
|
|
107
98
|
return option.label;
|
|
108
99
|
};
|
|
109
|
-
export
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
?
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
100
|
+
export const SelectBase = ({ 'aria-labelledby': ariaLabelledBy, 'aria-required': ariaRequired, as, forwardedButtonRef, localButtonRef, disabled, error, focusedOptionIndex = 0, grow, inputRef, menuPlacement = 'bottom', menuRef, menuVisibility = 'closed', onChange, onKeyDown, onClose, onOptionSelection, options, renderOption = defaultRenderOption, renderSelected = defaultRenderSelected, required, shouldMenuAutoFlip = true, shouldMenuAutoFocus = true, value, ...elemProps }) => {
|
|
101
|
+
const focusedOptionRef = React.useRef(null);
|
|
102
|
+
const menuId = useUniqueId();
|
|
103
|
+
const renderOptions = (renderOption) => {
|
|
104
|
+
const selectedOptionIndex = getCorrectedIndexByValue(options, value);
|
|
105
|
+
return options.map((option, index) => {
|
|
106
|
+
const optionProps = {
|
|
107
|
+
'aria-disabled': option.disabled ? true : undefined,
|
|
108
|
+
'aria-selected': selectedOptionIndex === index ? true : undefined,
|
|
109
|
+
error,
|
|
110
|
+
focused: focusedOptionIndex === index,
|
|
111
|
+
id: option.id,
|
|
112
|
+
interactive: menuVisibility === 'opening' || menuVisibility === 'opened',
|
|
113
|
+
key: option.id,
|
|
114
|
+
optionRef: focusedOptionIndex === index ? focusedOptionRef : undefined,
|
|
115
|
+
value: option.value,
|
|
116
|
+
...(onOptionSelection
|
|
117
|
+
? {
|
|
118
|
+
onClick: (event) => {
|
|
119
|
+
// TODO: Figure out why this preventDefault call exists.
|
|
120
|
+
// Removing it doesn't have any obvious consequences,
|
|
121
|
+
// but need to do more careful testing.
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
onOptionSelection(index);
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
: {}),
|
|
127
|
+
};
|
|
127
128
|
// Pass in additional information about the option state: focused, selected
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
const normalizedOption = {
|
|
130
|
+
...option,
|
|
131
|
+
focused: optionProps.focused,
|
|
132
|
+
selected: !!optionProps['aria-selected'],
|
|
133
|
+
};
|
|
134
|
+
return React.createElement(SelectOption, Object.assign({}, optionProps), renderOption(normalizedOption));
|
|
130
135
|
});
|
|
131
136
|
};
|
|
132
137
|
// If the focused option changed, scroll the newly focused option into view (if
|
|
133
138
|
// necessary) but do NOT center it
|
|
134
|
-
useLayoutEffect(
|
|
135
|
-
|
|
139
|
+
useLayoutEffect(() => {
|
|
140
|
+
const focusedOption = focusedOptionRef.current;
|
|
136
141
|
if (focusedOption) {
|
|
137
142
|
// TODO: Figure out if rAF is the best approach here. I initially added
|
|
138
143
|
// rAF to get the Select States Menu On story to render correctly in IE.
|
|
@@ -145,7 +150,7 @@ export var SelectBase = function (_a) {
|
|
|
145
150
|
// This rAF call also has the additional benefit of fixing a jarring menu
|
|
146
151
|
// placement issue in IE (https://github.com/Workday/canvas-kit/issues/791),
|
|
147
152
|
// so I'm leaving it in for now.
|
|
148
|
-
|
|
153
|
+
const animateId = requestAnimationFrame(() => {
|
|
149
154
|
// We cannot use the native Element.scrollIntoView() here because it
|
|
150
155
|
// doesn't work properly with the portalled menu: when using the keyboard
|
|
151
156
|
// to advance focus through the options, using scrollIntoView to keep the
|
|
@@ -153,16 +158,16 @@ export var SelectBase = function (_a) {
|
|
|
153
158
|
// call our own scrollIntoViewIfNeeded function.
|
|
154
159
|
scrollIntoViewIfNeeded(focusedOption, false);
|
|
155
160
|
});
|
|
156
|
-
return
|
|
157
|
-
cancelAnimationFrame(
|
|
161
|
+
return () => {
|
|
162
|
+
cancelAnimationFrame(animateId);
|
|
158
163
|
};
|
|
159
164
|
}
|
|
160
165
|
return undefined;
|
|
161
166
|
}, [focusedOptionIndex]);
|
|
162
167
|
// If the menu was just opened, scroll the focused option into view (if
|
|
163
168
|
// necessary) and center it
|
|
164
|
-
useLayoutEffect(
|
|
165
|
-
|
|
169
|
+
useLayoutEffect(() => {
|
|
170
|
+
const focusedOption = focusedOptionRef.current;
|
|
166
171
|
// We need to scroll if the menu is either opening or opened in case we decide to
|
|
167
172
|
// bypass the opening state and jump straight to opened (like in visual testing,
|
|
168
173
|
// for instance)
|
|
@@ -170,25 +175,25 @@ export var SelectBase = function (_a) {
|
|
|
170
175
|
// TODO: This rAF call is also necessary for the Menu On visual testing
|
|
171
176
|
// stories to render properly in IE (see above, both rAF calls need to be
|
|
172
177
|
// present). It has no bearing on the menu placement issue.
|
|
173
|
-
|
|
178
|
+
const animateId = requestAnimationFrame(() => {
|
|
174
179
|
scrollIntoViewIfNeeded(focusedOption, true);
|
|
175
180
|
});
|
|
176
|
-
return
|
|
177
|
-
cancelAnimationFrame(
|
|
181
|
+
return () => {
|
|
182
|
+
cancelAnimationFrame(animateId);
|
|
178
183
|
};
|
|
179
184
|
}
|
|
180
185
|
return undefined;
|
|
181
186
|
}, [menuVisibility]);
|
|
182
187
|
// Do a bit of error-checking in case options weren't provided
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
188
|
+
const hasOptions = options.length > 0;
|
|
189
|
+
const selectedOption = hasOptions ? options[getCorrectedIndexByValue(options, value)] : null;
|
|
190
|
+
const selectedOptionValue = selectedOption ? selectedOption.value : '';
|
|
186
191
|
return (React.createElement(SelectWrapper, { grow: grow, disabled: disabled },
|
|
187
|
-
React.createElement(SelectButton,
|
|
192
|
+
React.createElement(SelectButton, Object.assign({ "aria-expanded": menuVisibility !== 'closed' ? 'true' : undefined, "aria-haspopup": "listbox", "aria-controls": menuVisibility !== 'closed' ? menuId : undefined, as: as, disabled: disabled, error: error, grow: grow, menuVisibility: menuVisibility, onKeyDown: onKeyDown,
|
|
188
193
|
// Prevent Firefox from triggering click handler on spacebar during
|
|
189
194
|
// type-ahead when the menu is closed (and, thus, incorrectly displaying
|
|
190
195
|
// the menu)
|
|
191
|
-
onKeyUp:
|
|
196
|
+
onKeyUp: e => {
|
|
192
197
|
e.preventDefault();
|
|
193
198
|
}, ref: forwardedButtonRef, type: "button", value: selectedOptionValue }, elemProps), !!selectedOption && renderSelected(selectedOption)),
|
|
194
199
|
React.createElement(SelectInput, { onChange: onChange, ref: inputRef, type: "text", value: selectedOptionValue }),
|
|
@@ -1,35 +1,13 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
1
|
import React, { useState, useEffect, useLayoutEffect, useCallback } from 'react';
|
|
24
2
|
import { ErrorType, styled } from '@workday/canvas-kit-react/common';
|
|
25
3
|
import { Popper, useCloseOnEscape, useCloseOnOutsideClick, usePopupModel, useReturnFocus, useTransferOnFullscreenExit, } from '@workday/canvas-kit-react/popup';
|
|
26
4
|
import { colors, borderRadius, inputColors } from '@workday/canvas-kit-react/tokens';
|
|
27
5
|
import { buttonBorderWidth } from './SelectBase';
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
6
|
+
export const menuAnimationDuration = 200;
|
|
7
|
+
const menuBorderStyles = (theme, error) => {
|
|
8
|
+
let borderColor = theme.canvas.palette.common.focusOutline;
|
|
9
|
+
let dividerBorderColor = borderColor;
|
|
10
|
+
let dividerBorderWidth = 1;
|
|
33
11
|
if (error === ErrorType.Error) {
|
|
34
12
|
borderColor = theme.canvas.palette.error.main;
|
|
35
13
|
dividerBorderColor = borderColor;
|
|
@@ -39,7 +17,7 @@ var menuBorderStyles = function (theme, error) {
|
|
|
39
17
|
dividerBorderColor = theme.canvas.palette.alert.main;
|
|
40
18
|
dividerBorderWidth = 2;
|
|
41
19
|
}
|
|
42
|
-
|
|
20
|
+
const dividerBorder = `${dividerBorderWidth}px solid ${dividerBorderColor}`;
|
|
43
21
|
return {
|
|
44
22
|
borderColor: borderColor,
|
|
45
23
|
// Render the divider using a pseudo-element
|
|
@@ -62,9 +40,9 @@ var menuBorderStyles = function (theme, error) {
|
|
|
62
40
|
},
|
|
63
41
|
};
|
|
64
42
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
43
|
+
const menuListBorderStyles = (theme, error) => {
|
|
44
|
+
let borderColor = theme.canvas.palette.common.focusOutline;
|
|
45
|
+
let borderWidth = 1;
|
|
68
46
|
if (error === ErrorType.Error) {
|
|
69
47
|
borderColor = theme.canvas.palette.error.main;
|
|
70
48
|
}
|
|
@@ -72,7 +50,7 @@ var menuListBorderStyles = function (theme, error) {
|
|
|
72
50
|
borderColor = theme.canvas.palette.alert.main;
|
|
73
51
|
borderWidth = 2;
|
|
74
52
|
}
|
|
75
|
-
|
|
53
|
+
const border = `${borderWidth}px solid ${borderColor}`;
|
|
76
54
|
return {
|
|
77
55
|
borderLeft: border,
|
|
78
56
|
borderRight: border,
|
|
@@ -84,67 +62,59 @@ var menuListBorderStyles = function (theme, error) {
|
|
|
84
62
|
},
|
|
85
63
|
};
|
|
86
64
|
};
|
|
87
|
-
|
|
65
|
+
const Menu = styled('div')({
|
|
88
66
|
backgroundColor: colors.frenchVanilla100,
|
|
89
|
-
border:
|
|
67
|
+
border: `1px solid ${inputColors.border}`,
|
|
90
68
|
boxSizing: 'border-box',
|
|
91
69
|
position: 'relative',
|
|
92
|
-
transition:
|
|
70
|
+
transition: `opacity ${menuAnimationDuration}ms`,
|
|
93
71
|
'[data-popper-placement="bottom"] &': {
|
|
94
|
-
borderRadius:
|
|
72
|
+
borderRadius: `0 0 ${borderRadius.m} ${borderRadius.m}`,
|
|
95
73
|
borderTop: 0,
|
|
96
74
|
},
|
|
97
75
|
'[data-popper-placement="top"] &': {
|
|
98
|
-
borderRadius: borderRadius.m
|
|
76
|
+
borderRadius: `${borderRadius.m} ${borderRadius.m} 0 0`,
|
|
99
77
|
borderBottom: 0,
|
|
100
78
|
},
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}, function (_a) {
|
|
110
|
-
var width = _a.width;
|
|
111
|
-
return ({
|
|
112
|
-
width: width,
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
var MenuList = styled('ul')({
|
|
79
|
+
}, ({ error, theme }) => ({
|
|
80
|
+
...menuBorderStyles(theme, error),
|
|
81
|
+
}), ({ visibility }) => ({
|
|
82
|
+
opacity: visibility === 'opening' || visibility === 'opened' || visibility === 'close' ? 1 : 0,
|
|
83
|
+
}), ({ width }) => ({
|
|
84
|
+
width: width,
|
|
85
|
+
}));
|
|
86
|
+
const MenuList = styled('ul')({
|
|
116
87
|
listStyle: 'none',
|
|
117
88
|
margin: 0,
|
|
118
89
|
maxHeight: 200,
|
|
119
90
|
outline: 'none',
|
|
120
91
|
overflowY: 'auto',
|
|
121
92
|
padding: 0,
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
var fallbackPlacements = [];
|
|
93
|
+
}, ({ error, theme }) => ({
|
|
94
|
+
...menuListBorderStyles(theme, error),
|
|
95
|
+
}));
|
|
96
|
+
const generatePopperOptions = (props) => {
|
|
97
|
+
const { menuRef, placement, shouldAutoFlip, shouldAutoFocus } = props;
|
|
98
|
+
let fallbackPlacements = [];
|
|
129
99
|
if (shouldAutoFlip) {
|
|
130
100
|
fallbackPlacements = placement === 'top' ? ['bottom'] : ['top'];
|
|
131
101
|
}
|
|
132
|
-
|
|
102
|
+
const modifiers = [
|
|
133
103
|
{
|
|
134
104
|
name: 'flip',
|
|
135
105
|
options: {
|
|
136
|
-
fallbackPlacements
|
|
106
|
+
fallbackPlacements,
|
|
137
107
|
},
|
|
138
108
|
},
|
|
139
109
|
{
|
|
140
110
|
name: 'offset',
|
|
141
111
|
options: {
|
|
142
|
-
offset:
|
|
143
|
-
|
|
112
|
+
offset: () => {
|
|
113
|
+
const skidding = 0;
|
|
144
114
|
// Displace menu towards the button to obscure the bottom
|
|
145
115
|
// edge of the button and to create a smooth visual
|
|
146
116
|
// connection between the button and the menu
|
|
147
|
-
|
|
117
|
+
const distance = -parseInt(borderRadius.m, 10);
|
|
148
118
|
return [skidding, distance];
|
|
149
119
|
},
|
|
150
120
|
},
|
|
@@ -159,32 +129,31 @@ var generatePopperOptions = function (props) {
|
|
|
159
129
|
},
|
|
160
130
|
];
|
|
161
131
|
return {
|
|
162
|
-
modifiers
|
|
132
|
+
modifiers,
|
|
163
133
|
// TODO: Consider using a more general-purpose focus function here rather
|
|
164
134
|
// than relying on Popper's onFirstUpdate for better control over how
|
|
165
135
|
// focus is managed
|
|
166
|
-
onFirstUpdate:
|
|
136
|
+
onFirstUpdate: () => {
|
|
167
137
|
if (shouldAutoFocus && menuRef && menuRef.current) {
|
|
168
138
|
menuRef.current.focus();
|
|
169
139
|
}
|
|
170
140
|
},
|
|
171
141
|
};
|
|
172
142
|
};
|
|
173
|
-
export
|
|
174
|
-
|
|
175
|
-
var model = usePopupModel({
|
|
143
|
+
export const SelectMenu = ({ buttonRef, children, error, menuRef, onClose, placement = 'bottom', shouldAutoFlip = true, shouldAutoFocus = true, visibility = 'closed', ...elemProps }) => {
|
|
144
|
+
const model = usePopupModel({
|
|
176
145
|
initialVisibility: 'visible',
|
|
177
146
|
returnFocusRef: buttonRef,
|
|
178
147
|
onHide: onClose,
|
|
179
148
|
});
|
|
180
|
-
|
|
181
|
-
|
|
149
|
+
const [width, setWidth] = useState(0);
|
|
150
|
+
const handleWidthChange = useCallback(() => {
|
|
182
151
|
if (buttonRef && buttonRef.current && visibility !== 'closed') {
|
|
183
|
-
|
|
152
|
+
const newMenuWidth = buttonRef.current.clientWidth + 2 * buttonBorderWidth;
|
|
184
153
|
setWidth(newMenuWidth);
|
|
185
154
|
}
|
|
186
155
|
}, [buttonRef, visibility]);
|
|
187
|
-
useLayoutEffect(
|
|
156
|
+
useLayoutEffect(() => {
|
|
188
157
|
handleWidthChange();
|
|
189
158
|
}, [handleWidthChange]);
|
|
190
159
|
// TODO: Figure out a better way to handle width changes in the reference button.
|
|
@@ -193,10 +162,10 @@ export var SelectMenu = function (_a) {
|
|
|
193
162
|
// the case when `grow = true` and the user resizes the browser window while the
|
|
194
163
|
// menu is opened, but doesn't address cases where the reference button size changes
|
|
195
164
|
// through other means.
|
|
196
|
-
useEffect(
|
|
165
|
+
useEffect(() => {
|
|
197
166
|
// Update menu width state on resize to ensure menu resizes as window resizes
|
|
198
167
|
window.addEventListener('resize', handleWidthChange);
|
|
199
|
-
return
|
|
168
|
+
return () => {
|
|
200
169
|
window.removeEventListener('resize', handleWidthChange);
|
|
201
170
|
};
|
|
202
171
|
}, [handleWidthChange]);
|
|
@@ -205,11 +174,11 @@ export var SelectMenu = function (_a) {
|
|
|
205
174
|
useReturnFocus(model);
|
|
206
175
|
useTransferOnFullscreenExit(model);
|
|
207
176
|
return (React.createElement(Popper, { placement: placement, anchorElement: buttonRef, popperOptions: generatePopperOptions({
|
|
208
|
-
menuRef
|
|
209
|
-
placement
|
|
210
|
-
shouldAutoFlip
|
|
211
|
-
shouldAutoFocus
|
|
177
|
+
menuRef,
|
|
178
|
+
placement,
|
|
179
|
+
shouldAutoFlip,
|
|
180
|
+
shouldAutoFocus,
|
|
212
181
|
}), ref: model.state.stackRef },
|
|
213
182
|
React.createElement(Menu, { error: error, visibility: visibility, width: width },
|
|
214
|
-
React.createElement(MenuList,
|
|
183
|
+
React.createElement(MenuList, Object.assign({ error: error, ref: menuRef, role: "listbox", tabIndex: -1 }, elemProps), children))));
|
|
215
184
|
};
|
|
@@ -1,43 +1,24 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
1
|
import * as React from 'react';
|
|
24
2
|
import { ErrorType, pickForegroundColor, styled, } from '@workday/canvas-kit-react/common';
|
|
25
3
|
import { colors, commonColors, type } from '@workday/canvas-kit-react/tokens';
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
4
|
+
const optionPadding = 6;
|
|
5
|
+
const activeStyles = (theme) => {
|
|
6
|
+
const activeBgColor = theme.canvas.palette.primary.main;
|
|
29
7
|
return {
|
|
30
8
|
backgroundColor: activeBgColor,
|
|
31
9
|
color: pickForegroundColor(activeBgColor),
|
|
32
10
|
};
|
|
33
11
|
};
|
|
34
|
-
|
|
12
|
+
const Option = styled('li')({
|
|
13
|
+
...type.levels.subtext.large,
|
|
14
|
+
cursor: 'default',
|
|
35
15
|
// Apply listStyle at the list item style to ensure it's styled properly
|
|
36
16
|
// in Visual Testing States
|
|
37
|
-
listStyle: 'none',
|
|
17
|
+
listStyle: 'none',
|
|
38
18
|
// In case the content of the option is empty/undefined for some reason
|
|
39
|
-
minHeight: type.levels.subtext.large.lineHeight,
|
|
40
|
-
|
|
19
|
+
minHeight: type.levels.subtext.large.lineHeight,
|
|
20
|
+
textAlign: 'left',
|
|
21
|
+
}, ({ 'aria-disabled': disabled, focused, interactive, theme }) => {
|
|
41
22
|
if (disabled) {
|
|
42
23
|
// If the option is disabled, return disabled styles...
|
|
43
24
|
return {
|
|
@@ -46,35 +27,40 @@ var Option = styled('li')(__assign(__assign({}, type.levels.subtext.large), { cu
|
|
|
46
27
|
}
|
|
47
28
|
else if (focused) {
|
|
48
29
|
// ...else if the option is focused, return focused styles...
|
|
49
|
-
return
|
|
30
|
+
return {
|
|
31
|
+
...activeStyles(theme),
|
|
32
|
+
};
|
|
50
33
|
}
|
|
51
34
|
else {
|
|
52
35
|
// ...else return hover and selected (via aria-selected) styles
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
const selectedBgColor = theme.canvas.palette.primary.lightest;
|
|
37
|
+
const selectedStyles = {
|
|
55
38
|
'&[aria-selected="true"]': {
|
|
56
39
|
backgroundColor: selectedBgColor,
|
|
57
40
|
color: pickForegroundColor(selectedBgColor),
|
|
58
41
|
},
|
|
59
42
|
};
|
|
60
43
|
// Only display interactive (hover/active) styles if the option is interactive
|
|
61
|
-
|
|
44
|
+
const interactiveStyles = interactive
|
|
62
45
|
? {
|
|
63
46
|
'&:hover': {
|
|
64
47
|
backgroundColor: commonColors.hoverBackground,
|
|
65
48
|
},
|
|
66
|
-
'&:active, &:active[aria-selected="true"]':
|
|
49
|
+
'&:active, &:active[aria-selected="true"]': {
|
|
50
|
+
...activeStyles(theme),
|
|
51
|
+
},
|
|
67
52
|
}
|
|
68
53
|
: {};
|
|
69
|
-
return
|
|
54
|
+
return {
|
|
55
|
+
// Place selected styles after interactive styles to have selected styles
|
|
56
|
+
// override interactive styles (subject to CSS specificity rules)
|
|
57
|
+
...interactiveStyles,
|
|
58
|
+
...selectedStyles,
|
|
59
|
+
};
|
|
70
60
|
}
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
export var SelectOption = function (_a) {
|
|
78
|
-
var children = _a.children, _b = _a.focused, focused = _b === void 0 ? false : _b, _c = _a.interactive, interactive = _c === void 0 ? true : _c, optionRef = _a.optionRef, value = _a.value, elemProps = __rest(_a, ["children", "focused", "interactive", "optionRef", "value"]);
|
|
79
|
-
return (React.createElement(Option, __assign({ "data-value": value, focused: focused, interactive: interactive, ref: optionRef, role: "option" }, elemProps), children));
|
|
61
|
+
}, ({ error }) => ({
|
|
62
|
+
padding: `${optionPadding}px ${error === ErrorType.Alert ? optionPadding - 1 : optionPadding}px`,
|
|
63
|
+
}));
|
|
64
|
+
export const SelectOption = ({ children, focused = false, interactive = true, optionRef, value, ...elemProps }) => {
|
|
65
|
+
return (React.createElement(Option, Object.assign({ "data-value": value, focused: focused, interactive: interactive, ref: optionRef, role: "option" }, elemProps), children));
|
|
80
66
|
};
|