@box/combobox-with-api 0.38.10 → 0.40.0

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.
@@ -1,31 +1,31 @@
1
- import { ComboboxItemValue as oe } from "@ariakit/react";
2
- import { Combobox as m, useForkRef as te, LoadingIndicator as re, InlineNotice as ne, Text as ie } from "@box/blueprint-web";
3
- import { Search as se, Loader as ae } from "@box/blueprint-web-assets/icons/Fill";
4
- import { IconIconOnLightSecondary as le, Size6 as M, Size1 as ce } from "@box/blueprint-web-assets/tokens/tokens";
5
- import T from "clsx";
6
- import { forwardRef as k, useRef as v, useCallback as ue, useMemo as R, useEffect as de } from "react";
7
- import { useIntl as F, FormattedMessage as V } from "react-intl";
1
+ import { ComboboxItemValue as te } from "@ariakit/react";
2
+ import { Combobox as m, useForkRef as re, LoadingIndicator as ne, InlineNotice as ie, Text as se } from "@box/blueprint-web";
3
+ import { Search as ae, Loader as le } from "@box/blueprint-web-assets/icons/Fill";
4
+ import { IconIconOnLightSecondary as ce, Size6 as T, Size1 as ue } from "@box/blueprint-web-assets/tokens/tokens";
5
+ import S from "clsx";
6
+ import { forwardRef as F, useRef as v, useCallback as de, useMemo as R, useEffect as me } from "react";
7
+ import { useIntl as P, FormattedMessage as V } from "react-intl";
8
8
  import i from "./messages.js";
