@caqophony/ui 0.6.5 → 0.7.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.
package/dist/index.d.mts CHANGED
@@ -1119,6 +1119,12 @@ declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & Reac
1119
1119
  * text-muted-fg -> colors.mutedFg (placeholder)
1120
1120
  * bg-primary -> colors.primary (selected tag)
1121
1121
  *
1122
+ * Search on the server (#6524): with `onSearchChange`, the typed text is sent
1123
+ * to the caller (debounced by `searchDelayMs`) and the options are shown as
1124
+ * given, never filtered here, so a picker can reach records past a list's first
1125
+ * page. A picked option's label is kept, so the field still names it after the
1126
+ * caller replaces `options` with another search's results.
1127
+ *
1122
1128
  * Issue #2633 — B-7: Advanced Form Family
1123
1129
  * Authored by Caqophony
1124
1130
  */
@@ -1133,7 +1139,17 @@ interface ComboboxProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onCh
1133
1139
  onChange?: (value: string | string[]) => void;
1134
1140
  placeholder?: string;
1135
1141
  multi?: boolean;
1142
+ /** Filter `options` by the typed text here. Ignored with `onSearchChange`. */
1136
1143
  filterable?: boolean;
1144
+ /**
1145
+ * The typed text, sent to the caller once typing pauses for `searchDelayMs`.
1146
+ * When set, the search input always shows and `options` are drawn as given:
1147
+ * the caller searches (e.g. a list read with a search input) and passes the
1148
+ * results back.
1149
+ */
1150
+ onSearchChange?: (text: string) => void;
1151
+ /** How long typing pauses before `onSearchChange` is called (ms). */
1152
+ searchDelayMs?: number;
1137
1153
  }
1138
1154
  declare const Combobox: React.ForwardRefExoticComponent<ComboboxProps & React.RefAttributes<HTMLDivElement>>;
1139
1155
 
package/dist/index.js CHANGED
@@ -3330,6 +3330,7 @@ RadioGroup.displayName = "RadioGroup";
3330
3330
  // src/combobox.tsx
3331
3331
  import * as React23 from "react";
3332
3332
  import { jsx as jsx34, jsxs as jsxs27 } from "react/jsx-runtime";
3333
+ var SEARCH_DELAY_MS = 250;
3333
3334
  var Combobox = React23.forwardRef(
3334
3335
  ({
3335
3336
  className,
@@ -3339,16 +3340,35 @@ var Combobox = React23.forwardRef(
3339
3340
  placeholder = "Select...",
3340
3341
  multi = false,
3341
3342
  filterable = true,
3343
+ onSearchChange,
3344
+ searchDelayMs = SEARCH_DELAY_MS,
3342
3345
  ...props
3343
3346
  }, ref) => {
3344
3347
  const [open, setOpen] = React23.useState(false);
3345
3348
  const [search, setSearch] = React23.useState("");
3349
+ const searchesOnServer = onSearchChange !== void 0;
3350
+ const showsSearch = searchesOnServer || filterable;
3351
+ const onSearchRef = React23.useRef(onSearchChange);
3352
+ onSearchRef.current = onSearchChange;
3353
+ const sentRef = React23.useRef("");
3354
+ React23.useEffect(() => {
3355
+ if (!searchesOnServer || search === sentRef.current) return;
3356
+ const timer = setTimeout(() => {
3357
+ sentRef.current = search;
3358
+ onSearchRef.current?.(search);
3359
+ }, searchDelayMs);
3360
+ return () => clearTimeout(timer);
3361
+ }, [search, searchesOnServer, searchDelayMs]);
3362
+ const pickedLabels = React23.useRef(/* @__PURE__ */ new Map());
3363
+ const labelOf = (v) => options.find((o) => o.value === v)?.label ?? pickedLabels.current.get(v);
3346
3364
  const selected = multi ? Array.isArray(value) ? value : [] : typeof value === "string" ? value : "";
3347
- const filtered = filterable ? options.filter(
3365
+ const filtered = filterable && !searchesOnServer ? options.filter(
3348
3366
  (o) => o.label.toLowerCase().includes(search.toLowerCase())
3349
3367
  ) : options;
3350
3368
  const handleSelect = (optValue) => {
3351
3369
  if (!onChange) return;
3370
+ const picked = options.find((o) => o.value === optValue);
3371
+ if (picked) pickedLabels.current.set(picked.value, picked.label);
3352
3372
  if (multi) {
3353
3373
  const arr = Array.isArray(selected) ? selected : [];
3354
3374
  onChange(
@@ -3360,7 +3380,7 @@ var Combobox = React23.forwardRef(
3360
3380
  setSearch("");
3361
3381
  }
3362
3382
  };
3363
- const displayValue = multi ? null : options.find((o) => o.value === selected)?.label;
3383
+ const displayValue = multi || typeof selected !== "string" ? null : labelOf(selected);
3364
3384
  return /* @__PURE__ */ jsxs27("div", { ref, className: cn("relative", className), ...props, children: [
3365
3385
  /* @__PURE__ */ jsxs27(
3366
3386
  "div",
@@ -3373,7 +3393,7 @@ var Combobox = React23.forwardRef(
3373
3393
  {
3374
3394
  className: "text-primary-text inline-flex items-center gap-1 rounded bg-primary/10 px-2 py-0.5 text-xs font-medium",
3375
3395
  children: [
3376
- options.find((o) => o.value === v)?.label,
3396
+ labelOf(v),
3377
3397
  /* @__PURE__ */ jsx34(
3378
3398
  "button",
3379
3399
  {
@@ -3404,7 +3424,7 @@ var Combobox = React23.forwardRef(
3404
3424
  }
3405
3425
  ),
3406
3426
  open && /* @__PURE__ */ jsxs27("div", { className: "z-dropdown absolute mt-1 w-full rounded-md border border-border bg-card shadow-lg", children: [
3407
- filterable && /* @__PURE__ */ jsx34("div", { className: "border-b border-border p-2", children: /* @__PURE__ */ jsx34(
3427
+ showsSearch && /* @__PURE__ */ jsx34("div", { className: "border-b border-border p-2", children: /* @__PURE__ */ jsx34(
3408
3428
  "input",
3409
3429
  {
3410
3430
  type: "text",
@@ -5230,10 +5250,10 @@ var Progress = React45.forwardRef(
5230
5250
  Progress.displayName = "Progress";
5231
5251
 
5232
5252
  // src/hooks/use-debounce.ts
5233
- import { useEffect as useEffect7, useState as useState11 } from "react";
5253
+ import { useEffect as useEffect8, useState as useState11 } from "react";
5234
5254
  function useDebounce(value, ms) {
5235
5255
  const [debounced, setDebounced] = useState11(value);
5236
- useEffect7(() => {
5256
+ useEffect8(() => {
5237
5257
  const handle = setTimeout(() => setDebounced(value), ms);
5238
5258
  return () => clearTimeout(handle);
5239
5259
  }, [value, ms]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caqophony/ui",
3
- "version": "0.6.5",
3
+ "version": "0.7.0",
4
4
  "description": "Generic, optional React UI reuse library (Gossamer tokens). Centrally maintained by Caqophony.",
5
5
  "license": "MIT",
6
6
  "author": "Caqophony",