@salt-ds/lab 1.0.0-alpha.35 → 1.0.0-alpha.36

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 (39) hide show
  1. package/css/salt-lab.css +247 -6
  2. package/dist-cjs/combo-box-next/ComboBoxNext.css.js +6 -0
  3. package/dist-cjs/combo-box-next/ComboBoxNext.css.js.map +1 -0
  4. package/dist-cjs/combo-box-next/ComboBoxNext.js +31 -3
  5. package/dist-cjs/combo-box-next/ComboBoxNext.js.map +1 -1
  6. package/dist-cjs/dropdown-next/DropdownNext.js +1 -1
  7. package/dist-cjs/dropdown-next/DropdownNext.js.map +1 -1
  8. package/dist-cjs/option/Option.css.js +1 -1
  9. package/dist-cjs/option/OptionList.css.js +1 -1
  10. package/dist-cjs/pill-input/PillInput.css.js +6 -0
  11. package/dist-cjs/pill-input/PillInput.css.js.map +1 -0
  12. package/dist-cjs/pill-input/PillInput.js +256 -0
  13. package/dist-cjs/pill-input/PillInput.js.map +1 -0
  14. package/dist-cjs/pill-input/useTruncatePills.js +85 -0
  15. package/dist-cjs/pill-input/useTruncatePills.js.map +1 -0
  16. package/dist-cjs/utils/useValueEffect.js +40 -0
  17. package/dist-cjs/utils/useValueEffect.js.map +1 -0
  18. package/dist-es/combo-box-next/ComboBoxNext.css.js +4 -0
  19. package/dist-es/combo-box-next/ComboBoxNext.css.js.map +1 -0
  20. package/dist-es/combo-box-next/ComboBoxNext.js +32 -4
  21. package/dist-es/combo-box-next/ComboBoxNext.js.map +1 -1
  22. package/dist-es/dropdown-next/DropdownNext.js +1 -1
  23. package/dist-es/dropdown-next/DropdownNext.js.map +1 -1
  24. package/dist-es/option/Option.css.js +1 -1
  25. package/dist-es/option/OptionList.css.js +1 -1
  26. package/dist-es/pill-input/PillInput.css.js +4 -0
  27. package/dist-es/pill-input/PillInput.css.js.map +1 -0
  28. package/dist-es/pill-input/PillInput.js +252 -0
  29. package/dist-es/pill-input/PillInput.js.map +1 -0
  30. package/dist-es/pill-input/useTruncatePills.js +81 -0
  31. package/dist-es/pill-input/useTruncatePills.js.map +1 -0
  32. package/dist-es/utils/useValueEffect.js +36 -0
  33. package/dist-es/utils/useValueEffect.js.map +1 -0
  34. package/dist-types/combo-box-next/ComboBoxNext.d.ts +3 -3
  35. package/dist-types/pill-input/PillInput.d.ts +48 -0
  36. package/dist-types/pill-input/index.d.ts +1 -0
  37. package/dist-types/pill-input/useTruncatePills.d.ts +8 -0
  38. package/dist-types/utils/useValueEffect.d.ts +4 -0
  39. package/package.json +1 -1
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ var css_248z = "/* Style applied to the root element */\n.saltPillInput {\n --input-borderColor: var(--salt-editable-borderColor);\n --input-borderStyle: var(--salt-editable-borderStyle);\n --input-outlineColor: var(--salt-focused-outlineColor);\n --input-borderWidth: var(--salt-size-border);\n\n align-items: center;\n background: var(--saltInput-background, var(--input-background));\n color: var(--saltInput-color, var(--salt-content-primary-foreground));\n display: inline-flex;\n font-family: var(--salt-text-fontFamily);\n font-size: var(--saltInput-fontSize, var(--salt-text-fontSize));\n line-height: var(--saltInput-lineHeight, var(--salt-text-lineHeight));\n min-height: var(--saltInput-minHeight, var(--salt-size-base));\n min-width: var(--saltInput-minWidth, 4em);\n padding-left: var(--saltInput-paddingLeft, var(--salt-spacing-50));\n padding-right: var(--saltInput-paddingRight, var(--salt-spacing-100));\n position: relative;\n width: 100%;\n box-sizing: border-box;\n}\n\n.saltPillInput-truncate {\n height: var(--salt-size-base);\n}\n\n.saltPillInput-truncate .saltPillInput-inputWrapper {\n flex-wrap: nowrap;\n}\n\n.saltPillInput:hover {\n --input-borderStyle: var(--salt-editable-borderStyle-hover);\n --input-borderColor: var(--salt-editable-borderColor-hover);\n\n background: var(--saltInput-background-hover, var(--input-background-hover));\n cursor: var(--salt-editable-cursor-hover);\n}\n\n.saltPillInput:active {\n --input-borderColor: var(--salt-editable-borderColor-active);\n --input-borderStyle: var(--salt-editable-borderStyle-active);\n --input-borderWidth: var(--salt-editable-borderWidth-active);\n\n background: var(--saltInput-background-active, var(--input-background-active));\n cursor: var(--salt-editable-cursor-active);\n}\n\n/* Class applied if `variant=\"primary\"` */\n.saltPillInput-primary {\n --input-background: var(--salt-editable-primary-background);\n --input-background-active: var(--salt-editable-primary-background-active);\n --input-background-hover: var(--salt-editable-primary-background-hover);\n --input-background-disabled: var(--salt-editable-primary-background-disabled);\n --input-background-readonly: var(--salt-editable-primary-background-readonly);\n}\n\n/* Class applied if `variant=\"secondary\"` */\n.saltPillInput-secondary {\n --input-background: var(--salt-editable-secondary-background);\n --input-background-active: var(--salt-editable-secondary-background-active);\n --input-background-hover: var(--salt-editable-secondary-background-active);\n --input-background-disabled: var(--salt-editable-secondary-background-disabled);\n --input-background-readonly: var(--salt-editable-secondary-background-readonly);\n}\n\n/* Style applied to input if `validationState=\"error\"` */\n.saltPillInput-error,\n.saltPillInput-error:hover {\n --input-background: var(--salt-status-error-background);\n --input-background-active: var(--salt-status-error-background);\n --input-background-hover: var(--salt-status-error-background);\n --input-borderColor: var(--salt-status-error-borderColor);\n --input-outlineColor: var(--salt-status-error-borderColor);\n}\n\n/* Style applied to input if `validationState=\"warning\"` */\n.saltPillInput-warning,\n.saltPillInput-warning:hover {\n --input-background: var(--salt-status-warning-background);\n --input-background-active: var(--salt-status-warning-background);\n --input-background-hover: var(--salt-status-warning-background);\n --input-borderColor: var(--salt-status-warning-borderColor);\n --input-outlineColor: var(--salt-status-warning-borderColor);\n}\n\n/* Style applied to input if `validationState=\"success\"` */\n.saltPillInput-success,\n.saltPillInput-success:hover {\n --input-background: var(--salt-status-success-background);\n --input-background-active: var(--salt-status-success-background);\n --input-background-hover: var(--salt-status-success-background);\n --input-borderColor: var(--salt-status-success-borderColor);\n --input-outlineColor: var(--salt-status-success-borderColor);\n}\n\n/* Style applied to inner input component */\n.saltPillInput-input {\n background: none;\n border: none;\n box-sizing: content-box;\n color: inherit;\n cursor: inherit;\n display: block;\n flex: 1;\n font: inherit;\n height: 100%;\n letter-spacing: var(--saltInput-letterSpacing, 0);\n margin: 0;\n min-width: 0;\n overflow: hidden;\n padding: 0;\n text-align: var(--input-textAlign);\n width: 100%;\n}\n\n/* Reset in the class */\n.saltPillInput-input:focus {\n outline: none;\n}\n\n/* Style applied to selected input */\n.saltPillInput-input::selection {\n background: var(--salt-content-foreground-highlight);\n}\n\n/* Style applied to placeholder text */\n.saltPillInput-input::placeholder {\n color: var(--salt-content-secondary-foreground);\n font-weight: var(--salt-text-fontWeight-small);\n}\n\n/* Styling when focused */\n.saltPillInput-focused {\n --input-borderColor: var(--input-outlineColor);\n --input-borderWidth: var(--salt-editable-borderWidth-active);\n\n outline: var(--saltInput-outline, var(--salt-focused-outlineWidth) var(--salt-focused-outlineStyle) var(--input-outlineColor));\n}\n\n/* Style applied if `readOnly={true}` */\n.saltPillInput.saltPillInput-readOnly {\n --input-borderColor: var(--salt-editable-borderColor-readonly);\n --input-borderStyle: var(--salt-editable-borderStyle-readonly);\n --input-borderWidth: var(--salt-size-border);\n\n background: var(--input-background-readonly);\n cursor: var(--salt-editable-cursor-readonly);\n}\n\n/* Styling when focused if `disabled={true}` */\n.saltPillInput-focused.saltPillInput-disabled {\n --input-borderWidth: var(--salt-size-border);\n outline: none;\n}\n\n/* Styling when focused if `readOnly={true}` */\n.saltPillInput-focused.saltPillInput-readOnly {\n --input-borderWidth: var(--salt-size-border);\n}\n\n/* Style applied to selected input if `disabled={true}` */\n.saltPillInput-disabled .saltPillInput-input::selection {\n background: none;\n}\n\n/* Style applied to input if `disabled={true}` */\n.saltPillInput.saltPillInput-disabled,\n.saltPillInput.saltPillInput-disabled:hover,\n.saltPillInput.saltPillInput-disabled:active {\n --input-borderColor: var(--salt-editable-borderColor-disabled);\n --input-borderStyle: var(--salt-editable-borderStyle-disabled);\n --input-borderWidth: var(--salt-size-border);\n\n background: var(--input-background-disabled);\n cursor: var(--salt-editable-cursor-disabled);\n color: var(--saltInput-color-disabled, var(--salt-content-primary-foreground-disabled));\n}\n\n.saltPillInput-activationIndicator {\n left: 0;\n bottom: 0;\n width: 100%;\n position: absolute;\n border-bottom: var(--input-borderWidth) var(--input-borderStyle) var(--input-borderColor);\n}\n\n/* Style applied to start adornments */\n.saltPillInput-startAdornmentContainer {\n align-items: center;\n display: inline-flex;\n padding-right: var(--salt-spacing-100);\n column-gap: var(--salt-spacing-100);\n}\n\n/* Style applied to end adornments */\n.saltPillInput-endAdornmentContainer {\n align-items: center;\n display: inline-flex;\n padding-left: var(--salt-spacing-100);\n padding-top: var(--salt-spacing-50);\n column-gap: var(--salt-spacing-100);\n align-self: flex-start;\n}\n\n.saltPillInput-readOnly .saltPillInput-startAdornmentContainer {\n margin-left: var(--salt-spacing-50);\n}\n\n.saltPillInput-startAdornmentContainer .saltButton ~ .saltButton {\n margin-left: calc(-1 * var(--salt-spacing-50));\n}\n.saltPillInput-endAdornmentContainer .saltButton ~ .saltButton {\n margin-left: calc(-1 * var(--salt-spacing-50));\n}\n\n.saltPillInput-startAdornmentContainer .saltButton:first-child {\n margin-left: calc(var(--salt-spacing-50) * -1);\n}\n.saltPillInput-endAdornmentContainer .saltButton:last-child {\n margin-right: calc(var(--salt-spacing-50) * -1);\n}\n\n.saltPillInput-startAdornmentContainer > .saltButton,\n.saltPillInput-endAdornmentContainer > .saltButton {\n --saltButton-padding: var(--salt-spacing-50);\n --saltButton-height: calc(var(--salt-size-base) - var(--salt-spacing-100));\n}\n\n.saltPillInput-inputWrapper {\n display: flex;\n gap: var(--salt-spacing-50);\n align-items: center;\n flex: 1;\n padding: var(--salt-spacing-50) 0;\n flex-wrap: wrap;\n max-height: inherit;\n height: inherit;\n overflow-y: auto;\n box-sizing: border-box;\n}\n\n.saltPillInput-pillList {\n display: contents;\n}\n\n.saltPillInput .saltPill:focus-visible {\n background: var(--salt-selectable-background-hover);\n outline: none;\n}\n\n.saltPillInput .saltPill:hover {\n background: var(--salt-selectable-background-hover);\n}\n\n.saltPillInput .saltPill:active {\n background: var(--salt-actionable-primary-background-active);\n --saltPill-color: var(--salt-actionable-primary-foreground-active);\n --saltIcon-color: var(--salt-actionable-primary-foreground-active);\n}\n\ndiv[role=\"listitem\"] {\n display: inline;\n}\n\n.saltPillInput-overflowIndicator {\n width: calc(var(--salt-size-base) - var(--salt-spacing-100));\n height: calc(var(--salt-size-base) - var(--salt-spacing-100));\n display: flex;\n align-items: center;\n justify-content: center;\n}\n";
4
+
5
+ module.exports = css_248z;
6
+ //# sourceMappingURL=PillInput.css.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PillInput.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,256 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var clsx = require('clsx');
7
+ var React = require('react');
8
+ var styles = require('@salt-ds/styles');
9
+ var window = require('@salt-ds/window');
10
+ var core = require('@salt-ds/core');
11
+ var PillInput$1 = require('./PillInput.css.js');
12
+ var icons = require('@salt-ds/icons');
13
+ var useTruncatePills = require('./useTruncatePills.js');
14
+
15
+ const withBaseName = core.makePrefixer("saltPillInput");
16
+ const PillInput = React.forwardRef(function PillInput2({
17
+ "aria-activedescendant": ariaActiveDescendant,
18
+ "aria-expanded": ariaExpanded,
19
+ "aria-owns": ariaOwns,
20
+ className: classNameProp,
21
+ disabled,
22
+ emptyReadOnlyMarker = "\u2014",
23
+ endAdornment,
24
+ hidePillClose,
25
+ id: idProp,
26
+ inputProps = {},
27
+ inputRef: inputRefProp,
28
+ placeholder,
29
+ pills = [],
30
+ onPillRemove,
31
+ readOnly: readOnlyProp,
32
+ role,
33
+ startAdornment,
34
+ style,
35
+ textAlign = "left",
36
+ value: valueProp,
37
+ defaultValue: defaultValueProp = valueProp === void 0 ? "" : void 0,
38
+ validationStatus: validationStatusProp,
39
+ variant = "primary",
40
+ truncate,
41
+ ...other
42
+ }, ref) {
43
+ const targetWindow = window.useWindow();
44
+ styles.useComponentCssInjection({
45
+ testId: "salt-pill-input",
46
+ css: PillInput$1,
47
+ window: targetWindow
48
+ });
49
+ const {
50
+ a11yProps: {
51
+ "aria-describedby": formFieldDescribedBy,
52
+ "aria-labelledby": formFieldLabelledBy
53
+ } = {},
54
+ disabled: formFieldDisabled,
55
+ readOnly: formFieldReadOnly,
56
+ necessity: formFieldRequired,
57
+ validationStatus: formFieldValidationStatus
58
+ } = core.useFormFieldProps();
59
+ const restA11yProps = {
60
+ "aria-activedescendant": ariaActiveDescendant,
61
+ "aria-expanded": ariaExpanded,
62
+ "aria-owns": ariaOwns
63
+ };
64
+ const isDisabled = disabled || formFieldDisabled;
65
+ const isReadOnly = readOnlyProp || formFieldReadOnly;
66
+ const validationStatus = formFieldValidationStatus != null ? formFieldValidationStatus : validationStatusProp;
67
+ const [focusedPillIndex, setFocusedPillIndex] = React.useState(-1);
68
+ const isEmptyReadOnly = isReadOnly && !defaultValueProp && !valueProp;
69
+ const defaultValue = isEmptyReadOnly ? emptyReadOnlyMarker : defaultValueProp;
70
+ const {
71
+ "aria-describedby": inputDescribedBy,
72
+ "aria-labelledby": inputLabelledBy,
73
+ onChange,
74
+ required: inputPropsRequired,
75
+ onKeyDown: inputOnKeyDown,
76
+ ...restInputProps
77
+ } = inputProps;
78
+ const isRequired = formFieldRequired ? ["required", "asterisk"].includes(formFieldRequired) : inputPropsRequired;
79
+ const [value, setValue] = core.useControlled({
80
+ controlled: valueProp,
81
+ default: defaultValue,
82
+ name: "Input",
83
+ state: "value"
84
+ });
85
+ const { visiblePills, pillListRef } = useTruncatePills.useTruncatePills({
86
+ pills,
87
+ enable: truncate && pills.length > 0
88
+ });
89
+ const id = core.useId(idProp);
90
+ const pillListId = `${id}-optionsList`;
91
+ const pillElementsRef = React.useRef([]);
92
+ const inputRef = React.useRef(null);
93
+ const handleInputRef = core.useForkRef(inputRef, inputRefProp);
94
+ const handleChange = (event) => {
95
+ const value2 = event.target.value;
96
+ setValue(value2);
97
+ onChange == null ? void 0 : onChange(event);
98
+ };
99
+ const handleKeyDown = (event) => {
100
+ var _a;
101
+ const target = event.currentTarget;
102
+ if (target.selectionStart === 0 && target.selectionEnd == 0) {
103
+ const lastPillIndex = pills.length - 1;
104
+ const lastPill = pills[lastPillIndex];
105
+ if (event.key === "Backspace" && lastPill) {
106
+ event.preventDefault();
107
+ onPillRemove == null ? void 0 : onPillRemove(event, lastPillIndex);
108
+ } else if (event.key === "ArrowLeft") {
109
+ event.preventDefault();
110
+ (_a = pillElementsRef.current[lastPillIndex]) == null ? void 0 : _a.focus();
111
+ }
112
+ }
113
+ inputOnKeyDown == null ? void 0 : inputOnKeyDown(event);
114
+ };
115
+ const handlePillKeyDown = (event) => {
116
+ var _a, _b, _c, _d, _e, _f;
117
+ const target = event.currentTarget;
118
+ const index = Number(target.dataset.index);
119
+ if (event.key === "ArrowLeft") {
120
+ event.preventDefault();
121
+ (_a = pillElementsRef.current[index - 1]) == null ? void 0 : _a.focus();
122
+ } else if (event.key === "ArrowRight") {
123
+ event.preventDefault();
124
+ if (index === pills.length - 1) {
125
+ (_b = inputRef == null ? void 0 : inputRef.current) == null ? void 0 : _b.focus();
126
+ } else {
127
+ (_c = pillElementsRef.current[index + 1]) == null ? void 0 : _c.focus();
128
+ }
129
+ } else if (event.key == "Delete" || event.key === "Backspace") {
130
+ event.preventDefault();
131
+ onPillRemove == null ? void 0 : onPillRemove(event, index);
132
+ if (pills.length === 1) {
133
+ (_d = inputRef.current) == null ? void 0 : _d.focus();
134
+ } else if (index === pills.length - 1) {
135
+ (_e = pillElementsRef.current[pills.length - 2]) == null ? void 0 : _e.focus();
136
+ } else {
137
+ (_f = pillElementsRef.current[index]) == null ? void 0 : _f.focus();
138
+ }
139
+ }
140
+ };
141
+ const handlePillClick = (event) => {
142
+ var _a;
143
+ const target = event.currentTarget;
144
+ const index = Number(target.dataset.index);
145
+ onPillRemove == null ? void 0 : onPillRemove(event, index);
146
+ (_a = inputRef.current) == null ? void 0 : _a.focus();
147
+ };
148
+ const inputStyle = {
149
+ "--input-textAlign": textAlign,
150
+ ...style
151
+ };
152
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", {
153
+ className: clsx.clsx(
154
+ withBaseName(),
155
+ withBaseName(variant),
156
+ {
157
+ [withBaseName("disabled")]: isDisabled,
158
+ [withBaseName("readOnly")]: isReadOnly,
159
+ [withBaseName("truncate")]: truncate,
160
+ [withBaseName(validationStatus || "")]: validationStatus
161
+ },
162
+ classNameProp
163
+ ),
164
+ ref,
165
+ style: inputStyle,
166
+ ...other,
167
+ children: [
168
+ startAdornment && /* @__PURE__ */ jsxRuntime.jsx("div", {
169
+ className: withBaseName("startAdornmentContainer"),
170
+ children: startAdornment
171
+ }),
172
+ /* @__PURE__ */ jsxRuntime.jsxs("div", {
173
+ className: withBaseName("inputWrapper"),
174
+ ref: pillListRef,
175
+ children: [
176
+ /* @__PURE__ */ jsxRuntime.jsxs("div", {
177
+ role: "list",
178
+ className: withBaseName("pillList"),
179
+ "aria-labelledby": clsx.clsx(formFieldLabelledBy, pillListId),
180
+ "aria-label": "Selected Options",
181
+ id: pillListId,
182
+ children: [
183
+ visiblePills == null ? void 0 : visiblePills.map((pill, index) => /* @__PURE__ */ jsxRuntime.jsx("div", {
184
+ role: "listitem",
185
+ children: /* @__PURE__ */ jsxRuntime.jsxs(core.Pill, {
186
+ "data-index": index,
187
+ disabled,
188
+ ref: (element) => {
189
+ if (element) {
190
+ pillElementsRef.current[index] = element;
191
+ } else {
192
+ pillElementsRef.current = pillElementsRef.current.filter(
193
+ (pillEl) => pillEl !== element
194
+ );
195
+ }
196
+ },
197
+ onFocus: () => setFocusedPillIndex(index),
198
+ onKeyDown: handlePillKeyDown,
199
+ onClick: handlePillClick,
200
+ tabIndex: focusedPillIndex === -1 || focusedPillIndex === index ? 0 : -1,
201
+ children: [
202
+ pill,
203
+ !hidePillClose && /* @__PURE__ */ jsxRuntime.jsx(icons.CloseIcon, {
204
+ "aria-label": "click to close"
205
+ })
206
+ ]
207
+ })
208
+ }, index)),
209
+ visiblePills.length < pills.length && /* @__PURE__ */ jsxRuntime.jsx("div", {
210
+ role: "listitem",
211
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", {
212
+ "data-overflowindicator": true,
213
+ className: withBaseName("overflowIndicator"),
214
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.OverflowMenuIcon, {
215
+ "aria-hidden": true
216
+ })
217
+ })
218
+ })
219
+ ]
220
+ }),
221
+ /* @__PURE__ */ jsxRuntime.jsx("input", {
222
+ "aria-describedby": clsx.clsx(formFieldDescribedBy, inputDescribedBy),
223
+ "aria-labelledby": clsx.clsx(formFieldLabelledBy, inputLabelledBy),
224
+ className: clsx.clsx(withBaseName("input"), inputProps == null ? void 0 : inputProps.className),
225
+ disabled: isDisabled,
226
+ id,
227
+ readOnly: isReadOnly,
228
+ ref: handleInputRef,
229
+ role,
230
+ tabIndex: isDisabled ? -1 : 0,
231
+ onChange: handleChange,
232
+ onKeyDown: handleKeyDown,
233
+ placeholder,
234
+ value,
235
+ ...restA11yProps,
236
+ ...restInputProps,
237
+ required: isRequired
238
+ })
239
+ ]
240
+ }),
241
+ !isDisabled && !isReadOnly && validationStatus && /* @__PURE__ */ jsxRuntime.jsx(core.StatusAdornment, {
242
+ status: validationStatus
243
+ }),
244
+ endAdornment && /* @__PURE__ */ jsxRuntime.jsx("div", {
245
+ className: withBaseName("endAdornmentContainer"),
246
+ children: endAdornment
247
+ }),
248
+ /* @__PURE__ */ jsxRuntime.jsx("div", {
249
+ className: withBaseName("activationIndicator")
250
+ })
251
+ ]
252
+ });
253
+ });
254
+
255
+ exports.PillInput = PillInput;
256
+ //# sourceMappingURL=PillInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PillInput.js","sources":["../src/pill-input/PillInput.tsx"],"sourcesContent":["import { clsx } from \"clsx\";\nimport {\n ChangeEvent,\n KeyboardEvent,\n SyntheticEvent,\n ComponentPropsWithoutRef,\n MouseEvent,\n ForwardedRef,\n forwardRef,\n InputHTMLAttributes,\n ReactNode,\n Ref,\n useState,\n useRef,\n} from \"react\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport {\n makePrefixer,\n useControlled,\n useFormFieldProps,\n StatusAdornment,\n useId,\n Pill,\n useForkRef,\n} from \"@salt-ds/core\";\n\nimport pillInputCss from \"./PillInput.css\";\nimport { CloseIcon, OverflowMenuIcon } from \"@salt-ds/icons\";\nimport { useTruncatePills } from \"./useTruncatePills\";\n\nconst withBaseName = makePrefixer(\"saltPillInput\");\n\nexport interface PillInputProps\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"defaultValue\">,\n Pick<\n ComponentPropsWithoutRef<\"input\">,\n \"disabled\" | \"value\" | \"defaultValue\" | \"placeholder\"\n > {\n /**\n * The marker to use in an empty read only Input.\n * Use `''` to disable this feature. Defaults to '—'.\n */\n emptyReadOnlyMarker?: string;\n /**\n * End adornment component\n */\n endAdornment?: ReactNode;\n /**\n * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.\n */\n inputProps?: InputHTMLAttributes<HTMLInputElement>;\n /**\n * Optional ref for the input component\n */\n inputRef?: Ref<HTMLInputElement>;\n /**\n * If `true`, the component is read only.\n */\n readOnly?: boolean;\n /**\n * The tokens to display in the input.\n */\n pills?: any[];\n onPillRemove?: (event: SyntheticEvent, index: number) => void;\n /**\n * Start adornment component\n */\n startAdornment?: ReactNode;\n /**\n * Alignment of text within container. Defaults to \"left\"\n */\n textAlign?: \"left\" | \"center\" | \"right\";\n /**\n * Validation status.\n */\n validationStatus?: \"error\" | \"warning\" | \"success\";\n /**\n * Styling variant. Defaults to \"primary\".\n */\n variant?: \"primary\" | \"secondary\";\n hidePillClose?: boolean;\n truncate?: boolean;\n}\n\nexport const PillInput = forwardRef(function PillInput<Item>(\n {\n \"aria-activedescendant\": ariaActiveDescendant,\n \"aria-expanded\": ariaExpanded,\n \"aria-owns\": ariaOwns,\n className: classNameProp,\n disabled,\n emptyReadOnlyMarker = \"—\",\n endAdornment,\n hidePillClose,\n id: idProp,\n inputProps = {},\n inputRef: inputRefProp,\n placeholder,\n pills = [],\n onPillRemove,\n readOnly: readOnlyProp,\n role,\n startAdornment,\n style,\n textAlign = \"left\",\n value: valueProp,\n defaultValue: defaultValueProp = valueProp === undefined ? \"\" : undefined,\n validationStatus: validationStatusProp,\n variant = \"primary\",\n truncate,\n ...other\n }: PillInputProps,\n ref: ForwardedRef<HTMLDivElement>\n) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-pill-input\",\n css: pillInputCss,\n window: targetWindow,\n });\n\n const {\n a11yProps: {\n \"aria-describedby\": formFieldDescribedBy,\n \"aria-labelledby\": formFieldLabelledBy,\n } = {},\n disabled: formFieldDisabled,\n readOnly: formFieldReadOnly,\n necessity: formFieldRequired,\n validationStatus: formFieldValidationStatus,\n } = useFormFieldProps();\n\n const restA11yProps = {\n \"aria-activedescendant\": ariaActiveDescendant,\n \"aria-expanded\": ariaExpanded,\n \"aria-owns\": ariaOwns,\n };\n\n const isDisabled = disabled || formFieldDisabled;\n const isReadOnly = readOnlyProp || formFieldReadOnly;\n const validationStatus = formFieldValidationStatus ?? validationStatusProp;\n\n const [focusedPillIndex, setFocusedPillIndex] = useState(-1);\n\n const isEmptyReadOnly = isReadOnly && !defaultValueProp && !valueProp;\n const defaultValue = isEmptyReadOnly ? emptyReadOnlyMarker : defaultValueProp;\n\n const {\n \"aria-describedby\": inputDescribedBy,\n \"aria-labelledby\": inputLabelledBy,\n onChange,\n required: inputPropsRequired,\n onKeyDown: inputOnKeyDown,\n ...restInputProps\n } = inputProps;\n\n const isRequired = formFieldRequired\n ? [\"required\", \"asterisk\"].includes(formFieldRequired)\n : inputPropsRequired;\n\n const [value, setValue] = useControlled({\n controlled: valueProp,\n default: defaultValue,\n name: \"Input\",\n state: \"value\",\n });\n\n const { visiblePills, pillListRef } = useTruncatePills({\n pills,\n enable: truncate && pills.length > 0,\n });\n\n const id = useId(idProp);\n const pillListId = `${id}-optionsList`;\n\n const pillElementsRef = useRef<HTMLElement[]>([]);\n const inputRef = useRef<HTMLInputElement>(null);\n\n const handleInputRef = useForkRef(inputRef, inputRefProp);\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n const value = event.target.value;\n setValue(value);\n onChange?.(event);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n const target = event.currentTarget;\n if (target.selectionStart === 0 && target.selectionEnd == 0) {\n const lastPillIndex = pills.length - 1;\n const lastPill = pills[lastPillIndex];\n if (event.key === \"Backspace\" && lastPill) {\n event.preventDefault();\n onPillRemove?.(event, lastPillIndex);\n } else if (event.key === \"ArrowLeft\") {\n event.preventDefault();\n // Move focus to last pill\n pillElementsRef.current[lastPillIndex]?.focus();\n }\n }\n\n inputOnKeyDown?.(event);\n };\n\n const handlePillKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n const target = event.currentTarget;\n const index = Number(target.dataset.index);\n if (event.key === \"ArrowLeft\") {\n event.preventDefault();\n // Move focus to previous pill\n pillElementsRef.current[index - 1]?.focus();\n } else if (event.key === \"ArrowRight\") {\n event.preventDefault();\n // Move focus to next pill or input\n if (index === pills.length - 1) {\n inputRef?.current?.focus();\n } else {\n pillElementsRef.current[index + 1]?.focus();\n }\n } else if (event.key == \"Delete\" || event.key === \"Backspace\") {\n event.preventDefault();\n onPillRemove?.(event, index);\n\n if (pills.length === 1) {\n inputRef.current?.focus();\n } else if (index === pills.length - 1) {\n pillElementsRef.current[pills.length - 2]?.focus();\n } else {\n pillElementsRef.current[index]?.focus();\n }\n }\n };\n\n const handlePillClick = (event: MouseEvent<HTMLButtonElement>) => {\n const target = event.currentTarget;\n const index = Number(target.dataset.index);\n onPillRemove?.(event, index);\n inputRef.current?.focus();\n };\n\n const inputStyle = {\n \"--input-textAlign\": textAlign,\n ...style,\n };\n\n return (\n <div\n className={clsx(\n withBaseName(),\n withBaseName(variant),\n {\n [withBaseName(\"disabled\")]: isDisabled,\n [withBaseName(\"readOnly\")]: isReadOnly,\n [withBaseName(\"truncate\")]: truncate,\n [withBaseName(validationStatus || \"\")]: validationStatus,\n },\n classNameProp\n )}\n ref={ref}\n style={inputStyle}\n {...other}\n >\n {startAdornment && (\n <div className={withBaseName(\"startAdornmentContainer\")}>\n {startAdornment}\n </div>\n )}\n <div className={withBaseName(\"inputWrapper\")} ref={pillListRef}>\n <div\n role=\"list\"\n className={withBaseName(\"pillList\")}\n aria-labelledby={clsx(formFieldLabelledBy, pillListId)}\n aria-label=\"Selected Options\"\n id={pillListId}\n >\n {visiblePills?.map((pill, index) => (\n <div role=\"listitem\" key={index}>\n <Pill\n data-index={index}\n disabled={disabled}\n ref={(element) => {\n if (element) {\n pillElementsRef.current[index] = element;\n } else {\n pillElementsRef.current = pillElementsRef.current.filter(\n (pillEl) => pillEl !== element\n );\n }\n }}\n onFocus={() => setFocusedPillIndex(index)}\n onKeyDown={handlePillKeyDown}\n onClick={handlePillClick}\n tabIndex={\n focusedPillIndex === -1 || focusedPillIndex === index ? 0 : -1\n }\n >\n {pill}\n {!hidePillClose && <CloseIcon aria-label=\"click to close\" />}\n </Pill>\n </div>\n ))}\n {visiblePills.length < pills.length && (\n <div role=\"listitem\">\n <div\n data-overflowindicator\n className={withBaseName(\"overflowIndicator\")}\n >\n <OverflowMenuIcon aria-hidden />\n </div>\n </div>\n )}\n </div>\n <input\n aria-describedby={clsx(formFieldDescribedBy, inputDescribedBy)}\n aria-labelledby={clsx(formFieldLabelledBy, inputLabelledBy)}\n className={clsx(withBaseName(\"input\"), inputProps?.className)}\n disabled={isDisabled}\n id={id}\n readOnly={isReadOnly}\n ref={handleInputRef}\n role={role}\n tabIndex={isDisabled ? -1 : 0}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n placeholder={placeholder}\n value={value}\n {...restA11yProps}\n {...restInputProps}\n required={isRequired}\n />\n </div>\n {!isDisabled && !isReadOnly && validationStatus && (\n <StatusAdornment status={validationStatus} />\n )}\n {endAdornment && (\n <div className={withBaseName(\"endAdornmentContainer\")}>\n {endAdornment}\n </div>\n )}\n <div className={withBaseName(\"activationIndicator\")} />\n </div>\n );\n});\n"],"names":["makePrefixer","forwardRef","PillInput","useWindow","useComponentCssInjection","pillInputCss","useFormFieldProps","useState","useControlled","useTruncatePills","useId","useRef","useForkRef","value","jsxs","clsx","jsx","Pill","CloseIcon","OverflowMenuIcon","StatusAdornment"],"mappings":";;;;;;;;;;;;;;AA+BA,MAAM,YAAA,GAAeA,kBAAa,eAAe,CAAA,CAAA;AAsDpC,MAAA,SAAA,GAAYC,gBAAW,CAAA,SAASC,UAC3C,CAAA;AAAA,EACE,uBAAyB,EAAA,oBAAA;AAAA,EACzB,eAAiB,EAAA,YAAA;AAAA,EACjB,WAAa,EAAA,QAAA;AAAA,EACb,SAAW,EAAA,aAAA;AAAA,EACX,QAAA;AAAA,EACA,mBAAsB,GAAA,QAAA;AAAA,EACtB,YAAA;AAAA,EACA,aAAA;AAAA,EACA,EAAI,EAAA,MAAA;AAAA,EACJ,aAAa,EAAC;AAAA,EACd,QAAU,EAAA,YAAA;AAAA,EACV,WAAA;AAAA,EACA,QAAQ,EAAC;AAAA,EACT,YAAA;AAAA,EACA,QAAU,EAAA,YAAA;AAAA,EACV,IAAA;AAAA,EACA,cAAA;AAAA,EACA,KAAA;AAAA,EACA,SAAY,GAAA,MAAA;AAAA,EACZ,KAAO,EAAA,SAAA;AAAA,EACP,YAAc,EAAA,gBAAA,GAAmB,SAAc,KAAA,KAAA,CAAA,GAAY,EAAK,GAAA,KAAA,CAAA;AAAA,EAChE,gBAAkB,EAAA,oBAAA;AAAA,EAClB,OAAU,GAAA,SAAA;AAAA,EACV,QAAA;AAAA,EACG,GAAA,KAAA;AACL,CAAA,EACA,GACA,EAAA;AACA,EAAA,MAAM,eAAeC,gBAAU,EAAA,CAAA;AAC/B,EAAyBC,+BAAA,CAAA;AAAA,IACvB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AA,OACF,CAAA;AAAA,MACC,CAAC,UAAA,IAAc,CAAC,UAAA,IAAc,oCAC5BC,cAAA,CAAAI,oBAAA,EAAA;AAAA,QAAgB,MAAQ,EAAA,gBAAA;AAAA,OAAkB,CAAA;AAAA,MAE5C,gCACEJ,cAAA,CAAA,KAAA,EAAA;AAAA,QAAI,SAAA,EAAW,aAAa,uBAAuB,CAAA;AAAA,QACjD,QAAA,EAAA,YAAA;AAAA,OACH,CAAA;AAAA,sBAEDA,cAAA,CAAA,KAAA,EAAA;AAAA,QAAI,SAAA,EAAW,aAAa,qBAAqB,CAAA;AAAA,OAAG,CAAA;AAAA,KAAA;AAAA,GACvD,CAAA,CAAA;AAEJ,CAAC;;;;"}
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var core = require('@salt-ds/core');
7
+ var useValueEffect = require('../utils/useValueEffect.js');
8
+ var window = require('@salt-ds/window');
9
+ require('react/jsx-runtime');
10
+ var useResizeObserver = require('../responsive/useResizeObserver.js');
11
+
12
+ function useTruncatePills({
13
+ pills,
14
+ enable
15
+ }) {
16
+ const pillListRef = React.useRef(null);
17
+ const [{ visibleCount }, setVisibleItems] = useValueEffect.useValueEffect({
18
+ visibleCount: pills.length
19
+ });
20
+ const targetWindow = window.useWindow();
21
+ const updateOverflow = React.useCallback(() => {
22
+ if (!enable) {
23
+ return;
24
+ }
25
+ const computeVisible = (visibleCount2) => {
26
+ const pillList = pillListRef.current;
27
+ if (pillList && targetWindow) {
28
+ let pillElements = Array.from(
29
+ pillList.querySelectorAll('[role="listitem"]')
30
+ );
31
+ const maxWidth = pillList.getBoundingClientRect().width;
32
+ const listGap = parseInt(targetWindow.getComputedStyle(pillList).gap);
33
+ let isShowingOverflow = pillList.querySelector(
34
+ "[data-overflowindicator]"
35
+ );
36
+ let currentSize = 0;
37
+ let newVisibleCount = 0;
38
+ if (isShowingOverflow) {
39
+ let pill = pillElements.pop();
40
+ if (pill) {
41
+ let pillWidth = pill.getBoundingClientRect().width;
42
+ currentSize += pillWidth + listGap;
43
+ }
44
+ }
45
+ for (let pill of pillElements) {
46
+ let pillWidth = pill.getBoundingClientRect().width;
47
+ currentSize += pillWidth + listGap;
48
+ if (Math.round(currentSize) <= Math.round(maxWidth)) {
49
+ newVisibleCount++;
50
+ } else {
51
+ break;
52
+ }
53
+ }
54
+ return newVisibleCount;
55
+ }
56
+ return visibleCount2;
57
+ };
58
+ setVisibleItems(function* () {
59
+ yield {
60
+ visibleCount: pills.length
61
+ };
62
+ let newVisibleCount = computeVisible(pills.length);
63
+ let isMeasuring = newVisibleCount < pills.length && newVisibleCount > 0;
64
+ yield {
65
+ visibleCount: newVisibleCount
66
+ };
67
+ if (isMeasuring) {
68
+ newVisibleCount = computeVisible(visibleCount);
69
+ yield {
70
+ visibleCount: newVisibleCount
71
+ };
72
+ }
73
+ });
74
+ }, [pills, setVisibleItems, enable, targetWindow]);
75
+ core.useIsomorphicLayoutEffect(updateOverflow, [updateOverflow, pills]);
76
+ useResizeObserver.useResizeObserver(pillListRef, ["width"], updateOverflow, true);
77
+ return {
78
+ pillListRef,
79
+ visibleCount,
80
+ visiblePills: enable ? pills.slice(0, visibleCount) : pills
81
+ };
82
+ }
83
+
84
+ exports.useTruncatePills = useTruncatePills;
85
+ //# sourceMappingURL=useTruncatePills.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTruncatePills.js","sources":["../src/pill-input/useTruncatePills.ts"],"sourcesContent":["import { useCallback, useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"@salt-ds/core\";\nimport { useValueEffect } from \"../utils/useValueEffect\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { useResizeObserver } from \"../responsive\";\n\nexport function useTruncatePills({\n pills,\n enable,\n}: {\n pills: string[];\n enable?: boolean;\n}) {\n const pillListRef = useRef<HTMLDivElement>(null);\n const [{ visibleCount }, setVisibleItems] = useValueEffect({\n visibleCount: pills.length,\n });\n const targetWindow = useWindow();\n\n const updateOverflow = useCallback(() => {\n if (!enable) {\n return;\n }\n\n const computeVisible = (visibleCount: number) => {\n const pillList = pillListRef.current;\n\n if (pillList && targetWindow) {\n let pillElements = Array.from(\n pillList.querySelectorAll('[role=\"listitem\"]')\n ) as HTMLLIElement[];\n const maxWidth = pillList.getBoundingClientRect().width;\n const listGap = parseInt(targetWindow.getComputedStyle(pillList).gap);\n let isShowingOverflow = pillList.querySelector(\n \"[data-overflowindicator]\"\n );\n\n let currentSize = 0;\n let newVisibleCount = 0;\n\n if (isShowingOverflow) {\n let pill = pillElements.pop();\n if (pill) {\n let pillWidth = pill.getBoundingClientRect().width;\n currentSize += pillWidth + listGap;\n }\n }\n\n for (let pill of pillElements) {\n let pillWidth = pill.getBoundingClientRect().width;\n currentSize += pillWidth + listGap;\n\n if (Math.round(currentSize) <= Math.round(maxWidth)) {\n newVisibleCount++;\n } else {\n break;\n }\n }\n return newVisibleCount;\n }\n return visibleCount;\n };\n\n setVisibleItems(function* () {\n // Show all\n yield {\n visibleCount: pills.length,\n };\n\n // Measure the visible count\n let newVisibleCount = computeVisible(pills.length);\n let isMeasuring = newVisibleCount < pills.length && newVisibleCount > 0;\n yield {\n visibleCount: newVisibleCount,\n };\n\n // ensure the visible count is correct\n if (isMeasuring) {\n newVisibleCount = computeVisible(visibleCount);\n yield {\n visibleCount: newVisibleCount,\n };\n }\n });\n }, [pills, setVisibleItems, enable, targetWindow]);\n\n useIsomorphicLayoutEffect(updateOverflow, [updateOverflow, pills]);\n useResizeObserver(pillListRef, [\"width\"], updateOverflow, true);\n\n return {\n pillListRef,\n visibleCount,\n visiblePills: enable ? pills.slice(0, visibleCount) : pills,\n };\n}\n"],"names":["useRef","useValueEffect","useWindow","useCallback","visibleCount","useIsomorphicLayoutEffect","useResizeObserver"],"mappings":";;;;;;;;;;;AAMO,SAAS,gBAAiB,CAAA;AAAA,EAC/B,KAAA;AAAA,EACA,MAAA;AACF,CAGG,EAAA;A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,cAAc,MAAS,GAAA,KAAA,CAAM,KAAM,CAAA,CAAA,EAAG,YAAY,CAAI,GAAA,KAAA;AAAA,GACxD,CAAA;AACF;;;;"}
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var core = require('@salt-ds/core');
7
+ var useEventCallback = require('./useEventCallback.js');
8
+
9
+ function useValueEffect(defaultValue) {
10
+ let [value, setValue] = React.useState(defaultValue);
11
+ let effect = React.useRef(null);
12
+ let nextRef = useEventCallback.useEventCallback(() => {
13
+ if (!effect.current) {
14
+ return;
15
+ }
16
+ let newValue = effect.current.next();
17
+ if (newValue.done) {
18
+ effect.current = null;
19
+ return;
20
+ }
21
+ if (value === newValue.value) {
22
+ nextRef();
23
+ } else {
24
+ setValue(newValue.value);
25
+ }
26
+ });
27
+ core.useIsomorphicLayoutEffect(() => {
28
+ if (effect.current) {
29
+ nextRef();
30
+ }
31
+ });
32
+ let queue = useEventCallback.useEventCallback((fn) => {
33
+ effect.current = fn(value);
34
+ nextRef();
35
+ });
36
+ return [value, queue];
37
+ }
38
+
39
+ exports.useValueEffect = useValueEffect;
40
+ //# sourceMappingURL=useValueEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useValueEffect.js","sources":["../src/utils/useValueEffect.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { Dispatch, MutableRefObject, useRef, useState } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"@salt-ds/core\";\nimport { useEventCallback } from \"./useEventCallback\";\n\ntype SetValueAction<S> = (prev: S) => Generator<any, void, unknown>;\n\n// This hook works like `useState`, but when setting the value, you pass a generator function\n// that can yield multiple values. Each yielded value updates the state and waits for the next\n// layout effect, then continues the generator. This allows sequential updates to state to be\n// written linearly.\nexport function useValueEffect<S>(\n defaultValue: S | (() => S)\n): [S, Dispatch<SetValueAction<S>>] {\n let [value, setValue] = useState(defaultValue);\n let effect: MutableRefObject<Generator<S> | null> =\n useRef<Generator<S> | null>(null);\n\n // Store the function in a ref so we can always access the current version\n // which has the proper `value` in scope.\n let nextRef = useEventCallback(() => {\n if (!effect.current) {\n return;\n }\n // Run the generator to the next yield.\n let newValue = effect.current.next();\n\n // If the generator is done, reset the effect.\n if (newValue.done) {\n effect.current = null;\n return;\n }\n\n // If the value is the same as the current value,\n // then continue to the next yield. Otherwise,\n // set the value in state and wait for the next layout effect.\n if (value === newValue.value) {\n nextRef();\n } else {\n setValue(newValue.value);\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n // If there is an effect currently running, continue to the next yield.\n if (effect.current) {\n nextRef();\n }\n });\n\n let queue: Dispatch<SetValueAction<S>> = useEventCallback((fn) => {\n effect.current = fn(value);\n nextRef();\n });\n\n return [value, queue];\n}\n"],"names":["useState","useRef","useEventCallback","useIsomorphicLayoutEffect"],"mappings":";;;;;;;;AAsBO,SAAS,eACd,YACkC,EAAA;AAClC,EAAA,IAAI,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,eAAS,YAAY,CAAA,CAAA;AAC7C,EAAI,IAAA,MAAA,GACFC,aAA4B,IAAI,CAAA,CAAA;AAIlC,EAAI,IAAA,OAAA,GAAUC,kCAAiB,MAAM;AACnC,IAAI,IAAA,CAAC,OAAO,OAAS,EAAA;AACnB,MAAA,OAAA;AAAA,KACF;AAEA,IAAI,IAAA,QAAA,GAAW,MAAO,CAAA,OAAA,CAAQ,IAAK,EAAA,CAAA;AAGnC,IAAA,IAAI,SAAS,IAAM,EAAA;AACjB,MAAA,MAAA,CAAO,OAAU,GAAA,IAAA,CAAA;AACjB,MAAA,OAAA;AAAA,KACF;AAKA,IAAI,IAAA,KAAA,KAAU,SAAS,KAAO,EAAA;AAC5B,MAAQ,OAAA,EAAA,CAAA;AAAA,KACH,MAAA;AACL,MAAA,QAAA,CAAS,SAAS,KAAK,CAAA,CAAA;AAAA,KACzB;AAAA,GACD,CAAA,CAAA;AAED,EAAAC,8BAAA,CAA0B,MAAM;AAE9B,IAAA,IAAI,OAAO,OAAS,EAAA;AAClB,MAAQ,OAAA,EAAA,CAAA;AAAA,KACV;AAAA,GACD,CAAA,CAAA;AAED,EAAI,IAAA,KAAA,GAAqCD,iCAAiB,CAAA,CAAC,EAAO,KAAA;AAChE,IAAO,MAAA,CAAA,OAAA,GAAU,GAAG,KAAK,CAAA,CAAA;AACzB,IAAQ,OAAA,EAAA,CAAA;AAAA,GACT,CAAA,CAAA;AAED,EAAO,OAAA,CAAC,OAAO,KAAK,CAAA,CAAA;AACtB;;;;"}
@@ -0,0 +1,4 @@
1
+ var css_248z = ".saltComboBoxNext-focused {\n outline: var(--salt-focused-outline);\n}\n";
2
+
3
+ export { css_248z as default };
4
+ //# sourceMappingURL=ComboBoxNext.css.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ComboBoxNext.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
2
  import { forwardRef, useRef, useEffect } from 'react';