9
- import { useAsyncList as me } from "./use-async-list.js";
10
- import { useControllableState as pe } from "./utils/use-controllable-state.js";
11
- import { useTrackVisibility as he } from "./utils/use-intersection-observer.js";
12
- import { jsx as r, jsxs as N, Fragment as fe } from "react/jsx-runtime";
13
- import '../../../../styles/combobox-with-api-pagination.css';const be = "_container_syvk5_1", ge = "_disabled_syvk5_7", xe = "_highlightOptionText_syvk5_11", _e = "_selected_syvk5_23", Oe = "_option_syvk5_34", ye = "_errorComboboxOption_syvk5_38", ve = "_errorComboboxOptionText_syvk5_43", a = {
9
+ import { useAsyncList as pe } from "./use-async-list.js";
10
+ import { useControllableState as he } from "./utils/use-controllable-state.js";
11
+ import { useTrackVisibility as fe } from "./utils/use-intersection-observer.js";
12
+ import { jsx as r, jsxs as N, Fragment as ge } from "react/jsx-runtime";
13
+ import '../../../../styles/combobox-with-api-pagination.css';const be = "_container_syvk5_1", xe = "_disabled_syvk5_7", Oe = "_highlightOptionText_syvk5_11", _e = "_selected_syvk5_23", ye = "_option_syvk5_34", ve = "_errorComboboxOption_syvk5_38", Re = "_errorComboboxOptionText_syvk5_43", a = {
14
14
  container: be,
15
- disabled: ge,
16
- highlightOptionText: xe,
15
+ disabled: xe,
16
+ highlightOptionText: Oe,
17
17
  selected: _e,
18
- option: Oe,
19
- errorComboboxOption: ye,
20
- errorComboboxOptionText: ve
21
- }, S = /* @__PURE__ */ k(({
22
- onTryAgain: A
18
+ option: ye,
19
+ errorComboboxOption: ve,
20
+ errorComboboxOptionText: Re
21
+ }, k = /* @__PURE__ */ F(({
22
+ onTryAgain: L
23
23
  }, p) => {
24
24
  const {
25
25
  formatMessage: h
26
- } = F();
27
- return /* @__PURE__ */ N(fe, {
28
- children: [/* @__PURE__ */ r(ne, {
26
+ } = P();
27
+ return /* @__PURE__ */ N(ge, {
28
+ children: [/* @__PURE__ */ r(ie, {
29
29
  variant: "error",
30
30
  variantIconAriaLabel: h(i.loadingResultsErrorIconLabel),
31
31
  children: /* @__PURE__ */ r(V, {
@@ -34,15 +34,15 @@ import '../../../../styles/combobox-with-api-pagination.css';const be = "_contai
34
34
  }), /* @__PURE__ */ r(m.Option, {
35
35
  ref: p,
36
36
  className: a.errorComboboxOption,
37
- onClick: A,
38
- children: /* @__PURE__ */ N(ie, {
37
+ onClick: L,
38
+ children: /* @__PURE__ */ N(se, {
39
39
  as: "span",
40
40
  className: a.errorComboboxOptionText,
41
41
  color: "textOnLightLink",
42
42
  variant: "bodyDefaultBold",
43
43
  children: [/* @__PURE__ */ r(V, {
44
44
  ...i.loadingResultsErrorAction
45
- }), /* @__PURE__ */ r(ae, {
45
+ }), /* @__PURE__ */ r(le, {
46
46
  color: "currentColor",
47
47
  height: "12px",
48
48
  width: "12px"
@@ -50,37 +50,38 @@ import '../../../../styles/combobox-with-api-pagination.css';const be = "_contai
50
50
  })
51
51
  })]
52
52
  });
53
- }), C = "__LOADING__", L = "__LOADING_ERROR__", Re = "0px 0px 20px 0px", Ce = /* @__PURE__ */ r(se, {
54
- color: le,
55
- height: M,
53
+ }), C = "__LOADING__", A = "__LOADING_ERROR__", Ce = "0px 0px 20px 0px", Ae = /* @__PURE__ */ r(ae, {
54
+ color: ce,
55
+ height: T,
56
56
  role: "presentation",
57
57
  style: {
58
- padding: ce,
58
+ padding: ue,
59
59
  boxSizing: "border-box"
60
60
  },
61
- width: M
62
- }), De = /* @__PURE__ */ k(function(p, h) {
61
+ width: T
62
+ }), Be = /* @__PURE__ */ F(function(p, h) {
63
63
  const {
64
- defaultFetcher: P,
64
+ defaultFetcher: D,
65
65
  onInputValueChange: f,
66
- value: D,
66
+ value: B,
67
67
  onValueChange: w,
68
- noResultMessage: B,
69
- defaultValue: W = [],
70
- loadingAriaLabel: z,
68
+ noResultMessage: W,
69
+ defaultValue: z = [],
70
+ loadingAriaLabel: G,
71
71
  multiselect: l = !1,
72
- disabled: G,
73
- className: j,
74
- ...U
72
+ disabled: j,
73
+ className: U,
74
+ displaySingleSelectionAsChip: E = !0,
75
+ ...q
75
76
  } = p, {
76
77
  formatMessage: u
77
- } = F(), b = v(null), g = v(!0), e = me({
78
+ } = P(), g = v(null), b = v(!0), e = pe({
78
79
  async load({
79
80
  marker: o,
80
81
  searchInput: t,
81
82
  signal: y
82
83
  }) {
83
- const c = await P({
84
+ const c = await D({
84
85
  signal: y,
85
86
  marker: o,
86
87
  searchInput: t
@@ -90,15 +91,15 @@ import '../../../../styles/combobox-with-api-pagination.css';const be = "_contai
90
91
  marker: c.marker
91
92
  };
92
93
  }
93
- }), E = v(!1), q = ue(() => {
94
- E.current || (e.reload(), E.current = !0);
95
- }, []), [n, x] = pe({
96
- prop: D,
97
- defaultProp: W,
94
+ }), I = v(!1), H = de(() => {
95
+ I.current || (e.reload(), I.current = !0);
96
+ }, []), [n, x] = he({
97
+ prop: B,
98
+ defaultProp: z,
98
99
  onChange: w
99
- }), _ = !l && n.length === 1, H = (o) => {
100
- o === void 0 ? (x([]), g.current || (e.search(""), g.current = !0)) : Array.isArray(o) ? x(o) : x([o]);
101
- }, J = R(() => n.length === 0 ? l ? [] : void 0 : l ? n : n[0], [l, n]), O = R(() => n.filter((o) => !e.items.some((t) => t.value === o.value)), [n, e.items]), K = (o) => {
100
+ }), O = !l && n.length === 1, J = (o) => {
101
+ o === void 0 ? (x([]), b.current || (e.search(""), b.current = !0)) : Array.isArray(o) ? x(o) : x([o]);
102
+ }, K = R(() => n.length === 0 ? l ? [] : void 0 : l ? n : n[0], [l, n]), _ = R(() => n.filter((o) => !e.items.some((t) => t.value === o.value)), [n, e.items]), Q = (o) => {
102
103
  const {
103
104
  value: t,
104
105
  displayValue: y,
@@ -107,57 +108,57 @@ import '../../../../styles/combobox-with-api-pagination.css';const be = "_contai
107
108
  if (t === C)
108
109
  return e.hasNextPage ? /* @__PURE__ */ r(m.Option, {
109
110
  ...c,
110
- ref: Y,
111
+ ref: Z,
111
112
  disabled: !0,
112
113
  value: t,
113
- children: /* @__PURE__ */ r(re, {
114
+ children: /* @__PURE__ */ r(ne, {
114
115
  "aria-label": u(i.loadingMoreAriaLabel),
115
116
  style: {
116
117
  position: "unset"
117
118
  }
118
119
  })
119
120
  }) : null;
120
- if (t === L && e.hasError && !e.isEmpty)
121
- return /* @__PURE__ */ r(S, {
121
+ if (t === A && e.hasError && !e.isEmpty)
122
+ return /* @__PURE__ */ r(k, {
122
123
  onTryAgain: () => {
123
124
  var s;
124
- e.loadMore(), (s = b.current) == null || s.focus();
125
+ e.loadMore(), (s = g.current) == null || s.focus();
125
126
  }
126
127
  });
127
- if (O.some((s) => s.value === t))
128
+ if (_.some((s) => s.value === t))
128
129
  return null;
129
- const ee = n.some((s) => s.value === t);
130
+ const oe = n.some((s) => s.value === t);
130
131
  return /* @__PURE__ */ r(m.Option, {
131
132
  ...c,
132
133
  className: a.option,
133
134
  value: t,
134
- children: /* @__PURE__ */ r(oe, {
135
- className: T(a.highlightOptionText, ee && a.selected),
135
+ children: /* @__PURE__ */ r(te, {
136
+ className: S(a.highlightOptionText, oe && a.selected),
136
137
  value: y || t
137
138
  })
138
139
  });
139
- }, Q = (o) => {
140
- if (f == null || f(o), _ && o === "") {
141
- g.current = !1;
140
+ }, X = (o) => {
141
+ if (f == null || f(o), O && o === "") {
142
+ b.current = !1;
142
143
  return;
143
144
  }
144
145
  e.search(o);
145
- }, X = () => {
146
+ }, Y = () => {
146
147
  var o;
147
- e.reload(), (o = b.current) == null || o.focus();
148
+ e.reload(), (o = g.current) == null || o.focus();
148
149
  };
149
150
  let d;
150
- e.hasError && !e.isLoading ? d = /* @__PURE__ */ r(S, {
151
- onTryAgain: X
152
- }) : e.isEmpty && !e.isLoading ? d = B || u(i.noResults) : d = void 0;
153
- const [Y, {
154
- rootRef: Z,
155
- isVisible: I
156
- }] = he({
157
- rootMargin: Re
151
+ e.hasError && !e.isLoading ? d = /* @__PURE__ */ r(k, {
152
+ onTryAgain: Y
153
+ }) : e.isEmpty && !e.isLoading ? d = W || u(i.noResults) : d = void 0;
154
+ const [Z, {
155
+ rootRef: $,
156
+ isVisible: M
157
+ }] = fe({
158
+ rootMargin: Ce
158
159
  });
159
- de(() => {
160
- if (!(I && e.hasNextPage))
160
+ me(() => {
161
+ if (!(M && e.hasNextPage))
161
162
  return;
162
163
  const t = setTimeout(() => {
163
164
  e.loadMore();
@@ -165,42 +166,44 @@ import '../../../../styles/combobox-with-api-pagination.css';const be = "_contai
165
166
  return () => {
166
167
  clearTimeout(t);
167
168
  };
168
- }, [I]);
169
- const $ = R(() => {
169
+ }, [M]);
170
+ const ee = R(() => {
170
171
  const o = e.hasNextPage ? {
171
172
  displayValue: C,
172
173
  value: C
173
174
  } : null, t = !o && e.hasError && !e.isEmpty ? {
174
- displayValue: L,
175
- value: L
175
+ displayValue: A,
176
+ value: A
176
177
  } : null;
177
- return [...e.items, ...O, o, t].filter(Boolean);
178
- }, [e.hasNextPage, e.hasError, e.isEmpty, e.items, O]);
178
+ return [...e.items, ..._, o, t].filter(Boolean);
179
+ }, [e.hasNextPage, e.hasError, e.isEmpty, e.items, _]);
179
180
  return /* @__PURE__ */ r(m, {
181
+ ...q,
182
+ ref: re(g, h),
180
183
  as: "input",
181
- ...U,
182
- ref: te(b, h),
183
- className: T({
184
- [a.disabled]: _
185
- }, j),
184
+ className: S({
185
+ [a.disabled]: O
186
+ }, U),
186
187
  clearButtonAriaLabel: u(i.clearButtonAriaLabel),
187
- disabled: G || _,
188
+ clearOnBlur: !1,
189
+ disabled: j || O && E,
190
+ displaySingleSelectionAsChip: E,
188
191
  displayValue: (o) => o.displayValue || o.value,
189
- endComboboxIcon: Ce,
192
+ endComboboxIcon: Ae,
190
193
  focusLoop: !1,
191
- getPopoverRef: Z,
194
+ getPopoverRef: $,
192
195
  loading: e.isReloading,
193
- loadingAriaLabel: z || u(i.loadingAriaLabel),
196
+ loadingAriaLabel: G || u(i.loadingAriaLabel),
194
197
  multiselect: l,
195
198
  noResultMessage: d,
196
- onFocus: q,
197
- onInputValueChange: Q,
198
- onValueChange: H,
199
- options: $,
200
- renderOption: K,
201
- value: J
199
+ onFocus: H,
200
+ onInputValueChange: X,
201
+ onValueChange: J,
202
+ options: ee,
203
+ renderOption: Q,
204
+ value: K
202
205
  });
203
206
  });
204
207
  export {
205
- De as ComboboxWithApiPagination
208
+ Be as ComboboxWithApiPagination
206
209
  };
@@ -15,4 +15,5 @@ export declare const ComboboxWithApiPagination: import('react').ForwardRefExotic
15
15
  experimentalVirtualization?: boolean;
16
16
  className?: string;
17
17
  dataTargetId?: string;
18
+ displaySingleSelectionAsChip?: boolean;
18
19
  } & import('@box/blueprint-web').Labelable & import('react').RefAttributes<HTMLInputElement>>;
@@ -47,4 +47,5 @@ export type ComboboxWithApiPaginationProps<T extends BaseOptionType> = {
47
47
  experimentalVirtualization?: boolean;
48
48
  className?: string;
49
49
  dataTargetId?: string;
50
+ displaySingleSelectionAsChip?: boolean;
50
51
  } & Labelable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/combobox-with-api",
3
- "version": "0.38.10",
3
+ "version": "0.40.0",
4
4
  "peerDependencies": {
5
5
  "@ariakit/react": "0.4.15",
6
6
  "@box/blueprint-web": "^10.3.1",
@@ -11,11 +11,11 @@
11
11
  "react-intl": "^6.4.2"
12
12
  },
13
13
  "dependencies": {
14
- "@box/tree": "^0.48.8",
14
+ "@box/tree": "^0.48.9",
15
15
  "react-accessible-treeview": "2.9.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@box/blueprint-web": "^12.2.0",
18
+ "@box/blueprint-web": "^12.3.0",
19
19
  "@box/blueprint-web-assets": "^4.46.0",
20
20
  "@box/storybook-utils": "^0.12.5",
21
21
  "react": "^18.3.0",