@zendeskgarden/react-dropdowns 9.0.0-next.6 → 9.0.0-next.8

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 (70) hide show
  1. package/dist/esm/context/useComboboxContext.js +18 -0
  2. package/dist/esm/context/useFieldContext.js +18 -0
  3. package/dist/esm/context/useItemContext.js +18 -0
  4. package/dist/esm/context/useItemGroupContext.js +14 -0
  5. package/dist/esm/context/useMenuContext.js +18 -0
  6. package/dist/esm/context/useOptionContext.js +18 -0
  7. package/dist/esm/elements/combobox/Combobox.js +330 -0
  8. package/dist/esm/elements/combobox/Field.js +75 -0
  9. package/dist/esm/elements/combobox/Hint.js +57 -0
  10. package/dist/esm/elements/combobox/Label.js +68 -0
  11. package/dist/esm/elements/combobox/Listbox.js +155 -0
  12. package/dist/esm/elements/combobox/Message.js +63 -0
  13. package/dist/esm/elements/combobox/OptGroup.js +93 -0
  14. package/dist/esm/elements/combobox/Option.js +133 -0
  15. package/dist/esm/elements/combobox/OptionMeta.js +55 -0
  16. package/dist/esm/elements/combobox/Tag.js +98 -0
  17. package/dist/esm/elements/combobox/TagAvatar.js +13 -0
  18. package/dist/esm/elements/combobox/TagGroup.js +35 -0
  19. package/dist/esm/elements/combobox/utils.js +36 -0
  20. package/dist/esm/elements/menu/Item.js +140 -0
  21. package/dist/esm/elements/menu/ItemGroup.js +96 -0
  22. package/dist/esm/elements/menu/ItemMeta.js +55 -0
  23. package/dist/esm/elements/menu/Menu.js +157 -0
  24. package/dist/esm/elements/menu/MenuList.js +170 -0
  25. package/dist/esm/elements/menu/Separator.js +58 -0
  26. package/dist/esm/elements/menu/utils.js +55 -0
  27. package/dist/esm/index.js +19 -0
  28. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/check-lg-stroke.svg.js +28 -0
  29. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-down-stroke.svg.js +25 -0
  30. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-left-stroke.svg.js +25 -0
  31. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/chevron-right-stroke.svg.js +25 -0
  32. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/plus-stroke.svg.js +26 -0
  33. package/dist/esm/types/index.js +12 -0
  34. package/dist/esm/views/combobox/StyledCombobox.js +30 -0
  35. package/dist/esm/views/combobox/StyledContainer.js +22 -0
  36. package/dist/esm/views/combobox/StyledField.js +22 -0
  37. package/dist/esm/views/combobox/StyledFloatingListbox.js +27 -0
  38. package/dist/esm/views/combobox/StyledHint.js +23 -0
  39. package/dist/esm/views/combobox/StyledInput.js +41 -0
  40. package/dist/esm/views/combobox/StyledInputGroup.js +26 -0
  41. package/dist/esm/views/combobox/StyledInputIcon.js +56 -0
  42. package/dist/esm/views/combobox/StyledLabel.js +23 -0
  43. package/dist/esm/views/combobox/StyledListbox.js +31 -0
  44. package/dist/esm/views/combobox/StyledListboxSeparator.js +31 -0
  45. package/dist/esm/views/combobox/StyledMessage.js +23 -0
  46. package/dist/esm/views/combobox/StyledOptGroup.js +22 -0
  47. package/dist/esm/views/combobox/StyledOption.js +48 -0
  48. package/dist/esm/views/combobox/StyledOptionContent.js +22 -0
  49. package/dist/esm/views/combobox/StyledOptionIcon.js +37 -0
  50. package/dist/esm/views/combobox/StyledOptionMeta.js +31 -0
  51. package/dist/esm/views/combobox/StyledOptionTypeIcon.js +58 -0
  52. package/dist/esm/views/combobox/StyledTag.js +24 -0
  53. package/dist/esm/views/combobox/StyledTagsButton.js +28 -0
  54. package/dist/esm/views/combobox/StyledTrigger.js +94 -0
  55. package/dist/esm/views/combobox/StyledValue.js +32 -0
  56. package/dist/esm/views/menu/StyledButton.js +23 -0
  57. package/dist/esm/views/menu/StyledFloatingMenu.js +23 -0
  58. package/dist/esm/views/menu/StyledItem.js +23 -0
  59. package/dist/esm/views/menu/StyledItemContent.js +23 -0
  60. package/dist/esm/views/menu/StyledItemGroup.js +23 -0
  61. package/dist/esm/views/menu/StyledItemIcon.js +23 -0
  62. package/dist/esm/views/menu/StyledItemMeta.js +23 -0
  63. package/dist/esm/views/menu/StyledItemTypeIcon.js +24 -0
  64. package/dist/esm/views/menu/StyledMenu.js +27 -0
  65. package/dist/esm/views/menu/StyledSeparator.js +23 -0
  66. package/dist/index.cjs.js +95 -113
  67. package/dist/typings/elements/combobox/utils.d.ts +0 -8
  68. package/dist/typings/types/index.d.ts +1 -1
  69. package/package.json +10 -10
  70. package/dist/index.esm.js +0 -1973
