@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.
Files changed (97) hide show
  1. package/dist/commonjs/color-picker/lib/ColorPicker.js +24 -47
  2. package/dist/commonjs/color-picker/lib/parts/ColorReset.js +32 -23
  3. package/dist/commonjs/color-picker/lib/parts/SwatchBook.js +26 -39
  4. package/dist/commonjs/form-field/lib/FormField.js +10 -33
  5. package/dist/commonjs/form-field/lib/FormFieldHint.js +8 -31
  6. package/dist/commonjs/form-field/lib/FormFieldInput.js +6 -17
  7. package/dist/commonjs/form-field/lib/FormFieldLabel.js +8 -31
  8. package/dist/commonjs/form-field/lib/hooks/useFormFieldHint.js +4 -5
  9. package/dist/commonjs/form-field/lib/hooks/useFormFieldInput.js +5 -6
  10. package/dist/commonjs/form-field/lib/hooks/useFormFieldLabel.js +4 -5
  11. package/dist/commonjs/form-field/lib/hooks/useFormFieldModel.js +8 -16
  12. package/dist/commonjs/form-field/lib/hooks/useFormFieldOrientation.js +3 -3
  13. package/dist/commonjs/menu/lib/Menu.js +96 -129
  14. package/dist/commonjs/menu/lib/MenuItem.js +94 -109
  15. package/dist/commonjs/pill/lib/Pill.js +55 -60
  16. package/dist/commonjs/pill/lib/PillAvatar.js +6 -17
  17. package/dist/commonjs/pill/lib/PillCount.js +7 -30
  18. package/dist/commonjs/pill/lib/PillIcon.js +8 -31
  19. package/dist/commonjs/pill/lib/PillIconButton.js +13 -36
  20. package/dist/commonjs/pill/lib/PillLabel.js +10 -33
  21. package/dist/commonjs/pill/lib/usePillModel.js +8 -16
  22. package/dist/commonjs/segmented-control/lib/SegmentedControl.js +6 -7
  23. package/dist/commonjs/segmented-control/lib/SegmentedControlItem.js +24 -49
  24. package/dist/commonjs/segmented-control/lib/SegmentedControlList.js +13 -38
  25. package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlItem.js +8 -10
  26. package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlModel.js +31 -31
  27. package/dist/commonjs/select/lib/Select.js +147 -189
  28. package/dist/commonjs/select/lib/SelectBase.js +106 -101
  29. package/dist/commonjs/select/lib/SelectMenu.js +53 -84
  30. package/dist/commonjs/select/lib/SelectOption.js +33 -47
  31. package/dist/commonjs/select/lib/scrolling.js +6 -7
  32. package/dist/commonjs/select/lib/utils.js +4 -4
  33. package/dist/commonjs/side-panel/lib/SidePanel.js +36 -51
  34. package/dist/commonjs/side-panel/lib/SidePanelToggleButton.js +17 -40
  35. package/dist/commonjs/side-panel/lib/hooks.js +20 -20
  36. package/dist/commonjs/status-indicator/lib/StatusIndicator.js +10 -34
  37. package/dist/commonjs/status-indicator/lib/StatusIndicatorIcon.js +9 -21
  38. package/dist/commonjs/status-indicator/lib/StatusIndicatorLabel.js +5 -28
  39. package/dist/commonjs/status-indicator/lib/hooks/useStatusIndicatorModel.js +6 -15
  40. package/dist/commonjs/text-area/lib/TextArea.js +8 -31
  41. package/dist/commonjs/text-area/lib/TextAreaField.d.ts.map +1 -1
  42. package/dist/commonjs/text-area/lib/TextAreaField.js +12 -36
  43. package/dist/commonjs/text-input/lib/TextInput.js +8 -31
  44. package/dist/commonjs/text-input/lib/TextInputField.d.ts.map +1 -1
  45. package/dist/commonjs/text-input/lib/TextInputField.js +12 -24
  46. package/dist/commonjs/text-input/lib/hooks/useTextInputField.js +3 -3
  47. package/dist/commonjs/text-input/lib/hooks/useTextInputModel.js +1 -1
  48. package/dist/es6/color-picker/lib/ColorPicker.js +15 -38
  49. package/dist/es6/color-picker/lib/parts/ColorReset.js +27 -18
  50. package/dist/es6/color-picker/lib/parts/SwatchBook.js +21 -34
  51. package/dist/es6/form-field/lib/FormField.js +4 -27
  52. package/dist/es6/form-field/lib/FormFieldHint.js +4 -27
  53. package/dist/es6/form-field/lib/FormFieldInput.js +3 -14
  54. package/dist/es6/form-field/lib/FormFieldLabel.js +4 -27
  55. package/dist/es6/form-field/lib/hooks/useFormFieldHint.js +2 -3
  56. package/dist/es6/form-field/lib/hooks/useFormFieldInput.js +3 -4
  57. package/dist/es6/form-field/lib/hooks/useFormFieldLabel.js +2 -3
  58. package/dist/es6/form-field/lib/hooks/useFormFieldModel.js +8 -16
  59. package/dist/es6/form-field/lib/hooks/useFormFieldOrientation.js +2 -2
  60. package/dist/es6/menu/lib/Menu.js +91 -125
  61. package/dist/es6/menu/lib/MenuItem.js +90 -106
  62. package/dist/es6/pill/lib/Pill.js +45 -50
  63. package/dist/es6/pill/lib/PillAvatar.js +3 -14
  64. package/dist/es6/pill/lib/PillCount.js +4 -27
  65. package/dist/es6/pill/lib/PillIcon.js +3 -26
  66. package/dist/es6/pill/lib/PillIconButton.js +7 -30
  67. package/dist/es6/pill/lib/PillLabel.js +5 -28
  68. package/dist/es6/pill/lib/usePillModel.js +8 -16
  69. package/dist/es6/segmented-control/lib/SegmentedControl.js +2 -3
  70. package/dist/es6/segmented-control/lib/SegmentedControlItem.js +17 -42
  71. package/dist/es6/segmented-control/lib/SegmentedControlList.js +9 -34
  72. package/dist/es6/segmented-control/lib/hooks/useSegmentedControlItem.js +5 -7
  73. package/dist/es6/segmented-control/lib/hooks/useSegmentedControlModel.js +29 -29
  74. package/dist/es6/select/lib/Select.js +144 -186
  75. package/dist/es6/select/lib/SelectBase.js +99 -94
  76. package/dist/es6/select/lib/SelectMenu.js +49 -80
  77. package/dist/es6/select/lib/SelectOption.js +30 -44
  78. package/dist/es6/select/lib/scrolling.js +6 -7
  79. package/dist/es6/select/lib/utils.js +4 -4
  80. package/dist/es6/side-panel/lib/SidePanel.js +31 -46
  81. package/dist/es6/side-panel/lib/SidePanelToggleButton.js +10 -33
  82. package/dist/es6/side-panel/lib/hooks.js +19 -19
  83. package/dist/es6/status-indicator/lib/StatusIndicator.js +5 -29
  84. package/dist/es6/status-indicator/lib/StatusIndicatorIcon.js +6 -18
  85. package/dist/es6/status-indicator/lib/StatusIndicatorLabel.js +3 -26
  86. package/dist/es6/status-indicator/lib/hooks/useStatusIndicatorModel.js +6 -15
  87. package/dist/es6/text-area/lib/TextArea.js +4 -27
  88. package/dist/es6/text-area/lib/TextAreaField.d.ts.map +1 -1
  89. package/dist/es6/text-area/lib/TextAreaField.js +9 -33
  90. package/dist/es6/text-input/lib/TextInput.js +4 -27
  91. package/dist/es6/text-input/lib/TextInputField.d.ts.map +1 -1
  92. package/dist/es6/text-input/lib/TextInputField.js +9 -21
  93. package/dist/es6/text-input/lib/hooks/useTextInputField.js +1 -1
  94. package/dist/es6/text-input/lib/hooks/useTextInputModel.js +1 -1
  95. package/package.json +3 -4
  96. package/text-area/lib/TextAreaField.tsx +6 -2
  97. 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 var buttonBorderWidth = 1;
