@zendeskgarden/react-dropdowns 9.0.0-next.7 → 9.0.0-next.9

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 (74) 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 +43 -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 +29 -0
  50. package/dist/esm/views/combobox/StyledOptionMeta.js +31 -0
  51. package/dist/esm/views/combobox/StyledOptionTypeIcon.js +48 -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 +86 -128
  67. package/dist/typings/views/combobox/StyledInputIcon.d.ts +6 -6
  68. package/dist/typings/views/combobox/StyledOptionIcon.d.ts +1 -1
  69. package/dist/typings/views/combobox/StyledOptionTypeIcon.d.ts +3 -3
  70. package/dist/typings/views/menu/StyledButton.d.ts +2 -2
  71. package/dist/typings/views/menu/StyledItemIcon.d.ts +1 -1
  72. package/dist/typings/views/menu/StyledItemTypeIcon.d.ts +1 -1
  73. package/package.json +9 -9
  74. package/dist/index.esm.js +0 -1969
package/dist/index.esm.js DELETED
@@ -1,1969 +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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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 &{color:", ";}", "[aria-disabled='true'] &{color:", ";}"], props.isLabelHovered ? focusColor : color, 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.7'
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.7'
366
- }).withConfig({
367
- displayName: "StyledOption",
368
- componentId: "sc-jl4wn6-0"
369
- })(["display:flex;position:relative;transition:color 0.25s ease-in-out;cursor:", ";overflow-wrap:anywhere;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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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.7'
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 TagAvatarComponent = Tag$1.Avatar;
810
- TagAvatarComponent.displayName = 'Tag.Avatar';
811
- const TagAvatar = TagAvatarComponent;
812
-
813
- const TagComponent = forwardRef((_ref, ref) => {
814
- let {
815
- children,
816
- option,
817
- removeLabel,
818
- tooltipZIndex,
819
- ...props
820
- } = _ref;
821
- const {
822
- getTagProps,
823
- isCompact,
824
- removeSelection
825
- } = useComboboxContext();
826
- const text = option.label || option.value;
827
- const ariaLabel = useText(
828
- Tag, props, 'aria-label', `${text}, press delete or backspace to remove`, !option.disabled);
829
- const tagProps = getTagProps({
830
- option,
831
- 'aria-label': ariaLabel
832
- });
833
- const theme = useContext(ThemeContext) || DEFAULT_THEME;
834
- const doc = useDocument(theme);
835
- const handleClick = () => removeSelection(option.value);
836
- return React__default.createElement(StyledTag, _extends$5({
837
- "aria-disabled": option.disabled,
838
- tabIndex: option.disabled ? undefined : 0
839
- }, tagProps, props, {
840
- size: isCompact ? 'medium' : 'large',
841
- ref: ref
842
- }), children || React__default.createElement("span", null, text), !option.disabled && (removeLabel ?
843
- React__default.createElement(Tooltip, {
844
- appendToNode: doc?.body,
845
- content: removeLabel,
846
- zIndex: tooltipZIndex
847
- }, React__default.createElement(StyledTag.Close, {
848
- "aria-label": removeLabel,
849
- onClick: handleClick
850
- })) : React__default.createElement(StyledTag.Close, {
851
- onClick: handleClick
852
- })));
853
- });
854
- TagComponent.displayName = 'Tag';
855
- TagComponent.propTypes = {
856
- hue: PropTypes.string,
857
- isPill: PropTypes.bool,
858
- isRegular: PropTypes.bool,
859
- removeLabel: PropTypes.string
860
- };
861
- const Tag = TagComponent;
862
- Tag.Avatar = TagAvatar;
863
-
864
- const TagGroup = _ref => {
865
- let {
866
- children,
867
- isDisabled,
868
- isExpanded,
869
- listboxZIndex,
870
- maxTags,
871
- optionTagProps,
872
- selection
873
- } = _ref;
874
- return React__default.createElement(React__default.Fragment, null, selection.map((option, index) => {
875
- const disabled = isDisabled || option.disabled;
876
- return React__default.createElement(Tag, _extends$5({
877
- key: option.value,
878
- hidden: !isExpanded && index >= maxTags,
879
- option: {
880
- ...option,
881
- disabled
882
- },
883
- tooltipZIndex: listboxZIndex ? listboxZIndex + 1 : undefined
884
- }, optionTagProps[option.value]));
885
- }), children);
886
- };
887
- TagGroup.displayName = 'TagGroup';
888
-
889
- const toOption = props => {
890
- return {
891
- value: props.value,
892
- label: props.label,
893
- hidden: props.isHidden,
894
- disabled: props.isDisabled,
895
- selected: props.isSelected
896
- };
897
- };
898
- const toOptions = (children, optionTagProps) => Children.toArray(children).reduce((options, option) => {
899
- const retVal = options;
900
- if ( isValidElement(option)) {
901
- if ('value' in option.props) {
902
- retVal.push(toOption(option.props));
903
- optionTagProps[option.props.value] = option.props.tagProps;
904
- } else {
905
- const props = option.props;
906
- const groupOptions = toOptions(props.children, optionTagProps);
907
- retVal.push({
908
- label: props.legend,
909
- options: groupOptions
910
- });
911
- }
912
- }
913
- return retVal;
914
- }, []);
915
-
916
- const MAX_TAGS = 4;
917
- const Combobox = forwardRef((_ref, ref) => {
918
- let {
919
- children,
920
- activeIndex,
921
- defaultActiveIndex,
922
- defaultExpanded,
923
- endIcon,
924
- focusInset,
925
- inputProps: _inputProps,
926
- inputValue: _inputValue,
927
- isAutocomplete,
928
- isBare,
929
- isCompact,
930
- isDisabled,
931
- isEditable,
932
- isExpanded: _isExpanded,
933
- isMultiselectable,
934
- listboxAppendToNode,
935
- listboxAriaLabel,
936
- listboxMaxHeight,
937
- listboxMinHeight,
938
- listboxZIndex,
939
- maxHeight,
940
- maxTags = MAX_TAGS,
941
- onChange,
942
- placeholder,
943
- renderExpandTags,
944
- renderValue,
945
- selectionValue,
946
- startIcon,
947
- validation,
948
- ...props
949
- } = _ref;
950
- const {
951
- hasHint,
952
- hasMessage,
953
- labelProps,
954
- setLabelProps,
955
- hintProps,
956
- setHintProps,
957
- messageProps,
958
- setMessageProps
959
- } = useFieldContext();
960
- const [isInputHidden, setIsInputHidden] = useState(true);
961
- const [isLabelHovered, setIsLabelHovered] = useState(false);
962
- const [isTagGroupExpanded, setIsTagGroupExpanded] = useState(false);
963
- const [optionTagProps, setOptionTagProps] = useState({});
964
- const options = useMemo(() => {
965
- const tagProps = {};
966
- const retVal = toOptions(children, tagProps);
967
- if (isMultiselectable) {
968
- setOptionTagProps(value => ({
969
- ...value,
970
- ...tagProps
971
- }));
972
- }
973
- return retVal;
974
- }, [children, isMultiselectable]);
975
- const triggerRef = useRef(null);
976
- const inputRef = useRef(null);
977
- const listboxRef = useRef(null);
978
- const theme = useContext(ThemeContext) || DEFAULT_THEME;
979
- const environment = useWindow(theme);
980
- const {
981
- activeValue,
982
- inputValue,
983
- isExpanded,
984
- getTriggerProps,
985
- getHintProps,
986
- getInputProps,
987
- getLabelProps,
988
- getListboxProps,
989
- getMessageProps,
990
- getOptionProps,
991
- getOptGroupProps,
992
- getTagProps,
993
- removeSelection,
994
- selection
995
- } = useCombobox({
996
- idPrefix: props.id,
997
- triggerRef,
998
- inputRef,
999
- listboxRef,
1000
- options,
1001
- environment,
1002
- hasHint,
1003
- hasMessage,
1004
- isAutocomplete,
1005
- isEditable,
1006
- isMultiselectable,
1007
- disabled: isDisabled,
1008
- inputValue: _inputValue,
1009
- selectionValue,
1010
- isExpanded: _isExpanded,
1011
- defaultExpanded,
1012
- activeIndex,
1013
- defaultActiveIndex,
1014
- onChange
1015
- });
1016
- const contextValue = useMemo(() => ({
1017
- activeValue,
1018
- getOptionProps,
1019
- getOptGroupProps,
1020
- getTagProps,
1021
- isCompact,
1022
- removeSelection
1023
- }), [activeValue, getOptionProps, getOptGroupProps, getTagProps, isCompact, removeSelection]);
1024
- const hasChevron = useMemo(() => !isBare && (isAutocomplete || !isEditable), [isAutocomplete, isBare, isEditable]);
1025
- const expandTags = useText(Combobox, {
1026
- renderExpandTags
1027
- }, 'renderExpandTags', '+ {{value}} more', isMultiselectable || false);
1028
- const _listboxAriaLabel = useText(Combobox, {
1029
- listboxAriaLabel
1030
- }, 'listboxAriaLabel', 'Options');
1031
- const triggerProps = {
1032
- isAutocomplete,
1033
- isBare,
1034
- isCompact,
1035
- isEditable,
1036
- isLabelHovered,
1037
- isMultiselectable,
1038
- maxHeight,
1039
- focusInset,
1040
- validation,
1041
- ...getTriggerProps({
1042
- onFocus: () => {
1043
- if (!isDisabled) {
1044
- if (isEditable) {
1045
- setIsInputHidden(false);
1046
- }
1047
- if (isMultiselectable) {
1048
- setIsTagGroupExpanded(true);
1049
- }
1050
- }
1051
- },
1052
- onBlur: event => {
1053
- if (event.relatedTarget === null || !triggerRef.current?.contains(event.relatedTarget)) {
1054
- if (isEditable) {
1055
- setIsInputHidden(true);
1056
- }
1057
- if (isMultiselectable) {
1058
- setIsTagGroupExpanded(false);
1059
- }
1060
- }
1061
- }
1062
- })
1063
- };
1064
- const inputProps = {
1065
- 'aria-invalid': validation === 'error' || validation === 'warning',
1066
- hidden: isInputHidden,
1067
- isBare,
1068
- isCompact,
1069
- isEditable,
1070
- isMultiselectable,
1071
- placeholder,
1072
- ...getInputProps({
1073
- ..._inputProps
1074
- })
1075
- };
1076
- const listboxProps = getListboxProps({
1077
- 'aria-label': _listboxAriaLabel
1078
- });
1079
- useEffect(() => {
1080
- if (!labelProps) {
1081
- const _labelProps = getLabelProps({
1082
- onMouseEnter: () => setIsLabelHovered(true),
1083
- onMouseLeave: () => setIsLabelHovered(false)
1084
- });
1085
- setLabelProps(_labelProps);
1086
- }
1087
- return () => labelProps && setLabelProps(undefined);
1088
- }, [getLabelProps, labelProps, setLabelProps]);
1089
- useEffect(() => {
1090
- if (!hintProps) {
1091
- const _hintProps = getHintProps();
1092
- setHintProps(_hintProps);
1093
- }
1094
- return () => hintProps && setHintProps(undefined);
1095
- }, [getHintProps, hintProps, setHintProps]);
1096
- useEffect(() => {
1097
- if (!messageProps) {
1098
- const _messageProps = getMessageProps();
1099
- setMessageProps(_messageProps);
1100
- }
1101
- return () => messageProps && setMessageProps(undefined);
1102
- }, [getMessageProps, messageProps, setMessageProps]);
1103
- return React__default.createElement(ComboboxContext.Provider, {
1104
- value: contextValue
1105
- }, React__default.createElement(StyledCombobox, _extends$5({
1106
- isCompact: isCompact,
1107
- tabIndex: -1
1108
- }, props, {
1109
- ref: ref
1110
- }), React__default.createElement(StyledTrigger, triggerProps, React__default.createElement(StyledContainer, null, startIcon && React__default.createElement(StyledInputIcon, {
1111
- isLabelHovered: isLabelHovered,
1112
- isCompact: isCompact
1113
- }, startIcon), React__default.createElement(StyledInputGroup, null, isMultiselectable && Array.isArray(selection) && React__default.createElement(TagGroup, {
1114
- isDisabled: isDisabled,
1115
- isExpanded: isTagGroupExpanded,
1116
- maxTags: maxTags,
1117
- optionTagProps: optionTagProps,
1118
- selection: selection
1119
- }, selection.length > maxTags && React__default.createElement(StyledTagsButton, {
1120
- disabled: isDisabled,
1121
- hidden: isTagGroupExpanded,
1122
- isCompact: isCompact,
1123
- tabIndex: -1,
1124
- type: "button"
1125
- }, (() => {
1126
- const value = selection.length - maxTags;
1127
- return renderExpandTags ? renderExpandTags(value) : expandTags?.replace('{{value}}', value.toString());
1128
- })())), React__default.createElement(StyledValue, {
1129
- hidden: !isInputHidden,
1130
- isAutocomplete: isAutocomplete,
1131
- isBare: isBare,
1132
- isCompact: isCompact,
1133
- isDisabled: isDisabled,
1134
- isEditable: isEditable,
1135
- isMultiselectable: isMultiselectable,
1136
- isPlaceholder: !(inputValue || renderValue)
1137
- }, renderValue ? renderValue({
1138
- selection,
1139
- inputValue
1140
- }) : inputValue || placeholder), React__default.createElement(StyledInput, inputProps)), (hasChevron || endIcon) && React__default.createElement(StyledInputIcon, {
1141
- isCompact: isCompact,
1142
- isEnd: true,
1143
- isLabelHovered: isLabelHovered,
1144
- isRotated: hasChevron && isExpanded
1145
- }, hasChevron ? React__default.createElement(SvgChevronDownStroke, null) : endIcon))), React__default.createElement(Listbox, _extends$5({
1146
- appendToNode: listboxAppendToNode,
1147
- isCompact: isCompact,
1148
- isExpanded: isExpanded,
1149
- maxHeight: listboxMaxHeight,
1150
- minHeight: listboxMinHeight,
1151
- triggerRef: triggerRef,
1152
- zIndex: listboxZIndex
1153
- }, listboxProps), children)));
1154
- });
1155
- Combobox.displayName = 'Combobox';
1156
- Combobox.propTypes = {
1157
- activeIndex: PropTypes.number,
1158
- defaultActiveIndex: PropTypes.number,
1159
- defaultExpanded: PropTypes.bool,
1160
- endIcon: PropTypes.any,
1161
- focusInset: PropTypes.bool,
1162
- id: PropTypes.string,
1163
- inputProps: PropTypes.object,
1164
- inputValue: PropTypes.string,
1165
- isAutocomplete: PropTypes.bool,
1166
- isBare: PropTypes.bool,
1167
- isCompact: PropTypes.bool,
1168
- isDisabled: PropTypes.bool,
1169
- isEditable: PropTypes.bool,
1170
- isExpanded: PropTypes.bool,
1171
- isMultiselectable: PropTypes.bool,
1172
- listboxAppendToNode: PropTypes.any,
1173
- listboxAriaLabel: PropTypes.string,
1174
- listboxMaxHeight: PropTypes.string,
1175
- listboxMinHeight: PropTypes.string,
1176
- listboxZIndex: PropTypes.number,
1177
- maxHeight: PropTypes.string,
1178
- maxTags: PropTypes.number,
1179
- onChange: PropTypes.func,
1180
- placeholder: PropTypes.string,
1181
- renderExpandTags: PropTypes.func,
1182
- renderValue: PropTypes.func,
1183
- selectionValue: PropTypes.any,
1184
- startIcon: PropTypes.any,
1185
- validation: PropTypes.oneOf(VALIDATION)
1186
- };
1187
- Combobox.defaultProps = {
1188
- isEditable: true,
1189
- listboxMaxHeight: '400px',
1190
- listboxZIndex: 1000,
1191
- maxTags: MAX_TAGS
1192
- };
1193
-
1194
- const Hint = forwardRef((props, ref) => {
1195
- const {
1196
- hintProps,
1197
- setHasHint
1198
- } = useFieldContext();
1199
- useEffect(() => {
1200
- setHasHint(true);
1201
- return () => setHasHint(false);
1202
- }, [setHasHint]);
1203
- return React__default.createElement(StyledHint, _extends$5({}, hintProps, props, {
1204
- ref: ref
1205
- }));
1206
- });
1207
- Hint.displayName = 'Hint';
1208
-
1209
- const Label = forwardRef((_ref, ref) => {
1210
- let {
1211
- onClick,
1212
- onMouseEnter,
1213
- onMouseLeave,
1214
- ...props
1215
- } = _ref;
1216
- const {
1217
- labelProps
1218
- } = useFieldContext();
1219
- return React__default.createElement(StyledLabel, _extends$5({}, labelProps, {
1220
- onClick: composeEventHandlers(onClick, labelProps?.onClick),
1221
- onMouseEnter: composeEventHandlers(onMouseEnter, labelProps?.onMouseEnter),
1222
- onMouseLeave: composeEventHandlers(onMouseLeave, labelProps?.onMouseLeave)
1223
- }, props, {
1224
- ref: ref
1225
- }));
1226
- });
1227
- Label.displayName = 'Label';
1228
- Label.propTypes = {
1229
- hidden: PropTypes.bool,
1230
- isRegular: PropTypes.bool
1231
- };
1232
-
1233
- const Message = forwardRef((props, ref) => {
1234
- const {
1235
- messageProps,
1236
- setHasMessage
1237
- } = useFieldContext();
1238
- useEffect(() => {
1239
- setHasMessage(true);
1240
- return () => setHasMessage(false);
1241
- }, [setHasMessage]);
1242
- return React__default.createElement(StyledMessage, _extends$5({}, messageProps, props, {
1243
- ref: ref
1244
- }));
1245
- });
1246
- Message.displayName = 'Message';
1247
- Message.propTypes = {
1248
- validation: PropTypes.oneOf(VALIDATION),
1249
- validationLabel: PropTypes.string
1250
- };
1251
-
1252
- const FieldComponent = forwardRef((props, ref) => {
1253
- const [labelProps, setLabelProps] = useState(undefined);
1254
- const [hintProps, setHintProps] = useState(undefined);
1255
- const [messageProps, setMessageProps] = useState(undefined);
1256
- const [hasHint, setHasHint] = useState(false);
1257
- const [hasMessage, setHasMessage] = useState(false);
1258
- const contextValue = useMemo(() => ({
1259
- labelProps,
1260
- setLabelProps,
1261
- hasHint,
1262
- setHasHint,
1263
- hintProps,
1264
- setHintProps,
1265
- hasMessage,
1266
- setHasMessage,
1267
- messageProps,
1268
- setMessageProps
1269
- }), [labelProps, setLabelProps, hasHint, setHasHint, hintProps, setHintProps, hasMessage, setHasMessage, messageProps, setMessageProps]);
1270
- return React__default.createElement(FieldContext.Provider, {
1271
- value: contextValue
1272
- }, React__default.createElement(StyledField, _extends$5({}, props, {
1273
- ref: ref
1274
- })));
1275
- });
1276
- FieldComponent.displayName = 'Field';
1277
- const Field = FieldComponent;
1278
- Field.Hint = Hint;
1279
- Field.Label = Label;
1280
- Field.Message = Message;
1281
-
1282
- var _path$3;
1283
- 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); }
1284
- var SvgPlusStroke = function SvgPlusStroke(props) {
1285
- return /*#__PURE__*/React.createElement("svg", _extends$3({
1286
- xmlns: "http://www.w3.org/2000/svg",
1287
- width: 16,
1288
- height: 16,
1289
- focusable: "false",
1290
- viewBox: "0 0 16 16",
1291
- "aria-hidden": "true"
1292
- }, props), _path$3 || (_path$3 = /*#__PURE__*/React.createElement("path", {
1293
- stroke: "currentColor",
1294
- strokeLinecap: "round",
1295
- d: "M7.5 2.5v12m6-6h-12"
1296
- })));
1297
- };
1298
-
1299
- var _path$2;
1300
- 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); }
1301
- var SvgChevronRightStroke = function SvgChevronRightStroke(props) {
1302
- return /*#__PURE__*/React.createElement("svg", _extends$2({
1303
- xmlns: "http://www.w3.org/2000/svg",
1304
- width: 16,
1305
- height: 16,
1306
- focusable: "false",
1307
- viewBox: "0 0 16 16",
1308
- "aria-hidden": "true"
1309
- }, props), _path$2 || (_path$2 = /*#__PURE__*/React.createElement("path", {
1310
- fill: "currentColor",
1311
- 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"
1312
- })));
1313
- };
1314
-
1315
- var _path$1;
1316
- 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); }
1317
- var SvgChevronLeftStroke = function SvgChevronLeftStroke(props) {
1318
- return /*#__PURE__*/React.createElement("svg", _extends$1({
1319
- xmlns: "http://www.w3.org/2000/svg",
1320
- width: 16,
1321
- height: 16,
1322
- focusable: "false",
1323
- viewBox: "0 0 16 16",
1324
- "aria-hidden": "true"
1325
- }, props), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
1326
- fill: "currentColor",
1327
- 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"
1328
- })));
1329
- };
1330
-
1331
- var _path;
1332
- 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); }
1333
- var SvgCheckLgStroke = function SvgCheckLgStroke(props) {
1334
- return /*#__PURE__*/React.createElement("svg", _extends({
1335
- xmlns: "http://www.w3.org/2000/svg",
1336
- width: 16,
1337
- height: 16,
1338
- focusable: "false",
1339
- viewBox: "0 0 16 16",
1340
- "aria-hidden": "true"
1341
- }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
1342
- fill: "none",
1343
- stroke: "currentColor",
1344
- strokeLinecap: "round",
1345
- strokeLinejoin: "round",
1346
- d: "M1 9l4 4L15 3"
1347
- })));
1348
- };
1349
-
1350
- const OPTION_TYPE = ['add', 'danger', 'next', 'previous'];
1351
- const PLACEMENT = ['auto', ...PLACEMENT$1];
1352
-
1353
- const OptionContext = createContext(undefined);
1354
- const useOptionContext = () => {
1355
- const context = useContext(OptionContext);
1356
- if (!context) {
1357
- throw new Error('Error: this component must be rendered within an <Option>.');
1358
- }
1359
- return context;
1360
- };
1361
-
1362
- const OptionMetaComponent = forwardRef((props, ref) => {
1363
- const {
1364
- isDisabled
1365
- } = useOptionContext();
1366
- return React__default.createElement(StyledOptionMeta, _extends$5({
1367
- isDisabled: isDisabled
1368
- }, props, {
1369
- ref: ref
1370
- }));
1371
- });
1372
- OptionMetaComponent.displayName = 'Option.Meta';
1373
- const OptionMeta = OptionMetaComponent;
1374
-
1375
- const OptionComponent = forwardRef((_ref, ref) => {
1376
- let {
1377
- children,
1378
- icon,
1379
- isDisabled,
1380
- isHidden,
1381
- isSelected,
1382
- label,
1383
- type,
1384
- value,
1385
- ...props
1386
- } = _ref;
1387
- const contextValue = useMemo(() => ({
1388
- isDisabled
1389
- }), [isDisabled]);
1390
- const {
1391
- activeValue,
1392
- getOptionProps,
1393
- isCompact
1394
- } = useComboboxContext();
1395
- const isActive = value === activeValue;
1396
- const optionRef = useRef(null);
1397
- useEffect(() => {
1398
- if (isActive) {
1399
- setTimeout(() => {
1400
- if (optionRef.current && optionRef.current.scrollIntoView) {
1401
- optionRef.current.scrollIntoView({
1402
- block: 'nearest'
1403
- });
1404
- }
1405
- });
1406
- }
1407
- }, [isActive]);
1408
- const renderActionIcon = iconType => {
1409
- switch (iconType) {
1410
- case 'add':
1411
- return React__default.createElement(SvgPlusStroke, null);
1412
- case 'next':
1413
- return React__default.createElement(SvgChevronRightStroke, null);
1414
- case 'previous':
1415
- return React__default.createElement(SvgChevronLeftStroke, null);
1416
- default:
1417
- return React__default.createElement(SvgCheckLgStroke, null);
1418
- }
1419
- };
1420
- const option = toOption({
1421
- value,
1422
- label,
1423
- isDisabled,
1424
- isHidden,
1425
- isSelected
1426
- });
1427
- const optionProps = getOptionProps({
1428
- option,
1429
- ref: mergeRefs([optionRef, ref])
1430
- });
1431
- return React__default.createElement(OptionContext.Provider, {
1432
- value: contextValue
1433
- }, React__default.createElement(StyledOption, _extends$5({
1434
- isActive: isActive,
1435
- isCompact: isCompact,
1436
- $type: type
1437
- }, props, optionProps), React__default.createElement(StyledOptionTypeIcon, {
1438
- isCompact: isCompact,
1439
- type: type
1440
- }, renderActionIcon(type)), icon && React__default.createElement(StyledOptionIcon, null, icon), React__default.createElement(StyledOptionContent, null, children || label || value)));
1441
- });
1442
- OptionComponent.displayName = 'Option';
1443
- OptionComponent.propTypes = {
1444
- icon: PropTypes.any,
1445
- isDisabled: PropTypes.bool,
1446
- isSelected: PropTypes.bool,
1447
- isHidden: PropTypes.bool,
1448
- label: PropTypes.string,
1449
- tagProps: PropTypes.object,
1450
- type: PropTypes.oneOf(OPTION_TYPE),
1451
- value: PropTypes.string.isRequired
1452
- };
1453
- const Option = OptionComponent;
1454
- Option.Meta = OptionMeta;
1455
-
1456
- const OptGroup = forwardRef((_ref, ref) => {
1457
- let {
1458
- children,
1459
- content,
1460
- icon,
1461
- legend,
1462
- 'aria-label': ariaLabel,
1463
- onMouseDown,
1464
- ...props
1465
- } = _ref;
1466
- const {
1467
- getOptGroupProps,
1468
- isCompact
1469
- } = useComboboxContext();
1470
- const handleMouseDown = event => event.preventDefault();
1471
- const groupAriaLabel = useText(OptGroup, {
1472
- 'aria-label': ariaLabel
1473
- }, 'aria-label', 'Group', !legend );
1474
- const optGroupProps = getOptGroupProps({
1475
- 'aria-label': groupAriaLabel || legend
1476
- });
1477
- return React__default.createElement(StyledOption, _extends$5({
1478
- isCompact: isCompact,
1479
- $type: "group",
1480
- onMouseDown: composeEventHandlers(onMouseDown, handleMouseDown),
1481
- role: "none"
1482
- }, props, {
1483
- ref: ref
1484
- }), React__default.createElement(StyledOptionContent, null, (content || legend) && React__default.createElement(StyledOption, {
1485
- as: "div",
1486
- isCompact: isCompact,
1487
- $type: "header"
1488
- }, icon && React__default.createElement(StyledOptionTypeIcon, {
1489
- isCompact: isCompact,
1490
- type: "header"
1491
- }, icon), content || legend), React__default.createElement(StyledOptGroup, _extends$5({
1492
- isCompact: isCompact
1493
- }, optGroupProps), React__default.createElement(StyledListboxSeparator, {
1494
- role: "none"
1495
- }), children)));
1496
- });
1497
- OptGroup.displayName = 'OptGroup';
1498
- OptGroup.propTypes = {
1499
- content: PropTypes.any,
1500
- icon: PropTypes.any,
1501
- legend: PropTypes.string
1502
- };
1503
-
1504
- const MenuContext = createContext(undefined);
1505
- const useMenuContext = () => {
1506
- const context = useContext(MenuContext);
1507
- if (!context) {
1508
- throw new Error('Error: this component must be rendered within a <Menu>.');
1509
- }
1510
- return context;
1511
- };
1512
-
1513
- const toItem = props => ({
1514
- value: props.value,
1515
- label: props.label,
1516
- ...(props.name && {
1517
- name: props.name
1518
- }),
1519
- ...(props.isDisabled && {
1520
- disabled: props.isDisabled
1521
- }),
1522
- ...(props.isSelected && {
1523
- selected: props.isSelected
1524
- }),
1525
- ...(props.selectionType && {
1526
- type: props.selectionType
1527
- }),
1528
- ...(props.type === 'next' && {
1529
- isNext: true
1530
- }),
1531
- ...(props.type === 'previous' && {
1532
- isPrevious: true
1533
- })
1534
- });
1535
- const toItems = (children, type) => Children.toArray(children).reduce((items, item) => {
1536
- const retVal = items;
1537
- if ( isValidElement(item)) {
1538
- if ('value' in item.props) {
1539
- retVal.push(toItem({
1540
- ...item.props,
1541
- selectionType: type
1542
- }));
1543
- } else {
1544
- const props = item.props;
1545
- const groupLabel = props.legend || props['aria-label'];
1546
- const isSelectableGroup = props.type && ['checkbox', 'radio'].includes(props.type);
1547
- if (groupLabel || isSelectableGroup) {
1548
- const groupItems = toItems(props.children, props.type);
1549
- retVal.push({
1550
- label: props.legend || props['aria-label'],
1551
- items: groupItems
1552
- });
1553
- }
1554
- }
1555
- }
1556
- return retVal;
1557
- }, []);
1558
-
1559
- const PLACEMENT_DEFAULT = 'bottom-start';
1560
- const MenuList = forwardRef((_ref, ref) => {
1561
- let {
1562
- appendToNode,
1563
- hasArrow,
1564
- isCompact,
1565
- isExpanded,
1566
- fallbackPlacements: _fallbackPlacements,
1567
- maxHeight,
1568
- minHeight,
1569
- placement: _placement,
1570
- triggerRef,
1571
- zIndex,
1572
- children,
1573
- ...props
1574
- } = _ref;
1575
- const floatingRef = useRef(null);
1576
- const [isVisible, setIsVisible] = useState(isExpanded);
1577
- const [height, setHeight] = useState();
1578
- const theme = useContext(ThemeContext) || DEFAULT_THEME;
1579
- const [floatingPlacement, fallbackPlacements] = getFloatingPlacements(theme, _placement === 'auto' ? PLACEMENT_DEFAULT : _placement, _fallbackPlacements);
1580
- const {
1581
- refs,
1582
- placement,
1583
- update,
1584
- floatingStyles: {
1585
- transform
1586
- }
1587
- } = useFloating({
1588
- platform: {
1589
- ...platform,
1590
- isRTL: () => theme.rtl
1591
- },
1592
- elements: {
1593
- reference: triggerRef?.current,
1594
- floating: floatingRef?.current
1595
- },
1596
- placement: floatingPlacement,
1597
- middleware: [offset(theme.space.base * (hasArrow ? 2 : 1)), _placement === 'auto' ? autoPlacement() : flip({
1598
- fallbackPlacements
1599
- }), size({
1600
- apply: _ref2 => {
1601
- let {
1602
- rects,
1603
- availableHeight
1604
- } = _ref2;
1605
- if (!(minHeight === null || minHeight === 'fit-content')) {
1606
- if (rects.floating.height > availableHeight) {
1607
- setHeight(availableHeight);
1608
- }
1609
- }
1610
- }
1611
- })]
1612
- });
1613
- useEffect(() => {
1614
- let cleanup;
1615
- if (isExpanded && refs.reference.current && refs.floating.current) {
1616
- cleanup = autoUpdate(refs.reference.current, refs.floating.current, update, {
1617
- elementResize: typeof ResizeObserver === 'function'
1618
- });
1619
- }
1620
- return () => cleanup && cleanup();
1621
- }, [isExpanded, refs.reference, refs.floating, update]);
1622
- useEffect(() => {
1623
- let timeout;
1624
- if (isExpanded) {
1625
- setIsVisible(true);
1626
- } else {
1627
- timeout = setTimeout(() => {
1628
- setIsVisible(false);
1629
- setHeight(undefined);
1630
- }, 200 );
1631
- }
1632
- return () => clearTimeout(timeout);
1633
- }, [isExpanded]);
1634
- useEffect(() => {
1635
- if (height) {
1636
- setHeight(undefined);
1637
- update();
1638
- }
1639
- }, [
1640
- children, update]);
1641
- const Node = React__default.createElement(StyledFloatingMenu, {
1642
- "data-garden-animate": isVisible,
1643
- isHidden: !isExpanded,
1644
- position: getMenuPosition(placement),
1645
- zIndex: zIndex,
1646
- style: {
1647
- transform
1648
- },
1649
- ref: floatingRef
1650
- }, React__default.createElement(StyledMenu, _extends$5({
1651
- "data-garden-animate-arrow": isVisible,
1652
- arrowPosition: hasArrow ? getArrowPosition(theme, placement) : undefined,
1653
- isCompact: isCompact,
1654
- minHeight: minHeight,
1655
- maxHeight: maxHeight,
1656
- style: {
1657
- height
1658
- }
1659
- }, props, {
1660
- ref: ref
1661
- }), isVisible && children));
1662
- return appendToNode ? createPortal(Node, appendToNode) : Node;
1663
- });
1664
- MenuList.displayName = 'MenuList';
1665
- MenuList.propTypes = {
1666
- appendToNode: PropTypes.any,
1667
- hasArrow: PropTypes.bool,
1668
- isCompact: PropTypes.bool,
1669
- isExpanded: PropTypes.bool,
1670
- maxHeight: PropTypes.string,
1671
- minHeight: PropTypes.string,
1672
- placement: PropTypes.oneOf(PLACEMENT),
1673
- triggerRef: PropTypes.any,
1674
- zIndex: PropTypes.number
1675
- };
1676
- MenuList.defaultProps = {
1677
- maxHeight: '400px',
1678
- placement: PLACEMENT_DEFAULT,
1679
- zIndex: 1000
1680
- };
1681
-
1682
- const Menu = forwardRef((_ref, ref) => {
1683
- let {
1684
- button,
1685
- buttonProps: _buttonProps = {},
1686
- children,
1687
- isCompact,
1688
- focusedValue: _focusedValue,
1689
- defaultFocusedValue,
1690
- defaultExpanded,
1691
- isExpanded: _isExpanded,
1692
- selectedItems,
1693
- onChange,
1694
- onMouseLeave,
1695
- ...props
1696
- } = _ref;
1697
- const triggerRef = useRef(null);
1698
- const menuRef = useRef(null);
1699
- const items = toItems(children);
1700
- const theme = useContext(ThemeContext) || DEFAULT_THEME;
1701
- const environment = useWindow(theme);
1702
- const {
1703
- isExpanded,
1704
- focusedValue,
1705
- getTriggerProps,
1706
- getMenuProps,
1707
- getItemProps,
1708
- getItemGroupProps,
1709
- getSeparatorProps
1710
- } = useMenu({
1711
- rtl: theme.rtl,
1712
- environment,
1713
- defaultFocusedValue,
1714
- focusedValue: _focusedValue,
1715
- defaultExpanded,
1716
- isExpanded: _isExpanded,
1717
- selectedItems,
1718
- items,
1719
- menuRef,
1720
- triggerRef,
1721
- onChange
1722
- });
1723
- const {
1724
- onClick,
1725
- onKeyDown,
1726
- disabled,
1727
- ...buttonProps
1728
- } = _buttonProps;
1729
- const triggerProps = {
1730
- ...(isCompact && {
1731
- size: 'small'
1732
- }),
1733
- ...buttonProps,
1734
- ...getTriggerProps({
1735
- type: 'button',
1736
- onClick,
1737
- onKeyDown,
1738
- disabled
1739
- }),
1740
- ref: mergeRefs([triggerRef, ref])
1741
- };
1742
- const trigger = typeof button === 'function' ? button(triggerProps) : React__default.createElement(StyledButton, triggerProps, button, React__default.createElement(StyledButton.EndIcon, {
1743
- isRotated: isExpanded
1744
- }, React__default.createElement(SvgChevronDownStroke, null)));
1745
- const contextValue = useMemo(() => ({
1746
- isCompact,
1747
- focusedValue,
1748
- getItemProps,
1749
- getItemGroupProps,
1750
- getSeparatorProps
1751
- }), [isCompact, focusedValue, getItemProps, getItemGroupProps, getSeparatorProps]);
1752
- return React__default.createElement(MenuContext.Provider, {
1753
- value: contextValue
1754
- }, trigger, React__default.createElement(MenuList, _extends$5({}, props, getMenuProps({
1755
- onMouseLeave
1756
- }), {
1757
- ref: mergeRefs([menuRef, ref]),
1758
- isCompact: isCompact,
1759
- isExpanded: isExpanded,
1760
- triggerRef: triggerRef
1761
- }), children));
1762
- });
1763
- Menu.displayName = 'Menu';
1764
- Menu.propTypes = {
1765
- appendToNode: PropTypes.any,
1766
- button: PropTypes.any.isRequired,
1767
- buttonProps: PropTypes.object,
1768
- defaultExpanded: PropTypes.bool,
1769
- defaultFocusedValue: PropTypes.string,
1770
- fallbackPlacements: PropTypes.arrayOf(PropTypes.any),
1771
- focusedValue: PropTypes.string,
1772
- hasArrow: PropTypes.bool,
1773
- isCompact: PropTypes.bool,
1774
- isExpanded: PropTypes.bool,
1775
- maxHeight: PropTypes.string,
1776
- minHeight: PropTypes.string,
1777
- onChange: PropTypes.func,
1778
- placement: PropTypes.oneOf(PLACEMENT),
1779
- selectedItems: PropTypes.arrayOf(PropTypes.any),
1780
- zIndex: PropTypes.number
1781
- };
1782
- Menu.defaultProps = {
1783
- maxHeight: '400px',
1784
- placement: 'bottom-start',
1785
- zIndex: 1000
1786
- };
1787
-
1788
- const ItemGroupContext = createContext({});
1789
- const useItemGroupContext = () => {
1790
- return useContext(ItemGroupContext);
1791
- };
1792
-
1793
- const ItemGroup = forwardRef((_ref, ref) => {
1794
- let {
1795
- children,
1796
- content,
1797
- legend,
1798
- icon,
1799
- 'aria-label': ariaLabel,
1800
- type,
1801
- ...props
1802
- } = _ref;
1803
- const {
1804
- isCompact,
1805
- getItemGroupProps
1806
- } = useMenuContext();
1807
- const groupAriaLabel = useText(ItemGroup, {
1808
- 'aria-label': ariaLabel
1809
- }, 'aria-label', 'Group', !legend );
1810
- const groupProps = getItemGroupProps({
1811
- 'aria-label': groupAriaLabel || legend
1812
- });
1813
- const contextValue = useMemo(() => ({
1814
- type
1815
- }), [type]);
1816
- return React__default.createElement(ItemGroupContext.Provider, {
1817
- value: contextValue
1818
- }, React__default.createElement(StyledItem, _extends$5({
1819
- isCompact: isCompact,
1820
- $type: "group"
1821
- }, props, {
1822
- ref: ref
1823
- }), React__default.createElement(StyledItemContent, null, (content || legend) && React__default.createElement(StyledItem, {
1824
- as: "div",
1825
- isCompact: isCompact,
1826
- $type: "header"
1827
- }, icon && React__default.createElement(StyledItemTypeIcon, {
1828
- isCompact: isCompact,
1829
- type: "header"
1830
- }, icon), content || legend), React__default.createElement(StyledItemGroup, _extends$5({
1831
- isCompact: isCompact
1832
- }, groupProps), React__default.createElement(StyledSeparator, {
1833
- role: "none"
1834
- }), children))));
1835
- });
1836
- ItemGroup.displayName = 'ItemGroup';
1837
- ItemGroup.propTypes = {
1838
- content: PropTypes.any,
1839
- icon: PropTypes.any,
1840
- legend: PropTypes.string,
1841
- type: PropTypes.oneOf(['checkbox', 'radio', undefined])
1842
- };
1843
-
1844
- const ItemContext = createContext(undefined);
1845
- const useItemContext = () => {
1846
- const context = useContext(ItemContext);
1847
- if (!context) {
1848
- throw new Error('Error: this component must be rendered within an <Item>.');
1849
- }
1850
- return context;
1851
- };
1852
-
1853
- const ItemMetaComponent = forwardRef((props, ref) => {
1854
- const {
1855
- isDisabled
1856
- } = useItemContext();
1857
- return React__default.createElement(StyledItemMeta, _extends$5({
1858
- isDisabled: isDisabled
1859
- }, props, {
1860
- ref: ref
1861
- }));
1862
- });
1863
- ItemMetaComponent.displayName = 'Item.Meta';
1864
- const ItemMeta = ItemMetaComponent;
1865
-
1866
- const ItemComponent = forwardRef((_ref, ref) => {
1867
- let {
1868
- children,
1869
- value,
1870
- label = value,
1871
- isSelected,
1872
- icon,
1873
- isDisabled,
1874
- type,
1875
- name,
1876
- onClick,
1877
- onKeyDown,
1878
- onMouseEnter,
1879
- ...props
1880
- } = _ref;
1881
- const {
1882
- type: selectionType
1883
- } = useItemGroupContext();
1884
- const {
1885
- focusedValue,
1886
- getItemProps
1887
- } = useMenuContext();
1888
- const item = {
1889
- ...toItem({
1890
- value,
1891
- label,
1892
- name,
1893
- type,
1894
- isSelected,
1895
- isDisabled
1896
- }),
1897
- type: selectionType
1898
- };
1899
- const {
1900
- ref: _itemRef,
1901
- ...itemProps
1902
- } = getItemProps({
1903
- item,
1904
- onClick,
1905
- onKeyDown,
1906
- onMouseEnter
1907
- });
1908
- const isActive = value === focusedValue;
1909
- const {
1910
- isCompact
1911
- } = useMenuContext();
1912
- const renderActionIcon = iconType => {
1913
- switch (iconType) {
1914
- case 'add':
1915
- return React__default.createElement(SvgPlusStroke, null);
1916
- case 'next':
1917
- return React__default.createElement(SvgChevronRightStroke, null);
1918
- case 'previous':
1919
- return React__default.createElement(SvgChevronLeftStroke, null);
1920
- default:
1921
- return React__default.createElement(SvgCheckLgStroke, null);
1922
- }
1923
- };
1924
- const contextValue = useMemo(() => ({
1925
- isDisabled
1926
- }), [isDisabled]);
1927
- return React__default.createElement(ItemContext.Provider, {
1928
- value: contextValue
1929
- }, React__default.createElement(StyledItem, _extends$5({
1930
- $type: type,
1931
- isCompact: isCompact,
1932
- isActive: isActive
1933
- }, props, itemProps, {
1934
- ref: mergeRefs([_itemRef, ref])
1935
- }), React__default.createElement(StyledItemTypeIcon, {
1936
- isCompact: isCompact,
1937
- type: type
1938
- }, renderActionIcon(type)), icon && React__default.createElement(StyledItemIcon, null, icon), React__default.createElement(StyledItemContent, null, children || label)));
1939
- });
1940
- ItemComponent.displayName = 'Item';
1941
- ItemComponent.propTypes = {
1942
- icon: PropTypes.any,
1943
- isDisabled: PropTypes.bool,
1944
- isSelected: PropTypes.bool,
1945
- label: PropTypes.string,
1946
- name: PropTypes.string,
1947
- type: PropTypes.oneOf(OPTION_TYPE),
1948
- value: PropTypes.string.isRequired
1949
- };
1950
- const Item = ItemComponent;
1951
- Item.Meta = ItemMeta;
1952
-
1953
- const Separator = forwardRef(
1954
- (_ref, ref) => {
1955
- let {
1956
- children,
1957
- ...props
1958
- } = _ref;
1959
- const {
1960
- getSeparatorProps
1961
- } = useMenuContext();
1962
- const separatorProps = getSeparatorProps();
1963
- return React__default.createElement(StyledSeparator, _extends$5({}, props, separatorProps, {
1964
- ref: ref
1965
- }));
1966
- });
1967
- Separator.displayName = 'Separator';
1968
-
1969
- export { Combobox, Field, Hint, Item, ItemGroup, Label, Menu, Message, OptGroup, Option, Separator, Tag };