package/dist/index.esm.js DELETED
@@ -1,1973 +0,0 @@
1
- /**
2
- * Copyright Zendesk, Inc.
3
- *
4
- * Use of this source code is governed under the Apache License, Version 2.0
5
- * found at http://www.apache.org/licenses/LICENSE-2.0.
6
- */
7
-
8
- import * as React from 'react';
9
- import React__default, { createContext, useContext, cloneElement, Children, forwardRef, useRef, useState, useEffect, isValidElement, useMemo } from 'react';
10
- import PropTypes from 'prop-types';
11
- import styled, { css, ThemeContext } from 'styled-components';
12
- import { useCombobox } from '@zendeskgarden/container-combobox';
13
- import { retrieveComponentStyles, DEFAULT_THEME, menuStyles, getColorV8, getLineHeight, focusStyles, arrowStyles, useText, useDocument, useWindow, PLACEMENT as PLACEMENT$1, getFloatingPlacements, getMenuPosition, getArrowPosition } from '@zendeskgarden/react-theming';
14
- import { Field as Field$1, VALIDATION } from '@zendeskgarden/react-forms';
15
- export { VALIDATION } from '@zendeskgarden/react-forms';
16
- import { hideVisually, math } from 'polished';
17
- import { Tag as Tag$1 } from '@zendeskgarden/react-tags';
18
- import { Button } from '@zendeskgarden/react-buttons';
19
- import { createPortal } from 'react-dom';
20
- import { useFloating, offset, flip, size, autoUpdate, platform, autoPlacement } from '@floating-ui/react-dom';
21
- import { composeEventHandlers } from '@zendeskgarden/container-utilities';
22
- import { Tooltip } from '@zendeskgarden/react-tooltips';
23
- import { mergeRefs } from 'react-merge-refs';
24
- import { useMenu } from '@zendeskgarden/container-menu';
25
-
26
- function _extends$5() {
27
- _extends$5 = Object.assign ? Object.assign.bind() : function (target) {
28
- for (var i = 1; i < arguments.length; i++) {
29
- var source = arguments[i];
30
- for (var key in source) {
31
- if (Object.prototype.hasOwnProperty.call(source, key)) {
32
- target[key] = source[key];
33
- }
34
- }
35
- }
36
- return target;
37
- };
38
- return _extends$5.apply(this, arguments);
39
- }
40
-
41
- var _path$4;
42
- function _extends$4() { _extends$4 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$4.apply(this, arguments); }
43
- var SvgChevronDownStroke = function SvgChevronDownStroke(props) {
44
- return /*#__PURE__*/React.createElement("svg", _extends$4({
45
- xmlns: "http://www.w3.org/2000/svg",
46
- width: 16,
47
- height: 16,
48
- focusable: "false",
49
- viewBox: "0 0 16 16",
50
- "aria-hidden": "true"
51
- }, props), _path$4 || (_path$4 = /*#__PURE__*/React.createElement("path", {
52
- fill: "currentColor",
53
- d: "M12.688 5.61a.5.5 0 01.69.718l-.066.062-5 4a.5.5 0 01-.542.054l-.082-.054-5-4a.5.5 0 01.55-.83l.074.05L8 9.359l4.688-3.75z"
54
- })));
55
- };
56
-
57
- const ComboboxContext = createContext(undefined);
58
- const useComboboxContext = () => {
59
- const context = useContext(ComboboxContext);
60
- if (!context) {
61
- throw new Error('Error: this component must be rendered within a <Combobox>.');
62
- }
63
- return context;
64
- };
65
-
66
- const FieldContext = createContext(undefined);
67
- const useFieldContext = () => {
68
- const context = useContext(FieldContext);
69
- if (!context) {
70
- throw new Error('Error: this component must be rendered within a <Field>.');
71
- }
72
- return context;
73
- };
74
-
75
- const COMPONENT_ID$v = 'dropdowns.combobox.label';
76
- const StyledLabel = styled(Field$1.Label).attrs({
77
- 'data-garden-id': COMPONENT_ID$v,
78
- 'data-garden-version': '9.0.0-next.6'
79
- }).withConfig({
80
- displayName: "StyledLabel",
81
- componentId: "sc-az6now-0"
82
- })(["vertical-align:revert;", ";"], props => retrieveComponentStyles(COMPONENT_ID$v, props));
83
- StyledLabel.defaultProps = {
84
- theme: DEFAULT_THEME
85
- };
86
-
87
- const COMPONENT_ID$u = 'dropdowns.combobox.hint';
88
- const StyledHint = styled(Field$1.Hint).attrs({
89
- 'data-garden-id': COMPONENT_ID$u,
90
- 'data-garden-version': '9.0.0-next.6'
91
- }).withConfig({
92
- displayName: "StyledHint",
93
- componentId: "sc-106qvqx-0"
94
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID$u, props));
95
- StyledHint.defaultProps = {
96
- theme: DEFAULT_THEME
97
- };
98
-
99
- const COMPONENT_ID$t = 'dropdowns.combobox.message';
100
- const StyledMessage = styled(Field$1.Message).attrs({
101
- 'data-garden-id': COMPONENT_ID$t,
102
- 'data-garden-version': '9.0.0-next.6'
103
- }).withConfig({
104
- displayName: "StyledMessage",
105
- componentId: "sc-jux8m5-0"
106
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID$t, props));
107
- StyledMessage.defaultProps = {
108
- theme: DEFAULT_THEME
109
- };
110
-
111
- const COMPONENT_ID$s = 'dropdowns.combobox';
112
- const sizeStyles$a = props => {
113
- const minWidth = `${props.isCompact ? 100 : 144}px`;
114
- const marginTop = `${props.theme.space.base * (props.isCompact ? 1 : 2)}px`;
115
- return css(["min-width:", ";", ":not([hidden]) + &&,", " + &&,", " + &&,&& + ", ",&& + ", "{margin-top:", ";}"], minWidth, StyledLabel, StyledHint, StyledMessage, StyledHint, StyledMessage, marginTop);
116
- };
117
- const StyledCombobox = styled.div.attrs({
118
- 'data-garden-id': COMPONENT_ID$s,
119
- 'data-garden-version': '9.0.0-next.6'
120
- }).withConfig({
121
- displayName: "StyledCombobox",
122
- componentId: "sc-13eybg8-0"
123
- })(["", ";", ";"], sizeStyles$a, props => retrieveComponentStyles(COMPONENT_ID$s, props));
124
- StyledCombobox.defaultProps = {
125
- theme: DEFAULT_THEME
126
- };
127
-
128
- const COMPONENT_ID$r = 'dropdowns.combobox.container';
129
- const StyledContainer = styled.div.attrs({
130
- 'data-garden-id': COMPONENT_ID$r,
131
- 'data-garden-version': '9.0.0-next.6'
132
- }).withConfig({
133
- displayName: "StyledContainer",
134
- componentId: "sc-14i9jid-0"
135
- })(["display:flex;", ";"], props => retrieveComponentStyles(COMPONENT_ID$r, props));
136
- StyledContainer.defaultProps = {
137
- theme: DEFAULT_THEME
138
- };
139
-
140
- const COMPONENT_ID$q = 'dropdowns.combobox.field';
141
- const StyledField = styled.div.attrs({
142
- 'data-garden-id': COMPONENT_ID$q,
143
- 'data-garden-version': '9.0.0-next.6'
144
- }).withConfig({
145
- displayName: "StyledField",
146
- componentId: "sc-zc57xl-0"
147
- })(["direction:", ";", ";"], props => props.theme.rtl ? 'rtl' : 'ltr', props => retrieveComponentStyles(COMPONENT_ID$q, props));
148
- StyledField.defaultProps = {
149
- theme: DEFAULT_THEME
150
- };
151
-
152
- const COMPONENT_ID$p = 'dropdowns.combobox.floating';
153
- const StyledFloatingListbox = styled.div.attrs({
154
- 'data-garden-id': COMPONENT_ID$p,
155
- 'data-garden-version': '9.0.0-next.6'
156
- }).withConfig({
157
- displayName: "StyledFloatingListbox",
158
- componentId: "sc-1cp6spf-0"
159
- })(["top:0;left:0;", ";", ";"], props => menuStyles(props.position, {
160
- theme: props.theme,
161
- hidden: props.isHidden,
162
- animationModifier: '[data-garden-animate="true"]',
163
- zIndex: props.zIndex
164
- }), props => retrieveComponentStyles(COMPONENT_ID$p, props));
165
- StyledFloatingListbox.defaultProps = {
166
- theme: DEFAULT_THEME
167
- };
168
-
169
- const COMPONENT_ID$o = 'dropdowns.combobox.input';
170
- const colorStyles$8 = props => {
171
- const placeholderColor = getColorV8('neutralHue', 400, props.theme);
172
- return css(["background-color:inherit;color:inherit;&::placeholder{opacity:1;color:", ";}"], placeholderColor);
173
- };
174
- const getHeight = props => {
175
- if (props.isBare && !props.isMultiselectable) {
176
- return props.theme.space.base * 5;
177
- }
178
- return props.theme.space.base * (props.isCompact ? 5 : 8);
179
- };
180
- const sizeStyles$9 = props => {
181
- const height = props.theme.space.base * 5;
182
- const fontSize = props.theme.fontSizes.md;
183
- const lineHeight = getLineHeight(height, fontSize);
184
- const margin = math(`${props.theme.shadowWidths.sm} + ${(getHeight(props) - height) / 2}`);
185
- const minWidth = `${props.theme.space.base * 8}px`;
186
- return css(["min-width:", ";height:", "px;line-height:", ";font-size:", ";&&{margin-top:", ";margin-bottom:", ";}"], minWidth, height, lineHeight, fontSize, margin, margin);
187
- };
188
- const StyledInput = styled.input.attrs({
189
- 'data-garden-id': COMPONENT_ID$o,
190
- 'data-garden-version': '9.0.0-next.6'
191
- }).withConfig({
192
- displayName: "StyledInput",
193
- componentId: "sc-1lkqdg-0"
194
- })(["flex-basis:0;flex-grow:1;border:none;padding:0;font-family:inherit;&:focus{outline:none;}", ";", ";&[hidden]{display:revert;", "}&[aria-hidden='true']{display:none;}", ";"], sizeStyles$9, colorStyles$8, props => props.isEditable && hideVisually(), props => retrieveComponentStyles(COMPONENT_ID$o, props));
195
- StyledInput.defaultProps = {
196
- theme: DEFAULT_THEME
197
- };
198
-
199
- const COMPONENT_ID$n = 'dropdowns.combobox.input_group';
200
- const sizeStyles$8 = props => {
201
- const margin = props.theme.shadowWidths.sm;
202
- return css(["margin:-", ";min-width:0;& > *{margin:", ";}"], margin, margin);
203
- };
204
- const StyledInputGroup = styled.div.attrs({
205
- 'data-garden-id': COMPONENT_ID$n,
206
- 'data-garden-version': '9.0.0-next.6'
207
- }).withConfig({
208
- displayName: "StyledInputGroup",
209
- componentId: "sc-yx3q7u-0"
210
- })(["display:flex;flex-grow:1;flex-wrap:wrap;", ";", ";"], sizeStyles$8, props => retrieveComponentStyles(COMPONENT_ID$n, props));
211
- StyledInputGroup.defaultProps = {
212
- theme: DEFAULT_THEME
213
- };
214
-
215
- const COMPONENT_ID$m = 'dropdowns.combobox.trigger';
216
- const colorStyles$7 = props => {
217
- const SHADE = 600;
218
- let hue = 'neutralHue';
219
- if (props.validation === 'success') {
220
- hue = 'successHue';
221
- } else if (props.validation === 'warning') {
222
- hue = 'warningHue';
223
- } else if (props.validation === 'error') {
224
- hue = 'dangerHue';
225
- }
226
- const backgroundColor = props.isBare ? 'transparent' : getColorV8('background', 600 , props.theme);
227
- let borderColor;
228
- let hoverBorderColor;
229
- let focusBorderColor;
230
- let focusShade;
231
- if (props.validation) {
232
- borderColor = getColorV8(hue, SHADE, props.theme);
233
- hoverBorderColor = borderColor;
234
- if (props.validation === 'warning') {
235
- focusBorderColor = getColorV8(hue, SHADE + 100, props.theme);
236
- focusShade = SHADE + 100;
237
- } else {
238
- focusBorderColor = borderColor;
239
- }
240
- } else {
241
- borderColor = getColorV8('neutralHue', SHADE - 300, props.theme);
242
- hoverBorderColor = getColorV8('primaryHue', SHADE, props.theme);
243
- focusBorderColor = hoverBorderColor;
244
- }
245
- const disabledBackgroundColor = props.isBare ? undefined : getColorV8('neutralHue', SHADE - 500, props.theme);
246
- const disabledBorderColor = getColorV8('neutralHue', SHADE - 400, props.theme);
247
- const disabledForegroundColor = getColorV8('neutralHue', SHADE - 200, props.theme);
248
- const focusSelector = `
249
- &:focus-within:not([aria-disabled='true']),
250
- &:focus-visible
251
- `;
252
- return css(["border-color:", ";background-color:", ";color:", ";&:hover{border-color:", ";}", " &[aria-disabled='true']{border-color:", ";background-color:", ";color:", ";}"], props.isLabelHovered ? hoverBorderColor : borderColor, backgroundColor, getColorV8('foreground', 600 , props.theme), hoverBorderColor, focusStyles({
253
- theme: props.theme,
254
- inset: props.focusInset,
255
- hue: focusBorderColor,
256
- shade: focusShade,
257
- selector: focusSelector,
258
- styles: {
259
- borderColor: focusBorderColor
260
- },
261
- condition: !props.isBare
262
- }), disabledBorderColor, disabledBackgroundColor, disabledForegroundColor);
263
- };
264
- const sizeStyles$7 = props => {
265
- const inputHeight = getHeight(props);
266
- let minHeight;
267
- let horizontalPadding;
268
- if (props.isBare) {
269
- if (props.isMultiselectable) {
270
- minHeight = math(`${props.theme.shadowWidths.sm} * 2 + ${inputHeight}`);
271
- horizontalPadding = props.theme.shadowWidths.sm;
272
- } else {
273
- minHeight = `${inputHeight}px`;
274
- horizontalPadding = '0';
275
- }
276
- } else {
277
- minHeight = `${props.theme.space.base * (props.isCompact ? 3 : 2) + inputHeight}px`;
278
- horizontalPadding = `${props.theme.space.base * 3}px`;
279
- }
280
- const maxHeight = props.maxHeight || minHeight;
281
- const verticalPadding = math(`(${minHeight} - ${inputHeight} - (${props.isBare ? 0 : props.theme.borderWidths.sm} * 2)) / 2`);
282
- return css(["padding:", " ", ";min-height:", ";max-height:", ";font-size:", ";"], verticalPadding, horizontalPadding, minHeight, maxHeight, props.theme.fontSizes.md);
283
- };
284
- const StyledTrigger = styled.div.attrs({
285
- 'data-garden-id': COMPONENT_ID$m,
286
- 'data-garden-version': '9.0.0-next.6'
287
- }).withConfig({
288
- displayName: "StyledTrigger",
289
- componentId: "sc-116nftk-0"
290
- })(["overflow-y:auto;transition:border-color 0.25s ease-in-out,box-shadow 0.1s ease-in-out,background-color 0.25s ease-in-out,color 0.25s ease-in-out;border:", ";border-radius:", ";cursor:", ";box-sizing:border-box;", ";&:focus{outline:none;}", ";&[aria-disabled='true']{cursor:default;}", ";"], props => props.isBare ? 'none' : props.theme.borders.sm, props => props.isBare ? '0' : props.theme.borderRadii.md, props => !props.isAutocomplete && props.isEditable ? 'text' : 'pointer', sizeStyles$7, colorStyles$7, props => retrieveComponentStyles(COMPONENT_ID$m, props));
291
- StyledTrigger.defaultProps = {
292
- theme: DEFAULT_THEME
293
- };
294
-
295
- const COMPONENT_ID$l = 'dropdowns.combobox.input_icon';
296
- const colorStyles$6 = props => {
297
- const color = getColorV8('neutralHue', 600, props.theme);
298
- const focusColor = getColorV8('neutralHue', 700, props.theme);
299
- const disabledColor = getColorV8('neutralHue', 400, props.theme);
300
- return css(["color:", ";", ":hover &,", ":focus-within &,", ":focus &,", "[data-garden-focus-visible='true'] &{color:", ";}", "[aria-disabled='true'] &{color:", ";}"], props.isLabelHovered ? focusColor : color, StyledTrigger, StyledTrigger, StyledTrigger, StyledTrigger, focusColor, StyledTrigger, disabledColor);
301
- };
302
- const sizeStyles$6 = props => {
303
- const size = props.theme.iconSizes.md;
304
- const position = math(`(${getHeight(props)} - ${size}) / 2`);
305
- const margin = `${props.theme.space.base * 2}px`;
306
- let side;
307
- if (props.isEnd) {
308
- side = props.theme.rtl ? 'right' : 'left';
309
- } else {
310
- side = props.theme.rtl ? 'left' : 'right';
311
- }
312
- return css(["top:", ";margin-", ":", ";width:", ";height:", ";"], position, side, margin, size, size);
313
- };
314
- const StyledInputIcon = styled(_ref => {
315
- let {
316
- children,
317
- isCompact,
318
- isDisabled,
319
- isEnd,
320
- isLabelHovered,
321
- isRotated,
322
- theme,
323
- ...props
324
- } = _ref;
325
- return cloneElement(Children.only(children), props);
326
- }).attrs({
327
- 'data-garden-id': COMPONENT_ID$l,
328
- 'data-garden-version': '9.0.0-next.6'
329
- }).withConfig({
330
- displayName: "StyledInputIcon",
331
- componentId: "sc-gqbs1s-0"
332
- })(["position:sticky;flex-shrink:0;transform:", ";transition:transform 0.25s ease-in-out,color 0.25s ease-in-out;", ";", ";", ";"], props => props.isRotated && `rotate(${props.theme.rtl ? '-' : '+'}180deg)`, sizeStyles$6, colorStyles$6, props => retrieveComponentStyles(COMPONENT_ID$l, props));
333
- StyledInputIcon.defaultProps = {
334
- theme: DEFAULT_THEME
335
- };
336
-
337
- const COMPONENT_ID$k = 'dropdowns.combobox.option';
338
- const colorStyles$5 = props => {
339
- let backgroundColor;
340
- let boxShadow;
341
- if (props.isActive && props.$type !== 'group' && props.$type !== 'header') {
342
- const hue = props.$type === 'danger' ? 'dangerHue' : 'primaryHue';
343
- backgroundColor = getColorV8(hue, 600, props.theme, 0.08);
344
- boxShadow = `inset ${props.theme.rtl ? `-${props.theme.shadowWidths.md}` : props.theme.shadowWidths.md} 0 ${getColorV8(hue, 600, props.theme)}`;
345
- }
346
- const disabledForegroundColor = getColorV8('neutralHue', 400, props.theme);
347
- let foregroundColor = getColorV8('foreground', 600 , props.theme);
348
- if (props.$type === 'add') {
349
- foregroundColor = getColorV8('primaryHue', 600, props.theme);
350
- } else if (props.$type === 'danger') {
351
- foregroundColor = getColorV8('dangerHue', 600, props.theme);
352
- }
353
- return css(["box-shadow:", ";background-color:", ";color:", ";&[aria-disabled='true']{background-color:transparent;color:", ";}"], boxShadow, backgroundColor, foregroundColor, disabledForegroundColor);
354
- };
355
- const getMinHeight = props => props.theme.space.base * (props.isCompact ? 7 : 9);
356
- const sizeStyles$5 = props => {
357
- const lineHeight = props.theme.lineHeights.md;
358
- const minHeight = getMinHeight(props);
359
- const paddingHorizontal = props.$type === 'group' ? 0 : `${props.theme.space.base * 9}px`;
360
- const paddingVertical = props.$type === 'group' ? 0 : math(`(${minHeight} - ${lineHeight}) / 2`);
361
- return css(["box-sizing:border-box;padding:", " ", ";min-height:", "px;line-height:", ";"], paddingVertical, paddingHorizontal, minHeight, lineHeight);
362
- };
363
- const StyledOption = styled.li.attrs({
364
- 'data-garden-id': COMPONENT_ID$k,
365
- 'data-garden-version': '9.0.0-next.6'
366
- }).withConfig({
367
- displayName: "StyledOption",
368
- componentId: "sc-jl4wn6-0"
369
- })(["display:flex;position:relative;transition:color 0.25s ease-in-out;cursor:", ";word-wrap:break-word;font-weight:", ";user-select:none;&:focus{outline:none;}", ";", ";&[aria-disabled='true']{cursor:default;}&[aria-hidden='true']{", ";}", ";"], props => props.$type === 'group' || props.$type === 'header' ? 'default' : 'pointer', props => props.$type === 'header' || props.$type === 'previous' ? props.theme.fontWeights.semibold : props.theme.fontWeights.regular, sizeStyles$5, colorStyles$5, hideVisually(), props => retrieveComponentStyles(COMPONENT_ID$k, props));
370
- StyledOption.defaultProps = {
371
- theme: DEFAULT_THEME
372
- };
373
-
374
- const COMPONENT_ID$j = 'dropdowns.combobox.option.content';
375
- const StyledOptionContent = styled.div.attrs({
376
- 'data-garden-id': COMPONENT_ID$j,
377
- 'data-garden-version': '9.0.0-next.6'
378
- }).withConfig({
379
- displayName: "StyledOptionContent",
380
- componentId: "sc-121ujpu-0"
381
- })(["display:flex;flex-direction:column;flex-grow:1;", ";"], props => retrieveComponentStyles(COMPONENT_ID$j, props));
382
- StyledOptionContent.defaultProps = {
383
- theme: DEFAULT_THEME
384
- };
385
-
386
- const COMPONENT_ID$i = 'dropdowns.combobox.optgroup';
387
- const StyledOptGroup = styled.ul.attrs({
388
- 'data-garden-id': COMPONENT_ID$i,
389
- 'data-garden-version': '9.0.0-next.6'
390
- }).withConfig({
391
- displayName: "StyledOptGroup",
392
- componentId: "sc-1kavqsx-0"
393
- })(["margin:0;padding:0;list-style-type:none;", ";"], props => retrieveComponentStyles(COMPONENT_ID$i, props));
394
- StyledOptGroup.defaultProps = {
395
- theme: DEFAULT_THEME
396
- };
397
-
398
- const COMPONENT_ID$h = 'dropdowns.combobox.separator';
399
- const colorStyles$4 = props => {
400
- const backgroundColor = getColorV8('neutralHue', 200, props.theme);
401
- return css(["background-color:", ";"], backgroundColor);
402
- };
403
- const sizeStyles$4 = props => {
404
- const margin = `${props.theme.space.base}px`;
405
- const height = props.theme.borderWidths.sm;
406
- return css(["margin:", " 0;height:", ";"], margin, height);
407
- };
408
- const StyledListboxSeparator = styled.li.attrs({
409
- 'data-garden-id': COMPONENT_ID$h,
410
- 'data-garden-version': '9.0.0-next.6'
411
- }).withConfig({
412
- displayName: "StyledListboxSeparator",
413
- componentId: "sc-1p6toh2-0"
414
- })(["cursor:default;", ";", ";", ";"], sizeStyles$4, colorStyles$4, props => retrieveComponentStyles(COMPONENT_ID$h, props));
415
- StyledListboxSeparator.defaultProps = {
416
- theme: DEFAULT_THEME
417
- };
418
-
419
- const COMPONENT_ID$g = 'dropdowns.combobox.listbox';
420
- const sizeStyles$3 = props => {
421
- const padding = props.theme.space.base;
422
- const minHeight = props.minHeight === undefined ? `${getMinHeight(props) + padding * 2}px` : props.minHeight;
423
- return css(["min-height:", ";max-height:", ";&&&{padding-top:", "px;padding-bottom:", "px;}"], minHeight, props.maxHeight, padding, padding);
424
- };
425
- const StyledListbox = styled.ul.attrs({
426
- 'data-garden-id': COMPONENT_ID$g,
427
- 'data-garden-version': '9.0.0-next.6'
428
- }).withConfig({
429
- displayName: "StyledListbox",
430
- componentId: "sc-1k13ba7-0"
431
- })(["overflow-y:auto;list-style-type:none;", ";&&&{display:block;}", ":first-child ", " ", ":first-child ", "[role='none']:first-child{display:none;}"], sizeStyles$3, StyledOption, StyledOptionContent, StyledOptGroup, StyledListboxSeparator);
432
- StyledListbox.defaultProps = {
433
- theme: DEFAULT_THEME
434
- };
435
-
436
- const COMPONENT_ID$f = 'dropdowns.combobox.option.icon';
437
- const sizeStyles$2 = props => {
438
- const size = props.theme.iconSizes.md;
439
- const marginTop = math(`(${props.theme.lineHeights.md} - ${size}) / 2`);
440
- const marginHorizontal = `${props.theme.space.base * 2}px`;
441
- return css(["margin-top:", ";margin-", ":", ";width:", ";height:", ";"], marginTop, props.theme.rtl ? 'left' : 'right', marginHorizontal, size, size);
442
- };
443
- const StyledOptionIcon = styled(_ref => {
444
- let {
445
- children,
446
- theme,
447
- ...props
448
- } = _ref;
449
- return cloneElement(Children.only(children), props);
450
- }).attrs({
451
- 'data-garden-id': COMPONENT_ID$f,
452
- 'data-garden-version': '9.0.0-next.6'
453
- }).withConfig({
454
- displayName: "StyledOptionIcon",
455
- componentId: "sc-qsab3y-0"
456
- })(["flex-shrink:0;", ";", ";"], sizeStyles$2, props => retrieveComponentStyles(COMPONENT_ID$f, props));
457
- StyledOptionIcon.defaultProps = {
458
- theme: DEFAULT_THEME
459
- };
460
-
461
- const COMPONENT_ID$e = 'dropdowns.combobox.option.meta';
462
- const colorStyles$3 = props => {
463
- const color = getColorV8('neutralHue', props.isDisabled ? 400 : 600, props.theme);
464
- return css(["color:", ";"], color);
465
- };
466
- const sizeStyles$1 = props => {
467
- const lineHeight = props.theme.lineHeights.sm;
468
- const fontSize = props.theme.fontSizes.sm;
469
- return css(["line-height:", ";font-size:", ";"], lineHeight, fontSize);
470
- };
471
- const StyledOptionMeta = styled.div.attrs({
472
- 'data-garden-id': COMPONENT_ID$e,
473
- 'data-garden-version': '9.0.0-next.6'
474
- }).withConfig({
475
- displayName: "StyledOptionMeta",
476
- componentId: "sc-j6pu10-0"
477
- })(["transition:color 0.25s ease-in-out;font-weight:", ";", ";", ";", ";"], props => props.theme.fontWeights.regular, sizeStyles$1, colorStyles$3, props => retrieveComponentStyles(COMPONENT_ID$e, props));
478
- StyledOptionMeta.defaultProps = {
479
- theme: DEFAULT_THEME
480
- };
481
-
482
- const COMPONENT_ID$d = 'dropdowns.combobox.option.type_icon';
483
- const colorStyles$2 = props => {
484
- const opacity = props.type && props.type !== 'danger' ? 1 : 0;
485
- let color;
486
- if (props.type === 'add' || props.type === 'danger') {
487
- color = 'inherit';
488
- } else if (props.type === 'header' || props.type === 'next' || props.type === 'previous') {
489
- color = getColorV8('neutralHue', 600, props.theme);
490
- } else {
491
- color = getColorV8('primaryHue', 600, props.theme);
492
- }
493
- return css(["opacity:", ";color:", ";", "[aria-selected='true'] > &{opacity:1;}", "[aria-disabled='true'] > &{color:inherit;}"], opacity, color, StyledOption, StyledOption);
494
- };
495
- const sizeStyles = props => {
496
- const size = props.theme.iconSizes.md;
497
- const position = `${props.theme.space.base * 3}px`;
498
- const top = math(`(${getMinHeight(props)} - ${size}) / 2`);
499
- let side;
500
- if (props.type === 'next') {
501
- side = props.theme.rtl ? 'left' : 'right';
502
- } else {
503
- side = props.theme.rtl ? 'right' : 'left';
504
- }
505
- return css(["top:", ";", ":", ";width:", ";height:", ";"], top, side, position, size, size);
506
- };
507
- const StyledOptionTypeIcon = styled(_ref => {
508
- let {
509
- children,
510
- isCompact,
511
- theme,
512
- type,
513
- ...props
514
- } = _ref;
515
- return cloneElement(Children.only(children), props);
516
- }).attrs({
517
- 'data-garden-id': COMPONENT_ID$d,
518
- 'data-garden-version': '9.0.0-next.6'
519
- }).withConfig({
520
- displayName: "StyledOptionTypeIcon",
521
- componentId: "sc-xpink2-0"
522
- })(["position:absolute;transform:", ";transition:opacity 0.1s ease-in-out;", ";", ";", ";"], props => props.theme.rtl && (props.type === 'next' || props.type === 'previous') && 'rotate(180deg)', sizeStyles, colorStyles$2, props => retrieveComponentStyles(COMPONENT_ID$d, props));
523
- StyledOptionTypeIcon.defaultProps = {
524
- theme: DEFAULT_THEME
525
- };
526
-
527
- const COMPONENT_ID$c = 'dropdowns.combobox.tag';
528
- const StyledTag = styled(Tag$1).attrs({
529
- 'data-garden-id': COMPONENT_ID$c,
530
- 'data-garden-version': '9.0.0-next.6'
531
- }).withConfig({
532
- displayName: "StyledTag",
533
- componentId: "sc-1alam0r-0"
534
- })(["&[aria-disabled='true']{color:", ";}&[hidden]{display:revert;", "}", ";"], props => props.hue ? undefined : getColorV8('neutralHue', 400, props.theme), hideVisually(), props => retrieveComponentStyles(COMPONENT_ID$c, props));
535
- StyledTag.defaultProps = {
536
- theme: DEFAULT_THEME
537
- };
538
-
539
- const COMPONENT_ID$b = 'dropdowns.combobox.value';
540
- const colorStyles$1 = props => {
541
- const foregroundColor = props.isPlaceholder && getColorV8('neutralHue', 400, props.theme);
542
- return css(["color:", ";"], foregroundColor);
543
- };
544
- const StyledValue = styled.div.attrs({
545
- 'data-garden-id': COMPONENT_ID$b,
546
- 'data-garden-version': '9.0.0-next.6'
547
- }).withConfig({
548
- displayName: "StyledValue",
549
- componentId: "sc-t719sx-0"
550
- })(["flex-basis:0;flex-grow:1;cursor:", ";overflow:hidden;text-overflow:ellipsis;white-space:pre;user-select:none;", ";", ";&[hidden]{display:none;}", ";"], props => {
551
- if (props.isDisabled) {
552
- return 'default';
553
- }
554
- return props.isEditable && !props.isAutocomplete ? 'text' : 'pointer';
555
- }, sizeStyles$9, colorStyles$1, props => retrieveComponentStyles(COMPONENT_ID$b, props));
556
- StyledValue.defaultProps = {
557
- theme: DEFAULT_THEME
558
- };
559
-
560
- const COMPONENT_ID$a = 'dropdowns.combobox.tags_button';
561
- const colorStyles = props => {
562
- const color = getColorV8('primaryHue', 600, props.theme);
563
- return css(["color:", ";&:disabled{color:inherit;}"], color);
564
- };
565
- const StyledTagsButton = styled(StyledValue).attrs({
566
- as: 'button',
567
- 'data-garden-id': COMPONENT_ID$a,
568
- 'data-garden-version': '9.0.0-next.6'
569
- }).withConfig({
570
- displayName: "StyledTagsButton",
571
- componentId: "sc-6q5w33-0"
572
- })(["display:inline-flex;flex:0 1 auto;align-items:center;border:none;background-color:transparent;cursor:pointer;min-width:auto;font-family:inherit;&:hover{text-decoration:underline;}", ";&:disabled{cursor:default;text-decoration:none;}", ";"], colorStyles, props => retrieveComponentStyles(COMPONENT_ID$a, props));
573
- StyledTagsButton.defaultProps = {
574
- theme: DEFAULT_THEME
575
- };
576
-
577
- const COMPONENT_ID$9 = 'dropdowns.menu';
578
- const StyledMenu = styled(StyledListbox).attrs({
579
- 'data-garden-id': COMPONENT_ID$9,
580
- 'data-garden-version': '9.0.0-next.6'
581
- }).withConfig({
582
- displayName: "StyledMenu",
583
- componentId: "sc-f77ntu-0"
584
- })(["position:static !important;", ";", ";"], props => props.arrowPosition && arrowStyles(props.arrowPosition, {
585
- size: `${props.theme.space.base * 2}px`,
586
- inset: '2px',
587
- animationModifier: '[data-garden-animate-arrow="true"]'
588
- }), props => retrieveComponentStyles(COMPONENT_ID$9, props));
589
- StyledMenu.defaultProps = {
590
- theme: DEFAULT_THEME
591
- };
592
-
593
- const COMPONENT_ID$8 = 'dropdowns.menu.floating';
594
- const StyledFloatingMenu = styled(StyledFloatingListbox).attrs({
595
- 'data-garden-id': COMPONENT_ID$8,
596
- 'data-garden-version': '9.0.0-next.6'
597
- }).withConfig({
598
- displayName: "StyledFloatingMenu",
599
- componentId: "sc-1rc7ahb-0"
600
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID$8, props));
601
- StyledFloatingMenu.defaultProps = {
602
- theme: DEFAULT_THEME
603
- };
604
-
605
- const COMPONENT_ID$7 = 'dropdowns.menu.item';
606
- const StyledItem = styled(StyledOption).attrs({
607
- 'data-garden-id': COMPONENT_ID$7,
608
- 'data-garden-version': '9.0.0-next.6'
609
- }).withConfig({
610
- displayName: "StyledItem",
611
- componentId: "sc-1jp99dq-0"
612
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID$7, props));
613
- StyledItem.defaultProps = {
614
- theme: DEFAULT_THEME
615
- };
616
-
617
- const COMPONENT_ID$6 = 'dropdowns.menu.item.content';
618
- const StyledItemContent = styled(StyledOptionContent).attrs({
619
- 'data-garden-id': COMPONENT_ID$6,
620
- 'data-garden-version': '9.0.0-next.6'
621
- }).withConfig({
622
- displayName: "StyledItemContent",
623
- componentId: "sc-1opglsb-0"
624
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID$6, props));
625
- StyledItemContent.defaultProps = {
626
- theme: DEFAULT_THEME
627
- };
628
-
629
- const COMPONENT_ID$5 = 'dropdowns.menu.item_group';
630
- const StyledItemGroup = styled(StyledOptGroup).attrs({
631
- 'data-garden-id': COMPONENT_ID$5,
632
- 'data-garden-version': '9.0.0-next.6'
633
- }).withConfig({
634
- displayName: "StyledItemGroup",
635
- componentId: "sc-1umk3cg-0"
636
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID$5, props));
637
- StyledItemGroup.defaultProps = {
638
- theme: DEFAULT_THEME
639
- };
640
-
641
- const COMPONENT_ID$4 = 'dropdowns.menu.item.icon';
642
- const StyledItemIcon = styled(StyledOptionIcon).attrs({
643
- 'data-garden-id': COMPONENT_ID$4,
644
- 'data-garden-version': '9.0.0-next.6'
645
- }).withConfig({
646
- displayName: "StyledItemIcon",
647
- componentId: "sc-w9orqb-0"
648
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID$4, props));
649
- StyledItemIcon.defaultProps = {
650
- theme: DEFAULT_THEME
651
- };
652
-
653
- const COMPONENT_ID$3 = 'dropdowns.menu.item.meta';
654
- const StyledItemMeta = styled(StyledOptionMeta).attrs({
655
- 'data-garden-id': COMPONENT_ID$3,
656
- 'data-garden-version': '9.0.0-next.6'
657
- }).withConfig({
658
- displayName: "StyledItemMeta",
659
- componentId: "sc-1unw3x1-0"
660
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID$3, props));
661
- StyledItemMeta.defaultProps = {
662
- theme: DEFAULT_THEME
663
- };
664
-
665
- const COMPONENT_ID$2 = 'dropdowns.menu.item.type_icon';
666
- const StyledItemTypeIcon = styled(StyledOptionTypeIcon).attrs({
667
- 'data-garden-id': COMPONENT_ID$2,
668
- 'data-garden-version': '9.0.0-next.6'
669
- }).withConfig({
670
- displayName: "StyledItemTypeIcon",
671
- componentId: "sc-1pll3nu-0"
672
- })(["", "[aria-checked='true'] > &{opacity:1;}", ";"], StyledItem, props => retrieveComponentStyles(COMPONENT_ID$2, props));
673
- StyledItemTypeIcon.defaultProps = {
674
- theme: DEFAULT_THEME
675
- };
676
-
677
- const COMPONENT_ID$1 = 'dropdowns.menu.button';
678
- const StyledButton = styled(Button).attrs({
679
- 'data-garden-id': COMPONENT_ID$1,
680
- 'data-garden-version': '9.0.0-next.6'
681
- }).withConfig({
682
- displayName: "StyledButton",
683
- componentId: "sc-5hs2jg-0"
684
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID$1, props));
685
- StyledButton.defaultProps = {
686
- theme: DEFAULT_THEME
687
- };
688
-
689
- const COMPONENT_ID = 'dropdowns.menu.separator';
690
- const StyledSeparator = styled(StyledListboxSeparator).attrs({
691
- 'data-garden-id': COMPONENT_ID,
692
- 'data-garden-version': '9.0.0-next.6'
693
- }).withConfig({
694
- displayName: "StyledSeparator",
695
- componentId: "sc-8kqwen-0"
696
- })(["", ";"], props => retrieveComponentStyles(COMPONENT_ID, props));
697
- StyledSeparator.defaultProps = {
698
- theme: DEFAULT_THEME
699
- };
700
-
701
- const Listbox = forwardRef((_ref, ref) => {
702
- let {
703
- appendToNode,
704
- children,
705
- isCompact,
706
- isExpanded,
707
- maxHeight,
708
- minHeight,
709
- onMouseDown,
710
- triggerRef,
711
- zIndex,
712
- ...props
713
- } = _ref;
714
- const floatingRef = useRef(null);
715
- const [isVisible, setIsVisible] = useState(false);
716
- const [height, setHeight] = useState();
717
- const [width, setWidth] = useState();
718
- const theme = useContext(ThemeContext) || DEFAULT_THEME;
719
- const {
720
- refs,
721
- placement,
722
- update,
723
- floatingStyles: {
724
- transform
725
- }
726
- } = useFloating({
727
- elements: {
728
- reference: triggerRef?.current,
729
- floating: floatingRef?.current
730
- },
731
- placement: 'bottom-start',
732
- middleware: [offset(theme.space.base), flip(), size({
733
- apply: _ref2 => {
734
- let {
735
- rects,
736
- availableHeight
737
- } = _ref2;
738
- if (rects.reference.width > 0) {
739
- setWidth(rects.reference.width);
740
- if (!(minHeight === null || minHeight === 'fit-content') && rects.floating.height > availableHeight) {
741
- setHeight(availableHeight);
742
- }
743
- }
744
- }
745
- })]
746
- });
747
- const handleMouseDown = event => event.preventDefault();
748
- useEffect(() => {
749
- let cleanup;
750
- if (isExpanded && refs.reference.current && refs.floating.current) {
751
- cleanup = autoUpdate(refs.reference.current, refs.floating.current, update, {
752
- elementResize: typeof ResizeObserver === 'function'
753
- });
754
- }
755
- return () => cleanup && cleanup();
756
- }, [isExpanded, refs.reference, refs.floating, update]);
757
- useEffect(() => {
758
- let timeout;
759
- if (isExpanded) {
760
- setIsVisible(true);
761
- } else {
762
- timeout = setTimeout(() => {
763
- setIsVisible(false);
764
- setHeight(undefined);
765
- }, 200 );
766
- }
767
- return () => clearTimeout(timeout);
768
- }, [isExpanded]);
769
- useEffect(() => {
770
- if (height) {
771
- setHeight(undefined);
772
- update();
773
- }
774
- }, [
775
- children, update]);
776
- const Node = React__default.createElement(StyledFloatingListbox, {
777
- "data-garden-animate": isVisible ? 'true' : 'false',
778
- isHidden: !isExpanded,
779
- position: placement === 'bottom-start' ? 'bottom' : 'top',
780
- style: {
781
- transform,
782
- width
783
- },
784
- zIndex: zIndex,
785
- ref: floatingRef
786
- }, React__default.createElement(StyledListbox, _extends$5({
787
- isCompact: isCompact,
788
- maxHeight: maxHeight,
789
- minHeight: minHeight,
790
- onMouseDown: composeEventHandlers(onMouseDown, handleMouseDown),
791
- style: {
792
- height
793
- }
794
- }, props, {
795
- ref: ref
796
- }), isVisible && children));
797
- return appendToNode ? createPortal(Node, appendToNode) : Node;
798
- });
799
- Listbox.displayName = 'Listbox';
800
- Listbox.propTypes = {
801
- appendToNode: PropTypes.any,
802
- isCompact: PropTypes.bool,
803
- isExpanded: PropTypes.bool,
804
- maxHeight: PropTypes.string,
805
- triggerRef: PropTypes.any.isRequired,
806
- zIndex: PropTypes.number
807
- };
808
-
809
- const toString = option => typeof option.value === 'string' ? option.value : JSON.stringify(option.value);
810
- const toOption = props => {
811
- return {
812
- value: props.value,
813
- label: props.label,
814
- hidden: props.isHidden,
815
- disabled: props.isDisabled,
816
- selected: props.isSelected
817
- };
818
- };
819
- const toOptions = (children, optionTagProps) => Children.toArray(children).reduce((options, option) => {
820
- const retVal = options;
821
- if ( isValidElement(option)) {
822
- if ('value' in option.props) {
823
- retVal.push(toOption(option.props));
824
- optionTagProps[toString(option.props)] = option.props.tagProps;
825
- } else {
826
- const props = option.props;
827
- const groupOptions = toOptions(props.children, optionTagProps);
828
- retVal.push({
829
- label: props.legend,
830
- options: groupOptions
831
- });
832
- }
833
- }
834
- return retVal;
835
- }, []);
836
-
837
- const TagAvatarComponent = Tag$1.Avatar;
838
- TagAvatarComponent.displayName = 'Tag.Avatar';
839
- const TagAvatar = TagAvatarComponent;
840
-
841
- const TagComponent = forwardRef((_ref, ref) => {
842
- let {
843
- children,
844
- option,
845
- removeLabel,
846
- tooltipZIndex,
847
- ...props
848
- } = _ref;
849
- const {
850
- getTagProps,
851
- isCompact,
852
- removeSelection
853
- } = useComboboxContext();
854
- const text = option.label || toString(option);
855
- const ariaLabel = useText(
856
- Tag, props, 'aria-label', `${text}, press delete or backspace to remove`, !option.disabled);
857
- const tagProps = getTagProps({
858
- option,
859
- 'aria-label': ariaLabel
860
- });
861
- const theme = useContext(ThemeContext) || DEFAULT_THEME;
862
- const doc = useDocument(theme);
863
- const handleClick = () => removeSelection(option.value);
864
- return React__default.createElement(StyledTag, _extends$5({
865
- "aria-disabled": option.disabled,
866
- tabIndex: option.disabled ? undefined : 0
867
- }, tagProps, props, {
868
- size: isCompact ? 'medium' : 'large',
869
- ref: ref
870
- }), children || React__default.createElement("span", null, text), !option.disabled && (removeLabel ?
871
- React__default.createElement(Tooltip, {
872
- appendToNode: doc?.body,
873
- content: removeLabel,
874
- zIndex: tooltipZIndex
875
- }, React__default.createElement(StyledTag.Close, {
876
- "aria-label": removeLabel,
877
- onClick: handleClick
878
- })) : React__default.createElement(StyledTag.Close, {
879
- onClick: handleClick
880
- })));
881
- });
882
- TagComponent.displayName = 'Tag';
883
- TagComponent.propTypes = {
884
- hue: PropTypes.string,
885
- isPill: PropTypes.bool,
886
- isRegular: PropTypes.bool,
887
- removeLabel: PropTypes.string
888
- };
889
- const Tag = TagComponent;
890
- Tag.Avatar = TagAvatar;
891
-
892
- const TagGroup = _ref => {
893
- let {
894
- children,
895
- isDisabled,
896
- isExpanded,
897
- listboxZIndex,
898
- maxTags,
899
- optionTagProps,
900
- selection
901
- } = _ref;
902
- return React__default.createElement(React__default.Fragment, null, selection.map((option, index) => {
903
- const key = toString(option);
904
- const disabled = isDisabled || option.disabled;
905
- return React__default.createElement(Tag, _extends$5({
906
- key: key,
907
- hidden: !isExpanded && index >= maxTags,
908
- option: {
909
- ...option,
910
- disabled
911
- },
912
- tooltipZIndex: listboxZIndex ? listboxZIndex + 1 : undefined
913
- }, optionTagProps[key]));
914
- }), children);
915
- };
916
- TagGroup.displayName = 'TagGroup';
917
-
918
- const MAX_TAGS = 4;
919
- const Combobox = forwardRef((_ref, ref) => {
920
- let {
921
- children,
922
- activeIndex,
923
- defaultActiveIndex,
924
- defaultExpanded,
925
- endIcon,
926
- focusInset,
927
- inputProps: _inputProps,
928
- inputValue: _inputValue,
929
- isAutocomplete,
930
- isBare,
931
- isCompact,
932
- isDisabled,
933
- isEditable,
934
- isExpanded: _isExpanded,
935
- isMultiselectable,
936
- listboxAppendToNode,
937
- listboxAriaLabel,
938
- listboxMaxHeight,
939
- listboxMinHeight,
940
- listboxZIndex,
941
- maxHeight,
942
- maxTags = MAX_TAGS,
943
- onChange,
944
- placeholder,
945
- renderExpandTags,
946
- renderValue,
947
- selectionValue,
948
- startIcon,
949
- validation,
950
- ...props
951
- } = _ref;
952
- const {
953
- hasHint,
954
- hasMessage,
955
- labelProps,
956
- setLabelProps,
957
- hintProps,
958
- setHintProps,
959
- messageProps,
960
- setMessageProps
961
- } = useFieldContext();
962
- const [isInputHidden, setIsInputHidden] = useState(true);
963
- const [isLabelHovered, setIsLabelHovered] = useState(false);
964
- const [isTagGroupExpanded, setIsTagGroupExpanded] = useState(false);
965
- const [optionTagProps, setOptionTagProps] = useState({});
966
- const options = useMemo(() => {
967
- const tagProps = {};
968
- const retVal = toOptions(children, tagProps);
969
- if (isMultiselectable) {
970
- setOptionTagProps(value => ({
971
- ...value,
972
- ...tagProps
973
- }));
974
- }
975
- return retVal;
976
- }, [children, isMultiselectable]);
977
- const triggerRef = useRef(null);
978
- const inputRef = useRef(null);
979
- const listboxRef = useRef(null);
980
- const theme = useContext(ThemeContext) || DEFAULT_THEME;
981
- const environment = useWindow(theme);
982
- const {
983
- activeValue,
984
- inputValue,
985
- isExpanded,
986
- getTriggerProps,
987
- getHintProps,
988
- getInputProps,
989
- getLabelProps,
990
- getListboxProps,
991
- getMessageProps,
992
- getOptionProps,
993
- getOptGroupProps,
994
- getTagProps,
995
- removeSelection,
996
- selection
997
- } = useCombobox({
998
- idPrefix: props.id,
999
- triggerRef,
1000
- inputRef,
1001
- listboxRef,
1002
- options,
1003
- environment,
1004
- hasHint,
1005
- hasMessage,
1006
- isAutocomplete,
1007
- isEditable,
1008
- isMultiselectable,
1009
- disabled: isDisabled,
1010
- inputValue: _inputValue,
1011
- selectionValue,
1012
- isExpanded: _isExpanded,
1013
- defaultExpanded,
1014
- activeIndex,
1015
- defaultActiveIndex,
1016
- onChange
1017
- });
1018
- const contextValue = useMemo(() => ({
1019
- activeValue,
1020
- getOptionProps,
1021
- getOptGroupProps,
1022
- getTagProps,
1023
- isCompact,
1024
- removeSelection
1025
- }), [activeValue, getOptionProps, getOptGroupProps, getTagProps, isCompact, removeSelection]);
1026
- const hasChevron = useMemo(() => !isBare && (isAutocomplete || !isEditable), [isAutocomplete, isBare, isEditable]);
1027
- const expandTags = useText(Combobox, {
1028
- renderExpandTags
1029
- }, 'renderExpandTags', '+ {{value}} more', isMultiselectable || false);
1030
- const _listboxAriaLabel = useText(Combobox, {
1031
- listboxAriaLabel
1032
- }, 'listboxAriaLabel', 'Options');
1033
- const triggerProps = {
1034
- isAutocomplete,
1035
- isBare,
1036
- isCompact,
1037
- isEditable,
1038
- isLabelHovered,
1039
- isMultiselectable,
1040
- maxHeight,
1041
- focusInset,
1042
- validation,
1043
- ...getTriggerProps({
1044
- onFocus: () => {
1045
- if (!isDisabled) {
1046
- if (isEditable) {
1047
- setIsInputHidden(false);
1048
- }
1049
- if (isMultiselectable) {
1050
- setIsTagGroupExpanded(true);
1051
- }
1052
- }
1053
- },
1054
- onBlur: event => {
1055
- if (event.relatedTarget === null || !triggerRef.current?.contains(event.relatedTarget)) {
1056
- if (isEditable) {
1057
- setIsInputHidden(true);
1058
- }
1059
- if (isMultiselectable) {
1060
- setIsTagGroupExpanded(false);
1061
- }
1062
- }
1063
- }
1064
- })
1065
- };
1066
- const inputProps = {
1067
- 'aria-invalid': validation === 'error' || validation === 'warning',
1068
- hidden: isInputHidden,
1069
- isBare,
1070
- isCompact,
1071
- isEditable,
1072
- isMultiselectable,
1073
- placeholder,
1074
- ...getInputProps({
1075
- ..._inputProps
1076
- })
1077
- };
1078
- const listboxProps = getListboxProps({
1079
- 'aria-label': _listboxAriaLabel
1080
- });
1081
- useEffect(() => {
1082
- if (!labelProps) {
1083
- const _labelProps = getLabelProps({
1084
- onMouseEnter: () => setIsLabelHovered(true),
1085
- onMouseLeave: () => setIsLabelHovered(false)
1086
- });
1087
- setLabelProps(_labelProps);
1088
- }
1089
- return () => labelProps && setLabelProps(undefined);
1090
- }, [getLabelProps, labelProps, setLabelProps]);
1091
- useEffect(() => {
1092
- if (!hintProps) {
1093
- const _hintProps = getHintProps();
1094
- setHintProps(_hintProps);
1095
- }
1096
- return () => hintProps && setHintProps(undefined);
1097
- }, [getHintProps, hintProps, setHintProps]);
1098
- useEffect(() => {
1099
- if (!messageProps) {
1100
- const _messageProps = getMessageProps();
1101
- setMessageProps(_messageProps);
1102
- }
1103
- return () => messageProps && setMessageProps(undefined);
1104
- }, [getMessageProps, messageProps, setMessageProps]);
1105
- return React__default.createElement(ComboboxContext.Provider, {
1106
- value: contextValue
1107
- }, React__default.createElement(StyledCombobox, _extends$5({
1108
- isCompact: isCompact,
1109
- tabIndex: -1
1110
- }, props, {
1111
- ref: ref
1112
- }), React__default.createElement(StyledTrigger, triggerProps, React__default.createElement(StyledContainer, null, startIcon && React__default.createElement(StyledInputIcon, {
1113
- isLabelHovered: isLabelHovered,
1114
- isCompact: isCompact
1115
- }, startIcon), React__default.createElement(StyledInputGroup, null, isMultiselectable && Array.isArray(selection) && React__default.createElement(TagGroup, {
1116
- isDisabled: isDisabled,
1117
- isExpanded: isTagGroupExpanded,
1118
- maxTags: maxTags,
1119
- optionTagProps: optionTagProps,
1120
- selection: selection
1121
- }, selection.length > maxTags && React__default.createElement(StyledTagsButton, {
1122
- disabled: isDisabled,
1123
- hidden: isTagGroupExpanded,
1124
- isCompact: isCompact,
1125
- tabIndex: -1,
1126
- type: "button"
1127
- }, (() => {
1128
- const value = selection.length - maxTags;
1129
- return renderExpandTags ? renderExpandTags(value) : expandTags?.replace('{{value}}', value.toString());
1130
- })())), React__default.createElement(StyledValue, {
1131
- hidden: !isInputHidden,
1132
- isAutocomplete: isAutocomplete,
1133
- isBare: isBare,
1134
- isCompact: isCompact,
1135
- isDisabled: isDisabled,
1136
- isEditable: isEditable,
1137
- isMultiselectable: isMultiselectable,
1138
- isPlaceholder: !(inputValue || renderValue)
1139
- }, renderValue ? renderValue({
1140
- selection,
1141
- inputValue
1142
- }) : inputValue || placeholder), React__default.createElement(StyledInput, inputProps)), (hasChevron || endIcon) && React__default.createElement(StyledInputIcon, {
1143
- isCompact: isCompact,
1144
- isEnd: true,
1145
- isLabelHovered: isLabelHovered,
1146
- isRotated: hasChevron && isExpanded
1147
- }, hasChevron ? React__default.createElement(SvgChevronDownStroke, null) : endIcon))), React__default.createElement(Listbox, _extends$5({
1148
- appendToNode: listboxAppendToNode,
1149
- isCompact: isCompact,
1150
- isExpanded: isExpanded,
1151
- maxHeight: listboxMaxHeight,
1152
- minHeight: listboxMinHeight,
1153
- triggerRef: triggerRef,
1154
- zIndex: listboxZIndex
1155
- }, listboxProps), children)));
1156
- });
1157
- Combobox.displayName = 'Combobox';
1158
- Combobox.propTypes = {
1159
- activeIndex: PropTypes.number,
1160
- defaultActiveIndex: PropTypes.number,
1161
- defaultExpanded: PropTypes.bool,
1162
- endIcon: PropTypes.any,
1163
- focusInset: PropTypes.bool,
1164
- id: PropTypes.string,
1165
- inputProps: PropTypes.object,
1166
- inputValue: PropTypes.string,
1167
- isAutocomplete: PropTypes.bool,
1168
- isBare: PropTypes.bool,
1169
- isCompact: PropTypes.bool,
1170
- isDisabled: PropTypes.bool,
1171
- isEditable: PropTypes.bool,
1172
- isExpanded: PropTypes.bool,
1173
- isMultiselectable: PropTypes.bool,
1174
- listboxAppendToNode: PropTypes.any,
1175
- listboxAriaLabel: PropTypes.string,
1176
- listboxMaxHeight: PropTypes.string,
1177
- listboxMinHeight: PropTypes.string,
1178
- listboxZIndex: PropTypes.number,
1179
- maxHeight: PropTypes.string,
1180
- maxTags: PropTypes.number,
1181
- onChange: PropTypes.func,
1182
- placeholder: PropTypes.string,
1183
- renderExpandTags: PropTypes.func,
1184
- renderValue: PropTypes.func,
1185
- selectionValue: PropTypes.any,
1186
- startIcon: PropTypes.any,
1187
- validation: PropTypes.oneOf(VALIDATION)
1188
- };
1189
- Combobox.defaultProps = {
1190
- isEditable: true,
1191
- listboxMaxHeight: '400px',
1192
- listboxZIndex: 1000,
1193
- maxTags: MAX_TAGS
1194
- };
1195
-
1196
- const Hint = forwardRef((props, ref) => {
1197
- const {
1198
- hintProps,
1199
- setHasHint
1200
- } = useFieldContext();
1201
- useEffect(() => {
1202
- setHasHint(true);
1203
- return () => setHasHint(false);
1204
- }, [setHasHint]);
1205
- return React__default.createElement(StyledHint, _extends$5({}, hintProps, props, {
1206
- ref: ref
1207
- }));
1208
- });
1209
- Hint.displayName = 'Hint';
1210
-
1211
- const Label = forwardRef((_ref, ref) => {
1212
- let {
1213
- onClick,
1214
- onMouseEnter,
1215
- onMouseLeave,
1216
- ...props
1217
- } = _ref;
1218
- const {
1219
- labelProps
1220
- } = useFieldContext();
1221
- return React__default.createElement(StyledLabel, _extends$5({}, labelProps, {
1222
- onClick: composeEventHandlers(onClick, labelProps?.onClick),
1223
- onMouseEnter: composeEventHandlers(onMouseEnter, labelProps?.onMouseEnter),
1224
- onMouseLeave: composeEventHandlers(onMouseLeave, labelProps?.onMouseLeave)
1225
- }, props, {
1226
- ref: ref
1227
- }));
1228
- });
1229
- Label.displayName = 'Label';
1230
- Label.propTypes = {
1231
- hidden: PropTypes.bool,
1232
- isRegular: PropTypes.bool
1233
- };
1234
-
1235
- const Message = forwardRef((props, ref) => {
1236
- const {
1237
- messageProps,
1238
- setHasMessage
1239
- } = useFieldContext();
1240
- useEffect(() => {
1241
- setHasMessage(true);
1242
- return () => setHasMessage(false);
1243
- }, [setHasMessage]);
1244
- return React__default.createElement(StyledMessage, _extends$5({}, messageProps, props, {
1245
- ref: ref
1246
- }));
1247
- });
1248
- Message.displayName = 'Message';
1249
- Message.propTypes = {
1250
- validation: PropTypes.oneOf(VALIDATION),
1251
- validationLabel: PropTypes.string
1252
- };
1253
-
1254
- const FieldComponent = forwardRef((props, ref) => {
1255
- const [labelProps, setLabelProps] = useState(undefined);
1256
- const [hintProps, setHintProps] = useState(undefined);
1257
- const [messageProps, setMessageProps] = useState(undefined);
1258
- const [hasHint, setHasHint] = useState(false);
1259
- const [hasMessage, setHasMessage] = useState(false);
1260
- const contextValue = useMemo(() => ({
1261
- labelProps,
1262
- setLabelProps,
1263
- hasHint,
1264
- setHasHint,
1265
- hintProps,
1266
- setHintProps,
1267
- hasMessage,
1268
- setHasMessage,
1269
- messageProps,
1270
- setMessageProps
1271
- }), [labelProps, setLabelProps, hasHint, setHasHint, hintProps, setHintProps, hasMessage, setHasMessage, messageProps, setMessageProps]);
1272
- return React__default.createElement(FieldContext.Provider, {
1273
- value: contextValue
1274
- }, React__default.createElement(StyledField, _extends$5({}, props, {
1275
- ref: ref
1276
- })));
1277
- });
1278
- FieldComponent.displayName = 'Field';
1279
- const Field = FieldComponent;
1280
- Field.Hint = Hint;
1281
- Field.Label = Label;
1282
- Field.Message = Message;
1283
-
1284
- var _path$3;
1285
- function _extends$3() { _extends$3 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3.apply(this, arguments); }
1286
- var SvgPlusStroke = function SvgPlusStroke(props) {
1287
- return /*#__PURE__*/React.createElement("svg", _extends$3({
1288
- xmlns: "http://www.w3.org/2000/svg",
1289
- width: 16,
1290
- height: 16,
1291
- focusable: "false",
1292
- viewBox: "0 0 16 16",
1293
- "aria-hidden": "true"
1294
- }, props), _path$3 || (_path$3 = /*#__PURE__*/React.createElement("path", {
1295
- stroke: "currentColor",
1296
- strokeLinecap: "round",
1297
- d: "M7.5 2.5v12m6-6h-12"
1298
- })));
1299
- };
1300
-
1301
- var _path$2;
1302
- function _extends$2() { _extends$2 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$2.apply(this, arguments); }
1303
- var SvgChevronRightStroke = function SvgChevronRightStroke(props) {
1304
- return /*#__PURE__*/React.createElement("svg", _extends$2({
1305
- xmlns: "http://www.w3.org/2000/svg",
1306
- width: 16,
1307
- height: 16,
1308
- focusable: "false",
1309
- viewBox: "0 0 16 16",
1310
- "aria-hidden": "true"
1311
- }, props), _path$2 || (_path$2 = /*#__PURE__*/React.createElement("path", {
1312
- fill: "currentColor",
1313
- d: "M5.61 3.312a.5.5 0 01.718-.69l.062.066 4 5a.5.5 0 01.054.542l-.054.082-4 5a.5.5 0 01-.83-.55l.05-.074L9.359 8l-3.75-4.688z"
1314
- })));
1315
- };
1316
-
1317
- var _path$1;
1318
- function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
1319
- var SvgChevronLeftStroke = function SvgChevronLeftStroke(props) {
1320
- return /*#__PURE__*/React.createElement("svg", _extends$1({
1321
- xmlns: "http://www.w3.org/2000/svg",
1322
- width: 16,
1323
- height: 16,
1324
- focusable: "false",
1325
- viewBox: "0 0 16 16",
1326
- "aria-hidden": "true"
1327
- }, props), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
1328
- fill: "currentColor",
1329
- d: "M10.39 12.688a.5.5 0 01-.718.69l-.062-.066-4-5a.5.5 0 01-.054-.542l.054-.082 4-5a.5.5 0 01.83.55l-.05.074L6.641 8l3.75 4.688z"
1330
- })));
1331
- };
1332
-
1333
- var _path;
1334
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1335
- var SvgCheckLgStroke = function SvgCheckLgStroke(props) {
1336
- return /*#__PURE__*/React.createElement("svg", _extends({
1337
- xmlns: "http://www.w3.org/2000/svg",
1338
- width: 16,
1339
- height: 16,
1340
- focusable: "false",
1341
- viewBox: "0 0 16 16",
1342
- "aria-hidden": "true"
1343
- }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
1344
- fill: "none",
1345
- stroke: "currentColor",
1346
- strokeLinecap: "round",
1347
- strokeLinejoin: "round",
1348
- d: "M1 9l4 4L15 3"
1349
- })));
1350
- };
1351
-
1352
- const OPTION_TYPE = ['add', 'danger', 'next', 'previous'];
1353
- const PLACEMENT = ['auto', ...PLACEMENT$1];
1354
-
1355
- const OptionContext = createContext(undefined);
1356
- const useOptionContext = () => {
1357
- const context = useContext(OptionContext);
1358
- if (!context) {
1359
- throw new Error('Error: this component must be rendered within an <Option>.');
1360
- }
1361
- return context;
1362
- };
1363
-
1364
- const OptionMetaComponent = forwardRef((props, ref) => {
1365
- const {
1366
- isDisabled
1367
- } = useOptionContext();
1368
- return React__default.createElement(StyledOptionMeta, _extends$5({
1369
- isDisabled: isDisabled
1370
- }, props, {
1371
- ref: ref
1372
- }));
1373
- });
1374
- OptionMetaComponent.displayName = 'Option.Meta';
1375
- const OptionMeta = OptionMetaComponent;
1376
-
1377
- const OptionComponent = forwardRef((_ref, ref) => {
1378
- let {
1379
- children,
1380
- icon,
1381
- isDisabled,
1382
- isHidden,
1383
- isSelected,
1384
- label,
1385
- type,
1386
- value,
1387
- ...props
1388
- } = _ref;
1389
- const contextValue = useMemo(() => ({
1390
- isDisabled
1391
- }), [isDisabled]);
1392
- const {
1393
- activeValue,
1394
- getOptionProps,
1395
- isCompact
1396
- } = useComboboxContext();
1397
- const isActive = value === activeValue;
1398
- const optionRef = useRef(null);
1399
- useEffect(() => {
1400
- if (isActive) {
1401
- setTimeout(() => {
1402
- if (optionRef.current && optionRef.current.scrollIntoView) {
1403
- optionRef.current.scrollIntoView({
1404
- block: 'nearest'
1405
- });
1406
- }
1407
- });
1408
- }
1409
- }, [isActive]);
1410
- const renderActionIcon = iconType => {
1411
- switch (iconType) {
1412
- case 'add':
1413
- return React__default.createElement(SvgPlusStroke, null);
1414
- case 'next':
1415
- return React__default.createElement(SvgChevronRightStroke, null);
1416
- case 'previous':
1417
- return React__default.createElement(SvgChevronLeftStroke, null);
1418
- default:
1419
- return React__default.createElement(SvgCheckLgStroke, null);
1420
- }
1421
- };
1422
- const option = toOption({
1423
- value,
1424
- label,
1425
- isDisabled,
1426
- isHidden,
1427
- isSelected
1428
- });
1429
- const optionProps = getOptionProps({
1430
- option,
1431
- ref: mergeRefs([optionRef, ref])
1432
- });
1433
- return React__default.createElement(OptionContext.Provider, {
1434
- value: contextValue
1435
- }, React__default.createElement(StyledOption, _extends$5({
1436
- isActive: isActive,
1437
- isCompact: isCompact,
1438
- $type: type
1439
- }, props, optionProps), React__default.createElement(StyledOptionTypeIcon, {
1440
- isCompact: isCompact,
1441
- type: type
1442
- }, renderActionIcon(type)), icon && React__default.createElement(StyledOptionIcon, null, icon), React__default.createElement(StyledOptionContent, null, children || label || toString({
1443
- value
1444
- }))));
1445
- });
1446
- OptionComponent.displayName = 'Option';
1447
- OptionComponent.propTypes = {
1448
- icon: PropTypes.any,
1449
- isDisabled: PropTypes.bool,
1450
- isSelected: PropTypes.bool,
1451
- isHidden: PropTypes.bool,
1452
- label: PropTypes.string,
1453
- tagProps: PropTypes.object,
1454
- type: PropTypes.oneOf(OPTION_TYPE),
1455
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired
1456
- };
1457
- const Option = OptionComponent;
1458
- Option.Meta = OptionMeta;
1459
-
1460
- const OptGroup = forwardRef((_ref, ref) => {
1461
- let {
1462
- children,
1463
- content,
1464
- icon,
1465
- legend,
1466
- 'aria-label': ariaLabel,
1467
- onMouseDown,
1468
- ...props
1469
- } = _ref;
1470
- const {
1471
- getOptGroupProps,
1472
- isCompact
1473
- } = useComboboxContext();
1474
- const handleMouseDown = event => event.preventDefault();
1475
- const groupAriaLabel = useText(OptGroup, {
1476
- 'aria-label': ariaLabel
1477
- }, 'aria-label', 'Group', !legend );
1478
- const optGroupProps = getOptGroupProps({
1479
- 'aria-label': groupAriaLabel || legend
1480
- });
1481
- return React__default.createElement(StyledOption, _extends$5({
1482
- isCompact: isCompact,
1483
- $type: "group",
1484
- onMouseDown: composeEventHandlers(onMouseDown, handleMouseDown),
1485
- role: "none"
1486
- }, props, {
1487
- ref: ref
1488
- }), React__default.createElement(StyledOptionContent, null, (content || legend) && React__default.createElement(StyledOption, {
1489
- as: "div",
1490
- isCompact: isCompact,
1491
- $type: "header"
1492
- }, icon && React__default.createElement(StyledOptionTypeIcon, {
1493
- isCompact: isCompact,
1494
- type: "header"
1495
- }, icon), content || legend), React__default.createElement(StyledOptGroup, _extends$5({
1496
- isCompact: isCompact
1497
- }, optGroupProps), React__default.createElement(StyledListboxSeparator, {
1498
- role: "none"
1499
- }), children)));
1500
- });
1501
- OptGroup.displayName = 'OptGroup';
1502
- OptGroup.propTypes = {
1503
- content: PropTypes.any,
1504
- icon: PropTypes.any,
1505
- legend: PropTypes.string
1506
- };
1507
-
1508
- const MenuContext = createContext(undefined);
1509
- const useMenuContext = () => {
1510
- const context = useContext(MenuContext);
1511
- if (!context) {
1512
- throw new Error('Error: this component must be rendered within a <Menu>.');
1513
- }
1514
- return context;
1515
- };
1516
-
1517
- const toItem = props => ({
1518
- value: props.value,
1519
- label: props.label,
1520
- ...(props.name && {
1521
- name: props.name
1522
- }),
1523
- ...(props.isDisabled && {
1524
- disabled: props.isDisabled
1525
- }),
1526
- ...(props.isSelected && {
1527
- selected: props.isSelected
1528
- }),
1529
- ...(props.selectionType && {
1530
- type: props.selectionType
1531
- }),
1532
- ...(props.type === 'next' && {
1533
- isNext: true
1534
- }),
1535
- ...(props.type === 'previous' && {
1536
- isPrevious: true
1537
- })
1538
- });
1539
- const toItems = (children, type) => Children.toArray(children).reduce((items, item) => {
1540
- const retVal = items;
1541
- if ( isValidElement(item)) {
1542
- if ('value' in item.props) {
1543
- retVal.push(toItem({
1544
- ...item.props,
1545
- selectionType: type
1546
- }));
1547
- } else {
1548
- const props = item.props;
1549
- const groupLabel = props.legend || props['aria-label'];
1550
- const isSelectableGroup = props.type && ['checkbox', 'radio'].includes(props.type);
1551
- if (groupLabel || isSelectableGroup) {
1552
- const groupItems = toItems(props.children, props.type);
1553
- retVal.push({
1554
- label: props.legend || props['aria-label'],
1555
- items: groupItems
1556
- });
1557
- }
1558
- }
1559
- }
1560
- return retVal;
1561
- }, []);
1562
-
1563
- const PLACEMENT_DEFAULT = 'bottom-start';
1564
- const MenuList = forwardRef((_ref, ref) => {
1565
- let {
1566
- appendToNode,
1567
- hasArrow,
1568
- isCompact,
1569
- isExpanded,
1570
- fallbackPlacements: _fallbackPlacements,
1571
- maxHeight,
1572
- minHeight,
1573
- placement: _placement,
1574
- triggerRef,
1575
- zIndex,
1576
- children,
1577
- ...props
1578
- } = _ref;
1579
- const floatingRef = useRef(null);
1580
- const [isVisible, setIsVisible] = useState(isExpanded);
1581
- const [height, setHeight] = useState();
1582
- const theme = useContext(ThemeContext) || DEFAULT_THEME;
1583
- const [floatingPlacement, fallbackPlacements] = getFloatingPlacements(theme, _placement === 'auto' ? PLACEMENT_DEFAULT : _placement, _fallbackPlacements);
1584
- const {
1585
- refs,
1586
- placement,
1587
- update,
1588
- floatingStyles: {
1589
- transform
1590
- }
1591
- } = useFloating({
1592
- platform: {
1593
- ...platform,
1594
- isRTL: () => theme.rtl
1595
- },
1596
- elements: {
1597
- reference: triggerRef?.current,
1598
- floating: floatingRef?.current
1599
- },
1600
- placement: floatingPlacement,
1601
- middleware: [offset(theme.space.base * (hasArrow ? 2 : 1)), _placement === 'auto' ? autoPlacement() : flip({
1602
- fallbackPlacements
1603
- }), size({
1604
- apply: _ref2 => {
1605
- let {
1606
- rects,
1607
- availableHeight
1608
- } = _ref2;
1609
- if (!(minHeight === null || minHeight === 'fit-content')) {
1610
- if (rects.floating.height > availableHeight) {
1611
- setHeight(availableHeight);
1612
- }
1613
- }
1614
- }
1615
- })]
1616
- });
1617
- useEffect(() => {
1618
- let cleanup;
1619
- if (isExpanded && refs.reference.current && refs.floating.current) {
1620
- cleanup = autoUpdate(refs.reference.current, refs.floating.current, update, {
1621
- elementResize: typeof ResizeObserver === 'function'
1622
- });
1623
- }
1624
- return () => cleanup && cleanup();
1625
- }, [isExpanded, refs.reference, refs.floating, update]);
1626
- useEffect(() => {
1627
- let timeout;
1628
- if (isExpanded) {
1629
- setIsVisible(true);
1630
- } else {
1631
- timeout = setTimeout(() => {
1632
- setIsVisible(false);
1633
- setHeight(undefined);
1634
- }, 200 );
1635
- }
1636
- return () => clearTimeout(timeout);
1637
- }, [isExpanded]);
1638
- useEffect(() => {
1639
- if (height) {
1640
- setHeight(undefined);
1641
- update();
1642
- }
1643
- }, [
1644
- children, update]);
1645
- const Node = React__default.createElement(StyledFloatingMenu, {
1646
- "data-garden-animate": isVisible,
1647
- isHidden: !isExpanded,
1648
- position: getMenuPosition(placement),
1649
- zIndex: zIndex,
1650
- style: {
1651
- transform
1652
- },
1653
- ref: floatingRef
1654
- }, React__default.createElement(StyledMenu, _extends$5({
1655
- "data-garden-animate-arrow": isVisible,
1656
- arrowPosition: hasArrow ? getArrowPosition(theme, placement) : undefined,
1657
- isCompact: isCompact,
1658
- minHeight: minHeight,
1659
- maxHeight: maxHeight,
1660
- style: {
1661
- height
1662
- }
1663
- }, props, {
1664
- ref: ref
1665
- }), isVisible && children));
1666
- return appendToNode ? createPortal(Node, appendToNode) : Node;
1667
- });
1668
- MenuList.displayName = 'MenuList';
1669
- MenuList.propTypes = {
1670
- appendToNode: PropTypes.any,
1671
- hasArrow: PropTypes.bool,
1672
- isCompact: PropTypes.bool,
1673
- isExpanded: PropTypes.bool,
1674
- maxHeight: PropTypes.string,
1675
- minHeight: PropTypes.string,
1676
- placement: PropTypes.oneOf(PLACEMENT),
1677
- triggerRef: PropTypes.any,
1678
- zIndex: PropTypes.number
1679
- };
1680
- MenuList.defaultProps = {
1681
- maxHeight: '400px',
1682
- placement: PLACEMENT_DEFAULT,
1683
- zIndex: 1000
1684
- };
1685
-
1686
- const Menu = forwardRef((_ref, ref) => {
1687
- let {
1688
- button,
1689
- buttonProps: _buttonProps = {},
1690
- children,
1691
- isCompact,
1692
- focusedValue: _focusedValue,
1693
- defaultFocusedValue,
1694
- defaultExpanded,
1695
- isExpanded: _isExpanded,
1696
- selectedItems,
1697
- onChange,
1698
- onMouseLeave,
1699
- ...props
1700
- } = _ref;
1701
- const triggerRef = useRef(null);
1702
- const menuRef = useRef(null);
1703
- const items = toItems(children);
1704
- const theme = useContext(ThemeContext) || DEFAULT_THEME;
1705
- const environment = useWindow(theme);
1706
- const {
1707
- isExpanded,
1708
- focusedValue,
1709
- getTriggerProps,
1710
- getMenuProps,
1711
- getItemProps,
1712
- getItemGroupProps,
1713
- getSeparatorProps
1714
- } = useMenu({
1715
- rtl: theme.rtl,
1716
- environment,
1717
- defaultFocusedValue,
1718
- focusedValue: _focusedValue,
1719
- defaultExpanded,
1720
- isExpanded: _isExpanded,
1721
- selectedItems,
1722
- items,
1723
- menuRef,
1724
- triggerRef,
1725
- onChange
1726
- });
1727
- const {
1728
- onClick,
1729
- onKeyDown,
1730
- disabled,
1731
- ...buttonProps
1732
- } = _buttonProps;
1733
- const triggerProps = {
1734
- ...(isCompact && {
1735
- size: 'small'
1736
- }),
1737
- ...buttonProps,
1738
- ...getTriggerProps({
1739
- type: 'button',
1740
- onClick,
1741
- onKeyDown,
1742
- disabled
1743
- }),
1744
- ref: mergeRefs([triggerRef, ref])
1745
- };
1746
- const trigger = typeof button === 'function' ? button(triggerProps) : React__default.createElement(StyledButton, triggerProps, button, React__default.createElement(StyledButton.EndIcon, {
1747
- isRotated: isExpanded
1748
- }, React__default.createElement(SvgChevronDownStroke, null)));
1749
- const contextValue = useMemo(() => ({
1750
- isCompact,
1751
- focusedValue,
1752
- getItemProps,
1753
- getItemGroupProps,
1754
- getSeparatorProps
1755
- }), [isCompact, focusedValue, getItemProps, getItemGroupProps, getSeparatorProps]);
1756
- return React__default.createElement(MenuContext.Provider, {
1757
- value: contextValue
1758
- }, trigger, React__default.createElement(MenuList, _extends$5({}, props, getMenuProps({
1759
- onMouseLeave
1760
- }), {
1761
- ref: mergeRefs([menuRef, ref]),
1762
- isCompact: isCompact,
1763
- isExpanded: isExpanded,
1764
- triggerRef: triggerRef
1765
- }), children));
1766
- });
1767
- Menu.displayName = 'Menu';
1768
- Menu.propTypes = {
1769
- appendToNode: PropTypes.any,
1770
- button: PropTypes.any.isRequired,
1771
- buttonProps: PropTypes.object,
1772
- defaultExpanded: PropTypes.bool,
1773
- defaultFocusedValue: PropTypes.string,
1774
- fallbackPlacements: PropTypes.arrayOf(PropTypes.any),
1775
- focusedValue: PropTypes.string,
1776
- hasArrow: PropTypes.bool,
1777
- isCompact: PropTypes.bool,
1778
- isExpanded: PropTypes.bool,
1779
- maxHeight: PropTypes.string,
1780
- minHeight: PropTypes.string,
1781
- onChange: PropTypes.func,
1782
- placement: PropTypes.oneOf(PLACEMENT),
1783
- selectedItems: PropTypes.arrayOf(PropTypes.any),
1784
- zIndex: PropTypes.number
1785
- };
1786
- Menu.defaultProps = {
1787
- maxHeight: '400px',
1788
- placement: 'bottom-start',
1789
- zIndex: 1000
1790
- };
1791
-
1792
- const ItemGroupContext = createContext({});
1793
- const useItemGroupContext = () => {
1794
- return useContext(ItemGroupContext);
1795
- };
1796
-
1797
- const ItemGroup = forwardRef((_ref, ref) => {
1798
- let {
1799
- children,
1800
- content,
1801
- legend,
1802
- icon,
1803
- 'aria-label': ariaLabel,
1804
- type,
1805
- ...props
1806
- } = _ref;
1807
- const {
1808
- isCompact,
1809
- getItemGroupProps
1810
- } = useMenuContext();
1811
- const groupAriaLabel = useText(ItemGroup, {
1812
- 'aria-label': ariaLabel
1813
- }, 'aria-label', 'Group', !legend );
1814
- const groupProps = getItemGroupProps({
1815
- 'aria-label': groupAriaLabel || legend
1816
- });
1817
- const contextValue = useMemo(() => ({
1818
- type
1819
- }), [type]);
1820
- return React__default.createElement(ItemGroupContext.Provider, {
1821
- value: contextValue
1822
- }, React__default.createElement(StyledItem, _extends$5({
1823
- isCompact: isCompact,
1824
- $type: "group"
1825
- }, props, {
1826
- ref: ref
1827
- }), React__default.createElement(StyledItemContent, null, (content || legend) && React__default.createElement(StyledItem, {
1828
- as: "div",
1829
- isCompact: isCompact,
1830
- $type: "header"
1831
- }, icon && React__default.createElement(StyledItemTypeIcon, {
1832
- isCompact: isCompact,
1833
- type: "header"
1834
- }, icon), content || legend), React__default.createElement(StyledItemGroup, _extends$5({
1835
- isCompact: isCompact
1836
- }, groupProps), React__default.createElement(StyledSeparator, {
1837
- role: "none"
1838
- }), children))));
1839
- });
1840
- ItemGroup.displayName = 'ItemGroup';
1841
- ItemGroup.propTypes = {
1842
- content: PropTypes.any,
1843
- icon: PropTypes.any,
1844
- legend: PropTypes.string,
1845
- type: PropTypes.oneOf(['checkbox', 'radio', undefined])
1846
- };
1847
-
1848
- const ItemContext = createContext(undefined);
1849
- const useItemContext = () => {
1850
- const context = useContext(ItemContext);
1851
- if (!context) {
1852
- throw new Error('Error: this component must be rendered within an <Item>.');
1853
- }
1854
- return context;
1855
- };
1856
-
1857
- const ItemMetaComponent = forwardRef((props, ref) => {
1858
- const {
1859
- isDisabled
1860
- } = useItemContext();
1861
- return React__default.createElement(StyledItemMeta, _extends$5({
1862
- isDisabled: isDisabled
1863
- }, props, {
1864
- ref: ref
1865
- }));
1866
- });
1867
- ItemMetaComponent.displayName = 'Item.Meta';
1868
- const ItemMeta = ItemMetaComponent;
1869
-
1870
- const ItemComponent = forwardRef((_ref, ref) => {
1871
- let {
1872
- children,
1873
- value,
1874
- label = value,
1875
- isSelected,
1876
- icon,
1877
- isDisabled,
1878
- type,
1879
- name,
1880
- onClick,
1881
- onKeyDown,
1882
- onMouseEnter,
1883
- ...props
1884
- } = _ref;
1885
- const {
1886
- type: selectionType
1887
- } = useItemGroupContext();
1888
- const {
1889
- focusedValue,
1890
- getItemProps
1891
- } = useMenuContext();
1892
- const item = {
1893
- ...toItem({
1894
- value,
1895
- label,
1896
- name,
1897
- type,
1898
- isSelected,
1899
- isDisabled
1900
- }),
1901
- type: selectionType
1902
- };
1903
- const {
1904
- ref: _itemRef,
1905
- ...itemProps
1906
- } = getItemProps({
1907
- item,
1908
- onClick,
1909
- onKeyDown,
1910
- onMouseEnter
1911
- });
1912
- const isActive = value === focusedValue;
1913
- const {
1914
- isCompact
1915
- } = useMenuContext();
1916
- const renderActionIcon = iconType => {
1917
- switch (iconType) {
1918
- case 'add':
1919
- return React__default.createElement(SvgPlusStroke, null);
1920
- case 'next':
1921
- return React__default.createElement(SvgChevronRightStroke, null);
1922
- case 'previous':
1923
- return React__default.createElement(SvgChevronLeftStroke, null);
1924
- default:
1925
- return React__default.createElement(SvgCheckLgStroke, null);
1926
- }
1927
- };
1928
- const contextValue = useMemo(() => ({
1929
- isDisabled
1930
- }), [isDisabled]);
1931
- return React__default.createElement(ItemContext.Provider, {
1932
- value: contextValue
1933
- }, React__default.createElement(StyledItem, _extends$5({
1934
- $type: type,
1935
- isCompact: isCompact,
1936
- isActive: isActive
1937
- }, props, itemProps, {
1938
- ref: mergeRefs([_itemRef, ref])
1939
- }), React__default.createElement(StyledItemTypeIcon, {
1940
- isCompact: isCompact,
1941
- type: type
1942
- }, renderActionIcon(type)), icon && React__default.createElement(StyledItemIcon, null, icon), React__default.createElement(StyledItemContent, null, children || label)));
1943
- });
1944
- ItemComponent.displayName = 'Item';
1945
- ItemComponent.propTypes = {
1946
- icon: PropTypes.any,
1947
- isDisabled: PropTypes.bool,
1948
- isSelected: PropTypes.bool,
1949
- label: PropTypes.string,
1950
- name: PropTypes.string,
1951
- type: PropTypes.oneOf(OPTION_TYPE),
1952
- value: PropTypes.string.isRequired
1953
- };
1954
- const Item = ItemComponent;
1955
- Item.Meta = ItemMeta;
1956
-
1957
- const Separator = forwardRef(
1958
- (_ref, ref) => {
1959
- let {
1960
- children,
1961
- ...props
1962
- } = _ref;
1963
- const {
1964
- getSeparatorProps
1965
- } = useMenuContext();
1966
- const separatorProps = getSeparatorProps();
1967
- return React__default.createElement(StyledSeparator, _extends$5({}, props, separatorProps, {
1968
- ref: ref
1969
- }));
1970
- });
1971
- Separator.displayName = 'Separator';
1972
-
1973
- export { Combobox, Field, Hint, Item, ItemGroup, Label, Menu, Message, OptGroup, Option, Separator, Tag };