3
- import { makePrefixer, useFormFieldProps, useFloatingComponent, useFloatingUI, useForkRef, useId, Input, Button } from '@salt-ds/core';
3
+ import { makePrefixer, useFormFieldProps, useFloatingComponent, useFloatingUI, useForkRef, useId, Button } from '@salt-ds/core';
4
4
  import { defaultValueToString } from '../list-control/ListControlState.js';
5
5
  import { ListControlContext } from '../list-control/ListControlContext.js';
6
6
  import { clsx } from 'clsx';
@@ -8,6 +8,10 @@ import { size, flip, useInteractions, useDismiss, useFocus, useClick } from '@fl
8
8
  import { ChevronUpIcon, ChevronDownIcon } from '@salt-ds/icons';
9
9
  import { useComboBoxNext } from './useComboBoxNext.js';
10
10
  import { OptionList } from '../option/OptionList.js';
11
+ import { PillInput } from '../pill-input/PillInput.js';
12
+ import { useWindow } from '@salt-ds/window';
13
+ import { useComponentCssInjection } from '@salt-ds/styles';
14
+ import css_248z from './ComboBoxNext.css.js';
11
15
 
12
16
  const withBaseName = makePrefixer("saltComboBoxNext");
13
17
  const ComboBoxNext = forwardRef(function ComboBox(props, ref) {
@@ -35,8 +39,15 @@ const ComboBoxNext = forwardRef(function ComboBox(props, ref) {
35
39
  value,
36
40
  defaultValue,
37
41
  valueToString = defaultValueToString,
42
+ truncate,
38
43
  ...rest
39
44
  } = props;
45
+ const targetWindow = useWindow();
46
+ useComponentCssInjection({
47
+ testId: "salt-combo-box-next",
48
+ css: css_248z,
49
+ window: targetWindow
50
+ });
40
51
  const {
41
52
  a11yProps: { "aria-labelledby": formFieldLabelledBy } = {},
42
53
  disabled: formFieldDisabled,
@@ -214,6 +225,11 @@ const ComboBoxNext = forwardRef(function ComboBox(props, ref) {
214
225
  });
215
226
  onChange == null ? void 0 : onChange(event);
216
227
  };
228
+ const handlePillRemove = (event, index) => {
229
+ event.stopPropagation();
230
+ const removed = selectedState[index];
231
+ select(event, getOptionsMatching((option) => option.value === removed)[0]);
232
+ };
217
233
  const handleListMouseOver = () => {
218
234
  setFocusVisibleState(false);
219
235
  };
@@ -258,8 +274,15 @@ const ComboBoxNext = forwardRef(function ComboBox(props, ref) {
258
274
  return /* @__PURE__ */ jsxs(ListControlContext.Provider, {
259
275
  value: listControl,
260
276
  children: [
261
- /* @__PURE__ */ jsx(Input, {
262
- className: clsx(withBaseName(), className),
277
+ /* @__PURE__ */ jsx(PillInput, {
278
+ className: clsx(
279
+ withBaseName(),
280
+ {
281
+ [withBaseName("focused")]: focusedState,
282
+ [withBaseName("focusVisible")]: focusVisibleState
283
+ },
284
+ className
285
+ ),
263
286
  endAdornment: /* @__PURE__ */ jsxs(Fragment, {
264
287
  children: [
265
288
  endAdornment,
@@ -303,7 +326,12 @@ const ComboBoxNext = forwardRef(function ComboBox(props, ref) {
303
326
  onBlur,
304
327
  onFocus: handleFocus,
305
328
  ...rest
306
- })
329
+ }),
330
+ pills: multiselect ? selectedState.map((item) => valueToString(item)) : [],
331
+ truncate: truncate && !focusedState && !openState,
332
+ onPillRemove: handlePillRemove,
333
+ hidePillClose: !focusedState || readOnly,
334
+ emptyReadOnlyMarker: readOnly && selectedState.length > 0 ? "" : void 0
307
335
  }),
308
336
  /* @__PURE__ */ jsx(FloatingComponent, {
309
337
  open: (openState || focusedState) && !readOnly && children != void 0,