@caqophony/ui 0.7.0 → 0.8.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 +24 -1
- package/dist/index.js +93 -12
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1125,6 +1125,16 @@ declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & Reac
|
|
|
1125
1125
|
* page. A picked option's label is kept, so the field still names it after the
|
|
1126
1126
|
* caller replaces `options` with another search's results.
|
|
1127
1127
|
*
|
|
1128
|
+
* In a form (#6524, kit 0.8.0): with `name`, the picked value is carried by a
|
|
1129
|
+
* hidden native `<select>` (`multiple` in multi mode), so `new FormData(form)`
|
|
1130
|
+
* reads it exactly as a native select's: one entry, `""` when cleared, in
|
|
1131
|
+
* single mode; one entry per value, none when empty, in multi mode. A pick or a
|
|
1132
|
+
* clear fires a bubbling `change` on that select, so the form's `onChange` sees
|
|
1133
|
+
* it as an edit; the start value never does. Without `value` the picker is
|
|
1134
|
+
* uncontrolled: it starts at `defaultValue` and returns to it on the form's
|
|
1135
|
+
* reset. `defaultLabel` names a start value that is not among `options` (a
|
|
1136
|
+
* record past a list's first page, named from its own detail read).
|
|
1137
|
+
*
|
|
1128
1138
|
* Issue #2633 — B-7: Advanced Form Family
|
|
1129
1139
|
* Authored by Caqophony
|
|
1130
1140
|
*/
|
|
@@ -1133,10 +1143,23 @@ interface ComboboxOption {
|
|
|
1133
1143
|
value: string;
|
|
1134
1144
|
label: string;
|
|
1135
1145
|
}
|
|
1136
|
-
interface ComboboxProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
1146
|
+
interface ComboboxProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {
|
|
1137
1147
|
options: ComboboxOption[];
|
|
1148
|
+
/** The picked value, controlled. Without it the picker keeps its own (`defaultValue`). */
|
|
1138
1149
|
value?: string | string[];
|
|
1139
1150
|
onChange?: (value: string | string[]) => void;
|
|
1151
|
+
/**
|
|
1152
|
+
* The form field name: the value is submitted under it, as a native select's
|
|
1153
|
+
* (one entry, `""` when cleared; in multi mode one per value, none when empty).
|
|
1154
|
+
*/
|
|
1155
|
+
name?: string;
|
|
1156
|
+
/** The uncontrolled start value, used when `value` is not given. */
|
|
1157
|
+
defaultValue?: string | string[];
|
|
1158
|
+
/**
|
|
1159
|
+
* The label of a start value that is not among `options`: one label in
|
|
1160
|
+
* single mode, labels by value in multi mode.
|
|
1161
|
+
*/
|
|
1162
|
+
defaultLabel?: string | Readonly<Record<string, string>>;
|
|
1140
1163
|
placeholder?: string;
|
|
1141
1164
|
multi?: boolean;
|
|
1142
1165
|
/** Filter `options` by the typed text here. Ignored with `onSearchChange`. */
|
package/dist/index.js
CHANGED
|
@@ -3329,7 +3329,7 @@ RadioGroup.displayName = "RadioGroup";
|
|
|
3329
3329
|
|
|
3330
3330
|
// src/combobox.tsx
|
|
3331
3331
|
import * as React23 from "react";
|
|
3332
|
-
import { jsx as jsx34, jsxs as jsxs27 } from "react/jsx-runtime";
|
|
3332
|
+
import { Fragment as Fragment7, jsx as jsx34, jsxs as jsxs27 } from "react/jsx-runtime";
|
|
3333
3333
|
var SEARCH_DELAY_MS = 250;
|
|
3334
3334
|
var Combobox = React23.forwardRef(
|
|
3335
3335
|
({
|
|
@@ -3337,6 +3337,9 @@ var Combobox = React23.forwardRef(
|
|
|
3337
3337
|
options,
|
|
3338
3338
|
value,
|
|
3339
3339
|
onChange,
|
|
3340
|
+
name,
|
|
3341
|
+
defaultValue,
|
|
3342
|
+
defaultLabel,
|
|
3340
3343
|
placeholder = "Select...",
|
|
3341
3344
|
multi = false,
|
|
3342
3345
|
filterable = true,
|
|
@@ -3359,23 +3362,58 @@ var Combobox = React23.forwardRef(
|
|
|
3359
3362
|
}, searchDelayMs);
|
|
3360
3363
|
return () => clearTimeout(timer);
|
|
3361
3364
|
}, [search, searchesOnServer, searchDelayMs]);
|
|
3365
|
+
const controlled = value !== void 0;
|
|
3366
|
+
const [own, setOwn] = React23.useState(defaultValue);
|
|
3367
|
+
const current = controlled ? value : own;
|
|
3368
|
+
const interactive = !controlled || onChange !== void 0;
|
|
3369
|
+
const start = React23.useRef(controlled ? value : defaultValue);
|
|
3362
3370
|
const pickedLabels = React23.useRef(/* @__PURE__ */ new Map());
|
|
3363
|
-
const
|
|
3364
|
-
|
|
3371
|
+
const startLabelOf = (v) => {
|
|
3372
|
+
if (defaultLabel === void 0) return void 0;
|
|
3373
|
+
if (typeof defaultLabel === "string")
|
|
3374
|
+
return v === start.current ? defaultLabel : void 0;
|
|
3375
|
+
return Object.prototype.hasOwnProperty.call(defaultLabel, v) ? defaultLabel[v] : void 0;
|
|
3376
|
+
};
|
|
3377
|
+
const labelOf = (v) => options.find((o) => o.value === v)?.label ?? pickedLabels.current.get(v) ?? startLabelOf(v);
|
|
3378
|
+
const selected = multi ? Array.isArray(current) ? current : [] : typeof current === "string" ? current : "";
|
|
3379
|
+
const picks = Array.isArray(selected) ? selected : [];
|
|
3380
|
+
const pick = typeof selected === "string" ? selected : "";
|
|
3381
|
+
const formControl = React23.useRef(null);
|
|
3382
|
+
const announce = React23.useRef(false);
|
|
3383
|
+
const selectedKey = JSON.stringify(selected);
|
|
3384
|
+
React23.useEffect(() => {
|
|
3385
|
+
if (!announce.current) return;
|
|
3386
|
+
announce.current = false;
|
|
3387
|
+
formControl.current?.dispatchEvent(
|
|
3388
|
+
new Event("change", { bubbles: true })
|
|
3389
|
+
);
|
|
3390
|
+
}, [selectedKey]);
|
|
3391
|
+
React23.useEffect(() => {
|
|
3392
|
+
const form = formControl.current?.form;
|
|
3393
|
+
if (controlled || !form) return;
|
|
3394
|
+
const onReset = () => setOwn(start.current);
|
|
3395
|
+
form.addEventListener("reset", onReset);
|
|
3396
|
+
return () => form.removeEventListener("reset", onReset);
|
|
3397
|
+
}, [controlled]);
|
|
3398
|
+
const commit = (next) => {
|
|
3399
|
+
announce.current = name !== void 0 && JSON.stringify(next) !== selectedKey;
|
|
3400
|
+
if (!controlled) setOwn(next);
|
|
3401
|
+
onChange?.(next);
|
|
3402
|
+
};
|
|
3365
3403
|
const filtered = filterable && !searchesOnServer ? options.filter(
|
|
3366
3404
|
(o) => o.label.toLowerCase().includes(search.toLowerCase())
|
|
3367
3405
|
) : options;
|
|
3368
3406
|
const handleSelect = (optValue) => {
|
|
3369
|
-
if (!
|
|
3407
|
+
if (!interactive) return;
|
|
3370
3408
|
const picked = options.find((o) => o.value === optValue);
|
|
3371
3409
|
if (picked) pickedLabels.current.set(picked.value, picked.label);
|
|
3372
3410
|
if (multi) {
|
|
3373
3411
|
const arr = Array.isArray(selected) ? selected : [];
|
|
3374
|
-
|
|
3412
|
+
commit(
|
|
3375
3413
|
arr.includes(optValue) ? arr.filter((v) => v !== optValue) : [...arr, optValue]
|
|
3376
3414
|
);
|
|
3377
3415
|
} else {
|
|
3378
|
-
|
|
3416
|
+
commit(optValue);
|
|
3379
3417
|
setOpen(false);
|
|
3380
3418
|
setSearch("");
|
|
3381
3419
|
}
|
|
@@ -3398,6 +3436,7 @@ var Combobox = React23.forwardRef(
|
|
|
3398
3436
|
"button",
|
|
3399
3437
|
{
|
|
3400
3438
|
type: "button",
|
|
3439
|
+
"aria-label": `Remove ${labelOf(v) ?? v}`,
|
|
3401
3440
|
onClick: (e) => {
|
|
3402
3441
|
e.stopPropagation();
|
|
3403
3442
|
handleSelect(v);
|
|
@@ -3419,10 +3458,49 @@ var Combobox = React23.forwardRef(
|
|
|
3419
3458
|
children: displayValue || placeholder
|
|
3420
3459
|
}
|
|
3421
3460
|
),
|
|
3422
|
-
|
|
3461
|
+
!multi && interactive && selected !== "" && /* @__PURE__ */ jsx34(
|
|
3462
|
+
"button",
|
|
3463
|
+
{
|
|
3464
|
+
type: "button",
|
|
3465
|
+
"aria-label": "Clear",
|
|
3466
|
+
className: "ml-auto text-xs text-muted-foreground hover:text-foreground",
|
|
3467
|
+
onClick: (e) => {
|
|
3468
|
+
e.stopPropagation();
|
|
3469
|
+
commit("");
|
|
3470
|
+
},
|
|
3471
|
+
children: "\u2715"
|
|
3472
|
+
}
|
|
3473
|
+
),
|
|
3474
|
+
/* @__PURE__ */ jsx34(
|
|
3475
|
+
"span",
|
|
3476
|
+
{
|
|
3477
|
+
className: cn(
|
|
3478
|
+
"text-muted-foreground",
|
|
3479
|
+
(multi || !interactive || selected === "") && "ml-auto"
|
|
3480
|
+
),
|
|
3481
|
+
children: "\u25BE"
|
|
3482
|
+
}
|
|
3483
|
+
)
|
|
3423
3484
|
]
|
|
3424
3485
|
}
|
|
3425
3486
|
),
|
|
3487
|
+
name !== void 0 && /* @__PURE__ */ jsx34(
|
|
3488
|
+
"select",
|
|
3489
|
+
{
|
|
3490
|
+
ref: formControl,
|
|
3491
|
+
name,
|
|
3492
|
+
multiple: multi,
|
|
3493
|
+
value: selected,
|
|
3494
|
+
onChange: () => void 0,
|
|
3495
|
+
hidden: true,
|
|
3496
|
+
"aria-hidden": true,
|
|
3497
|
+
tabIndex: -1,
|
|
3498
|
+
children: multi ? picks.map((v) => /* @__PURE__ */ jsx34("option", { value: v, children: v }, v)) : /* @__PURE__ */ jsxs27(Fragment7, { children: [
|
|
3499
|
+
/* @__PURE__ */ jsx34("option", { value: "" }),
|
|
3500
|
+
pick !== "" && /* @__PURE__ */ jsx34("option", { value: pick, children: pick }, pick)
|
|
3501
|
+
] })
|
|
3502
|
+
}
|
|
3503
|
+
),
|
|
3426
3504
|
open && /* @__PURE__ */ jsxs27("div", { className: "z-dropdown absolute mt-1 w-full rounded-md border border-border bg-card shadow-lg", children: [
|
|
3427
3505
|
showsSearch && /* @__PURE__ */ jsx34("div", { className: "border-b border-border p-2", children: /* @__PURE__ */ jsx34(
|
|
3428
3506
|
"input",
|
|
@@ -3432,6 +3510,9 @@ var Combobox = React23.forwardRef(
|
|
|
3432
3510
|
placeholder: "Search...",
|
|
3433
3511
|
value: search,
|
|
3434
3512
|
onChange: (e) => setSearch(e.target.value),
|
|
3513
|
+
onKeyDown: (e) => {
|
|
3514
|
+
if (e.key === "Enter") e.preventDefault();
|
|
3515
|
+
},
|
|
3435
3516
|
autoFocus: true
|
|
3436
3517
|
}
|
|
3437
3518
|
) }),
|
|
@@ -4355,7 +4436,7 @@ function EmptyState({
|
|
|
4355
4436
|
|
|
4356
4437
|
// src/action-panel.tsx
|
|
4357
4438
|
import * as React34 from "react";
|
|
4358
|
-
import { Fragment as
|
|
4439
|
+
import { Fragment as Fragment8, jsx as jsx48, jsxs as jsxs38 } from "react/jsx-runtime";
|
|
4359
4440
|
var BORDER_INTENT = {
|
|
4360
4441
|
default: "border-l-primary",
|
|
4361
4442
|
warning: "border-l-intent-warning",
|
|
@@ -4381,13 +4462,13 @@ var ActionPanel = React34.forwardRef(
|
|
|
4381
4462
|
className
|
|
4382
4463
|
),
|
|
4383
4464
|
...props,
|
|
4384
|
-
children: variant === "split" ? /* @__PURE__ */ jsxs38(
|
|
4465
|
+
children: variant === "split" ? /* @__PURE__ */ jsxs38(Fragment8, { children: [
|
|
4385
4466
|
/* @__PURE__ */ jsxs38("div", { className: "min-w-0", children: [
|
|
4386
4467
|
/* @__PURE__ */ jsx48("h3", { className: "font-semibold text-foreground", children: title }),
|
|
4387
4468
|
description && /* @__PURE__ */ jsx48("p", { className: "mt-1 text-sm text-muted-foreground", children: description })
|
|
4388
4469
|
] }),
|
|
4389
4470
|
action && /* @__PURE__ */ jsx48("div", { className: "flex-shrink-0", children: action })
|
|
4390
|
-
] }) : /* @__PURE__ */ jsxs38(
|
|
4471
|
+
] }) : /* @__PURE__ */ jsxs38(Fragment8, { children: [
|
|
4391
4472
|
/* @__PURE__ */ jsx48("h3", { className: "font-semibold text-foreground", children: title }),
|
|
4392
4473
|
description && /* @__PURE__ */ jsx48("p", { className: "mt-1 text-sm text-muted-foreground", children: description }),
|
|
4393
4474
|
action && /* @__PURE__ */ jsx48("div", { className: "mt-4", children: action })
|
|
@@ -4732,7 +4813,7 @@ SidePanelLayout.displayName = "SidePanelLayout";
|
|
|
4732
4813
|
|
|
4733
4814
|
// src/overflow-menu.tsx
|
|
4734
4815
|
import * as React39 from "react";
|
|
4735
|
-
import { Fragment as
|
|
4816
|
+
import { Fragment as Fragment9, jsx as jsx53, jsxs as jsxs42 } from "react/jsx-runtime";
|
|
4736
4817
|
function OverflowMenu({
|
|
4737
4818
|
label,
|
|
4738
4819
|
items,
|
|
@@ -4763,7 +4844,7 @@ function OverflowMenu({
|
|
|
4763
4844
|
children: /* @__PURE__ */ jsx53(Icon, { name: "ellipsis", size: "sm" })
|
|
4764
4845
|
}
|
|
4765
4846
|
),
|
|
4766
|
-
open && /* @__PURE__ */ jsxs42(
|
|
4847
|
+
open && /* @__PURE__ */ jsxs42(Fragment9, { children: [
|
|
4767
4848
|
/* @__PURE__ */ jsx53(
|
|
4768
4849
|
"div",
|
|
4769
4850
|
{
|