33
- export var buttonDefaultWidth = 280;
34
- var menuIconSize = 24;
35
- var buttonPadding = spaceNumbers.xxs - buttonBorderWidth;
36
- var SelectButton = styled('button')(__assign(__assign({}, type.levels.subtext.large), { border: buttonBorderWidth + "px solid " + inputColors.border, cursor: 'default', display: 'block', backgroundColor: inputColors.background, borderRadius: borderRadius.m, boxSizing: 'border-box', height: space.xl, outline: 'none', overflow: 'hidden', padding: buttonPadding, paddingRight: spaceNumbers.xxs + menuIconSize + buttonPadding, textAlign: 'left', textOverflow: 'ellipsis', transition: '0.2s box-shadow, 0.2s border-color', whiteSpace: 'nowrap',
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, '&::placeholder': {
33
+ width: buttonDefaultWidth,
34
+ '&::placeholder': {
40
35
  color: inputColors.placeholder,
41
- }, '&:disabled': {
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
- } }), function (_a) {
49
- var error = _a.error, menuVisibility = _a.menuVisibility, theme = _a.theme;
50
- var themedFocusOutlineColor = theme.canvas.palette.common.focusOutline;
51
- var buttonFocusStyles = {
44
+ },
45
+ }, ({ error, menuVisibility, theme }) => {
46
+ const themedFocusOutlineColor = theme.canvas.palette.common.focusOutline;
47
+ const buttonFocusStyles = {
52
48
  borderColor: themedFocusOutlineColor,
53
- boxShadow: "inset 0 0 0 1px " + themedFocusOutlineColor,
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])': __assign({}, buttonFocusStyles),
57
+ '&:focus:not([disabled])': {
58
+ ...buttonFocusStyles,
59
+ },
62
60
  '&:hover:not([disabled]):not(:focus)': {
63
61
  borderColor: inputColors.hoverBorder,
64
62
  },
65
63
  }
66
- : __assign({}, buttonFocusStyles);
64
+ : { ...buttonFocusStyles };
67
65
  }
