@gerege-systems/ui 0.14.1 → 0.16.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/README.md +6 -6
- package/dist-lib/components/ui/Alert.js +11 -9
- package/dist-lib/components/ui/Alert.js.map +1 -1
- package/dist-lib/components/ui/Avatar.js +1 -0
- package/dist-lib/components/ui/Avatar.js.map +1 -1
- package/dist-lib/components/ui/Button.js +4 -4
- package/dist-lib/components/ui/Button.js.map +1 -1
- package/dist-lib/components/ui/Calendar.js +3 -1
- package/dist-lib/components/ui/Calendar.js.map +1 -1
- package/dist-lib/components/ui/Carousel.js.map +1 -1
- package/dist-lib/components/ui/Chart.js +55 -55
- package/dist-lib/components/ui/Chart.js.map +1 -1
- package/dist-lib/components/ui/Combobox.js +19 -18
- package/dist-lib/components/ui/Combobox.js.map +1 -1
- package/dist-lib/components/ui/DataGrid.d.ts +7 -2
- package/dist-lib/components/ui/DataGrid.js +66 -54
- package/dist-lib/components/ui/DataGrid.js.map +1 -1
- package/dist-lib/components/ui/DesignSystemProvider.js +25 -25
- package/dist-lib/components/ui/DesignSystemProvider.js.map +1 -1
- package/dist-lib/components/ui/Dialog.d.ts +5 -1
- package/dist-lib/components/ui/Dialog.js +54 -57
- package/dist-lib/components/ui/Dialog.js.map +1 -1
- package/dist-lib/components/ui/ErrorState.d.ts +5 -3
- package/dist-lib/components/ui/ErrorState.js +1 -1
- package/dist-lib/components/ui/ErrorState.js.map +1 -1
- package/dist-lib/components/ui/FileUpload.d.ts +6 -0
- package/dist-lib/components/ui/FileUpload.js +59 -55
- package/dist-lib/components/ui/FileUpload.js.map +1 -1
- package/dist-lib/components/ui/Icon.js +12 -12
- package/dist-lib/components/ui/Icon.js.map +1 -1
- package/dist-lib/components/ui/IconButton.js +4 -4
- package/dist-lib/components/ui/IconButton.js.map +1 -1
- package/dist-lib/components/ui/MultiSelect.js +40 -39
- package/dist-lib/components/ui/MultiSelect.js.map +1 -1
- package/dist-lib/components/ui/Pagination.js +35 -33
- package/dist-lib/components/ui/Pagination.js.map +1 -1
- package/dist-lib/components/ui/RelativeTime.d.ts +5 -1
- package/dist-lib/components/ui/RelativeTime.js +23 -19
- package/dist-lib/components/ui/RelativeTime.js.map +1 -1
- package/dist-lib/components/ui/Sidebar.d.ts +3 -1
- package/dist-lib/components/ui/Sidebar.js +97 -97
- package/dist-lib/components/ui/Sidebar.js.map +1 -1
- package/dist-lib/components/ui/Slider.js +28 -28
- package/dist-lib/components/ui/Slider.js.map +1 -1
- package/dist-lib/components/ui/Spinner.d.ts +1 -1
- package/dist-lib/components/ui/Spinner.js.map +1 -1
- package/dist-lib/components/ui/Toast.js +0 -1
- package/dist-lib/components/ui/Toast.js.map +1 -1
- package/dist-lib/hooks/use-debounce.js +14 -17
- package/dist-lib/hooks/use-debounce.js.map +1 -1
- package/dist-lib/hooks/use-delayed-loading.js +8 -8
- package/dist-lib/hooks/use-delayed-loading.js.map +1 -1
- package/dist-lib/hooks/use-modifier-key.d.ts +0 -4
- package/dist-lib/hooks/use-modifier-key.js +11 -12
- package/dist-lib/hooks/use-modifier-key.js.map +1 -1
- package/dist-lib/lib/strings.d.ts +4 -0
- package/dist-lib/lib/strings.js +3 -1
- package/dist-lib/lib/strings.js.map +1 -1
- package/dist-lib/lib/strings.mn.js +3 -1
- package/dist-lib/lib/strings.mn.js.map +1 -1
- package/dist-lib/styles.css +1 -1
- package/dist-lib/theme.css +63 -49
- package/package.json +5 -11
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as o } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { Suspense as l, lazy as d } from "react";
|
|
4
4
|
import r from "lucide-react/dynamicIconImports";
|
|
5
|
-
const
|
|
6
|
-
function
|
|
7
|
-
const t =
|
|
5
|
+
const p = Object.keys(r), i = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
|
|
6
|
+
function u(e) {
|
|
7
|
+
const t = i.get(e);
|
|
8
8
|
if (t) return t;
|
|
9
9
|
const n = r[e];
|
|
10
10
|
if (typeof n != "function")
|
|
11
|
-
return typeof process < "u" && process.env.NODE_ENV !== "production" && !
|
|
11
|
+
return typeof process < "u" && process.env.NODE_ENV !== "production" && !s.has(e) && (s.add(e), console.warn(
|
|
12
12
|
`[@gerege-systems/ui] <Icon name="${e}"> is not a lucide icon; rendering nothing.`
|
|
13
13
|
)), null;
|
|
14
|
-
const c =
|
|
15
|
-
return
|
|
14
|
+
const c = d(n);
|
|
15
|
+
return i.set(e, c), c;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
const c =
|
|
17
|
+
function y({ name: e, fallback: t, ...n }) {
|
|
18
|
+
const c = u(e), a = t ?? /* @__PURE__ */ o(
|
|
19
19
|
"span",
|
|
20
20
|
{
|
|
21
21
|
"aria-hidden": !0,
|
|
@@ -23,10 +23,10 @@ function g({ name: e, fallback: t, ...n }) {
|
|
|
23
23
|
style: { display: "inline-block", width: n.size ?? "1em", height: n.size ?? "1em" }
|
|
24
24
|
}
|
|
25
25
|
);
|
|
26
|
-
return c ? /* @__PURE__ */ o(
|
|
26
|
+
return c ? /* @__PURE__ */ o(l, { fallback: a, children: /* @__PURE__ */ o(c, { ...n }) }) : null;
|
|
27
27
|
}
|
|
28
28
|
export {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
y as Icon,
|
|
30
|
+
p as iconNames
|
|
31
31
|
};
|
|
32
32
|
//# sourceMappingURL=Icon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.js","sources":["../../../src/components/ui/Icon.tsx"],"sourcesContent":["'use client';\n\nimport { lazy, Suspense,
|
|
1
|
+
{"version":3,"file":"Icon.js","sources":["../../../src/components/ui/Icon.tsx"],"sourcesContent":["'use client';\n\nimport { lazy, Suspense, type LazyExoticComponent, type ReactNode } from 'react';\nimport dynamicIconImports from 'lucide-react/dynamicIconImports';\nimport type { LucideIcon, LucideProps } from 'lucide-react';\n\n/** Every lucide icon name, kebab-case — e.g. `calendar`, `chevrons-up-down`. */\nexport type IconName = keyof typeof dynamicIconImports;\n\n/** All available icon names (useful for pickers and docs). */\nexport const iconNames = Object.keys(dynamicIconImports) as IconName[];\n\n// lazy() must return a stable component per name or React remounts (and\n// re-suspends) on every render.\nconst cache = new Map<IconName, LazyExoticComponent<LucideIcon>>();\nconst warned = new Set<string>();\n\nfunction getIcon(name: IconName): LazyExoticComponent<LucideIcon> | null {\n const cached = cache.get(name);\n if (cached) return cached;\n const loader = dynamicIconImports[name];\n if (typeof loader !== 'function') {\n // Unknown name (data-driven input) → render nothing, warn once in dev.\n if (\n typeof process !== 'undefined' &&\n process.env.NODE_ENV !== 'production' &&\n !warned.has(name)\n ) {\n warned.add(name);\n console.warn(\n `[@gerege-systems/ui] <Icon name=\"${name}\"> is not a lucide icon; rendering nothing.`,\n );\n }\n return null;\n }\n const created = lazy(loader);\n cache.set(name, created);\n return created;\n}\n\nexport interface IconProps extends Omit<LucideProps, 'ref'> {\n /** Lucide icon name in kebab-case, e.g. `name=\"calendar\"`. Autocompletes. */\n name: IconName;\n /**\n * Shown while the icon chunk loads (first use only — icons are cached).\n * Defaults to an invisible square so layout doesn't shift.\n */\n fallback?: ReactNode;\n}\n\n/**\n * Name-addressed lucide icon. Use when the icon is dynamic (data-driven\n * nav items, user-configurable dashboards) or when importing components for\n * every icon is friction.\n *\n * Each icon is code-split and loaded on first use, so referencing the full\n * lucide set costs nothing up front — `<Icon name=\"rocket\" />` ships only\n * the rocket.\n *\n * @example\n * <Icon name=\"calendar\" className=\"size-4\" />\n * <Icon name=\"chevrons-up-down\" size={16} strokeWidth={1.5} />\n *\n * @do Use `size-4` (16px) inline with text, `size-5` (20px) inside buttons.\n * @dont Reach for this in hot lists with hundreds of distinct icons on first\n * paint — statically imported icons from `Icons` skip the lazy hop.\n */\nexport function Icon({ name, fallback, ...props }: IconProps) {\n // getIcon caches one lazy component per name at module level, so this is a\n // lookup, not a component created during render — the rule cannot see the cache.\n const LucideIcon = getIcon(name);\n\n const placeholder = fallback ?? (\n <span\n aria-hidden\n className={props.className}\n style={{ display: 'inline-block', width: props.size ?? '1em', height: props.size ?? '1em' }}\n />\n );\n\n if (!LucideIcon) return null;\n\n return (\n <Suspense fallback={placeholder}>\n {/* eslint-disable-next-line react-hooks/static-components -- module-level cache, stable per name */}\n <LucideIcon {...props} />\n </Suspense>\n );\n}\n"],"names":["iconNames","dynamicIconImports","cache","warned","getIcon","name","cached","loader","created","lazy","Icon","fallback","props","LucideIcon","placeholder","jsx","Suspense"],"mappings":";;;;AAUO,MAAMA,IAAY,OAAO,KAAKC,CAAkB,GAIjDC,wBAAY,IAAA,GACZC,wBAAa,IAAA;AAEnB,SAASC,EAAQC,GAAwD;AACvE,QAAMC,IAASJ,EAAM,IAAIG,CAAI;AAC7B,MAAIC,EAAQ,QAAOA;AACnB,QAAMC,IAASN,EAAmBI,CAAI;AACtC,MAAI,OAAOE,KAAW;AAEpB,WACE,OAAO,UAAY,OACnB,QAAQ,IAAI,aAAa,gBACzB,CAACJ,EAAO,IAAIE,CAAI,MAEhBF,EAAO,IAAIE,CAAI,GACf,QAAQ;AAAA,MACN,oCAAoCA,CAAI;AAAA,IAAA,IAGrC;AAET,QAAMG,IAAUC,EAAKF,CAAM;AAC3B,SAAAL,EAAM,IAAIG,GAAMG,CAAO,GAChBA;AACT;AA6BO,SAASE,EAAK,EAAE,MAAAL,GAAM,UAAAM,GAAU,GAAGC,KAAoB;AAG5D,QAAMC,IAAaT,EAAQC,CAAI,GAEzBS,IAAcH,KAClB,gBAAAI;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,eAAW;AAAA,MACX,WAAWH,EAAM;AAAA,MACjB,OAAO,EAAE,SAAS,gBAAgB,OAAOA,EAAM,QAAQ,OAAO,QAAQA,EAAM,QAAQ,MAAA;AAAA,IAAM;AAAA,EAAA;AAI9F,SAAKC,IAGH,gBAAAE,EAACC,KAAS,UAAUF,GAElB,4BAACD,GAAA,EAAY,GAAGD,GAAO,EAAA,CACzB,IANsB;AAQ1B;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as o } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef as g } from "react";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { cn as b } from "../../lib/utils.js";
|
|
5
|
+
import { Loader2 as f } from "../../icons/index.js";
|
|
6
6
|
import { cva as m } from "class-variance-authority";
|
|
7
7
|
const l = m(
|
|
8
8
|
[
|
|
@@ -48,10 +48,10 @@ const l = m(
|
|
|
48
48
|
"aria-busy": e || void 0,
|
|
49
49
|
"aria-disabled": e || void 0,
|
|
50
50
|
disabled: s,
|
|
51
|
-
className:
|
|
51
|
+
className: b(l({ variant: n, size: i }), r),
|
|
52
52
|
onClick: e ? p : d,
|
|
53
53
|
...u,
|
|
54
|
-
children: e ? /* @__PURE__ */ o(
|
|
54
|
+
children: e ? /* @__PURE__ */ o(f, { className: "animate-spin", "aria-hidden": "true" }) : a
|
|
55
55
|
}
|
|
56
56
|
);
|
|
57
57
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconButton.js","sources":["../../../src/components/ui/IconButton.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, type ButtonHTMLAttributes, type ReactNode, type SyntheticEvent } from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"IconButton.js","sources":["../../../src/components/ui/IconButton.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, type ButtonHTMLAttributes, type ReactNode, type SyntheticEvent } from 'react';\nimport { cn } from '@/lib/utils';\nimport { cva, type VariantProps } from '@/lib/cva';\nimport { Loader2 } from '@/icons';\n\nconst iconButton = cva(\n [\n 'inline-flex items-center justify-center shrink-0',\n 'rounded-md',\n 'transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]',\n 'outline-hidden',\n 'focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n 'focus-visible:ring-offset-background',\n 'disabled:pointer-events-none disabled:opacity-50',\n 'aria-busy:pointer-events-none',\n '[&_svg]:pointer-events-none',\n ],\n {\n variants: {\n variant: {\n primary: 'bg-accent text-on-accent hover:bg-accent-hover active:bg-accent-active',\n secondary:\n 'bg-secondary text-foreground hover:bg-secondary-hover active:bg-secondary-active',\n outline:\n 'border border-border-input bg-transparent text-foreground hover:bg-background-muted',\n ghost:\n 'bg-transparent text-foreground-muted hover:bg-background-muted hover:text-foreground',\n destructive: 'bg-danger text-on-danger hover:bg-danger-hover active:bg-danger-active',\n },\n size: {\n // Matches Button heights: sm 32 / md 36 / lg 40 / xl 44 (touch / marketing).\n sm: 'h-8 w-8 [&_svg]:size-4',\n md: 'h-9 w-9 [&_svg]:size-4',\n lg: 'h-10 w-10 [&_svg]:size-5',\n xl: 'h-11 w-11 [&_svg]:size-5',\n },\n },\n defaultVariants: {\n variant: 'ghost',\n size: 'md',\n },\n },\n);\n\nexport interface IconButtonProps\n extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof iconButton> {\n /**\n * Accessible label for screen readers. **Required** — an icon-only button\n * with no label is invisible to assistive tech.\n */\n 'aria-label': string;\n /** The Lucide icon to render. */\n icon: ReactNode;\n /** Show a spinner instead of the icon; blocks interaction but keeps focus (`aria-disabled`). */\n loading?: boolean;\n}\n\n/**\n * Square, icon-only button. Default variant is `ghost` because most\n * IconButtons sit in dense toolbars or tables. Always pass `aria-label`.\n *\n * @example Toolbar action\n * <IconButton aria-label=\"Edit row\" icon={<Edit2 />} onClick={onEdit} />\n *\n * @example Dismissible chip\n * <IconButton aria-label=\"Remove tag\" size=\"sm\" icon={<X />} />\n *\n * @do Use `ghost` for in-row actions; `outline` when next to a label-less\n * primary button you want users to consider as an alternative.\n * @dont Use IconButton when the action's meaning isn't universally\n * recognised. If users need to learn the icon, ship a Button with text.\n */\nexport const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(\n { className, variant, size, icon, loading, disabled, type = 'button', onClick, ...props },\n ref,\n) {\n return (\n <button\n data-slot=\"icon-button\"\n ref={ref}\n type={type}\n aria-busy={loading || undefined}\n aria-disabled={loading || undefined}\n disabled={disabled}\n className={cn(iconButton({ variant, size }), className)}\n onClick={loading ? blockEvent : onClick}\n {...props}\n >\n {loading ? <Loader2 className=\"animate-spin\" aria-hidden=\"true\" /> : icon}\n </button>\n );\n});\n\nIconButton.displayName = 'IconButton';\n\nfunction blockEvent(e: SyntheticEvent) {\n e.preventDefault();\n e.stopPropagation();\n}\n"],"names":["iconButton","cva","IconButton","forwardRef","className","variant","size","icon","loading","disabled","type","onClick","props","ref","jsx","cn","blockEvent","Loader2","e"],"mappings":";;;;;;AAOA,MAAMA,IAAaC;AAAA,EACjB;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAAA,EAEF;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,WACE;AAAA,QACF,SACE;AAAA,QACF,OACE;AAAA,QACF,aAAa;AAAA,MAAA;AAAA,MAEf,MAAM;AAAA;AAAA,QAEJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MAAA;AAAA,IACN;AAAA,IAEF,iBAAiB;AAAA,MACf,SAAS;AAAA,MACT,MAAM;AAAA,IAAA;AAAA,EACR;AAEJ,GA8BaC,IAAaC,EAA+C,SACvE,EAAE,WAAAC,GAAW,SAAAC,GAAS,MAAAC,GAAM,MAAAC,GAAM,SAAAC,GAAS,UAAAC,GAAU,MAAAC,IAAO,UAAU,SAAAC,GAAS,GAAGC,EAAA,GAClFC,GACA;AACA,SACE,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAU;AAAA,MACV,KAAAD;AAAA,MACA,MAAAH;AAAA,MACA,aAAWF,KAAW;AAAA,MACtB,iBAAeA,KAAW;AAAA,MAC1B,UAAAC;AAAA,MACA,WAAWM,EAAGf,EAAW,EAAE,SAAAK,GAAS,MAAAC,EAAA,CAAM,GAAGF,CAAS;AAAA,MACtD,SAASI,IAAUQ,IAAaL;AAAA,MAC/B,GAAGC;AAAA,MAEH,cAAU,gBAAAE,EAACG,GAAA,EAAQ,WAAU,gBAAe,eAAY,QAAO,IAAKV;AAAA,IAAA;AAAA,EAAA;AAG3E,CAAC;AAEDL,EAAW,cAAc;AAEzB,SAASc,EAAWE,GAAmB;AACrC,EAAAA,EAAE,eAAA,GACFA,EAAE,gBAAA;AACJ;"}
|
|
@@ -1,72 +1,72 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsxs as i, jsx as t } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef as Y, useState as N, useRef as
|
|
3
|
+
import { forwardRef as Y, useState as N, useRef as P, useCallback as k, useMemo as j } from "react";
|
|
4
4
|
import * as g from "@radix-ui/react-popover";
|
|
5
|
-
import { Command as
|
|
6
|
-
import { X as
|
|
7
|
-
import { cn as
|
|
5
|
+
import { Command as h } from "cmdk";
|
|
6
|
+
import { X as B, ChevronsUpDown as Z, Check as _ } from "../../icons/index.js";
|
|
7
|
+
import { cn as l } from "../../lib/utils.js";
|
|
8
8
|
import { useStrings as ee } from "../../hooks/use-strings.js";
|
|
9
9
|
import { formatString as te } from "../../lib/strings.js";
|
|
10
10
|
import { useFieldIds as re } from "../../hooks/use-field-ids.js";
|
|
11
11
|
const oe = Y(function({
|
|
12
|
-
options:
|
|
12
|
+
options: d,
|
|
13
13
|
value: r,
|
|
14
14
|
onChange: n,
|
|
15
|
-
label:
|
|
16
|
-
helperText:
|
|
15
|
+
label: c,
|
|
16
|
+
helperText: b,
|
|
17
17
|
error: x,
|
|
18
|
-
placeholder:
|
|
18
|
+
placeholder: F,
|
|
19
19
|
emptyText: L,
|
|
20
20
|
maxVisibleChips: M = 3,
|
|
21
21
|
clearable: E = !0,
|
|
22
|
-
disabled:
|
|
22
|
+
disabled: a,
|
|
23
23
|
id: S,
|
|
24
24
|
className: K
|
|
25
25
|
}, U) {
|
|
26
|
-
const s = ee(), z =
|
|
27
|
-
hasHelper: !!
|
|
26
|
+
const s = ee(), z = F ?? s.multiSelect.placeholder, $ = L ?? s.multiSelect.empty, v = !!x, { fieldId: u, helperId: q, errorId: H, describedBy: Q } = re(S, {
|
|
27
|
+
hasHelper: !!b,
|
|
28
28
|
hasError: v
|
|
29
|
-
}), [f, m] = N(!1), [p, X] = N(""), C =
|
|
29
|
+
}), [f, m] = N(!1), [p, X] = N(""), C = P(null), I = P(null), [G, J] = N(void 0), T = k((e) => J(e == null ? void 0 : e.id), []), w = j(() => d.filter((e) => r.includes(e.value)), [d, r]), D = k(
|
|
30
30
|
(e) => {
|
|
31
31
|
r.includes(e) ? n(r.filter((o) => o !== e)) : n([...r, e]);
|
|
32
32
|
},
|
|
33
33
|
[r, n]
|
|
34
34
|
), V = k(() => n([]), [n]), W = (e) => {
|
|
35
35
|
e.key === "Backspace" && p === "" && r.length > 0 ? n(r.slice(0, -1)) : (e.key === "ArrowDown" || e.key === "ArrowUp") && !f && m(!0);
|
|
36
|
-
}, R =
|
|
37
|
-
() =>
|
|
38
|
-
[
|
|
36
|
+
}, R = j(
|
|
37
|
+
() => d.filter((e) => e.label.toLowerCase().includes(p.toLowerCase())),
|
|
38
|
+
[d, p]
|
|
39
39
|
), y = w.slice(0, M), A = w.length - y.length;
|
|
40
40
|
return (
|
|
41
41
|
// min-w-0: as a grid or flex child the trigger's chips would otherwise
|
|
42
42
|
// set a min-content width and push the field past its column.
|
|
43
|
-
/* @__PURE__ */ i("div", { ref: U, className:
|
|
44
|
-
|
|
43
|
+
/* @__PURE__ */ i("div", { ref: U, className: l("flex min-w-0 flex-col gap-1.5", K), children: [
|
|
44
|
+
c && /* @__PURE__ */ t(
|
|
45
45
|
"label",
|
|
46
46
|
{
|
|
47
47
|
id: `${u}-label`,
|
|
48
48
|
htmlFor: u,
|
|
49
49
|
className: "text-foreground text-sm font-medium",
|
|
50
|
-
children:
|
|
50
|
+
children: c
|
|
51
51
|
}
|
|
52
52
|
),
|
|
53
|
-
/* @__PURE__ */ t(
|
|
53
|
+
/* @__PURE__ */ t(h, { shouldFilter: !1, className: "flex w-full flex-col", children: /* @__PURE__ */ i(g.Root, { open: f, onOpenChange: m, children: [
|
|
54
54
|
/* @__PURE__ */ t(g.Anchor, { asChild: !0, children: /* @__PURE__ */ i(
|
|
55
55
|
"div",
|
|
56
56
|
{
|
|
57
57
|
"data-slot": "multi-select",
|
|
58
58
|
ref: I,
|
|
59
|
-
"aria-disabled":
|
|
60
|
-
className:
|
|
59
|
+
"aria-disabled": a || void 0,
|
|
60
|
+
className: l(
|
|
61
61
|
"bg-card flex h-9 w-full cursor-text items-center gap-1.5 overflow-hidden rounded-md border px-2 py-1 text-sm",
|
|
62
62
|
"transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]",
|
|
63
63
|
"focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2",
|
|
64
64
|
v ? "border-danger focus-within:border-danger focus-within:ring-danger" : "border-border-input focus-within:border-accent focus-within:ring-ring",
|
|
65
|
-
|
|
65
|
+
a && "pointer-events-none opacity-50"
|
|
66
66
|
),
|
|
67
67
|
onClick: () => {
|
|
68
68
|
var e;
|
|
69
|
-
(e = C.current) == null || e.focus(),
|
|
69
|
+
(e = C.current) == null || e.focus(), a || m(!0);
|
|
70
70
|
},
|
|
71
71
|
children: [
|
|
72
72
|
/* @__PURE__ */ i("div", { className: "flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden", children: [
|
|
@@ -85,7 +85,7 @@ const oe = Y(function({
|
|
|
85
85
|
onClick: (o) => {
|
|
86
86
|
o.stopPropagation(), D(e.value);
|
|
87
87
|
},
|
|
88
|
-
children: /* @__PURE__ */ t(
|
|
88
|
+
children: /* @__PURE__ */ t(B, { className: "size-3", "aria-hidden": !0 })
|
|
89
89
|
}
|
|
90
90
|
)
|
|
91
91
|
]
|
|
@@ -104,8 +104,9 @@ const oe = Y(function({
|
|
|
104
104
|
type: "text",
|
|
105
105
|
autoComplete: "off",
|
|
106
106
|
value: p,
|
|
107
|
-
onChange: (e) =>
|
|
108
|
-
|
|
107
|
+
onChange: (e) => {
|
|
108
|
+
X(e.target.value), a || m(!0);
|
|
109
|
+
},
|
|
109
110
|
onKeyDown: W,
|
|
110
111
|
placeholder: y.length === 0 ? z : void 0,
|
|
111
112
|
role: "combobox",
|
|
@@ -113,12 +114,12 @@ const oe = Y(function({
|
|
|
113
114
|
"aria-controls": f ? G : void 0,
|
|
114
115
|
"aria-haspopup": "listbox",
|
|
115
116
|
"aria-autocomplete": "list",
|
|
116
|
-
"aria-labelledby":
|
|
117
|
-
"aria-label":
|
|
117
|
+
"aria-labelledby": c ? `${u}-label` : void 0,
|
|
118
|
+
"aria-label": c || S ? void 0 : z,
|
|
118
119
|
"aria-invalid": v || void 0,
|
|
119
120
|
"aria-describedby": Q,
|
|
120
121
|
className: "placeholder:text-foreground-subtle min-w-[6ch] flex-1 bg-transparent text-lg outline-hidden md:text-sm",
|
|
121
|
-
disabled:
|
|
122
|
+
disabled: a
|
|
122
123
|
}
|
|
123
124
|
)
|
|
124
125
|
] }),
|
|
@@ -132,7 +133,7 @@ const oe = Y(function({
|
|
|
132
133
|
e.stopPropagation(), V();
|
|
133
134
|
},
|
|
134
135
|
className: "text-foreground-subtle hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background inline-flex size-6 shrink-0 items-center justify-center rounded-sm outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2",
|
|
135
|
-
children: /* @__PURE__ */ t(
|
|
136
|
+
children: /* @__PURE__ */ t(B, { className: "size-4", "aria-hidden": !0 })
|
|
136
137
|
}
|
|
137
138
|
),
|
|
138
139
|
/* @__PURE__ */ t(Z, { className: "text-foreground-subtle size-4", "aria-hidden": !0 })
|
|
@@ -146,7 +147,7 @@ const oe = Y(function({
|
|
|
146
147
|
align: "start",
|
|
147
148
|
sideOffset: 4,
|
|
148
149
|
"aria-label": s.command.suggestions,
|
|
149
|
-
className:
|
|
150
|
+
className: l(
|
|
150
151
|
"border-border bg-popover text-popover-foreground z-[var(--z-popover)] w-[var(--radix-popover-trigger-width)] overflow-hidden rounded-lg border shadow-md",
|
|
151
152
|
"data-[state=open]:animate-in data-[state=closed]:animate-out",
|
|
152
153
|
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
@@ -154,12 +155,12 @@ const oe = Y(function({
|
|
|
154
155
|
),
|
|
155
156
|
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
156
157
|
onInteractOutside: (e) => {
|
|
157
|
-
var
|
|
158
|
+
var O;
|
|
158
159
|
const o = e.target;
|
|
159
|
-
o && ((
|
|
160
|
+
o && ((O = I.current) != null && O.contains(o)) && e.preventDefault();
|
|
160
161
|
},
|
|
161
162
|
children: /* @__PURE__ */ i(
|
|
162
|
-
|
|
163
|
+
h.List,
|
|
163
164
|
{
|
|
164
165
|
ref: T,
|
|
165
166
|
label: s.command.suggestions,
|
|
@@ -168,12 +169,12 @@ const oe = Y(function({
|
|
|
168
169
|
R.map((e) => {
|
|
169
170
|
const o = r.includes(e.value);
|
|
170
171
|
return /* @__PURE__ */ i(
|
|
171
|
-
|
|
172
|
+
h.Item,
|
|
172
173
|
{
|
|
173
174
|
value: e.value,
|
|
174
175
|
disabled: e.disabled,
|
|
175
176
|
onSelect: () => D(e.value),
|
|
176
|
-
className:
|
|
177
|
+
className: l(
|
|
177
178
|
"text-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm",
|
|
178
179
|
"data-[selected=true]:bg-background-muted",
|
|
179
180
|
"data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50"
|
|
@@ -183,7 +184,7 @@ const oe = Y(function({
|
|
|
183
184
|
"span",
|
|
184
185
|
{
|
|
185
186
|
"aria-hidden": !0,
|
|
186
|
-
className:
|
|
187
|
+
className: l(
|
|
187
188
|
"flex size-4 items-center justify-center rounded-sm border",
|
|
188
189
|
o ? "border-accent bg-accent text-on-accent" : "border-border-input"
|
|
189
190
|
),
|
|
@@ -197,14 +198,14 @@ const oe = Y(function({
|
|
|
197
198
|
e.value
|
|
198
199
|
);
|
|
199
200
|
}),
|
|
200
|
-
R.length === 0 && /* @__PURE__ */ t(
|
|
201
|
+
R.length === 0 && /* @__PURE__ */ t(h.Empty, { className: "text-foreground-subtle px-2 py-6 text-center text-sm", children: $ })
|
|
201
202
|
]
|
|
202
203
|
}
|
|
203
204
|
)
|
|
204
205
|
}
|
|
205
206
|
) })
|
|
206
207
|
] }) }),
|
|
207
|
-
x ? /* @__PURE__ */ t("p", { id: H, className: "text-danger-text text-xs", children: x }) :
|
|
208
|
+
x ? /* @__PURE__ */ t("p", { id: H, className: "text-danger-text text-xs", children: x }) : b ? /* @__PURE__ */ t("p", { id: q, className: "text-foreground-subtle text-xs", children: b }) : null
|
|
208
209
|
] })
|
|
209
210
|
);
|
|
210
211
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiSelect.js","sources":["../../../src/components/ui/MultiSelect.tsx"],"sourcesContent":["'use client';\n\nimport {\n forwardRef,\n useCallback,\n useMemo,\n useRef,\n useState,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { Command as CommandPrimitive } from 'cmdk';\nimport { Check, ChevronsUpDown, X } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { useStrings } from '@/hooks/use-strings';\nimport { formatString } from '@/lib/strings';\nimport { useFieldIds } from '@/hooks/use-field-ids';\n\nexport interface MultiSelectOption {\n /** Stable, unique value submitted in `onChange`. */\n value: string;\n /** Visible label shown both in the menu and in the selected chip. */\n label: string;\n /** Optional secondary text shown after the label in the menu. */\n description?: string;\n /** Disable selecting this option. */\n disabled?: boolean;\n}\n\nexport interface MultiSelectProps {\n /** All possible options. */\n options: MultiSelectOption[];\n /** Currently selected values. Controlled. */\n value: string[];\n /** Called whenever the selection changes. */\n onChange: (next: string[]) => void;\n /** Visible label above the field. */\n label?: ReactNode;\n /** Hint below the field. Hidden when `error` is set. */\n helperText?: ReactNode;\n /** Validation message. */\n error?: ReactNode;\n /** Empty-state placeholder shown when nothing is selected. */\n placeholder?: string;\n /** Text shown when no options match the search. */\n emptyText?: string;\n /** Max number of chips rendered inline; remainder shown as \"+N more\". */\n maxVisibleChips?: number;\n /** Whether the user can clear all selections with a single click. */\n clearable?: boolean;\n /** Disable the entire field. */\n disabled?: boolean;\n /** Consumer-supplied id for the search input (label association). */\n id?: string;\n className?: string;\n}\n\n/**\n * Chip-based multi-select with a searchable menu (cmdk under the hood).\n *\n * Keyboard:\n * - Backspace on the input with empty query removes the last chip\n * - ArrowUp / ArrowDown move the highlight, Enter toggles the highlighted option\n * - Escape closes the menu\n *\n * @example Tag picker\n * <MultiSelect label=\"Tags\"\n * options={tags}\n * value={selected}\n * onChange={setSelected}\n * placeholder=\"Pick tags\" />\n *\n * @example Bounded with overflow chip\n * <MultiSelect options={users}\n * value={value}\n * onChange={setValue}\n * maxVisibleChips={3} />\n *\n * @do Cap `maxVisibleChips` (3–5) on narrow surfaces so the field doesn't\n * reflow as the user adds selections.\n * @dont Use MultiSelect for fewer than ~6 options. CheckboxGroup is clearer.\n */\nexport const MultiSelect = forwardRef<HTMLDivElement, MultiSelectProps>(function MultiSelect(\n {\n options,\n value,\n onChange,\n label,\n helperText,\n error,\n placeholder: placeholderProp,\n emptyText: emptyTextProp,\n maxVisibleChips = 3,\n clearable = true,\n disabled,\n id,\n className,\n },\n ref,\n) {\n const strings = useStrings();\n const placeholder = placeholderProp ?? strings.multiSelect.placeholder;\n const emptyText = emptyTextProp ?? strings.multiSelect.empty;\n const isError = Boolean(error);\n const { fieldId, helperId, errorId, describedBy } = useFieldIds(id, {\n hasHelper: Boolean(helperText),\n hasError: isError,\n });\n\n const [open, setOpen] = useState(false);\n const [query, setQuery] = useState('');\n const inputRef = useRef<HTMLInputElement>(null);\n const fieldRef = useRef<HTMLDivElement>(null);\n // cmdk assigns its own id to the list (ours is ignored), so read it back\n // from the node once the portal mounts to keep aria-controls truthful.\n const [listId, setListId] = useState<string | undefined>(undefined);\n const listRef = useCallback((el: HTMLDivElement | null) => setListId(el?.id), []);\n\n const selected = useMemo(() => options.filter((o) => value.includes(o.value)), [options, value]);\n\n const toggle = useCallback(\n (v: string) => {\n if (value.includes(v)) onChange(value.filter((x) => x !== v));\n else onChange([...value, v]);\n },\n [value, onChange],\n );\n\n const clear = useCallback(() => onChange([]), [onChange]);\n\n const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'Backspace' && query === '' && value.length > 0) {\n onChange(value.slice(0, -1));\n } else if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !open) {\n setOpen(true);\n }\n };\n\n const filtered = useMemo(\n () => options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase())),\n [options, query],\n );\n\n const visibleChips = selected.slice(0, maxVisibleChips);\n const overflow = selected.length - visibleChips.length;\n\n return (\n // min-w-0: as a grid or flex child the trigger's chips would otherwise\n // set a min-content width and push the field past its column.\n <div ref={ref} className={cn('flex min-w-0 flex-col gap-1.5', className)}>\n {label && (\n <label\n id={`${fieldId}-label`}\n htmlFor={fieldId}\n className=\"text-foreground text-sm font-medium\"\n >\n {label}\n </label>\n )}\n\n {/* The Command root wraps the whole field so cmdk's root keydown handler\n (ArrowUp/Down/Enter) sees the input even though the list is portaled.\n A plain <input> is used instead of Command.Input because cmdk forces\n its own id / aria-* on that element, breaking the label association. */}\n <CommandPrimitive shouldFilter={false} className=\"flex w-full flex-col\">\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n <PopoverPrimitive.Anchor asChild>\n {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions -- click-to-focus wrapper; the <input role=\"combobox\"> inside owns keyboard handling */}\n <div\n data-slot=\"multi-select\"\n ref={fieldRef}\n aria-disabled={disabled || undefined}\n className={cn(\n 'bg-card flex h-9 w-full cursor-text items-center gap-1.5 overflow-hidden rounded-md border px-2 py-1 text-sm',\n 'transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]',\n 'focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',\n isError\n ? 'border-danger focus-within:border-danger focus-within:ring-danger'\n : 'border-border-input focus-within:border-accent focus-within:ring-ring',\n disabled && 'pointer-events-none opacity-50',\n )}\n onClick={() => {\n inputRef.current?.focus();\n if (!disabled) setOpen(true);\n }}\n >\n <div className=\"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden\">\n {visibleChips.map((opt) => (\n <span\n key={opt.value}\n className=\"bg-accent-soft text-on-accent-soft inline-flex max-w-[10rem] shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-xs font-medium\"\n >\n <span className=\"truncate\" title={opt.label}>\n {opt.label}\n </span>\n <button\n type=\"button\"\n aria-label={formatString(strings.multiSelect.remove, { label: opt.label })}\n className=\"text-on-accent-soft hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background relative inline-flex items-center rounded-sm outline-hidden before:absolute before:-inset-1.5 before:content-[''] focus-visible:ring-2 focus-visible:ring-offset-1\"\n onClick={(e) => {\n e.stopPropagation();\n toggle(opt.value);\n }}\n >\n <X className=\"size-3\" aria-hidden />\n </button>\n </span>\n ))}\n {overflow > 0 && (\n <span className=\"bg-background-muted text-foreground-muted shrink-0 rounded-md px-1.5 py-0.5 text-xs font-medium\">\n +{overflow}\n </span>\n )}\n <input\n ref={inputRef}\n id={fieldId}\n type=\"text\"\n autoComplete=\"off\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n onFocus={() => setOpen(true)}\n onKeyDown={handleKeyDown}\n placeholder={visibleChips.length === 0 ? placeholder : undefined}\n role=\"combobox\"\n aria-expanded={open}\n aria-controls={open ? listId : undefined}\n aria-haspopup=\"listbox\"\n aria-autocomplete=\"list\"\n // Unlabelled field: name the input after the placeholder. A\n // consumer `id` implies an external <label htmlFor>.\n aria-labelledby={label ? `${fieldId}-label` : undefined}\n aria-label={label || id ? undefined : placeholder}\n aria-invalid={isError || undefined}\n aria-describedby={describedBy}\n className=\"placeholder:text-foreground-subtle min-w-[6ch] flex-1 bg-transparent text-lg outline-hidden md:text-sm\"\n disabled={disabled}\n />\n </div>\n <span className=\"flex shrink-0 items-center gap-1 pl-1\">\n {clearable && selected.length > 0 && (\n <button\n type=\"button\"\n aria-label={strings.multiSelect.clearAll}\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n className=\"text-foreground-subtle hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background inline-flex size-6 shrink-0 items-center justify-center rounded-sm outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2\"\n >\n <X className=\"size-4\" aria-hidden />\n </button>\n )}\n <ChevronsUpDown className=\"text-foreground-subtle size-4\" aria-hidden />\n </span>\n </div>\n </PopoverPrimitive.Anchor>\n\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n align=\"start\"\n sideOffset={4}\n // Radix gives the content role=\"dialog\"; a dialog needs a name.\n aria-label={strings.command.suggestions}\n className={cn(\n 'border-border bg-popover text-popover-foreground z-[var(--z-popover)] w-[var(--radix-popover-trigger-width)] overflow-hidden rounded-lg border shadow-md',\n 'data-[state=open]:animate-in data-[state=closed]:animate-out',\n 'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',\n 'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',\n )}\n onOpenAutoFocus={(e) => e.preventDefault()}\n onInteractOutside={(e) => {\n // Clicks inside the anchor (chips, clear) must not close the menu.\n const target = e.target as Node | null;\n if (target && fieldRef.current?.contains(target)) e.preventDefault();\n }}\n >\n <CommandPrimitive.List\n ref={listRef}\n label={strings.command.suggestions}\n className=\"max-h-64 overflow-y-auto p-1\"\n >\n {filtered.map((opt) => {\n const isSelected = value.includes(opt.value);\n return (\n <CommandPrimitive.Item\n key={opt.value}\n value={opt.value}\n disabled={opt.disabled}\n onSelect={() => toggle(opt.value)}\n className={cn(\n 'text-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm',\n 'data-[selected=true]:bg-background-muted',\n 'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50',\n )}\n >\n <span\n aria-hidden\n className={cn(\n 'flex size-4 items-center justify-center rounded-sm border',\n isSelected\n ? 'border-accent bg-accent text-on-accent'\n : 'border-border-input',\n )}\n >\n {isSelected && <Check className=\"size-3\" aria-hidden />}\n </span>\n <span className=\"flex-1\">{opt.label}</span>\n {opt.description && (\n <span className=\"text-foreground-subtle text-xs\">{opt.description}</span>\n )}\n </CommandPrimitive.Item>\n );\n })}\n {filtered.length === 0 && (\n <CommandPrimitive.Empty className=\"text-foreground-subtle px-2 py-6 text-center text-sm\">\n {emptyText}\n </CommandPrimitive.Empty>\n )}\n </CommandPrimitive.List>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n </CommandPrimitive>\n\n {error ? (\n <p id={errorId} className=\"text-danger-text text-xs\">\n {error}\n </p>\n ) : helperText ? (\n <p id={helperId} className=\"text-foreground-subtle text-xs\">\n {helperText}\n </p>\n ) : null}\n </div>\n );\n});\n\nMultiSelect.displayName = 'MultiSelect';\n"],"names":["MultiSelect","forwardRef","options","value","onChange","label","helperText","error","placeholderProp","emptyTextProp","maxVisibleChips","clearable","disabled","id","className","ref","strings","useStrings","placeholder","emptyText","isError","fieldId","helperId","errorId","describedBy","useFieldIds","open","setOpen","useState","query","setQuery","inputRef","useRef","fieldRef","listId","setListId","listRef","useCallback","el","selected","useMemo","o","toggle","v","x","clear","handleKeyDown","filtered","visibleChips","overflow","cn","jsx","CommandPrimitive","jsxs","PopoverPrimitive","_a","opt","formatString","e","X","ChevronsUpDown","target","isSelected","Check"],"mappings":";;;;;;;;;;AAmFO,MAAMA,KAAcC,EAA6C,SACtE;AAAA,EACE,SAAAC;AAAA,EACA,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KAAA,EAAE,IAAIgB,GAAU,WAAU,kCACxB,aACH,IACE;AAAA,IAAA,EAAA,CACN;AAAA;AAEJ,CAAC;AAEDtB,GAAY,cAAc;"}
|
|
1
|
+
{"version":3,"file":"MultiSelect.js","sources":["../../../src/components/ui/MultiSelect.tsx"],"sourcesContent":["'use client';\n\nimport {\n forwardRef,\n useCallback,\n useMemo,\n useRef,\n useState,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { Command as CommandPrimitive } from 'cmdk';\nimport { Check, ChevronsUpDown, X } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { useStrings } from '@/hooks/use-strings';\nimport { formatString } from '@/lib/strings';\nimport { useFieldIds } from '@/hooks/use-field-ids';\n\nexport interface MultiSelectOption {\n /** Stable, unique value submitted in `onChange`. */\n value: string;\n /** Visible label shown both in the menu and in the selected chip. */\n label: string;\n /** Optional secondary text shown after the label in the menu. */\n description?: string;\n /** Disable selecting this option. */\n disabled?: boolean;\n}\n\nexport interface MultiSelectProps {\n /** All possible options. */\n options: MultiSelectOption[];\n /** Currently selected values. Controlled. */\n value: string[];\n /** Called whenever the selection changes. */\n onChange: (next: string[]) => void;\n /** Visible label above the field. */\n label?: ReactNode;\n /** Hint below the field. Hidden when `error` is set. */\n helperText?: ReactNode;\n /** Validation message. */\n error?: ReactNode;\n /** Empty-state placeholder shown when nothing is selected. */\n placeholder?: string;\n /** Text shown when no options match the search. */\n emptyText?: string;\n /** Max number of chips rendered inline; remainder shown as \"+N more\". */\n maxVisibleChips?: number;\n /** Whether the user can clear all selections with a single click. */\n clearable?: boolean;\n /** Disable the entire field. */\n disabled?: boolean;\n /** Consumer-supplied id for the search input (label association). */\n id?: string;\n className?: string;\n}\n\n/**\n * Chip-based multi-select with a searchable menu (cmdk under the hood).\n *\n * Keyboard:\n * - Backspace on the input with empty query removes the last chip\n * - ArrowUp / ArrowDown move the highlight, Enter toggles the highlighted option\n * - Escape closes the menu\n *\n * @example Tag picker\n * <MultiSelect label=\"Tags\"\n * options={tags}\n * value={selected}\n * onChange={setSelected}\n * placeholder=\"Pick tags\" />\n *\n * @example Bounded with overflow chip\n * <MultiSelect options={users}\n * value={value}\n * onChange={setValue}\n * maxVisibleChips={3} />\n *\n * @do Cap `maxVisibleChips` (3–5) on narrow surfaces so the field doesn't\n * reflow as the user adds selections.\n * @dont Use MultiSelect for fewer than ~6 options. CheckboxGroup is clearer.\n */\nexport const MultiSelect = forwardRef<HTMLDivElement, MultiSelectProps>(function MultiSelect(\n {\n options,\n value,\n onChange,\n label,\n helperText,\n error,\n placeholder: placeholderProp,\n emptyText: emptyTextProp,\n maxVisibleChips = 3,\n clearable = true,\n disabled,\n id,\n className,\n },\n ref,\n) {\n const strings = useStrings();\n const placeholder = placeholderProp ?? strings.multiSelect.placeholder;\n const emptyText = emptyTextProp ?? strings.multiSelect.empty;\n const isError = Boolean(error);\n const { fieldId, helperId, errorId, describedBy } = useFieldIds(id, {\n hasHelper: Boolean(helperText),\n hasError: isError,\n });\n\n const [open, setOpen] = useState(false);\n const [query, setQuery] = useState('');\n const inputRef = useRef<HTMLInputElement>(null);\n const fieldRef = useRef<HTMLDivElement>(null);\n // cmdk assigns its own id to the list (ours is ignored), so read it back\n // from the node once the portal mounts to keep aria-controls truthful.\n const [listId, setListId] = useState<string | undefined>(undefined);\n const listRef = useCallback((el: HTMLDivElement | null) => setListId(el?.id), []);\n\n const selected = useMemo(() => options.filter((o) => value.includes(o.value)), [options, value]);\n\n const toggle = useCallback(\n (v: string) => {\n if (value.includes(v)) onChange(value.filter((x) => x !== v));\n else onChange([...value, v]);\n },\n [value, onChange],\n );\n\n const clear = useCallback(() => onChange([]), [onChange]);\n\n const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'Backspace' && query === '' && value.length > 0) {\n onChange(value.slice(0, -1));\n } else if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !open) {\n setOpen(true);\n }\n };\n\n const filtered = useMemo(\n () => options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase())),\n [options, query],\n );\n\n const visibleChips = selected.slice(0, maxVisibleChips);\n const overflow = selected.length - visibleChips.length;\n\n return (\n // min-w-0: as a grid or flex child the trigger's chips would otherwise\n // set a min-content width and push the field past its column.\n <div ref={ref} className={cn('flex min-w-0 flex-col gap-1.5', className)}>\n {label && (\n <label\n id={`${fieldId}-label`}\n htmlFor={fieldId}\n className=\"text-foreground text-sm font-medium\"\n >\n {label}\n </label>\n )}\n\n {/* The Command root wraps the whole field so cmdk's root keydown handler\n (ArrowUp/Down/Enter) sees the input even though the list is portaled.\n A plain <input> is used instead of Command.Input because cmdk forces\n its own id / aria-* on that element, breaking the label association. */}\n <CommandPrimitive shouldFilter={false} className=\"flex w-full flex-col\">\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n <PopoverPrimitive.Anchor asChild>\n {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions -- click-to-focus wrapper; the <input role=\"combobox\"> inside owns keyboard handling */}\n <div\n data-slot=\"multi-select\"\n ref={fieldRef}\n aria-disabled={disabled || undefined}\n className={cn(\n 'bg-card flex h-9 w-full cursor-text items-center gap-1.5 overflow-hidden rounded-md border px-2 py-1 text-sm',\n 'transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]',\n 'focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',\n isError\n ? 'border-danger focus-within:border-danger focus-within:ring-danger'\n : 'border-border-input focus-within:border-accent focus-within:ring-ring',\n disabled && 'pointer-events-none opacity-50',\n )}\n onClick={() => {\n inputRef.current?.focus();\n if (!disabled) setOpen(true);\n }}\n >\n <div className=\"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden\">\n {visibleChips.map((opt) => (\n <span\n key={opt.value}\n className=\"bg-accent-soft text-on-accent-soft inline-flex max-w-[10rem] shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-xs font-medium\"\n >\n <span className=\"truncate\" title={opt.label}>\n {opt.label}\n </span>\n <button\n type=\"button\"\n aria-label={formatString(strings.multiSelect.remove, { label: opt.label })}\n className=\"text-on-accent-soft hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background relative inline-flex items-center rounded-sm outline-hidden before:absolute before:-inset-1.5 before:content-[''] focus-visible:ring-2 focus-visible:ring-offset-1\"\n onClick={(e) => {\n e.stopPropagation();\n toggle(opt.value);\n }}\n >\n <X className=\"size-3\" aria-hidden />\n </button>\n </span>\n ))}\n {overflow > 0 && (\n <span className=\"bg-background-muted text-foreground-muted shrink-0 rounded-md px-1.5 py-0.5 text-xs font-medium\">\n +{overflow}\n </span>\n )}\n <input\n ref={inputRef}\n id={fieldId}\n type=\"text\"\n autoComplete=\"off\"\n value={query}\n // Typing opens the list; focus alone does not, so tabbing\n // through a form never pops a listbox on every pass.\n onChange={(e) => {\n setQuery(e.target.value);\n if (!disabled) setOpen(true);\n }}\n onKeyDown={handleKeyDown}\n placeholder={visibleChips.length === 0 ? placeholder : undefined}\n role=\"combobox\"\n aria-expanded={open}\n aria-controls={open ? listId : undefined}\n aria-haspopup=\"listbox\"\n aria-autocomplete=\"list\"\n // Unlabelled field: name the input after the placeholder. A\n // consumer `id` implies an external <label htmlFor>.\n aria-labelledby={label ? `${fieldId}-label` : undefined}\n aria-label={label || id ? undefined : placeholder}\n aria-invalid={isError || undefined}\n aria-describedby={describedBy}\n className=\"placeholder:text-foreground-subtle min-w-[6ch] flex-1 bg-transparent text-lg outline-hidden md:text-sm\"\n disabled={disabled}\n />\n </div>\n <span className=\"flex shrink-0 items-center gap-1 pl-1\">\n {clearable && selected.length > 0 && (\n <button\n type=\"button\"\n aria-label={strings.multiSelect.clearAll}\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n className=\"text-foreground-subtle hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background inline-flex size-6 shrink-0 items-center justify-center rounded-sm outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2\"\n >\n <X className=\"size-4\" aria-hidden />\n </button>\n )}\n <ChevronsUpDown className=\"text-foreground-subtle size-4\" aria-hidden />\n </span>\n </div>\n </PopoverPrimitive.Anchor>\n\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n align=\"start\"\n sideOffset={4}\n // Radix gives the content role=\"dialog\"; a dialog needs a name.\n aria-label={strings.command.suggestions}\n className={cn(\n 'border-border bg-popover text-popover-foreground z-[var(--z-popover)] w-[var(--radix-popover-trigger-width)] overflow-hidden rounded-lg border shadow-md',\n 'data-[state=open]:animate-in data-[state=closed]:animate-out',\n 'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',\n 'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',\n )}\n onOpenAutoFocus={(e) => e.preventDefault()}\n onInteractOutside={(e) => {\n // Clicks inside the anchor (chips, clear) must not close the menu.\n const target = e.target as Node | null;\n if (target && fieldRef.current?.contains(target)) e.preventDefault();\n }}\n >\n <CommandPrimitive.List\n ref={listRef}\n label={strings.command.suggestions}\n className=\"max-h-64 overflow-y-auto p-1\"\n >\n {filtered.map((opt) => {\n const isSelected = value.includes(opt.value);\n return (\n <CommandPrimitive.Item\n key={opt.value}\n value={opt.value}\n disabled={opt.disabled}\n onSelect={() => toggle(opt.value)}\n className={cn(\n 'text-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm',\n 'data-[selected=true]:bg-background-muted',\n 'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50',\n )}\n >\n <span\n aria-hidden\n className={cn(\n 'flex size-4 items-center justify-center rounded-sm border',\n isSelected\n ? 'border-accent bg-accent text-on-accent'\n : 'border-border-input',\n )}\n >\n {isSelected && <Check className=\"size-3\" aria-hidden />}\n </span>\n <span className=\"flex-1\">{opt.label}</span>\n {opt.description && (\n <span className=\"text-foreground-subtle text-xs\">{opt.description}</span>\n )}\n </CommandPrimitive.Item>\n );\n })}\n {filtered.length === 0 && (\n <CommandPrimitive.Empty className=\"text-foreground-subtle px-2 py-6 text-center text-sm\">\n {emptyText}\n </CommandPrimitive.Empty>\n )}\n </CommandPrimitive.List>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n </CommandPrimitive>\n\n {error ? (\n <p id={errorId} className=\"text-danger-text text-xs\">\n {error}\n </p>\n ) : helperText ? (\n <p id={helperId} className=\"text-foreground-subtle text-xs\">\n {helperText}\n </p>\n ) : null}\n </div>\n );\n});\n\nMultiSelect.displayName = 'MultiSelect';\n"],"names":["MultiSelect","forwardRef","options","value","onChange","label","helperText","error","placeholderProp","emptyTextProp","maxVisibleChips","clearable","disabled","id","className","ref","strings","useStrings","placeholder","emptyText","isError","fieldId","helperId","errorId","describedBy","useFieldIds","open","setOpen","useState","query","setQuery","inputRef","useRef","fieldRef","listId","setListId","listRef","useCallback","el","selected","useMemo","o","toggle","v","x","clear","handleKeyDown","filtered","visibleChips","overflow","cn","jsx","CommandPrimitive","jsxs","PopoverPrimitive","_a","opt","formatString","e","X","ChevronsUpDown","target","isSelected","Check"],"mappings":";;;;;;;;;;AAmFO,MAAMA,KAAcC,EAA6C,SACtE;AAAA,EACE,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAaC;AAAA,EACb,WAAWC;AAAA,EACX,iBAAAC,IAAkB;AAAA,EAClB,WAAAC,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA,IAAAC;AAAA,EACA,WAAAC;AACF,GACAC,GACA;AACA,QAAMC,IAAUC,GAAA,GACVC,IAAcV,KAAmBQ,EAAQ,YAAY,aACrDG,IAAYV,KAAiBO,EAAQ,YAAY,OACjDI,IAAU,EAAQb,GAClB,EAAE,SAAAc,GAAS,UAAAC,GAAU,SAAAC,GAAS,aAAAC,EAAA,IAAgBC,GAAYZ,GAAI;AAAA,IAClE,WAAW,EAAQP;AAAA,IAC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BAAA,gBAAAC;AAAA,4BAAC;AAAA,4BAAA;AAAA,8BACC,eAAW;AAAA,8BACX,WAAWD;AAAA,gCACT;AAAA,gCACAY,IACI,2CACA;AAAA,8BAAA;AAAA,8BAGL,eAAc,gBAAAX,EAACY,GAAA,EAAM,WAAU,UAAS,eAAW,GAAA,CAAC;AAAA,4BAAA;AAAA,0BAAA;AAAA,0BAEvD,gBAAAZ,EAAC,QAAA,EAAK,WAAU,UAAU,YAAI,OAAM;AAAA,0BACnCK,EAAI,eACH,gBAAAL,EAAC,UAAK,WAAU,kCAAkC,YAAI,YAAA,CAAY;AAAA,wBAAA;AAAA,sBAAA;AAAA,sBAvB/DK,EAAI;AAAA,oBAAA;AAAA,kBA2Bf,CAAC;AAAA,kBACAT,EAAS,WAAW,KACnB,gBAAAI,EAACC,EAAiB,OAAjB,EAAuB,WAAU,wDAC/B,UAAAjC,EAAA,CACH;AAAA,gBAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UAEJ;AAAA,QAAA,EACF,CACF;AAAA,MAAA,EAAA,CACF,EAAA,CACF;AAAA,MAECZ,IACC,gBAAA4C,EAAC,KAAA,EAAE,IAAI5B,GAAS,WAAU,4BACvB,UAAAhB,EAAA,CACH,IACED,sBACD,KAAA,EAAE,IAAIgB,GAAU,WAAU,kCACxB,aACH,IACE;AAAA,IAAA,EAAA,CACN;AAAA;AAEJ,CAAC;AAEDtB,GAAY,cAAc;"}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs as
|
|
2
|
+
import { jsxs as d, jsx as i } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef as A, useId as B, useMemo as E } from "react";
|
|
4
4
|
import { ChevronsLeft as T, ChevronLeft as V, ChevronRight as _, ChevronsRight as $ } from "../../icons/index.js";
|
|
5
5
|
import { cn as g } from "../../lib/utils.js";
|
|
6
6
|
import { useStrings as q } from "../../hooks/use-strings.js";
|
|
7
|
-
import { defaultStrings as z, formatString as
|
|
7
|
+
import { defaultStrings as z, formatString as h } from "../../lib/strings.js";
|
|
8
8
|
import { Select as D, SelectTrigger as G, SelectContent as H, SelectItem as K } from "./Select.js";
|
|
9
|
-
function y(
|
|
9
|
+
function y(t) {
|
|
10
10
|
return {
|
|
11
|
-
showing: (e,
|
|
12
|
-
rowsPerPage:
|
|
13
|
-
first:
|
|
14
|
-
last:
|
|
15
|
-
prev:
|
|
16
|
-
next:
|
|
17
|
-
page: (e) =>
|
|
18
|
-
perPage: (e) =>
|
|
19
|
-
nav:
|
|
11
|
+
showing: (e, r, c) => h(t.showing, { from: e, to: r, total: c }),
|
|
12
|
+
rowsPerPage: t.rowsPerPage,
|
|
13
|
+
first: t.first,
|
|
14
|
+
last: t.last,
|
|
15
|
+
prev: t.prev,
|
|
16
|
+
next: t.next,
|
|
17
|
+
page: (e) => h(t.page, { n: e }),
|
|
18
|
+
perPage: (e) => h(t.perPage, { n: e }),
|
|
19
|
+
nav: t.nav
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
const ee = y(
|
|
23
23
|
z.pagination
|
|
24
24
|
);
|
|
25
|
-
function Q(
|
|
26
|
-
if (e <=
|
|
27
|
-
const
|
|
25
|
+
function Q(t, e, r = 7) {
|
|
26
|
+
if (e <= r) return Array.from({ length: e }, (l, f) => f + 1);
|
|
27
|
+
const c = 1, a = [], s = Math.max(2, t - c), u = Math.min(e - 1, t + c);
|
|
28
28
|
a.push(1), s > 2 && a.push("gap");
|
|
29
29
|
for (let l = s; l <= u; l++) a.push(l);
|
|
30
30
|
return u < e - 1 && a.push("gap"), a.push(e), a;
|
|
31
31
|
}
|
|
32
32
|
const U = A(function({
|
|
33
33
|
page: e,
|
|
34
|
-
pageCount:
|
|
35
|
-
onPageChange:
|
|
34
|
+
pageCount: r,
|
|
35
|
+
onPageChange: c,
|
|
36
36
|
totalItems: a,
|
|
37
37
|
pageSize: s,
|
|
38
38
|
pageSizeOptions: u,
|
|
@@ -43,10 +43,10 @@ const U = A(function({
|
|
|
43
43
|
"aria-label": C,
|
|
44
44
|
...L
|
|
45
45
|
}, M) {
|
|
46
|
-
const R = q(), o = { ...y(R.pagination), ...P }, v = B(), S = E(() => Q(e,
|
|
47
|
-
n < 1 || n >
|
|
46
|
+
const R = q(), o = { ...y(R.pagination), ...P }, v = B(), S = E(() => Q(e, r), [e, r]), x = !a || r <= 0, N = s === void 0 ? void 0 : x ? 0 : (e - 1) * s + 1, p = s === void 0 || a === void 0 ? void 0 : x ? 0 : Math.min(e * s, a), k = e <= 1 || r <= 0, w = e >= r, m = (n) => {
|
|
47
|
+
n < 1 || n > r || n === e || c(n);
|
|
48
48
|
};
|
|
49
|
-
return /* @__PURE__ */
|
|
49
|
+
return /* @__PURE__ */ d(
|
|
50
50
|
"nav",
|
|
51
51
|
{
|
|
52
52
|
"data-slot": "pagination",
|
|
@@ -55,17 +55,17 @@ const U = A(function({
|
|
|
55
55
|
className: g("flex flex-wrap items-center justify-between gap-3", j),
|
|
56
56
|
...L,
|
|
57
57
|
children: [
|
|
58
|
-
/* @__PURE__ */
|
|
58
|
+
/* @__PURE__ */ d("div", { className: "text-foreground-muted flex items-center gap-3 text-sm", children: [
|
|
59
59
|
a !== void 0 && s !== void 0 && N !== void 0 && p !== void 0 && /* @__PURE__ */ i("span", { className: "tabular", children: o.showing(N, p, a) }),
|
|
60
|
-
u && l && s !== void 0 && /* @__PURE__ */
|
|
60
|
+
u && l && s !== void 0 && /* @__PURE__ */ d("div", { className: "flex items-center gap-2", children: [
|
|
61
61
|
/* @__PURE__ */ i("label", { htmlFor: v, className: "sr-only", children: o.rowsPerPage }),
|
|
62
|
-
/* @__PURE__ */
|
|
62
|
+
/* @__PURE__ */ d(D, { value: String(s), onValueChange: (n) => l(Number(n)), children: [
|
|
63
63
|
/* @__PURE__ */ i(G, { id: v, size: "sm", className: "w-[7.5rem] whitespace-nowrap" }),
|
|
64
64
|
/* @__PURE__ */ i(H, { children: u.map((n) => /* @__PURE__ */ i(K, { value: String(n), children: o.perPage(n) }, n)) })
|
|
65
65
|
] })
|
|
66
66
|
] })
|
|
67
67
|
] }),
|
|
68
|
-
/* @__PURE__ */
|
|
68
|
+
/* @__PURE__ */ d("ul", { className: "flex items-center gap-1", children: [
|
|
69
69
|
f && /* @__PURE__ */ i("li", { className: "hidden sm:block", children: /* @__PURE__ */ i(
|
|
70
70
|
"button",
|
|
71
71
|
{
|
|
@@ -73,7 +73,7 @@ const U = A(function({
|
|
|
73
73
|
"aria-label": o.first,
|
|
74
74
|
disabled: k,
|
|
75
75
|
onClick: () => m(1),
|
|
76
|
-
className:
|
|
76
|
+
className: b,
|
|
77
77
|
children: /* @__PURE__ */ i(T, { className: "size-4", "aria-hidden": !0 })
|
|
78
78
|
}
|
|
79
79
|
) }),
|
|
@@ -84,14 +84,14 @@ const U = A(function({
|
|
|
84
84
|
"aria-label": o.prev,
|
|
85
85
|
disabled: k,
|
|
86
86
|
onClick: () => m(e - 1),
|
|
87
|
-
className:
|
|
87
|
+
className: b,
|
|
88
88
|
children: /* @__PURE__ */ i(V, { className: "size-4", "aria-hidden": !0 })
|
|
89
89
|
}
|
|
90
90
|
) }),
|
|
91
|
-
/* @__PURE__ */
|
|
91
|
+
/* @__PURE__ */ d("li", { className: "tabular text-foreground-muted px-2 text-sm sm:hidden", "aria-current": "page", children: [
|
|
92
92
|
e,
|
|
93
93
|
" / ",
|
|
94
|
-
|
|
94
|
+
r
|
|
95
95
|
] }),
|
|
96
96
|
S.map(
|
|
97
97
|
(n, F) => n === "gap" ? /* @__PURE__ */ i("li", { className: "text-foreground-subtle hidden px-2 sm:block", children: "…" }, `gap-${F}`) : /* @__PURE__ */ i("li", { className: "hidden sm:block", children: /* @__PURE__ */ i(
|
|
@@ -118,7 +118,7 @@ const U = A(function({
|
|
|
118
118
|
"aria-label": o.next,
|
|
119
119
|
disabled: w,
|
|
120
120
|
onClick: () => m(e + 1),
|
|
121
|
-
className:
|
|
121
|
+
className: b,
|
|
122
122
|
children: /* @__PURE__ */ i(_, { className: "size-4", "aria-hidden": !0 })
|
|
123
123
|
}
|
|
124
124
|
) }),
|
|
@@ -128,8 +128,8 @@ const U = A(function({
|
|
|
128
128
|
type: "button",
|
|
129
129
|
"aria-label": o.last,
|
|
130
130
|
disabled: w,
|
|
131
|
-
onClick: () => m(
|
|
132
|
-
className:
|
|
131
|
+
onClick: () => m(r),
|
|
132
|
+
className: b,
|
|
133
133
|
children: /* @__PURE__ */ i($, { className: "size-4", "aria-hidden": !0 })
|
|
134
134
|
}
|
|
135
135
|
) })
|
|
@@ -139,8 +139,10 @@ const U = A(function({
|
|
|
139
139
|
);
|
|
140
140
|
});
|
|
141
141
|
U.displayName = "Pagination";
|
|
142
|
-
const
|
|
143
|
-
"inline-flex size-8 items-center justify-center rounded-md text-foreground-muted",
|
|
142
|
+
const b = g(
|
|
143
|
+
"relative inline-flex size-8 items-center justify-center rounded-md text-foreground-muted",
|
|
144
|
+
// 32px visual, 44px hit area via an invisible halo (WCAG 2.5.8).
|
|
145
|
+
'before:absolute before:-inset-1.5 before:content-[""]',
|
|
144
146
|
"transition-colors duration-[var(--duration-fast)]",
|
|
145
147
|
"hover:bg-background-muted hover:text-foreground",
|
|
146
148
|
"disabled:opacity-50 disabled:pointer-events-none",
|