@caqophony/ui 0.6.4 → 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 +16 -0
- package/dist/index.js +40 -12
- package/package.json +1 -1
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 :
|
|
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
|
-
|
|
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
|
-
|
|
3427
|
+
showsSearch && /* @__PURE__ */ jsx34("div", { className: "border-b border-border p-2", children: /* @__PURE__ */ jsx34(
|
|
3408
3428
|
"input",
|
|
3409
3429
|
{
|
|
3410
3430
|
type: "text",
|
|
@@ -4500,10 +4520,11 @@ PageContent.displayName = "PageContent";
|
|
|
4500
4520
|
import * as React37 from "react";
|
|
4501
4521
|
import { jsx as jsx51, jsxs as jsxs40 } from "react/jsx-runtime";
|
|
4502
4522
|
var MEDIA_SIZE = {
|
|
4503
|
-
sm: "h-8 w-8",
|
|
4504
|
-
md: "h-10 w-10",
|
|
4505
|
-
lg: "h-12 w-12"
|
|
4523
|
+
sm: "min-h-8 min-w-8",
|
|
4524
|
+
md: "min-h-10 min-w-10",
|
|
4525
|
+
lg: "min-h-12 min-w-12"
|
|
4506
4526
|
};
|
|
4527
|
+
var MEDIA_SLOT = "flex flex-shrink-0 items-center justify-center";
|
|
4507
4528
|
var MediaObject = React37.forwardRef(
|
|
4508
4529
|
({
|
|
4509
4530
|
className,
|
|
@@ -4527,7 +4548,7 @@ var MediaObject = React37.forwardRef(
|
|
|
4527
4548
|
),
|
|
4528
4549
|
...props,
|
|
4529
4550
|
children: [
|
|
4530
|
-
/* @__PURE__ */ jsx51("div", { className: cn(
|
|
4551
|
+
/* @__PURE__ */ jsx51("div", { className: cn(MEDIA_SLOT, MEDIA_SIZE[mediaSize]), children: media }),
|
|
4531
4552
|
/* @__PURE__ */ jsxs40("div", { className: "min-w-0", children: [
|
|
4532
4553
|
title && /* @__PURE__ */ jsx51("p", { className: "font-medium text-foreground", children: title }),
|
|
4533
4554
|
description && /* @__PURE__ */ jsx51("p", { className: "text-sm text-muted-foreground", children: description })
|
|
@@ -4548,7 +4569,7 @@ var MediaObject = React37.forwardRef(
|
|
|
4548
4569
|
),
|
|
4549
4570
|
...props,
|
|
4550
4571
|
children: [
|
|
4551
|
-
/* @__PURE__ */ jsx51("div", { className: cn(
|
|
4572
|
+
/* @__PURE__ */ jsx51("div", { className: cn(MEDIA_SLOT, MEDIA_SIZE[mediaSize]), children: media }),
|
|
4552
4573
|
/* @__PURE__ */ jsxs40("div", { className: "min-w-0 flex-1", children: [
|
|
4553
4574
|
title && /* @__PURE__ */ jsx51("p", { className: "font-medium text-foreground", children: title }),
|
|
4554
4575
|
description && /* @__PURE__ */ jsx51("p", { className: "text-sm text-muted-foreground", children: description })
|
|
@@ -4597,7 +4618,14 @@ var PageHeading = React38.forwardRef(
|
|
|
4597
4618
|
...props,
|
|
4598
4619
|
children: [
|
|
4599
4620
|
/* @__PURE__ */ jsxs41("div", { className: "flex min-w-0 flex-1 flex-col gap-1 sm:basis-80", children: [
|
|
4600
|
-
/* @__PURE__ */ jsx52(
|
|
4621
|
+
/* @__PURE__ */ jsx52(
|
|
4622
|
+
"h1",
|
|
4623
|
+
{
|
|
4624
|
+
className: "line-clamp-2 break-words text-2xl font-semibold tracking-tight text-foreground sm:text-3xl",
|
|
4625
|
+
title: typeof title === "string" ? title : void 0,
|
|
4626
|
+
children: title
|
|
4627
|
+
}
|
|
4628
|
+
),
|
|
4601
4629
|
description && /* @__PURE__ */ jsx52("p", { className: "break-words text-sm text-muted-foreground sm:text-base", children: description }),
|
|
4602
4630
|
meta && /* @__PURE__ */ jsx52("div", { className: "mt-2 flex flex-wrap gap-2", children: meta })
|
|
4603
4631
|
] }),
|
|
@@ -5222,10 +5250,10 @@ var Progress = React45.forwardRef(
|
|
|
5222
5250
|
Progress.displayName = "Progress";
|
|
5223
5251
|
|
|
5224
5252
|
// src/hooks/use-debounce.ts
|
|
5225
|
-
import { useEffect as
|
|
5253
|
+
import { useEffect as useEffect8, useState as useState11 } from "react";
|
|
5226
5254
|
function useDebounce(value, ms) {
|
|
5227
5255
|
const [debounced, setDebounced] = useState11(value);
|
|
5228
|
-
|
|
5256
|
+
useEffect8(() => {
|
|
5229
5257
|
const handle = setTimeout(() => setDebounced(value), ms);
|
|
5230
5258
|
return () => clearTimeout(handle);
|
|
5231
5259
|
}, [value, ms]);
|