68
- return __assign({}, errorRing(error, theme));
69
- }, function (_a) {
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
- var SelectMenuIcon = styled(SystemIcon)({
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
- var SelectInput = styled('input')({
82
+ const SelectInput = styled('input')({
86
83
  display: 'none',
87
84
  });
88
- var SelectWrapper = styled('div')({
85
+ const SelectWrapper = styled('div')({
89
86
  position: 'relative',
90
- }, function (_a) {
91
- var grow = _a.grow;
92
- return ({
93
- display: grow ? 'block' : 'inline-block',
94
- });
95
- }, function (_a) {
96
- var disabled = _a.disabled;
97
- return ({
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
- var defaultRenderSelected = function (option) {
97
+ const defaultRenderSelected = option => {
107
98
  return option.label;
108
99
  };
109
- export var SelectBase = function (_a) {
110
- var ariaLabelledBy = _a["aria-labelledby"], ariaRequired = _a["aria-required"], as = _a.as, forwardedButtonRef = _a.forwardedButtonRef, localButtonRef = _a.localButtonRef, disabled = _a.disabled, error = _a.error, _b = _a.focusedOptionIndex, focusedOptionIndex = _b === void 0 ? 0 : _b, grow = _a.grow, inputRef = _a.inputRef, _c = _a.menuPlacement, menuPlacement = _c === void 0 ? 'bottom' : _c, menuRef = _a.menuRef, _d = _a.menuVisibility, menuVisibility = _d === void 0 ? 'closed' : _d, onChange = _a.onChange, onKeyDown = _a.onKeyDown, onClose = _a.onClose, onOptionSelection = _a.onOptionSelection, options = _a.options, _e = _a.renderOption, renderOption = _e === void 0 ? defaultRenderOption : _e, _f = _a.renderSelected, renderSelected = _f === void 0 ? defaultRenderSelected : _f, required = _a.required, _g = _a.shouldMenuAutoFlip, shouldMenuAutoFlip = _g === void 0 ? true : _g, _h = _a.shouldMenuAutoFocus, shouldMenuAutoFocus = _h === void 0 ? true : _h, value = _a.value, elemProps = __rest(_a, ['aria-labelledby', 'aria-required', "as", "forwardedButtonRef", "localButtonRef", "disabled", "error", "focusedOptionIndex", "grow", "inputRef", "menuPlacement", "menuRef", "menuVisibility", "onChange", "onKeyDown", "onClose", "onOptionSelection", "options", "renderOption", "renderSelected", "required", "shouldMenuAutoFlip", "shouldMenuAutoFocus", "value"]);
111
- var focusedOptionRef = React.useRef(null);
112
- var menuId = useUniqueId();
113
- var renderOptions = function (renderOption) {
114
- var selectedOptionIndex = getCorrectedIndexByValue(options, value);
115
- return options.map(function (option, index) {
116
- var optionProps = __assign({ 'aria-disabled': option.disabled ? true : undefined, 'aria-selected': selectedOptionIndex === index ? true : undefined, error: error, focused: focusedOptionIndex === index, id: option.id, interactive: menuVisibility === 'opening' || menuVisibility === 'opened', key: option.id, optionRef: focusedOptionIndex === index ? focusedOptionRef : undefined, value: option.value }, (onOptionSelection
117
- ? {
118
- onClick: function (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
- : {}));
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
- var normalizedOption = __assign(__assign({}, option), { focused: optionProps.focused, selected: !!optionProps['aria-selected'] });
129
- return React.createElement(SelectOption, __assign({}, optionProps), renderOption(normalizedOption));
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(function () {
135
- var focusedOption = focusedOptionRef.current;
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
- var animateId_1 = requestAnimationFrame(function () {
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 function () {
157
- cancelAnimationFrame(animateId_1);
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(function () {
165
- var focusedOption = focusedOptionRef.current;
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
- var animateId_2 = requestAnimationFrame(function () {
178
+ const animateId = requestAnimationFrame(() => {
174
179
  scrollIntoViewIfNeeded(focusedOption, true);
175
180
  });
176
- return function () {
177
- cancelAnimationFrame(animateId_2);
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
- var hasOptions = options.length > 0;
184
- var selectedOption = hasOptions ? options[getCorrectedIndexByValue(options, value)] : null;
185
- var selectedOptionValue = selectedOption ? selectedOption.value : '';
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, __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,
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: function (e) {
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 var menuAnimationDuration = 200;
29
- var menuBorderStyles = function (theme, error) {
30
- var borderColor = theme.canvas.palette.common.focusOutline;
31
- var dividerBorderColor = borderColor;
32
- var dividerBorderWidth = 1;
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
- var dividerBorder = dividerBorderWidth + "px solid " + dividerBorderColor;
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
- var menuListBorderStyles = function (theme, error) {
66
- var borderColor = theme.canvas.palette.common.focusOutline;
67
- var borderWidth = 1;
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
- var border = borderWidth + "px solid " + borderColor;
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
- var Menu = styled('div')({
65
+ const Menu = styled('div')({
88
66
  backgroundColor: colors.frenchVanilla100,
89
- border: "1px solid " + inputColors.border,
67
+ border: `1px solid ${inputColors.border}`,
90
68
  boxSizing: 'border-box',
91
69
  position: 'relative',
92
- transition: "opacity " + menuAnimationDuration + "ms",
70
+ transition: `opacity ${menuAnimationDuration}ms`,
93
71
  '[data-popper-placement="bottom"] &': {
94
- borderRadius: "0 0 " + borderRadius.m + " " + borderRadius.m,
72
+ borderRadius: `0 0 ${borderRadius.m} ${borderRadius.m}`,
95
73
  borderTop: 0,
96
74
  },
97
75
  '[data-popper-placement="top"] &': {
98
- borderRadius: borderRadius.m + " " + borderRadius.m + " 0 0",
76
+ borderRadius: `${borderRadius.m} ${borderRadius.m} 0 0`,
99
77
  borderBottom: 0,
100
78
  },
101
- }, function (_a) {
102
- var error = _a.error, theme = _a.theme;
103
- return (__assign({}, menuBorderStyles(theme, error)));
104
- }, function (_a) {
105
- var visibility = _a.visibility;
106
- return ({
107
- opacity: visibility === 'opening' || visibility === 'opened' || visibility === 'close' ? 1 : 0,
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
- }, function (_a) {
123
- var error = _a.error, theme = _a.theme;
124
- return (__assign({}, menuListBorderStyles(theme, error)));
125
- });
126
- var generatePopperOptions = function (props) {
127
- var menuRef = props.menuRef, placement = props.placement, shouldAutoFlip = props.shouldAutoFlip, shouldAutoFocus = props.shouldAutoFocus;
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
- var modifiers = [
102
+ const modifiers = [
133
103
  {
134
104
  name: 'flip',
135
105
  options: {
136
- fallbackPlacements: fallbackPlacements,
106
+ fallbackPlacements,
137
107
  },
138
108
  },
139
109
  {
140
110
  name: 'offset',
141
111
  options: {
142
- offset: function () {
143
- var skidding = 0;
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
- var distance = -parseInt(borderRadius.m, 10);
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: 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: function () {
136
+ onFirstUpdate: () => {
167
137
  if (shouldAutoFocus && menuRef && menuRef.current) {
168
138
  menuRef.current.focus();
169
139
  }
170
140
  },
171
141
  };
172
142
  };
173
- export var SelectMenu = function (_a) {
174
- var buttonRef = _a.buttonRef, children = _a.children, error = _a.error, menuRef = _a.menuRef, onClose = _a.onClose, _b = _a.placement, placement = _b === void 0 ? 'bottom' : _b, _c = _a.shouldAutoFlip, shouldAutoFlip = _c === void 0 ? true : _c, _d = _a.shouldAutoFocus, shouldAutoFocus = _d === void 0 ? true : _d, _e = _a.visibility, visibility = _e === void 0 ? 'closed' : _e, elemProps = __rest(_a, ["buttonRef", "children", "error", "menuRef", "onClose", "placement", "shouldAutoFlip", "shouldAutoFocus", "visibility"]);
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
- var _f = useState(0), width = _f[0], setWidth = _f[1];
181
- var handleWidthChange = useCallback(function () {
149
+ const [width, setWidth] = useState(0);
150
+ const handleWidthChange = useCallback(() => {
182
151
  if (buttonRef && buttonRef.current && visibility !== 'closed') {
183
- var newMenuWidth = buttonRef.current.clientWidth + 2 * buttonBorderWidth;
152
+ const newMenuWidth = buttonRef.current.clientWidth + 2 * buttonBorderWidth;
184
153
  setWidth(newMenuWidth);
185
154
  }
186
155
  }, [buttonRef, visibility]);
187
- useLayoutEffect(function () {
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(function () {
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 function () {
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: menuRef,
209
- placement: placement,
210
- shouldAutoFlip: shouldAutoFlip,
211
- shouldAutoFocus: 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, __assign({ error: error, ref: menuRef, role: "listbox", tabIndex: -1 }, elemProps), children))));
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
- var optionPadding = 6;
27
- var activeStyles = function (theme) {
28
- var activeBgColor = theme.canvas.palette.primary.main;
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
- var Option = styled('li')(__assign(__assign({}, type.levels.subtext.large), { cursor: 'default',
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, textAlign: 'left' }), function (_a) {
40
- var disabled = _a["aria-disabled"], focused = _a.focused, interactive = _a.interactive, theme = _a.theme;
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 __assign({}, activeStyles(theme));
30
+ return {
31
+ ...activeStyles(theme),
32
+ };
50
33
  }
51
34
  else {
52
35
  // ...else return hover and selected (via aria-selected) styles
53
- var selectedBgColor = theme.canvas.palette.primary.lightest;
54
- var selectedStyles = {
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
- var interactiveStyles = interactive
44
+ const interactiveStyles = interactive
62
45
  ? {
63
46
  '&:hover': {
64
47
  backgroundColor: commonColors.hoverBackground,
65
48
  },
66
- '&:active, &:active[aria-selected="true"]': __assign({}, activeStyles(theme)),
49
+ '&:active, &:active[aria-selected="true"]': {
50
+ ...activeStyles(theme),
51
+ },
67
52
  }
68
53
  : {};
69
- return __assign(__assign({}, interactiveStyles), selectedStyles);
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
- }, function (_a) {
72
- var error = _a.error;
73
- return ({
74
- padding: optionPadding + "px " + (error === ErrorType.Alert ? optionPadding - 1 : optionPadding) + "px",
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
  };