@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,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
@@ -29,50 +18,57 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
29
18
|
__setModuleDefault(result, mod);
|
|
30
19
|
return result;
|
|
31
20
|
};
|
|
32
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
33
|
-
var t = {};
|
|
34
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
35
|
-
t[p] = s[p];
|
|
36
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
37
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
38
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
39
|
-
t[p[i]] = s[p[i]];
|
|
40
|
-
}
|
|
41
|
-
return t;
|
|
42
|
-
};
|
|
43
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
22
|
exports.SelectBase = exports.buttonDefaultWidth = exports.buttonBorderWidth = void 0;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
23
|
+
const react_1 = __importStar(require("react"));
|
|
24
|
+
const common_1 = require("@workday/canvas-kit-react/common");
|
|
25
|
+
const tokens_1 = require("@workday/canvas-kit-react/tokens");
|
|
26
|
+
const canvas_system_icons_web_1 = require("@workday/canvas-system-icons-web");
|
|
27
|
+
const icon_1 = require("@workday/canvas-kit-react/icon");
|
|
28
|
+
const SelectMenu_1 = require("./SelectMenu");
|
|
29
|
+
const SelectOption_1 = require("./SelectOption");
|
|
30
|
+
const scrolling_1 = require("./scrolling");
|
|
31
|
+
const utils_1 = require("./utils");
|
|
54
32
|
exports.buttonBorderWidth = 1;
|
|
55
33
|
exports.buttonDefaultWidth = 280;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
34
|
+
const menuIconSize = 24;
|
|
35
|
+
const buttonPadding = tokens_1.spaceNumbers.xxs - exports.buttonBorderWidth;
|
|
36
|
+
const SelectButton = common_1.styled('button')({
|
|
37
|
+
...tokens_1.type.levels.subtext.large,
|
|
38
|
+
border: `${exports.buttonBorderWidth}px solid ${tokens_1.inputColors.border}`,
|
|
39
|
+
cursor: 'default',
|
|
40
|
+
display: 'block',
|
|
41
|
+
backgroundColor: tokens_1.inputColors.background,
|
|
42
|
+
borderRadius: tokens_1.borderRadius.m,
|
|
43
|
+
boxSizing: 'border-box',
|
|
44
|
+
height: tokens_1.space.xl,
|
|
45
|
+
outline: 'none',
|
|
46
|
+
overflow: 'hidden',
|
|
47
|
+
padding: buttonPadding,
|
|
48
|
+
paddingRight: tokens_1.spaceNumbers.xxs + menuIconSize + buttonPadding,
|
|
49
|
+
textAlign: 'left',
|
|
50
|
+
textOverflow: 'ellipsis',
|
|
51
|
+
transition: '0.2s box-shadow, 0.2s border-color',
|
|
52
|
+
whiteSpace: 'nowrap',
|
|
59
53
|
// width is required (instead of minWidth) in order for the button to
|
|
60
54
|
// be sized properly for lengthy options
|
|
61
|
-
width: exports.buttonDefaultWidth,
|
|
55
|
+
width: exports.buttonDefaultWidth,
|
|
56
|
+
'&::placeholder': {
|
|
62
57
|
color: tokens_1.inputColors.placeholder,
|
|
63
|
-
},
|
|
58
|
+
},
|
|
59
|
+
'&:disabled': {
|
|
64
60
|
backgroundColor: tokens_1.inputColors.disabled.background,
|
|
65
61
|
borderColor: tokens_1.inputColors.disabled.border,
|
|
66
62
|
color: tokens_1.inputColors.disabled.text,
|
|
67
63
|
'&::placeholder': {
|
|
68
64
|
color: tokens_1.inputColors.disabled.text,
|
|
69
65
|
},
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
},
|
|
67
|
+
}, ({ error, menuVisibility, theme }) => {
|
|
68
|
+
const themedFocusOutlineColor = theme.canvas.palette.common.focusOutline;
|
|
69
|
+
const buttonFocusStyles = {
|
|
74
70
|
borderColor: themedFocusOutlineColor,
|
|
75
|
-
boxShadow:
|
|
71
|
+
boxShadow: `inset 0 0 0 1px ${themedFocusOutlineColor}`,
|
|
76
72
|
};
|
|
77
73
|
if (error === undefined) {
|
|
78
74
|
// If there isn't an error, apply focus and hover styles if the menu is
|
|
@@ -80,21 +76,22 @@ var SelectButton = common_1.styled('button')(__assign(__assign({}, tokens_1.type
|
|
|
80
76
|
// or in the process of opening: style the button as if it had focus)
|
|
81
77
|
return menuVisibility === 'closed' || menuVisibility === 'closing'
|
|
82
78
|
? {
|
|
83
|
-
'&:focus:not([disabled])':
|
|
79
|
+
'&:focus:not([disabled])': {
|
|
80
|
+
...buttonFocusStyles,
|
|
81
|
+
},
|
|
84
82
|
'&:hover:not([disabled]):not(:focus)': {
|
|
85
83
|
borderColor: tokens_1.inputColors.hoverBorder,
|
|
86
84
|
},
|
|
87
85
|
}
|
|
88
|
-
:
|
|
86
|
+
: { ...buttonFocusStyles };
|
|
89
87
|
}
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
var grow = _a.grow;
|
|
93
|
-
return grow && {
|
|
94
|
-
width: '100%',
|
|
88
|
+
return {
|
|
89
|
+
...common_1.errorRing(error, theme),
|
|
95
90
|
};
|
|
91
|
+
}, ({ grow }) => grow && {
|
|
92
|
+
width: '100%',
|
|
96
93
|
});
|
|
97
|
-
|
|
94
|
+
const SelectMenuIcon = common_1.styled(icon_1.SystemIcon)({
|
|
98
95
|
position: 'absolute',
|
|
99
96
|
top: tokens_1.space.xxxs,
|
|
100
97
|
right: tokens_1.space.xxxs,
|
|
@@ -104,57 +101,65 @@ var SelectMenuIcon = common_1.styled(icon_1.SystemIcon)({
|
|
|
104
101
|
transition: '100ms fill',
|
|
105
102
|
},
|
|
106
103
|
});
|
|
107
|
-
|
|
104
|
+
const SelectInput = common_1.styled('input')({
|
|
108
105
|
display: 'none',
|
|
109
106
|
});
|
|
110
|
-
|
|
107
|
+
const SelectWrapper = common_1.styled('div')({
|
|
111
108
|
position: 'relative',
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
'&:hover .menu-icon path': {
|
|
121
|
-
fill: disabled ? undefined : tokens_1.colors.licorice500,
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
var defaultRenderOption = function (option) {
|
|
109
|
+
}, ({ grow }) => ({
|
|
110
|
+
display: grow ? 'block' : 'inline-block',
|
|
111
|
+
}), ({ disabled }) => ({
|
|
112
|
+
'&:hover .menu-icon path': {
|
|
113
|
+
fill: disabled ? undefined : tokens_1.colors.licorice500,
|
|
114
|
+
},
|
|
115
|
+
}));
|
|
116
|
+
const defaultRenderOption = option => {
|
|
126
117
|
return react_1.default.createElement("div", null, defaultRenderSelected(option));
|
|
127
118
|
};
|
|
128
|
-
|
|
119
|
+
const defaultRenderSelected = option => {
|
|
129
120
|
return option.label;
|
|
130
121
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
?
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
122
|
+
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 }) => {
|
|
123
|
+
const focusedOptionRef = react_1.default.useRef(null);
|
|
124
|
+
const menuId = common_1.useUniqueId();
|
|
125
|
+
const renderOptions = (renderOption) => {
|
|
126
|
+
const selectedOptionIndex = utils_1.getCorrectedIndexByValue(options, value);
|
|
127
|
+
return options.map((option, index) => {
|
|
128
|
+
const optionProps = {
|
|
129
|
+
'aria-disabled': option.disabled ? true : undefined,
|
|
130
|
+
'aria-selected': selectedOptionIndex === index ? true : undefined,
|
|
131
|
+
error,
|
|
132
|
+
focused: focusedOptionIndex === index,
|
|
133
|
+
id: option.id,
|
|
134
|
+
interactive: menuVisibility === 'opening' || menuVisibility === 'opened',
|
|
135
|
+
key: option.id,
|
|
136
|
+
optionRef: focusedOptionIndex === index ? focusedOptionRef : undefined,
|
|
137
|
+
value: option.value,
|
|
138
|
+
...(onOptionSelection
|
|
139
|
+
? {
|
|
140
|
+
onClick: (event) => {
|
|
141
|
+
// TODO: Figure out why this preventDefault call exists.
|
|
142
|
+
// Removing it doesn't have any obvious consequences,
|
|
143
|
+
// but need to do more careful testing.
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
onOptionSelection(index);
|
|
146
|
+
},
|
|
147
|
+
}
|
|
148
|
+
: {}),
|
|
149
|
+
};
|
|
149
150
|
// Pass in additional information about the option state: focused, selected
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
const normalizedOption = {
|
|
152
|
+
...option,
|
|
153
|
+
focused: optionProps.focused,
|
|
154
|
+
selected: !!optionProps['aria-selected'],
|
|
155
|
+
};
|
|
156
|
+
return react_1.default.createElement(SelectOption_1.SelectOption, Object.assign({}, optionProps), renderOption(normalizedOption));
|
|
152
157
|
});
|
|
153
158
|
};
|
|
154
159
|
// If the focused option changed, scroll the newly focused option into view (if
|
|
155
160
|
// necessary) but do NOT center it
|
|
156
|
-
react_1.useLayoutEffect(
|
|
157
|
-
|
|
161
|
+
react_1.useLayoutEffect(() => {
|
|
162
|
+
const focusedOption = focusedOptionRef.current;
|
|
158
163
|
if (focusedOption) {
|
|
159
164
|
// TODO: Figure out if rAF is the best approach here. I initially added
|
|
160
165
|
// rAF to get the Select States Menu On story to render correctly in IE.
|
|
@@ -167,7 +172,7 @@ var SelectBase = function (_a) {
|
|
|
167
172
|
// This rAF call also has the additional benefit of fixing a jarring menu
|
|
168
173
|
// placement issue in IE (https://github.com/Workday/canvas-kit/issues/791),
|
|
169
174
|
// so I'm leaving it in for now.
|
|
170
|
-
|
|
175
|
+
const animateId = requestAnimationFrame(() => {
|
|
171
176
|
// We cannot use the native Element.scrollIntoView() here because it
|
|
172
177
|
// doesn't work properly with the portalled menu: when using the keyboard
|
|
173
178
|
// to advance focus through the options, using scrollIntoView to keep the
|
|
@@ -175,16 +180,16 @@ var SelectBase = function (_a) {
|
|
|
175
180
|
// call our own scrollIntoViewIfNeeded function.
|
|
176
181
|
scrolling_1.scrollIntoViewIfNeeded(focusedOption, false);
|
|
177
182
|
});
|
|
178
|
-
return
|
|
179
|
-
cancelAnimationFrame(
|
|
183
|
+
return () => {
|
|
184
|
+
cancelAnimationFrame(animateId);
|
|
180
185
|
};
|
|
181
186
|
}
|
|
182
187
|
return undefined;
|
|
183
188
|
}, [focusedOptionIndex]);
|
|
184
189
|
// If the menu was just opened, scroll the focused option into view (if
|
|
185
190
|
// necessary) and center it
|
|
186
|
-
react_1.useLayoutEffect(
|
|
187
|
-
|
|
191
|
+
react_1.useLayoutEffect(() => {
|
|
192
|
+
const focusedOption = focusedOptionRef.current;
|
|
188
193
|
// We need to scroll if the menu is either opening or opened in case we decide to
|
|
189
194
|
// bypass the opening state and jump straight to opened (like in visual testing,
|
|
190
195
|
// for instance)
|
|
@@ -192,25 +197,25 @@ var SelectBase = function (_a) {
|
|
|
192
197
|
// TODO: This rAF call is also necessary for the Menu On visual testing
|
|
193
198
|
// stories to render properly in IE (see above, both rAF calls need to be
|
|
194
199
|
// present). It has no bearing on the menu placement issue.
|
|
195
|
-
|
|
200
|
+
const animateId = requestAnimationFrame(() => {
|
|
196
201
|
scrolling_1.scrollIntoViewIfNeeded(focusedOption, true);
|
|
197
202
|
});
|
|
198
|
-
return
|
|
199
|
-
cancelAnimationFrame(
|
|
203
|
+
return () => {
|
|
204
|
+
cancelAnimationFrame(animateId);
|
|
200
205
|
};
|
|
201
206
|
}
|
|
202
207
|
return undefined;
|
|
203
208
|
}, [menuVisibility]);
|
|
204
209
|
// Do a bit of error-checking in case options weren't provided
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
210
|
+
const hasOptions = options.length > 0;
|
|
211
|
+
const selectedOption = hasOptions ? options[utils_1.getCorrectedIndexByValue(options, value)] : null;
|
|
212
|
+
const selectedOptionValue = selectedOption ? selectedOption.value : '';
|
|
208
213
|
return (react_1.default.createElement(SelectWrapper, { grow: grow, disabled: disabled },
|
|
209
|
-
react_1.default.createElement(SelectButton,
|
|
214
|
+
react_1.default.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,
|
|
210
215
|
// Prevent Firefox from triggering click handler on spacebar during
|
|
211
216
|
// type-ahead when the menu is closed (and, thus, incorrectly displaying
|
|
212
217
|
// the menu)
|
|
213
|
-
onKeyUp:
|
|
218
|
+
onKeyUp: e => {
|
|
214
219
|
e.preventDefault();
|
|
215
220
|
}, ref: forwardedButtonRef, type: "button", value: selectedOptionValue }, elemProps), !!selectedOption && renderSelected(selectedOption)),
|
|
216
221
|
react_1.default.createElement(SelectInput, { onChange: onChange, ref: inputRef, type: "text", value: selectedOptionValue }),
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
@@ -29,29 +18,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
29
18
|
__setModuleDefault(result, mod);
|
|
30
19
|
return result;
|
|
31
20
|
};
|
|
32
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
33
|
-
var t = {};
|
|
34
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
35
|
-
t[p] = s[p];
|
|
36
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
37
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
38
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
39
|
-
t[p[i]] = s[p[i]];
|
|
40
|
-
}
|
|
41
|
-
return t;
|
|
42
|
-
};
|
|
43
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
22
|
exports.SelectMenu = exports.menuAnimationDuration = void 0;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
23
|
+
const react_1 = __importStar(require("react"));
|
|
24
|
+
const common_1 = require("@workday/canvas-kit-react/common");
|
|
25
|
+
const popup_1 = require("@workday/canvas-kit-react/popup");
|
|
26
|
+
const tokens_1 = require("@workday/canvas-kit-react/tokens");
|
|
27
|
+
const SelectBase_1 = require("./SelectBase");
|
|
50
28
|
exports.menuAnimationDuration = 200;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
29
|
+
const menuBorderStyles = (theme, error) => {
|
|
30
|
+
let borderColor = theme.canvas.palette.common.focusOutline;
|
|
31
|
+
let dividerBorderColor = borderColor;
|
|
32
|
+
let dividerBorderWidth = 1;
|
|
55
33
|
if (error === common_1.ErrorType.Error) {
|
|
56
34
|
borderColor = theme.canvas.palette.error.main;
|
|
57
35
|
dividerBorderColor = borderColor;
|
|
@@ -61,7 +39,7 @@ var menuBorderStyles = function (theme, error) {
|
|
|
61
39
|
dividerBorderColor = theme.canvas.palette.alert.main;
|
|
62
40
|
dividerBorderWidth = 2;
|
|
63
41
|
}
|
|
64
|
-
|
|
42
|
+
const dividerBorder = `${dividerBorderWidth}px solid ${dividerBorderColor}`;
|
|
65
43
|
return {
|
|
66
44
|
borderColor: borderColor,
|
|
67
45
|
// Render the divider using a pseudo-element
|
|
@@ -84,9 +62,9 @@ var menuBorderStyles = function (theme, error) {
|
|
|
84
62
|
},
|
|
85
63
|
};
|
|
86
64
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
65
|
+
const menuListBorderStyles = (theme, error) => {
|
|
66
|
+
let borderColor = theme.canvas.palette.common.focusOutline;
|
|
67
|
+
let borderWidth = 1;
|
|
90
68
|
if (error === common_1.ErrorType.Error) {
|
|
91
69
|
borderColor = theme.canvas.palette.error.main;
|
|
92
70
|
}
|
|
@@ -94,7 +72,7 @@ var menuListBorderStyles = function (theme, error) {
|
|
|
94
72
|
borderColor = theme.canvas.palette.alert.main;
|
|
95
73
|
borderWidth = 2;
|
|
96
74
|
}
|
|
97
|
-
|
|
75
|
+
const border = `${borderWidth}px solid ${borderColor}`;
|
|
98
76
|
return {
|
|
99
77
|
borderLeft: border,
|
|
100
78
|
borderRight: border,
|
|
@@ -106,67 +84,59 @@ var menuListBorderStyles = function (theme, error) {
|
|
|
106
84
|
},
|
|
107
85
|
};
|
|
108
86
|
};
|
|
109
|
-
|
|
87
|
+
const Menu = common_1.styled('div')({
|
|
110
88
|
backgroundColor: tokens_1.colors.frenchVanilla100,
|
|
111
|
-
border:
|
|
89
|
+
border: `1px solid ${tokens_1.inputColors.border}`,
|
|
112
90
|
boxSizing: 'border-box',
|
|
113
91
|
position: 'relative',
|
|
114
|
-
transition:
|
|
92
|
+
transition: `opacity ${exports.menuAnimationDuration}ms`,
|
|
115
93
|
'[data-popper-placement="bottom"] &': {
|
|
116
|
-
borderRadius:
|
|
94
|
+
borderRadius: `0 0 ${tokens_1.borderRadius.m} ${tokens_1.borderRadius.m}`,
|
|
117
95
|
borderTop: 0,
|
|
118
96
|
},
|
|
119
97
|
'[data-popper-placement="top"] &': {
|
|
120
|
-
borderRadius: tokens_1.borderRadius.m
|
|
98
|
+
borderRadius: `${tokens_1.borderRadius.m} ${tokens_1.borderRadius.m} 0 0`,
|
|
121
99
|
borderBottom: 0,
|
|
122
100
|
},
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}, function (_a) {
|
|
132
|
-
var width = _a.width;
|
|
133
|
-
return ({
|
|
134
|
-
width: width,
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
var MenuList = common_1.styled('ul')({
|
|
101
|
+
}, ({ error, theme }) => ({
|
|
102
|
+
...menuBorderStyles(theme, error),
|
|
103
|
+
}), ({ visibility }) => ({
|
|
104
|
+
opacity: visibility === 'opening' || visibility === 'opened' || visibility === 'close' ? 1 : 0,
|
|
105
|
+
}), ({ width }) => ({
|
|
106
|
+
width: width,
|
|
107
|
+
}));
|
|
108
|
+
const MenuList = common_1.styled('ul')({
|
|
138
109
|
listStyle: 'none',
|
|
139
110
|
margin: 0,
|
|
140
111
|
maxHeight: 200,
|
|
141
112
|
outline: 'none',
|
|
142
113
|
overflowY: 'auto',
|
|
143
114
|
padding: 0,
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var fallbackPlacements = [];
|
|
115
|
+
}, ({ error, theme }) => ({
|
|
116
|
+
...menuListBorderStyles(theme, error),
|
|
117
|
+
}));
|
|
118
|
+
const generatePopperOptions = (props) => {
|
|
119
|
+
const { menuRef, placement, shouldAutoFlip, shouldAutoFocus } = props;
|
|
120
|
+
let fallbackPlacements = [];
|
|
151
121
|
if (shouldAutoFlip) {
|
|
152
122
|
fallbackPlacements = placement === 'top' ? ['bottom'] : ['top'];
|
|
153
123
|
}
|
|
154
|
-
|
|
124
|
+
const modifiers = [
|
|
155
125
|
{
|
|
156
126
|
name: 'flip',
|
|
157
127
|
options: {
|
|
158
|
-
fallbackPlacements
|
|
128
|
+
fallbackPlacements,
|
|
159
129
|
},
|
|
160
130
|
},
|
|
161
131
|
{
|
|
162
132
|
name: 'offset',
|
|
163
133
|
options: {
|
|
164
|
-
offset:
|
|
165
|
-
|
|
134
|
+
offset: () => {
|
|
135
|
+
const skidding = 0;
|
|
166
136
|
// Displace menu towards the button to obscure the bottom
|
|
167
137
|
// edge of the button and to create a smooth visual
|
|
168
138
|
// connection between the button and the menu
|
|
169
|
-
|
|
139
|
+
const distance = -parseInt(tokens_1.borderRadius.m, 10);
|
|
170
140
|
return [skidding, distance];
|
|
171
141
|
},
|
|
172
142
|
},
|
|
@@ -181,32 +151,31 @@ var generatePopperOptions = function (props) {
|
|
|
181
151
|
},
|
|
182
152
|
];
|
|
183
153
|
return {
|
|
184
|
-
modifiers
|
|
154
|
+
modifiers,
|
|
185
155
|
// TODO: Consider using a more general-purpose focus function here rather
|
|
186
156
|
// than relying on Popper's onFirstUpdate for better control over how
|
|
187
157
|
// focus is managed
|
|
188
|
-
onFirstUpdate:
|
|
158
|
+
onFirstUpdate: () => {
|
|
189
159
|
if (shouldAutoFocus && menuRef && menuRef.current) {
|
|
190
160
|
menuRef.current.focus();
|
|
191
161
|
}
|
|
192
162
|
},
|
|
193
163
|
};
|
|
194
164
|
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
var model = popup_1.usePopupModel({
|
|
165
|
+
const SelectMenu = ({ buttonRef, children, error, menuRef, onClose, placement = 'bottom', shouldAutoFlip = true, shouldAutoFocus = true, visibility = 'closed', ...elemProps }) => {
|
|
166
|
+
const model = popup_1.usePopupModel({
|
|
198
167
|
initialVisibility: 'visible',
|
|
199
168
|
returnFocusRef: buttonRef,
|
|
200
169
|
onHide: onClose,
|
|
201
170
|
});
|
|
202
|
-
|
|
203
|
-
|
|
171
|
+
const [width, setWidth] = react_1.useState(0);
|
|
172
|
+
const handleWidthChange = react_1.useCallback(() => {
|
|
204
173
|
if (buttonRef && buttonRef.current && visibility !== 'closed') {
|
|
205
|
-
|
|
174
|
+
const newMenuWidth = buttonRef.current.clientWidth + 2 * SelectBase_1.buttonBorderWidth;
|
|
206
175
|
setWidth(newMenuWidth);
|
|
207
176
|
}
|
|
208
177
|
}, [buttonRef, visibility]);
|
|
209
|
-
react_1.useLayoutEffect(
|
|
178
|
+
react_1.useLayoutEffect(() => {
|
|
210
179
|
handleWidthChange();
|
|
211
180
|
}, [handleWidthChange]);
|
|
212
181
|
// TODO: Figure out a better way to handle width changes in the reference button.
|
|
@@ -215,10 +184,10 @@ var SelectMenu = function (_a) {
|
|
|
215
184
|
// the case when `grow = true` and the user resizes the browser window while the
|
|
216
185
|
// menu is opened, but doesn't address cases where the reference button size changes
|
|
217
186
|
// through other means.
|
|
218
|
-
react_1.useEffect(
|
|
187
|
+
react_1.useEffect(() => {
|
|
219
188
|
// Update menu width state on resize to ensure menu resizes as window resizes
|
|
220
189
|
window.addEventListener('resize', handleWidthChange);
|
|
221
|
-
return
|
|
190
|
+
return () => {
|
|
222
191
|
window.removeEventListener('resize', handleWidthChange);
|
|
223
192
|
};
|
|
224
193
|
}, [handleWidthChange]);
|
|
@@ -227,12 +196,12 @@ var SelectMenu = function (_a) {
|
|
|
227
196
|
popup_1.useReturnFocus(model);
|
|
228
197
|
popup_1.useTransferOnFullscreenExit(model);
|
|
229
198
|
return (react_1.default.createElement(popup_1.Popper, { placement: placement, anchorElement: buttonRef, popperOptions: generatePopperOptions({
|
|
230
|
-
menuRef
|
|
231
|
-
placement
|
|
232
|
-
shouldAutoFlip
|
|
233
|
-
shouldAutoFocus
|
|
199
|
+
menuRef,
|
|
200
|
+
placement,
|
|
201
|
+
shouldAutoFlip,
|
|
202
|
+
shouldAutoFocus,
|
|
234
203
|
}), ref: model.state.stackRef },
|
|
235
204
|
react_1.default.createElement(Menu, { error: error, visibility: visibility, width: width },
|
|
236
|
-
react_1.default.createElement(MenuList,
|
|
205
|
+
react_1.default.createElement(MenuList, Object.assign({ error: error, ref: menuRef, role: "listbox", tabIndex: -1 }, elemProps), children))));
|
|
237
206
|
};
|
|
238
207
|
exports.SelectMenu = SelectMenu;
|