@alea-design/ui 0.2.0 → 0.3.1
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 +2 -2
- package/dist/components/accordion/Accordion.js +29 -0
- package/dist/components/ai/AI.d.ts +5 -1
- package/dist/components/ai/AI.js +187 -0
- package/dist/components/app/AppParts.d.ts +16 -4
- package/dist/components/app/AppParts.js +134 -0
- package/dist/components/button/Button.d.ts +1 -1
- package/dist/components/button/Button.js +137 -0
- package/dist/components/button/Groups.d.ts +1 -1
- package/dist/components/button/Groups.js +112 -0
- package/dist/components/card/Card.d.ts +3 -2
- package/dist/components/card/Card.js +47 -0
- package/dist/components/chat/Chat.d.ts +4 -2
- package/dist/components/chat/Chat.js +275 -0
- package/dist/components/choice/Choice.js +69 -0
- package/dist/components/color/Color.d.ts +3 -3
- package/dist/components/color/Color.js +98 -0
- package/dist/components/combobox/Autocomplete.d.ts +5 -5
- package/dist/components/combobox/Autocomplete.js +126 -0
- package/dist/components/combobox/ComboBox.d.ts +4 -4
- package/dist/components/combobox/ComboBox.js +112 -0
- package/dist/components/combobox/Highlight.js +50 -0
- package/dist/components/command/CommandPalette.d.ts +10 -3
- package/dist/components/command/CommandPalette.js +56 -0
- package/dist/components/content/Content.d.ts +1 -1
- package/dist/components/content/Content.js +125 -0
- package/dist/components/data/Data.js +79 -0
- package/dist/components/date/Date.js +109 -0
- package/dist/components/display/Display.d.ts +5 -3
- package/dist/components/display/Display.js +89 -0
- package/dist/components/display/Display2.d.ts +3 -1
- package/dist/components/display/Display2.js +75 -0
- package/dist/components/emoji/EmojiPicker.js +52 -0
- package/dist/components/emoji/emoji-data.js +27 -0
- package/dist/components/extras/CodeSteps.d.ts +1 -0
- package/dist/components/extras/CodeSteps.js +19 -0
- package/dist/components/extras/Extras.d.ts +1 -1
- package/dist/components/extras/Extras.js +116 -0
- package/dist/components/feedback/Feedback.d.ts +11 -8
- package/dist/components/feedback/Feedback.js +185 -0
- package/dist/components/feedback/Spinner.js +18 -0
- package/dist/components/feedback/Status.d.ts +6 -2
- package/dist/components/feedback/Status.js +48 -0
- package/dist/components/field/Field.d.ts +1 -1
- package/dist/components/field/Field.js +187 -0
- package/dist/components/field/FieldLoading.d.ts +1 -1
- package/dist/components/field/FieldLoading.js +18 -0
- package/dist/components/filter/FilterBar.js +96 -0
- package/dist/components/form/Form.d.ts +5 -5
- package/dist/components/form/Form.js +53 -0
- package/dist/components/icon/Icon.d.ts +2 -2
- package/dist/components/icon/Icon.js +66 -0
- package/dist/components/icon/icon-cells.js +39 -0
- package/dist/components/icon/icon-contexts.d.ts +1 -1
- package/dist/components/icon/icon-contexts.js +38 -0
- package/dist/components/icon/icon-names.d.ts +1 -1
- package/dist/components/icon/icon-names.js +376 -0
- package/dist/components/layout/Bento.d.ts +1 -1
- package/dist/components/layout/Bento.js +38 -0
- package/dist/components/layout/Layout.d.ts +1 -1
- package/dist/components/layout/Layout.js +54 -0
- package/dist/components/layout/Layout2.d.ts +36 -6
- package/dist/components/layout/Layout2.js +105 -0
- package/dist/components/layout/Layout3.js +35 -0
- package/dist/components/layout/Responsive.d.ts +1 -1
- package/dist/components/layout/Responsive.js +32 -0
- package/dist/components/list/List.d.ts +3 -2
- package/dist/components/list/List.js +82 -0
- package/dist/components/list/Lists2.d.ts +6 -4
- package/dist/components/list/Lists2.js +60 -0
- package/dist/components/media/Media.d.ts +8 -4
- package/dist/components/media/Media.js +188 -0
- package/dist/components/menu/Menu.d.ts +23 -12
- package/dist/components/menu/Menu.js +68 -0
- package/dist/components/more/More.d.ts +7 -7
- package/dist/components/more/More.js +182 -0
- package/dist/components/navigation/Navbar.d.ts +1 -1
- package/dist/components/navigation/Navbar.js +27 -0
- package/dist/components/navigation/Navigation.js +121 -0
- package/dist/components/navigation/Navigation2.d.ts +6 -2
- package/dist/components/navigation/Navigation2.js +355 -0
- package/dist/components/overlay/Drawer.d.ts +11 -6
- package/dist/components/overlay/Drawer.js +39 -0
- package/dist/components/overlay/Modal.d.ts +6 -3
- package/dist/components/overlay/Modal.js +27 -0
- package/dist/components/overlay/Overlay.d.ts +14 -9
- package/dist/components/overlay/Overlay.js +76 -0
- package/dist/components/overlay/Sheet.d.ts +11 -5
- package/dist/components/overlay/Sheet.js +52 -0
- package/dist/components/page/Page.d.ts +5 -5
- package/dist/components/page/Page.js +132 -0
- package/dist/components/page/PageParts.d.ts +5 -5
- package/dist/components/page/PageParts.js +109 -0
- package/dist/components/picker/Picker.d.ts +11 -11
- package/dist/components/picker/Picker.js +294 -0
- package/dist/components/picker/Wheel.js +132 -0
- package/dist/components/rating/Rating.d.ts +2 -1
- package/dist/components/rating/Rating.js +66 -0
- package/dist/components/select/Select.d.ts +8 -6
- package/dist/components/select/Select.js +146 -0
- package/dist/components/shell/AppShell.d.ts +3 -3
- package/dist/components/shell/AppShell.js +56 -0
- package/dist/components/shell/AppSidebar.d.ts +5 -5
- package/dist/components/shell/AppSidebar.js +62 -0
- package/dist/components/slider/Slider.d.ts +2 -1
- package/dist/components/slider/Slider.js +36 -0
- package/dist/components/surface/Surface.d.ts +16 -0
- package/dist/components/surface/Surface.js +7 -0
- package/dist/components/table/Table.d.ts +4 -3
- package/dist/components/table/Table.js +58 -0
- package/dist/components/tabs/Tabs.d.ts +1 -0
- package/dist/components/tabs/Tabs.js +120 -0
- package/dist/components/theme/Theme.d.ts +11 -6
- package/dist/components/theme/Theme.js +186 -0
- package/dist/components/theme/lens.js +104 -0
- package/dist/components/tree/Tree.js +303 -0
- package/dist/components/typography/Typography.js +43 -0
- package/dist/components/upload/Upload.js +71 -0
- package/dist/components/work/Ops.js +24 -0
- package/dist/components/work/Work.d.ts +4 -2
- package/dist/components/work/Work.js +241 -0
- package/dist/css/accordion.css +1 -0
- package/dist/css/ai.css +1 -0
- package/dist/css/app.css +1 -0
- package/dist/css/base.css +1 -0
- package/dist/css/button.css +1 -0
- package/dist/css/card.css +1 -0
- package/dist/css/chat.css +1 -0
- package/dist/css/choice.css +1 -0
- package/dist/css/color.css +1 -0
- package/dist/css/combobox.css +1 -0
- package/dist/css/command.css +1 -0
- package/dist/css/content.css +1 -0
- package/dist/css/data.css +1 -0
- package/dist/css/date.css +1 -0
- package/dist/css/display.css +1 -0
- package/dist/css/emoji.css +1 -0
- package/dist/css/extras.css +1 -0
- package/dist/css/feedback.css +1 -0
- package/dist/css/field.css +1 -0
- package/dist/css/filter.css +1 -0
- package/dist/css/form.css +1 -0
- package/dist/css/groups.json +346 -0
- package/dist/css/icon.css +1 -0
- package/dist/css/layout.css +1 -0
- package/dist/css/list.css +1 -0
- package/dist/css/media.css +1 -0
- package/dist/css/menu.css +1 -0
- package/dist/css/more.css +1 -0
- package/dist/css/navigation.css +1 -0
- package/dist/css/overlay.css +1 -0
- package/dist/css/page.css +1 -0
- package/dist/css/picker.css +1 -0
- package/dist/css/rating.css +1 -0
- package/dist/css/select.css +1 -0
- package/dist/css/shell.css +1 -0
- package/dist/css/slider.css +1 -0
- package/dist/css/surface.css +1 -0
- package/dist/css/table.css +1 -0
- package/dist/css/tabs.css +1 -0
- package/dist/css/tree.css +1 -0
- package/dist/css/typography.css +1 -0
- package/dist/css/upload.css +1 -0
- package/dist/css/work.css +1 -0
- package/dist/i18n/strings.js +842 -0
- package/dist/index.d.ts +71 -70
- package/dist/index.js +398 -7436
- package/dist/styles.css +1 -1
- package/dist/utils/Blueprint.js +131 -0
- package/dist/utils/DotField.js +32 -0
- package/dist/utils/attr.d.ts +1 -1
- package/dist/utils/attr.js +18 -0
- package/dist/utils/blueprintScene.js +161 -0
- package/dist/utils/controlled.js +11 -0
- package/dist/utils/cx.js +11 -0
- package/dist/utils/inert.js +9 -0
- package/dist/utils/refs.d.ts +3 -0
- package/dist/utils/refs.js +11 -0
- package/dist/utils/responsive.js +12 -0
- package/dist/utils/scrollEdges.js +31 -0
- package/dist/utils/space.js +10 -0
- package/dist/utils/vocabulary.d.ts +6 -0
- package/dist/utils/vocabulary.js +17 -0
- package/package.json +12 -8
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as a, jsxs as n, Fragment as $ } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef as M } from "react";
|
|
4
|
+
import { ColorArea as k, ColorThumb as p, parseColor as f, ColorField as w, Label as b, Input as A, Text as R, FieldError as T, ColorPicker as B, ColorSlider as F, SliderTrack as x, ColorSwatch as g, ColorSwatchPicker as v, ColorSwatchPickerItem as y, SliderOutput as V, ColorWheel as W, ColorWheelTrack as j } from "react-aria-components";
|
|
5
|
+
import { parseColor as la } from "react-aria-components";
|
|
6
|
+
import { cx as m } from "../../utils/cx.js";
|
|
7
|
+
import { useControlled as I } from "../../utils/controlled.js";
|
|
8
|
+
import { Badge as E } from "../display/Display.js";
|
|
9
|
+
import { useStrings as P } from "../../i18n/strings.js";
|
|
10
|
+
function U({ label: l, swatches: e, showField: o = !0, contrastWith: r, className: c, ...t }) {
|
|
11
|
+
const i = P();
|
|
12
|
+
return /* @__PURE__ */ a(B, { ...t, children: ({ color: u }) => /* @__PURE__ */ n("div", { className: m("alea-color-picker", c), children: [
|
|
13
|
+
l && /* @__PURE__ */ a("span", { className: "alea-label", children: l }),
|
|
14
|
+
/* @__PURE__ */ a(k, { colorSpace: "hsb", xChannel: "saturation", yChannel: "brightness", className: "alea-color-area", children: /* @__PURE__ */ a(p, { className: "alea-color-thumb" }) }),
|
|
15
|
+
/* @__PURE__ */ n(F, { colorSpace: "hsb", channel: "hue", className: "alea-color-slider", children: [
|
|
16
|
+
/* @__PURE__ */ a(b, { className: "alea-visually-hidden", children: i.hue }),
|
|
17
|
+
/* @__PURE__ */ a(x, { className: "alea-color-track", children: /* @__PURE__ */ a(p, { className: "alea-color-thumb" }) })
|
|
18
|
+
] }),
|
|
19
|
+
/* @__PURE__ */ n("div", { className: "alea-color-row", children: [
|
|
20
|
+
/* @__PURE__ */ a(g, { className: "alea-color-swatch" }),
|
|
21
|
+
o && /* @__PURE__ */ a(w, { className: "alea-color-field", "aria-label": i.hex, children: /* @__PURE__ */ a(A, { className: "alea-input" }) }),
|
|
22
|
+
r && /* @__PURE__ */ a(O, { foreground: u.toString("hex"), background: r })
|
|
23
|
+
] }),
|
|
24
|
+
e != null && e.length ? /* @__PURE__ */ a(v, { className: "alea-swatch-picker", children: e.map((d) => /* @__PURE__ */ a(y, { color: d, className: "alea-swatch-item", children: /* @__PURE__ */ a(g, { className: "alea-color-swatch" }) }, d)) }) : null
|
|
25
|
+
] }) });
|
|
26
|
+
}
|
|
27
|
+
function S(l) {
|
|
28
|
+
const e = l.toFormat("rgb"), o = (r) => {
|
|
29
|
+
const c = r / 255;
|
|
30
|
+
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
31
|
+
};
|
|
32
|
+
return 0.2126 * o(e.getChannelValue("red")) + 0.7152 * o(e.getChannelValue("green")) + 0.0722 * o(e.getChannelValue("blue"));
|
|
33
|
+
}
|
|
34
|
+
function L(l, e) {
|
|
35
|
+
const o = S(f(l)), r = S(f(e));
|
|
36
|
+
return (Math.max(o, r) + 0.05) / (Math.min(o, r) + 0.05);
|
|
37
|
+
}
|
|
38
|
+
const O = M(function({ foreground: e, background: o, large: r, showSample: c = !0, className: t, ...i }, u) {
|
|
39
|
+
const d = P(), h = L(e, o), s = h >= (r ? 4.5 : 7) ? "AAA" : h >= (r ? 3 : 4.5) ? "AA" : !r && h >= 3 ? "AA large" : "Fail", C = s === "Fail" ? "danger" : s === "AA large" ? "warning" : "success", N = (Math.floor(h * 100) / 100).toFixed(2);
|
|
40
|
+
return /* @__PURE__ */ n("span", { ref: u, ...i, className: m("alea-contrast", t), role: "img", "aria-label": i["aria-label"] ?? d.contrastSummary(String(N), s === "Fail" ? d.wcagFail : d.wcagPass(s)), children: [
|
|
41
|
+
c && /* @__PURE__ */ a("span", { className: "alea-contrast-sample", "aria-hidden": "true", "data-sample": "Aa", style: { color: e, background: o } }),
|
|
42
|
+
/* @__PURE__ */ n("span", { className: "alea-contrast-ratio", "aria-hidden": "true", children: [
|
|
43
|
+
N,
|
|
44
|
+
":1"
|
|
45
|
+
] }),
|
|
46
|
+
/* @__PURE__ */ a(E, { size: "sm", tone: C, "aria-hidden": "true", children: s === "Fail" ? d.contrastFail : s })
|
|
47
|
+
] });
|
|
48
|
+
});
|
|
49
|
+
function X({ size: l, className: e, style: o, colorSpace: r = "hsb", xChannel: c = "saturation", yChannel: t = "brightness", ...i }) {
|
|
50
|
+
return /* @__PURE__ */ a(k, { ...i, colorSpace: r, xChannel: c, yChannel: t, className: m("alea-color-area", e), style: { ...l ? { width: l, height: l * 0.75 } : {}, ...o }, children: /* @__PURE__ */ a(p, { className: "alea-color-thumb" }) });
|
|
51
|
+
}
|
|
52
|
+
function Y({ label: l, showValue: e, className: o, orientation: r, ...c }) {
|
|
53
|
+
return /* @__PURE__ */ n(F, { ...c, orientation: r, className: m("alea-color-slider", o), "data-orientation": r, children: [
|
|
54
|
+
(l || e) && /* @__PURE__ */ n("div", { className: "alea-color-slider-head", children: [
|
|
55
|
+
l ? /* @__PURE__ */ a(b, { className: "alea-label", children: l }) : /* @__PURE__ */ a("span", {}),
|
|
56
|
+
e && /* @__PURE__ */ a(V, { className: "alea-color-slider-value" })
|
|
57
|
+
] }),
|
|
58
|
+
/* @__PURE__ */ a(x, { className: "alea-color-track", children: /* @__PURE__ */ a(p, { className: "alea-color-thumb" }) })
|
|
59
|
+
] });
|
|
60
|
+
}
|
|
61
|
+
function Z({ size: l = 200, thickness: e = 24, className: o, ...r }) {
|
|
62
|
+
return /* @__PURE__ */ n(W, { ...r, outerRadius: l / 2, innerRadius: l / 2 - e, className: m("alea-color-wheel", o), children: [
|
|
63
|
+
/* @__PURE__ */ a(j, { className: "alea-color-wheel-track" }),
|
|
64
|
+
/* @__PURE__ */ a(p, { className: "alea-color-thumb" })
|
|
65
|
+
] });
|
|
66
|
+
}
|
|
67
|
+
function _({ label: l, description: e, errorMessage: o, showSwatch: r = !0, placeholder: c, className: t, value: i, defaultValue: u, onChange: d, ...h }) {
|
|
68
|
+
const [s, C] = I(i, u ?? null, d), N = typeof s == "string" ? (() => {
|
|
69
|
+
try {
|
|
70
|
+
return f(s);
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
})() : s;
|
|
75
|
+
return /* @__PURE__ */ a(w, { ...h, value: s, onChange: C, className: m("alea-field alea-color-input", t), children: () => /* @__PURE__ */ n($, { children: [
|
|
76
|
+
l && /* @__PURE__ */ a(b, { className: "alea-label", children: l }),
|
|
77
|
+
/* @__PURE__ */ n("div", { className: "alea-input-wrap", children: [
|
|
78
|
+
r && !h.channel && /* @__PURE__ */ a("span", { className: "alea-input-affix", "data-side": "start", "aria-hidden": "true", children: /* @__PURE__ */ a("span", { className: "alea-color-chip", style: { background: N ? N.toString("css") : "transparent" } }) }),
|
|
79
|
+
/* @__PURE__ */ a(A, { className: "alea-input", placeholder: c })
|
|
80
|
+
] }),
|
|
81
|
+
e && /* @__PURE__ */ a(R, { slot: "description", className: "alea-description", children: e }),
|
|
82
|
+
/* @__PURE__ */ a(T, { className: "alea-field-error", children: o })
|
|
83
|
+
] }) });
|
|
84
|
+
}
|
|
85
|
+
function z({ colors: l, size: e = "md", shape: o = "rounded", className: r, ...c }) {
|
|
86
|
+
return /* @__PURE__ */ a(v, { ...c, className: m("alea-swatch-picker", r), "data-size": e, "data-shape": o, children: l.map((t) => /* @__PURE__ */ a(y, { color: t, className: "alea-swatch-item", children: /* @__PURE__ */ a(g, { className: "alea-color-swatch" }) }, t)) });
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
X as ColorArea,
|
|
90
|
+
_ as ColorField,
|
|
91
|
+
U as ColorPicker,
|
|
92
|
+
Y as ColorSlider,
|
|
93
|
+
z as ColorSwatchPicker,
|
|
94
|
+
Z as ColorWheel,
|
|
95
|
+
O as ContrastBadge,
|
|
96
|
+
L as contrastRatio,
|
|
97
|
+
la as parseColor
|
|
98
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
1
|
+
import { type ReactNode, type HTMLAttributes } from 'react';
|
|
2
2
|
import { type Key } from 'react-aria-components';
|
|
3
3
|
import type { MotionProp } from '@alea-design/motion';
|
|
4
|
-
import { type MatchStyle } from './Highlight';
|
|
4
|
+
import { type MatchStyle } from './Highlight.js';
|
|
5
5
|
export interface AutocompleteItem {
|
|
6
6
|
id: Key;
|
|
7
7
|
label: string;
|
|
@@ -9,7 +9,7 @@ export interface AutocompleteItem {
|
|
|
9
9
|
group?: string;
|
|
10
10
|
icon?: ReactNode;
|
|
11
11
|
}
|
|
12
|
-
export { Highlight, getMatchRanges } from './Highlight';
|
|
12
|
+
export { Highlight, getMatchRanges } from './Highlight.js';
|
|
13
13
|
export interface AutocompleteProps {
|
|
14
14
|
/** The visible label. */
|
|
15
15
|
label?: ReactNode;
|
|
@@ -44,7 +44,7 @@ export interface AutocompleteProps {
|
|
|
44
44
|
}
|
|
45
45
|
/** Search with suggestions: static or loaded as you type, grouped, matches highlighted, recent searches when empty. */
|
|
46
46
|
export declare function Autocomplete({ motion, label, description, placeholder, items, loadItems, debounce, recent, isLoading, highlightMatch, matchStyle, onSelect, onSubmit, minChars, className }: AutocompleteProps): import("react").JSX.Element;
|
|
47
|
-
export interface MultiSelectProps {
|
|
47
|
+
export interface MultiSelectProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {
|
|
48
48
|
/** The visible label. */
|
|
49
49
|
label?: ReactNode;
|
|
50
50
|
/** Help text shown under the field. */
|
|
@@ -73,4 +73,4 @@ export interface MultiSelectProps {
|
|
|
73
73
|
motion?: MotionProp;
|
|
74
74
|
}
|
|
75
75
|
/** Pick several options from a list with checkboxes; the trigger summarizes the picks. */
|
|
76
|
-
export declare
|
|
76
|
+
export declare const MultiSelect: import("react").ForwardRefExoticComponent<MultiSelectProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs as n, jsx as e, Fragment as X } from "react/jsx-runtime";
|
|
3
|
+
import { useState as S, useRef as G, useEffect as J, useMemo as j, forwardRef as U, useId as Y } from "react";
|
|
4
|
+
import { useFilter as O, ComboBox as Z, Input as _, Button as P, ListBox as R, ListBoxSection as ee, Header as ae, Collection as te, ListBoxItem as I, DialogTrigger as le, Dialog as se } from "react-aria-components";
|
|
5
|
+
import { Search as ie, X as ne, Clock as oe, ChevronDown as re, Check as ce } from "lucide-react";
|
|
6
|
+
import { cx as q } from "../../utils/cx.js";
|
|
7
|
+
import { Label as de, Description as pe, SearchField as me } from "../field/Field.js";
|
|
8
|
+
import { Popover as H } from "../overlay/Overlay.js";
|
|
9
|
+
import { Spinner as ue } from "../feedback/Spinner.js";
|
|
10
|
+
import { loadingAttrs as he } from "../field/FieldLoading.js";
|
|
11
|
+
import { useStrings as Q } from "../../i18n/strings.js";
|
|
12
|
+
import { OptionMatchContext as fe, MatchedText as K } from "./Highlight.js";
|
|
13
|
+
import { Highlight as Fe, getMatchRanges as Le } from "./Highlight.js";
|
|
14
|
+
function Ae({ motion: D, label: T, description: o, placeholder: b, items: h, loadItems: m, debounce: B = 250, recent: c, isLoading: F, highlightMatch: L = !0, matchStyle: E, onSelect: f, onSubmit: v, minChars: y = 1, className: V }) {
|
|
15
|
+
const s = Q();
|
|
16
|
+
b ?? (b = s.search);
|
|
17
|
+
const [i, x] = S(""), [w, g] = S([]), [$, C] = S(!1), d = $ || !!F, { contains: k } = O({ sensitivity: "base" }), r = G(null);
|
|
18
|
+
J(() => {
|
|
19
|
+
if (!m) return;
|
|
20
|
+
if (i.trim().length < y) {
|
|
21
|
+
g([]), C(!1);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
C(!0);
|
|
25
|
+
const a = setTimeout(async () => {
|
|
26
|
+
var z;
|
|
27
|
+
(z = r.current) == null || z.abort();
|
|
28
|
+
const l = new AbortController();
|
|
29
|
+
r.current = l;
|
|
30
|
+
try {
|
|
31
|
+
const A = await m(i, l.signal);
|
|
32
|
+
l.signal.aborted || g(A);
|
|
33
|
+
} catch {
|
|
34
|
+
} finally {
|
|
35
|
+
l.signal.aborted || C(!1);
|
|
36
|
+
}
|
|
37
|
+
}, B);
|
|
38
|
+
return () => clearTimeout(a);
|
|
39
|
+
}, [i, m, B, y]);
|
|
40
|
+
const p = !i && (c == null ? void 0 : c.length), u = p ? c : m ? w : i.trim().length < y ? [] : (h || []).filter((a) => k(a.label, i) || a.description && k(a.description, i)), N = j(() => {
|
|
41
|
+
const a = [];
|
|
42
|
+
for (const l of u) {
|
|
43
|
+
const z = p ? s.recent : l.group || "";
|
|
44
|
+
let A = a.find((W) => W.id === z);
|
|
45
|
+
A || a.push(A = { id: z, items: [] }), A.items.push(l);
|
|
46
|
+
}
|
|
47
|
+
return a;
|
|
48
|
+
}, [u, p]), t = j(() => new Map(u.map((a) => [a.id, a])), [u]), M = j(() => ({ query: p ? "" : i, style: E ?? "tint", match: "words" }), [i, E, p]);
|
|
49
|
+
return /* @__PURE__ */ n(
|
|
50
|
+
Z,
|
|
51
|
+
{
|
|
52
|
+
className: q("alea-field alea-autocomplete", V),
|
|
53
|
+
...he(d),
|
|
54
|
+
items: N,
|
|
55
|
+
inputValue: i,
|
|
56
|
+
onInputChange: x,
|
|
57
|
+
selectedKey: null,
|
|
58
|
+
allowsCustomValue: !0,
|
|
59
|
+
allowsEmptyCollection: !0,
|
|
60
|
+
menuTrigger: "focus",
|
|
61
|
+
onSelectionChange: (a) => {
|
|
62
|
+
const l = a != null ? t.get(a) : void 0;
|
|
63
|
+
l && (x(l.label), f == null || f(l));
|
|
64
|
+
},
|
|
65
|
+
onKeyDown: (a) => {
|
|
66
|
+
a.key === "Enter" && !a.target.getAttribute("aria-activedescendant") && (v == null || v(i));
|
|
67
|
+
},
|
|
68
|
+
children: [
|
|
69
|
+
T && /* @__PURE__ */ e(de, { children: T }),
|
|
70
|
+
/* @__PURE__ */ n("div", { className: "alea-input-wrap", children: [
|
|
71
|
+
/* @__PURE__ */ e("span", { className: "alea-input-affix", "data-side": "start", "aria-hidden": "true", children: /* @__PURE__ */ e(ie, { size: 16 }) }),
|
|
72
|
+
/* @__PURE__ */ e(_, { className: "alea-input", placeholder: b, "aria-busy": d || void 0 }),
|
|
73
|
+
d ? /* @__PURE__ */ e("span", { className: "alea-autocomplete-spin", children: /* @__PURE__ */ e(ue, { size: "sm", "aria-label": s.loadingSuggestions }) }) : i ? /* @__PURE__ */ e(P, { className: "alea-input-clear alea-focus-ring", "aria-label": s.clear, onPress: () => x(""), children: /* @__PURE__ */ e(ne, { size: 14 }) }) : null
|
|
74
|
+
] }),
|
|
75
|
+
o && /* @__PURE__ */ e(pe, { children: o }),
|
|
76
|
+
/* @__PURE__ */ e(H, { className: "alea-popover alea-select-popover", motion: D, children: /* @__PURE__ */ e(fe.Provider, { value: M, children: /* @__PURE__ */ e(R, { className: "alea-listbox", renderEmptyState: () => /* @__PURE__ */ e("p", { className: "alea-listbox-empty", children: d ? s.searching : i ? s.nothingFor(i) : s.startTyping }), children: (a) => /* @__PURE__ */ n(ee, { id: a.id, className: "alea-option-section", children: [
|
|
77
|
+
a.id && /* @__PURE__ */ e(ae, { className: "alea-option-header", children: a.id }),
|
|
78
|
+
/* @__PURE__ */ e(te, { items: a.items, children: (l) => /* @__PURE__ */ n(I, { id: l.id, textValue: l.label, className: "alea-option", children: [
|
|
79
|
+
p ? /* @__PURE__ */ e(oe, { size: 16, className: "alea-option-icon", "aria-hidden": "true" }) : l.icon && /* @__PURE__ */ e("span", { className: "alea-option-icon", "aria-hidden": "true", children: l.icon }),
|
|
80
|
+
/* @__PURE__ */ n("span", { className: "alea-option-text", children: [
|
|
81
|
+
/* @__PURE__ */ e("span", { children: L ? /* @__PURE__ */ e(K, { text: l.label }) : l.label }),
|
|
82
|
+
l.description && /* @__PURE__ */ e("span", { className: "alea-option-desc", children: L ? /* @__PURE__ */ e(K, { text: l.description }) : l.description })
|
|
83
|
+
] })
|
|
84
|
+
] }) })
|
|
85
|
+
] }) }) }) })
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const Se = U(function({ motion: T, label: o, description: b, items: h, value: m, defaultValue: B = [], onChange: c, placeholder: F, searchable: L, showActions: E = !0, isDisabled: f, className: v, ...y }, V) {
|
|
91
|
+
const s = Q();
|
|
92
|
+
F ?? (F = s.selectPlaceholder);
|
|
93
|
+
const [i, x] = S(B), w = m ?? i, [g, $] = S(""), { contains: C } = O({ sensitivity: "base" }), d = (t) => {
|
|
94
|
+
m === void 0 && x(t), c == null || c(t);
|
|
95
|
+
}, k = h.filter((t) => C(t.label, g)), r = h.filter((t) => w.includes(t.id)).map((t) => t.label), p = r.length ? r.length <= 2 ? r.join(", ") : `${r.slice(0, 2).join(", ")} +${r.length - 2}` : F, u = L ?? h.length > 8, N = "alea-ms" + Y().replace(/:/g, "");
|
|
96
|
+
return /* @__PURE__ */ n("div", { ref: V, ...y, className: q("alea-field alea-multiselect", v), "data-disabled": f || void 0, children: [
|
|
97
|
+
o && /* @__PURE__ */ e("span", { className: "alea-label", id: N, children: o }),
|
|
98
|
+
/* @__PURE__ */ n(le, { children: [
|
|
99
|
+
/* @__PURE__ */ n(P, { className: "alea-select-trigger alea-focus-ring", "aria-labelledby": o ? `${N} ${N}-v` : void 0, isDisabled: f, children: [
|
|
100
|
+
/* @__PURE__ */ e("span", { id: `${N}-v`, className: "alea-select-value", "data-placeholder": !r.length || void 0, children: p }),
|
|
101
|
+
/* @__PURE__ */ e(re, { size: 16, "aria-hidden": "true", className: "alea-select-chevron" })
|
|
102
|
+
] }),
|
|
103
|
+
/* @__PURE__ */ e(H, { className: "alea-popover alea-select-popover", placement: "bottom start", motion: T, children: /* @__PURE__ */ n(se, { "aria-label": typeof o == "string" ? o : s.options, className: "alea-multiselect-dialog", children: [
|
|
104
|
+
u && /* @__PURE__ */ e(me, { "aria-label": s.filterOptions, size: "sm", value: g, onChange: $, autoFocus: !0 }),
|
|
105
|
+
E && /* @__PURE__ */ n("div", { className: "alea-multiselect-actions", children: [
|
|
106
|
+
/* @__PURE__ */ e("button", { type: "button", className: "alea-link alea-focus-ring", "data-variant": "standalone", onClick: () => d(Array.from(/* @__PURE__ */ new Set([...w, ...k.map((t) => t.id)]))), children: g ? s.selectAllShown : s.selectAll }),
|
|
107
|
+
/* @__PURE__ */ e("button", { type: "button", className: "alea-link alea-focus-ring", "data-variant": "muted", onClick: () => d([]), children: s.clear })
|
|
108
|
+
] }),
|
|
109
|
+
/* @__PURE__ */ e(R, { "aria-label": typeof o == "string" ? o : s.options, escapeKeyBehavior: "none", items: k, selectionMode: "multiple", selectedKeys: w, onSelectionChange: (t) => d(t === "all" ? h.map((M) => M.id) : [...t]), className: "alea-listbox alea-multiselect-list", autoFocus: !u, renderEmptyState: () => /* @__PURE__ */ e("p", { className: "alea-listbox-empty", children: s.noMatches }), children: (t) => /* @__PURE__ */ e(I, { id: t.id, textValue: t.label, className: "alea-option", children: ({ isSelected: M }) => /* @__PURE__ */ n(X, { children: [
|
|
110
|
+
/* @__PURE__ */ e("span", { className: "alea-check-box alea-ms-box", "data-on": M || void 0, "aria-hidden": "true", children: /* @__PURE__ */ e(ce, { size: 12, strokeWidth: 3 }) }),
|
|
111
|
+
/* @__PURE__ */ n("span", { className: "alea-option-text", children: [
|
|
112
|
+
/* @__PURE__ */ e("span", { children: t.label }),
|
|
113
|
+
t.description && /* @__PURE__ */ e("span", { className: "alea-option-desc", children: t.description })
|
|
114
|
+
] })
|
|
115
|
+
] }) }) })
|
|
116
|
+
] }) })
|
|
117
|
+
] }),
|
|
118
|
+
b && /* @__PURE__ */ e("span", { className: "alea-description", children: b })
|
|
119
|
+
] });
|
|
120
|
+
});
|
|
121
|
+
export {
|
|
122
|
+
Ae as Autocomplete,
|
|
123
|
+
Fe as Highlight,
|
|
124
|
+
Se as MultiSelect,
|
|
125
|
+
Le as getMatchRanges
|
|
126
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
2
|
import { type ComboBoxProps as RACComboBoxProps, type ValidationResult, type Key } from 'react-aria-components';
|
|
3
3
|
import type { MotionProp } from '@alea-design/motion';
|
|
4
|
-
import { type FieldSize, type FieldVariant } from '../field/Field';
|
|
5
|
-
import type { Responsive } from '../../utils/responsive';
|
|
6
|
-
import { type SelectOption } from '../select/Select';
|
|
7
|
-
import { type MatchStyle } from './Highlight';
|
|
4
|
+
import { type FieldSize, type FieldVariant } from '../field/Field.js';
|
|
5
|
+
import type { Responsive } from '../../utils/responsive.js';
|
|
6
|
+
import { type SelectOption } from '../select/Select.js';
|
|
7
|
+
import { type MatchStyle } from './Highlight.js';
|
|
8
8
|
export interface ComboBoxProps<T extends object = SelectOption> extends Omit<RACComboBoxProps<T>, 'children'> {
|
|
9
9
|
/** The visible label. */
|
|
10
10
|
label?: ReactNode;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs as d, jsx as t } from "react/jsx-runtime";
|
|
3
|
+
import { useState as q, useMemo as K, useContext as R } from "react";
|
|
4
|
+
import { useFilter as T, ComboBox as P, Input as X, Button as L, Virtualizer as A, ListLayout as E, ComboBoxStateContext as j, ListBox as $ } from "react-aria-components";
|
|
5
|
+
import { ChevronDown as G, X as z } from "lucide-react";
|
|
6
|
+
import { withBase as J, cx as Q } from "../../utils/cx.js";
|
|
7
|
+
import { Label as U, Description as W, FieldError as Y } from "../field/Field.js";
|
|
8
|
+
import { FieldSpinner as Z, loadingAttrs as _ } from "../field/FieldLoading.js";
|
|
9
|
+
import { responsiveAttrs as k } from "../../utils/responsive.js";
|
|
10
|
+
import { Popover as ee } from "../overlay/Overlay.js";
|
|
11
|
+
import { SelectItem as te } from "../select/Select.js";
|
|
12
|
+
import { useStrings as D } from "../../i18n/strings.js";
|
|
13
|
+
import { OptionMatchContext as ae } from "./Highlight.js";
|
|
14
|
+
function le({ style: r, children: i }) {
|
|
15
|
+
const n = R(j), u = n && !(n.selectedItem && n.inputValue === n.selectedItem.textValue) ? n.inputValue : "", s = K(() => ({ query: u, style: r ?? "tint", match: "phrase" }), [u, r]);
|
|
16
|
+
return /* @__PURE__ */ t(ae.Provider, { value: s, children: i });
|
|
17
|
+
}
|
|
18
|
+
function ie() {
|
|
19
|
+
const r = D(), i = R(j);
|
|
20
|
+
return !i || !i.inputValue && i.selectedKey == null ? null : /* @__PURE__ */ t(L, { slot: null, className: "alea-input-clear alea-focus-ring", "aria-label": r.clear, onPress: () => {
|
|
21
|
+
i.setSelectedKey(null), i.setInputValue("");
|
|
22
|
+
}, children: /* @__PURE__ */ t(z, { size: 14 }) });
|
|
23
|
+
}
|
|
24
|
+
function ne({ motion: r, label: i, description: n, errorMessage: u, warningMessage: s, showOptional: v, placeholder: x, children: N, emptyText: m, size: V, variant: S = "outline", labelPosition: g = "top", prefix: w, isClearable: B, highlightMatch: p, matchStyle: I, isLoading: y, footer: a, virtualized: o, className: C, ...f }) {
|
|
25
|
+
const c = D();
|
|
26
|
+
m ?? (m = c.noMatches);
|
|
27
|
+
const { contains: O } = T({ sensitivity: "base" }), h = /* @__PURE__ */ t($, { className: "alea-listbox", renderEmptyState: () => /* @__PURE__ */ t("p", { className: "alea-listbox-empty", children: y ? c.loading : m }), children: N ?? ((l) => /* @__PURE__ */ t(te, { id: l.id, textValue: l.textValue ?? (typeof l.label == "string" ? l.label : String(l.id)), description: l.description, icon: l.icon, isDisabled: l.isDisabled, children: l.label })) });
|
|
28
|
+
return /* @__PURE__ */ d(
|
|
29
|
+
P,
|
|
30
|
+
{
|
|
31
|
+
defaultFilter: O,
|
|
32
|
+
menuTrigger: "input",
|
|
33
|
+
allowsEmptyCollection: !0,
|
|
34
|
+
...f,
|
|
35
|
+
className: J("alea-field alea-combobox", C),
|
|
36
|
+
...k("size", V, "md"),
|
|
37
|
+
"data-variant": S !== "outline" ? S : void 0,
|
|
38
|
+
"data-label-position": g !== "top" ? g : void 0,
|
|
39
|
+
"data-warning": s ? !0 : void 0,
|
|
40
|
+
..._(y),
|
|
41
|
+
children: [
|
|
42
|
+
i && /* @__PURE__ */ d(U, { children: [
|
|
43
|
+
i,
|
|
44
|
+
f.isRequired && /* @__PURE__ */ t("span", { className: "alea-label-required", "aria-hidden": "true", children: " *" }),
|
|
45
|
+
v && !f.isRequired && /* @__PURE__ */ d("span", { className: "alea-label-optional", children: [
|
|
46
|
+
" (",
|
|
47
|
+
c.optional,
|
|
48
|
+
")"
|
|
49
|
+
] })
|
|
50
|
+
] }),
|
|
51
|
+
/* @__PURE__ */ d("div", { className: "alea-input-wrap", children: [
|
|
52
|
+
w && /* @__PURE__ */ t("span", { className: "alea-input-affix", "data-side": "start", "aria-hidden": "true", children: w }),
|
|
53
|
+
/* @__PURE__ */ t(X, { className: "alea-input", placeholder: x, "aria-busy": y || void 0 }),
|
|
54
|
+
y && /* @__PURE__ */ t(Z, {}),
|
|
55
|
+
B && !f.isDisabled && !f.isReadOnly && /* @__PURE__ */ t(ie, {}),
|
|
56
|
+
/* @__PURE__ */ t(L, { className: "alea-input-clear alea-focus-ring", "aria-label": c.showSuggestions, children: /* @__PURE__ */ t(G, { size: 16 }) })
|
|
57
|
+
] }),
|
|
58
|
+
(n || s) && /* @__PURE__ */ d(W, { children: [
|
|
59
|
+
n,
|
|
60
|
+
s && /* @__PURE__ */ t("span", { className: "alea-field-warning", children: s })
|
|
61
|
+
] }),
|
|
62
|
+
/* @__PURE__ */ t(Y, { children: u }),
|
|
63
|
+
/* @__PURE__ */ d(ee, { className: "alea-popover alea-select-popover", motion: r, children: [
|
|
64
|
+
p ? /* @__PURE__ */ t(le, { style: I, children: o ? /* @__PURE__ */ t(A, { layout: E, layoutOptions: { rowHeight: o }, children: h }) : h }) : o ? /* @__PURE__ */ t(A, { layout: E, layoutOptions: { rowHeight: o }, children: h }) : h,
|
|
65
|
+
a && /* @__PURE__ */ t("div", { className: "alea-select-footer", children: a })
|
|
66
|
+
] })
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
function ye({ label: r, description: i, items: n, value: u, defaultValue: s = [], onChange: v, placeholder: x, allowsCustomValue: N, max: m, isLoading: V, highlightMatch: S, isDisabled: g, className: w, style: B }) {
|
|
72
|
+
const p = D();
|
|
73
|
+
x ?? (x = p.typeToAdd);
|
|
74
|
+
const [I, y] = q(s), a = u ?? I, [o, C] = q(""), { contains: f } = T({ sensitivity: "base" }), c = (e) => {
|
|
75
|
+
u === void 0 && y(e), v == null || v(e);
|
|
76
|
+
}, O = K(() => new Map(n.map((e) => [e.id, e])), [n]), h = n.filter((e) => !a.includes(e.id)), l = m !== void 0 && a.length >= m, F = (e) => {
|
|
77
|
+
e == null || a.includes(e) || l || (c([...a, e]), C(""));
|
|
78
|
+
};
|
|
79
|
+
return /* @__PURE__ */ d("div", { className: Q("alea-field alea-tagfield", w), style: B, "data-disabled": g || void 0, children: [
|
|
80
|
+
/* @__PURE__ */ t(
|
|
81
|
+
ne,
|
|
82
|
+
{
|
|
83
|
+
label: r,
|
|
84
|
+
isLoading: V,
|
|
85
|
+
highlightMatch: S,
|
|
86
|
+
description: i ?? (m ? p.nOfTotal(a.length, m) : void 0),
|
|
87
|
+
items: h.filter((e) => f(e.textValue ?? (typeof e.label == "string" ? e.label : String(e.id)), o)),
|
|
88
|
+
inputValue: o,
|
|
89
|
+
onInputChange: C,
|
|
90
|
+
selectedKey: null,
|
|
91
|
+
onSelectionChange: F,
|
|
92
|
+
allowsCustomValue: N,
|
|
93
|
+
isDisabled: g || l,
|
|
94
|
+
placeholder: l ? p.limitReached : x,
|
|
95
|
+
onKeyDown: (e) => {
|
|
96
|
+
e.key === "Enter" && N && o.trim() && !e.target.getAttribute("aria-activedescendant") && !h.some((b) => String(b.label).toLowerCase() === o.trim().toLowerCase()) && F(o.trim()), e.key === "Backspace" && !o && a.length && c(a.slice(0, -1));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
),
|
|
100
|
+
a.length > 0 && /* @__PURE__ */ t("ul", { className: "alea-tagfield-tags", "aria-label": p.selected, children: a.map((e) => {
|
|
101
|
+
const b = O.get(e), H = b && typeof b.label == "string" ? b.label : String(e);
|
|
102
|
+
return /* @__PURE__ */ d("li", { className: "alea-tag", "data-allows-removing": "true", children: [
|
|
103
|
+
b ? b.label : String(e),
|
|
104
|
+
!g && /* @__PURE__ */ t("button", { type: "button", className: "alea-tag-remove alea-focus-ring", "aria-label": p.removeItem(String(H)), onClick: () => c(a.filter((M) => M !== e)), children: /* @__PURE__ */ t(z, { size: 12 }) })
|
|
105
|
+
] }, String(e));
|
|
106
|
+
}) })
|
|
107
|
+
] });
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
ne as ComboBox,
|
|
111
|
+
ye as TagField
|
|
112
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as a, Fragment as f } from "react/jsx-runtime";
|
|
3
|
+
import { createContext as g, useContext as d } from "react";
|
|
4
|
+
const m = (t) => {
|
|
5
|
+
const n = t.normalize("NFD").replace(new RegExp("\\p{M}", "gu"), "").toLowerCase();
|
|
6
|
+
if (n.length === 1) return n;
|
|
7
|
+
const r = t.toLowerCase();
|
|
8
|
+
return r.length === 1 ? r : t;
|
|
9
|
+
}, p = (t) => {
|
|
10
|
+
let n = "";
|
|
11
|
+
for (let r = 0; r < t.length; r++) n += m(t[r]);
|
|
12
|
+
return n;
|
|
13
|
+
};
|
|
14
|
+
function M(t, n, r = "words") {
|
|
15
|
+
const i = n.trim();
|
|
16
|
+
if (!i) return [];
|
|
17
|
+
const h = (r === "phrase" ? [i.replace(/\s+/g, " ")] : i.split(/\s+/)).map(p).filter(Boolean), c = p(t), s = [];
|
|
18
|
+
for (const o of h) for (let e = c.indexOf(o); e !== -1; e = c.indexOf(o, e + 1)) s.push([e, e + o.length]);
|
|
19
|
+
s.sort((o, e) => o[0] - e[0] || o[1] - e[1]);
|
|
20
|
+
const l = [];
|
|
21
|
+
for (const [o, e] of s) {
|
|
22
|
+
const u = l[l.length - 1];
|
|
23
|
+
u && o < u[1] ? u[1] = Math.max(u[1], e) : l.push([o, e]);
|
|
24
|
+
}
|
|
25
|
+
return l.map(([o, e]) => {
|
|
26
|
+
for (; e < t.length && new RegExp("\\p{M}", "u").test(t[e]); ) e++;
|
|
27
|
+
return [o, e];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function w({ text: t, query: n, match: r = "words", matchStyle: i = "tint" }) {
|
|
31
|
+
const h = M(t, n, r);
|
|
32
|
+
if (!h.length) return /* @__PURE__ */ a(f, { children: t });
|
|
33
|
+
const c = [];
|
|
34
|
+
let s = 0;
|
|
35
|
+
return h.forEach(([l, o], e) => {
|
|
36
|
+
l > s && c.push(t.slice(s, l)), c.push(/* @__PURE__ */ a("mark", { className: "alea-mark", "data-style": i !== "tint" ? i : void 0, children: t.slice(l, o) }, e)), s = o;
|
|
37
|
+
}), s < t.length && c.push(t.slice(s)), /* @__PURE__ */ a(f, { children: c });
|
|
38
|
+
}
|
|
39
|
+
function k({ text: t }) {
|
|
40
|
+
const n = C();
|
|
41
|
+
return n != null && n.query ? /* @__PURE__ */ a(w, { text: t, query: n.query, match: n.match, matchStyle: n.style }) : /* @__PURE__ */ a(f, { children: t });
|
|
42
|
+
}
|
|
43
|
+
const y = g(null), C = () => d(y);
|
|
44
|
+
export {
|
|
45
|
+
w as Highlight,
|
|
46
|
+
k as MatchedText,
|
|
47
|
+
y as OptionMatchContext,
|
|
48
|
+
M as getMatchRanges,
|
|
49
|
+
C as useOptionMatch
|
|
50
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
1
|
+
import { type ReactNode, type CSSProperties } from 'react';
|
|
2
2
|
import type { MotionProp } from '@alea-design/motion';
|
|
3
3
|
import { type Key } from 'react-aria-components';
|
|
4
|
+
import { type SurfaceProps } from '../surface/Surface.js';
|
|
4
5
|
export interface Command {
|
|
5
6
|
id: Key;
|
|
6
7
|
label: string;
|
|
@@ -15,11 +16,13 @@ export interface Command {
|
|
|
15
16
|
keywords?: string[];
|
|
16
17
|
onAction: () => void;
|
|
17
18
|
}
|
|
18
|
-
export interface CommandPaletteProps {
|
|
19
|
+
export interface CommandPaletteProps extends SurfaceProps {
|
|
19
20
|
/** The commands, in groups: id, label, icon, shortcut, keywords and onAction. */
|
|
20
21
|
commands: Command[];
|
|
21
22
|
/** Whether it is open (controlled). Without it, the shortcut toggles it. */
|
|
22
23
|
isOpen?: boolean;
|
|
24
|
+
/** Open at first (uncontrolled). */
|
|
25
|
+
defaultOpen?: boolean;
|
|
23
26
|
/** Called when it opens or closes. */
|
|
24
27
|
onOpenChange?: (open: boolean) => void;
|
|
25
28
|
/** Opens with ⌘K / Ctrl+K anywhere. Default true. */
|
|
@@ -30,6 +33,10 @@ export interface CommandPaletteProps {
|
|
|
30
33
|
emptyText?: ReactNode;
|
|
31
34
|
/** How it enters and leaves (default rise): a preset, false, or options. */
|
|
32
35
|
motion?: MotionProp;
|
|
36
|
+
/** Extra class names for the palette. */
|
|
37
|
+
className?: string;
|
|
38
|
+
/** Inline style for the palette. */
|
|
39
|
+
style?: CSSProperties;
|
|
33
40
|
}
|
|
34
41
|
/** Search every action and page from the keyboard (⌘K). */
|
|
35
|
-
export declare
|
|
42
|
+
export declare const CommandPalette: import("react").ForwardRefExoticComponent<CommandPaletteProps & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as o, jsxs as n } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef as A, useState as C, useEffect as D, useMemo as h } from "react";
|
|
4
|
+
import { cx as F } from "../../utils/cx.js";
|
|
5
|
+
import { useFilter as I, Autocomplete as L, SearchField as g, Input as z, Menu as R, MenuSection as H, Header as V, Collection as q, MenuItem as B, Keyboard as G } from "react-aria-components";
|
|
6
|
+
import { Search as J } from "lucide-react";
|
|
7
|
+
import { DialogModal as Q, Dialog as U } from "../overlay/Overlay.js";
|
|
8
|
+
import { Kbd as W } from "../typography/Typography.js";
|
|
9
|
+
import { useStrings as X } from "../../i18n/strings.js";
|
|
10
|
+
const oe = A(function({ commands: s, isOpen: c, defaultOpen: f, onOpenChange: l, motion: N, hotkey: w = !0, placeholder: m, emptyText: d, className: y, style: b, surface: v, radius: M }, S) {
|
|
11
|
+
const i = X();
|
|
12
|
+
m ?? (m = i.commandPlaceholder), d ?? (d = i.noResults);
|
|
13
|
+
const [k, x] = C(f ?? !1), u = c ?? k, p = (a) => {
|
|
14
|
+
c === void 0 && x(a), l == null || l(a);
|
|
15
|
+
};
|
|
16
|
+
D(() => {
|
|
17
|
+
if (!w) return;
|
|
18
|
+
const a = (t) => {
|
|
19
|
+
t.key.toLowerCase() === "k" && (t.metaKey || t.ctrlKey) && (t.preventDefault(), p(!u));
|
|
20
|
+
};
|
|
21
|
+
return window.addEventListener("keydown", a), () => window.removeEventListener("keydown", a);
|
|
22
|
+
});
|
|
23
|
+
const { contains: E } = I({ sensitivity: "base" }), K = h(() => {
|
|
24
|
+
const a = [];
|
|
25
|
+
for (const t of s) {
|
|
26
|
+
const e = t.group || "";
|
|
27
|
+
let r = a.find((j) => j.id === e);
|
|
28
|
+
r || a.push(r = { id: e, title: e, items: [] }), r.items.push(t);
|
|
29
|
+
}
|
|
30
|
+
return a;
|
|
31
|
+
}, [s]), P = h(() => new Map(s.map((a) => [a.id, a])), [s]);
|
|
32
|
+
return /* @__PURE__ */ o(Q, { isOpen: u, onOpenChange: p, size: "md", className: "alea-command-overlay", motion: N, surface: v, radius: M, children: /* @__PURE__ */ o(U, { ref: S, style: b, "aria-label": i.commandPalette, hideClose: !0, className: F("alea-command", y), children: ({ close: a }) => /* @__PURE__ */ n(L, { filter: (t, e) => E(t, e), children: [
|
|
33
|
+
/* @__PURE__ */ n(g, { "aria-label": i.searchCommands, autoFocus: !0, className: "alea-command-search", children: [
|
|
34
|
+
/* @__PURE__ */ o(J, { size: 18, "aria-hidden": "true" }),
|
|
35
|
+
/* @__PURE__ */ o(z, { placeholder: m, className: "alea-command-input" }),
|
|
36
|
+
/* @__PURE__ */ o(W, { children: i.esc })
|
|
37
|
+
] }),
|
|
38
|
+
/* @__PURE__ */ o(R, { items: K, className: "alea-command-list", onAction: (t) => {
|
|
39
|
+
const e = P.get(t);
|
|
40
|
+
a(), e == null || e.onAction();
|
|
41
|
+
}, renderEmptyState: () => /* @__PURE__ */ o("p", { className: "alea-command-empty", children: d }), children: (t) => /* @__PURE__ */ n(H, { id: t.id, className: "alea-option-section", children: [
|
|
42
|
+
t.title && /* @__PURE__ */ o(V, { className: "alea-option-header", children: t.title }),
|
|
43
|
+
/* @__PURE__ */ o(q, { items: t.items, children: (e) => /* @__PURE__ */ n(B, { id: e.id, textValue: [e.label, ...e.keywords || []].join(" "), className: "alea-option alea-command-item", children: [
|
|
44
|
+
e.icon && /* @__PURE__ */ o("span", { className: "alea-option-icon", "aria-hidden": "true", children: e.icon }),
|
|
45
|
+
/* @__PURE__ */ n("span", { className: "alea-option-text", children: [
|
|
46
|
+
/* @__PURE__ */ o("span", { slot: "label", children: e.label }),
|
|
47
|
+
e.description && /* @__PURE__ */ o("span", { className: "alea-option-desc", slot: "description", children: e.description })
|
|
48
|
+
] }),
|
|
49
|
+
e.shortcut && /* @__PURE__ */ o(G, { className: "alea-menu-shortcut", children: e.shortcut })
|
|
50
|
+
] }) })
|
|
51
|
+
] }) })
|
|
52
|
+
] }) }) });
|
|
53
|
+
});
|
|
54
|
+
export {
|
|
55
|
+
oe as CommandPalette
|
|
56
|
+
};
|