@antadesign/anta 0.3.4 → 0.3.5

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.
Files changed (38) hide show
  1. package/dist/components/Calendar.d.ts +3 -2
  2. package/dist/components/Calendar.js +18 -7
  3. package/dist/components/InputDate.d.ts +3 -2
  4. package/dist/components/InputDate.js +36 -91
  5. package/dist/components/InputDate.module.css +1 -1
  6. package/dist/components/InputTime.d.ts +105 -0
  7. package/dist/components/InputTime.js +110 -0
  8. package/dist/components/Menu.d.ts +6 -1
  9. package/dist/components/Menu.js +2 -0
  10. package/dist/components/Select.d.ts +24 -6
  11. package/dist/components/Select.js +12 -2
  12. package/dist/components/Select.module.css +1 -1
  13. package/dist/components/SelectFaceted.d.ts +184 -0
  14. package/dist/components/SelectFaceted.js +331 -0
  15. package/dist/components/SelectFaceted.module.css +1 -0
  16. package/dist/components/Tabs.d.ts +6 -0
  17. package/dist/components/Tabs.js +3 -1
  18. package/dist/elements/a-button.css +1 -1
  19. package/dist/elements/a-calendar.css +1 -1
  20. package/dist/elements/a-input-time.css +1 -0
  21. package/dist/elements/a-input-time.d.ts +27 -0
  22. package/dist/elements/a-input-time.js +856 -0
  23. package/dist/elements/a-input.css +1 -1
  24. package/dist/elements/a-input.js +7 -1
  25. package/dist/elements/a-menu-item.css +1 -1
  26. package/dist/elements/a-menu.js +11 -1
  27. package/dist/elements/a-tab.css +1 -1
  28. package/dist/elements/a-tabs.css +1 -1
  29. package/dist/elements/a-tooltip.js +1 -1
  30. package/dist/elements/index.d.ts +1 -0
  31. package/dist/elements/index.js +3 -0
  32. package/dist/general_types.d.ts +52 -0
  33. package/dist/index.d.ts +4 -0
  34. package/dist/index.js +4 -0
  35. package/dist/jsx-runtime.d.ts +2 -1
  36. package/dist/reset.css +1 -1
  37. package/dist/tokens.css +1 -1
  38. package/package.json +1 -1
@@ -44,6 +44,7 @@ const Select = (props) => {
44
44
  onValueChange,
45
45
  placeholder,
46
46
  icon,
47
+ leading,
47
48
  label,
48
49
  hint,
49
50
  size,
@@ -55,6 +56,8 @@ const Select = (props) => {
55
56
  filter,
56
57
  selectAll,
57
58
  selectAllLabel = "Select all",
59
+ clearable,
60
+ clearLabel = "Clear",
58
61
  renderOption,
59
62
  renderIndicator,
60
63
  renderTrigger,
@@ -158,6 +161,11 @@ const Select = (props) => {
158
161
  if (!controlled) setInternal(next);
159
162
  emit?.(next, { all: true, selected: !allSelected });
160
163
  };
164
+ const clear = () => {
165
+ const next = multiple ? [] : void 0;
166
+ if (!controlled) setInternal(next);
167
+ emit?.(next, { all: true, selected: false });
168
+ };
161
169
  const renderOptionRow = (o, disabled2) => {
162
170
  const optState = { value: o.value, selected: isSelected(o.value), disabled: disabled2 };
163
171
  const custom = renderOption?.(o, optState);
@@ -256,7 +264,7 @@ const Select = (props) => {
256
264
  readOnly: true,
257
265
  dimActions: true,
258
266
  disabled,
259
- leading: icon ? /* @__PURE__ */ jsx(Icon, { shape: icon }) : void 0,
267
+ leading: leading ?? (icon ? /* @__PURE__ */ jsx(Icon, { shape: icon }) : void 0),
260
268
  size,
261
269
  status,
262
270
  statusIcon,
@@ -329,7 +337,9 @@ const Select = (props) => {
329
337
  ),
330
338
  /* @__PURE__ */ jsx(MenuSeparator, {})
331
339
  ] }),
332
- visibleLeaves.length === 0 ? renderEmpty?.({ query: q }) : flattening ? renderFlat() : renderTree(options, false)
340
+ visibleLeaves.length === 0 ? renderEmpty?.({ query: q }) : flattening ? renderFlat() : renderTree(options, false),
341
+ clearable && selectedValues.length > 0 && // Pinned in the footer so it never scrolls away in a long / filtered list.
342
+ /* @__PURE__ */ jsx("div", { slot: "footer", className: styles.footer, children: /* @__PURE__ */ jsx(MenuItem, { icon: "x", label: clearLabel, "data-menu-open": "", onSelect: clear }) })
333
343
  ]
334
344
  }
335
345
  )
@@ -1 +1 @@
1
- .chevron{margin-inline-end:7px;transition:transform .15s ease}.chevron.open{transform:rotate(180deg)}.filter{padding:4px 4px 0}
1
+ .chevron{margin-inline-end:7px;transition:transform .15s ease}.chevron.open{transform:rotate(180deg)}.filter{padding:4px 4px 0}.footer{padding:var(--menu-padding, 4px);border-top:1px solid var(--border-4)}
@@ -0,0 +1,184 @@
1
+ import type { BaseProps } from '../general_types';
2
+ import type { IconShape } from '../elements/a-icon.shapes';
3
+ import type { SelectItem, SelectOption } from './Select';
4
+ interface FacetBase {
5
+ /** The facet's namespace — the key its value is stored under in the value
6
+ * record, and what `onValueChange`'s `attrs.facet` reports. Unique across
7
+ * `facets`. */
8
+ key: string;
9
+ /** The facet's row label in the menu. */
10
+ label: string;
11
+ /** Leading icon on the facet's row. */
12
+ icon?: IconShape;
13
+ }
14
+ /** A per-facet option-list filter (like `Select`'s `filter`): `true` uses the
15
+ * built-in case-insensitive substring match on an option's value / label /
16
+ * hint; a function `(option, query) => boolean` does custom matching. */
17
+ export type FacetFilter = boolean | ((option: SelectOption, query: string) => boolean);
18
+ /** Pick **one** option. Value: the chosen option's `value` string (or
19
+ * `undefined` when cleared). Re-picking the selected option clears it. Options
20
+ * are `Select`'s `SelectItem`s — bare strings or `SelectOption`s carrying the
21
+ * same fields (`value`, `label`, `hint`, `icon`, `tone`, `disabled`). */
22
+ export interface SelectFacetSingle extends FacetBase {
23
+ kind: 'single';
24
+ /** The options — bare strings or `SelectOption`s (groups / submenus are
25
+ * flattened to their leaves). */
26
+ options: SelectItem[];
27
+ /** Add a search field atop this facet's flyout that filters its options. */
28
+ filter?: FacetFilter;
29
+ }
30
+ /** Pick **any number** of options. Value: an array of the chosen `value`
31
+ * strings (empty array clears the facet). Options are the same `SelectItem`s
32
+ * as `single`. */
33
+ export interface SelectFacetMultiple extends FacetBase {
34
+ kind: 'multiple';
35
+ /** The options — bare strings or `SelectOption`s (groups / submenus flattened). */
36
+ options: SelectItem[];
37
+ /** Add a search field atop this facet's flyout that filters its options. */
38
+ filter?: FacetFilter;
39
+ /** Add a "Select all" row that toggles every option. */
40
+ selectAll?: boolean;
41
+ /** Label for the `selectAll` row.
42
+ * @defaultValue Select all */
43
+ selectAllLabel?: string;
44
+ }
45
+ /** Free-form substring. Value: the typed string (or `undefined` when empty).
46
+ * Applies on Enter or blur — not on every keystroke. */
47
+ export interface SelectFacetText extends FacetBase {
48
+ kind: 'text';
49
+ /** Placeholder for the text field. */
50
+ placeholder?: string;
51
+ }
52
+ /** Context handed to a `custom` facet's `render`. */
53
+ export interface SelectFacetCustomContext<V> {
54
+ /** The facet's current value (`undefined` when unset). */
55
+ value: V | undefined;
56
+ /** Apply a new value for this facet — pass `undefined` to clear it. */
57
+ onChange: (next: V | undefined) => void;
58
+ /** Close the whole filter menu (e.g. after applying from a custom editor). */
59
+ close: () => void;
60
+ }
61
+ /** Bring your own editor and value type — the escape hatch for anything the
62
+ * built-in kinds don't cover, including object-shaped values (a date range, a
63
+ * numeric comparator, …). */
64
+ export interface SelectFacetCustom<V = unknown> extends FacetBase {
65
+ kind: 'custom';
66
+ /** Render the facet's editor inside its flyout. The returned node stays
67
+ * mounted while the menu is open. */
68
+ render: (ctx: SelectFacetCustomContext<V>) => React.ReactNode;
69
+ /** Reduce an active value to a short summary shown on the facet's row (a
70
+ * string or any node). Called only when the value is set. */
71
+ summary: (value: V) => React.ReactNode;
72
+ }
73
+ /** One facet (dimension) of the filter, discriminated by `kind`. */
74
+ export type SelectFacet = SelectFacetSingle | SelectFacetMultiple | SelectFacetText | SelectFacetCustom;
75
+ /** The filter value: a facet key → that facet's value. Per kind the value is a
76
+ * `string` (single / text), a `string[]` (multiple), or your own `V` (custom).
77
+ * A cleared facet is absent from the record (not a falsy entry). */
78
+ export type SelectFacetedValue = Record<string, unknown>;
79
+ /** Second argument to `onValueChange` — what changed. A single-facet edit
80
+ * carries `facet` / `kind` / the facet's new `value`; the "Clear all" row
81
+ * carries `all: true`. Narrow on `'all' in attrs`. */
82
+ export type SelectFacetedChangeAttrs = {
83
+ /** The facet key that changed. */
84
+ facet: string;
85
+ /** That facet's kind. */
86
+ kind: SelectFacet['kind'];
87
+ /** The facet's new value (`undefined` when the facet was cleared). */
88
+ value: unknown;
89
+ } | {
90
+ /** Marks the change as the "Clear all" row emptying every facet. */
91
+ all: true;
92
+ };
93
+ /** Snapshot passed to `renderTrigger` so a custom trigger can reflect the
94
+ * current filter and open state. */
95
+ export interface SelectFacetedTriggerState {
96
+ /** Whether the menu is open — use it for `aria-expanded` and a chevron. */
97
+ open: boolean;
98
+ /** The whole current value record. */
99
+ value: SelectFacetedValue;
100
+ /** Number of **active facets** (each facet with a value counts once,
101
+ * regardless of how many options it holds) — the default badge count. */
102
+ count: number;
103
+ /** Whether the whole control is disabled. */
104
+ disabled: boolean;
105
+ }
106
+ export interface SelectFacetedProps extends Omit<BaseProps, 'children'> {
107
+ /** The facets (dimensions) to filter across, each with its own editor kind. */
108
+ facets: SelectFacet[];
109
+ /** Controlled value — the facet-keyed record. When provided, the consumer
110
+ * owns state: a pick only *requests* a change via `onValueChange` (reject by
111
+ * not updating). Leave undefined for uncontrolled. */
112
+ value?: SelectFacetedValue;
113
+ /** Initial value for the uncontrolled case (the wrapper then owns it). */
114
+ defaultValue?: SelectFacetedValue;
115
+ /** Fires after any facet changes, with the new full value record and an
116
+ * attrs snapshot of what changed. */
117
+ onValueChange?: (value: SelectFacetedValue, attrs: SelectFacetedChangeAttrs) => void;
118
+ /** Default trigger's button label.
119
+ * @defaultValue Filter */
120
+ label?: string;
121
+ /** Default trigger's leading icon.
122
+ * @defaultValue filter */
123
+ icon?: IconShape;
124
+ /** Default trigger's button size.
125
+ * @defaultValue medium */
126
+ size?: 'small' | 'medium' | 'large';
127
+ /** Default trigger's button priority.
128
+ * @defaultValue secondary */
129
+ priority?: 'primary' | 'secondary';
130
+ /** Disable the whole control. */
131
+ disabled?: boolean;
132
+ /** Add a single search field to the top of the root menu that flattens every
133
+ * `single` / `multiple` facet's options into one list and searches across them
134
+ * — typing "alice" surfaces it under both an Assignee and an Owner facet, each
135
+ * selectable in place. `text` / `custom` facets are reachable when the search is
136
+ * empty. Matching uses each facet's `filter` function if it has one, else the
137
+ * built-in substring match. */
138
+ searchable?: boolean;
139
+ /** Placeholder for the global search field.
140
+ * @defaultValue Filter… */
141
+ searchPlaceholder?: string;
142
+ /** Show the per-facet "Clear" row and the "Clear all" row.
143
+ * @defaultValue true */
144
+ clearable?: boolean;
145
+ /** Label for the "Clear all" row.
146
+ * @defaultValue Clear all */
147
+ clearAllLabel?: string;
148
+ /** Render your own trigger in place of the default `Button`. Receives a
149
+ * `SelectFacetedTriggerState`; **return exactly one focusable element** (the
150
+ * menu anchors to it as its previous sibling and opens it on click). Give it
151
+ * `aria-haspopup="menu"` plus `aria-expanded={state.open}`. The custom trigger
152
+ * owns its own styling — `className` / `style` / other props apply to the
153
+ * *default* trigger only, so put your own on the element you return. */
154
+ renderTrigger?: (state: SelectFacetedTriggerState) => React.ReactNode;
155
+ }
156
+ /**
157
+ * `<SelectFaceted>` — a faceted filter: one trigger opens a menu of facets
158
+ * (dimensions), each a submenu flyout with its own editor. Facet kinds:
159
+ * `'single'` (pick one), `'multiple'` (pick many), `'text'` (free-form
160
+ * substring, applied on Enter / blur), and `'custom'` (bring your own editor +
161
+ * value, including object-shaped values). The value is a
162
+ * `Record<facetKey, value>`, so the same option value under two facets stays
163
+ * distinct.
164
+ *
165
+ * Controlled (`value` + `onValueChange`) or uncontrolled (`defaultValue`).
166
+ * There is no `a-select-faceted` element — this wrapper is the coordinator.
167
+ *
168
+ * Requires `@antadesign/anta/elements` (client-side only).
169
+ *
170
+ * @example
171
+ * ```tsx
172
+ * <SelectFaceted
173
+ * facets={[
174
+ * { key: 'assignee', label: 'Assignee', kind: 'multiple', options: people },
175
+ * { key: 'owner', label: 'Owner', kind: 'single', options: people },
176
+ * { key: 'title', label: 'Title', kind: 'text' },
177
+ * ]}
178
+ * value={filters}
179
+ * onValueChange={setFilters}
180
+ * />
181
+ * ```
182
+ */
183
+ export declare const SelectFaceted: (props: SelectFacetedProps) => any;
184
+ export {};
@@ -0,0 +1,331 @@
1
+ import { Fragment, jsx, jsxs } from "@antadesign/anta/jsx-runtime";
2
+ import { useState, useMemo } from "../jsx-runtime";
3
+ import { nativeStateChange } from "../anta_helpers";
4
+ import { Button } from "./Button";
5
+ import { Menu } from "./Menu";
6
+ import { MenuItem } from "./MenuItem";
7
+ import { MenuGroup } from "./MenuGroup";
8
+ import { MenuSeparator } from "./MenuSeparator";
9
+ import { Tag } from "./Tag";
10
+ import { Input } from "./Input";
11
+ import styles from "./SelectFaceted.module.css";
12
+ const normalizeOpt = (o) => typeof o === "string" ? { value: o, label: o } : o;
13
+ const leavesOf = (items) => {
14
+ const out = [];
15
+ for (const it of items) {
16
+ if (typeof it !== "string" && Array.isArray(it.submenu))
17
+ out.push(...leavesOf(it.submenu));
18
+ else if (typeof it !== "string" && Array.isArray(it.options))
19
+ out.push(...leavesOf(it.options));
20
+ else out.push(normalizeOpt(it));
21
+ }
22
+ return out;
23
+ };
24
+ const isEmpty = (v) => v == null || v === "" || Array.isArray(v) && v.length === 0;
25
+ const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
26
+ const defaultMatch = (o, query) => {
27
+ const q = query.trim();
28
+ if (!q) return true;
29
+ const re = new RegExp(q.split(/\s+/).map(escapeRe).join("\\s+"), "i");
30
+ return [o.value, o.label, o.hint].some((v) => typeof v === "string" && re.test(v));
31
+ };
32
+ const SelectFaceted = (props) => {
33
+ const {
34
+ facets,
35
+ value,
36
+ defaultValue,
37
+ onValueChange,
38
+ label = "Filter",
39
+ icon = "filter",
40
+ size,
41
+ priority = "secondary",
42
+ disabled,
43
+ searchable,
44
+ searchPlaceholder = "Filter\u2026",
45
+ clearable = true,
46
+ clearAllLabel = "Clear all",
47
+ renderTrigger,
48
+ className,
49
+ style,
50
+ ...rest
51
+ } = props;
52
+ const controlled = value !== void 0;
53
+ const [internal, setInternal] = useState(defaultValue ?? {});
54
+ const current = controlled ? value : internal;
55
+ const [open, setOpen] = useState(false);
56
+ const [drafts, setDrafts] = useState({});
57
+ const [seenText, setSeenText] = useState({});
58
+ {
59
+ let nextSeen = null;
60
+ let nextDrafts = drafts;
61
+ for (const f of facets) {
62
+ if (f.kind !== "text") continue;
63
+ if (seenText[f.key] !== current[f.key]) {
64
+ nextSeen = { ...nextSeen ?? seenText, [f.key]: current[f.key] };
65
+ nextDrafts = { ...nextDrafts, [f.key]: current[f.key] ?? "" };
66
+ }
67
+ }
68
+ if (nextSeen) {
69
+ setSeenText(nextSeen);
70
+ setDrafts(nextDrafts);
71
+ }
72
+ }
73
+ const [queries, setQueries] = useState({});
74
+ const [rootQuery, setRootQuery] = useState("");
75
+ const [activeIds, setActiveIds] = useState({});
76
+ const onActive = (key) => (e) => {
77
+ const id = nativeStateChange(e).detail?.id ?? null;
78
+ setActiveIds((s) => s[key] === id ? s : { ...s, [key]: id });
79
+ };
80
+ const activeCount = facets.reduce((n, f) => n + (isEmpty(current[f.key]) ? 0 : 1), 0);
81
+ const leavesByKey = useMemo(
82
+ () => new Map(
83
+ facets.map((f) => [
84
+ f.key,
85
+ f.kind === "single" || f.kind === "multiple" ? leavesOf(f.options) : []
86
+ ])
87
+ ),
88
+ [facets]
89
+ );
90
+ const commit = (next, attrs) => {
91
+ if (!controlled) setInternal(next);
92
+ onValueChange?.(next, attrs);
93
+ };
94
+ const setFacet = (facet, nextValue) => {
95
+ const cleared = isEmpty(nextValue);
96
+ const next = { ...current };
97
+ if (cleared) delete next[facet.key];
98
+ else next[facet.key] = nextValue;
99
+ commit(next, { facet: facet.key, kind: facet.kind, value: cleared ? void 0 : nextValue });
100
+ };
101
+ const clearAll = () => commit({}, { all: true });
102
+ const visibleLeavesOf = (facet) => {
103
+ const leaves = leavesByKey.get(facet.key) ?? [];
104
+ if (!facet.filter) return leaves;
105
+ const q = queries[facet.key] ?? "";
106
+ const match = typeof facet.filter === "function" ? facet.filter : defaultMatch;
107
+ return leaves.filter((o) => match(o, q));
108
+ };
109
+ const filterHeader = (facet) => facet.filter ? /* @__PURE__ */ jsx("div", { slot: "header", "data-menu-open": "", style: { padding: "4px" }, children: /* @__PURE__ */ jsx(
110
+ Input,
111
+ {
112
+ "data-menu-search": "",
113
+ size: "small",
114
+ value: queries[facet.key] ?? "",
115
+ placeholder: "Filter\u2026",
116
+ "aria-label": `Filter ${facet.label}`,
117
+ "aria-autocomplete": "list",
118
+ "aria-activedescendant": activeIds[facet.key] ?? void 0,
119
+ onInput: (e) => setQueries((s) => ({ ...s, [facet.key]: e.currentTarget.value }))
120
+ }
121
+ ) }) : null;
122
+ const optionRow = (facet, opt, keyPrefix = "") => {
123
+ const shared = {
124
+ icon: opt.icon,
125
+ label: opt.label ?? opt.value,
126
+ hint: opt.hint,
127
+ tone: opt.tone,
128
+ disabled: opt.disabled,
129
+ "data-menu-open": ""
130
+ };
131
+ if (facet.kind === "single") {
132
+ const cur = current[facet.key];
133
+ return /* @__PURE__ */ jsx(
134
+ MenuItem,
135
+ {
136
+ ...shared,
137
+ selectionIndicator: "check",
138
+ selected: cur === opt.value,
139
+ onSelect: () => setFacet(facet, cur === opt.value ? void 0 : opt.value)
140
+ },
141
+ `${keyPrefix}${opt.value}`
142
+ );
143
+ }
144
+ const arr = current[facet.key] ?? [];
145
+ return /* @__PURE__ */ jsx(
146
+ MenuItem,
147
+ {
148
+ ...shared,
149
+ selectionIndicator: "checkbox",
150
+ selected: arr.includes(opt.value),
151
+ onSelect: () => setFacet(facet, arr.includes(opt.value) ? arr.filter((v) => v !== opt.value) : [...arr, opt.value])
152
+ },
153
+ `${keyPrefix}${opt.value}`
154
+ );
155
+ };
156
+ const renderSingle = (facet) => visibleLeavesOf(facet).map((opt) => optionRow(facet, opt));
157
+ const renderMultiple = (facet) => {
158
+ const arr = current[facet.key] ?? [];
159
+ const leaves = visibleLeavesOf(facet);
160
+ const enabled = leaves.filter((o) => !o.disabled).map((o) => o.value);
161
+ const allOn = enabled.length > 0 && enabled.every((v) => arr.includes(v));
162
+ const someOn = enabled.some((v) => arr.includes(v));
163
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
164
+ facet.selectAll && leaves.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
165
+ /* @__PURE__ */ jsx(
166
+ MenuItem,
167
+ {
168
+ selectionIndicator: "checkbox",
169
+ selected: allOn,
170
+ indeterminate: someOn && !allOn,
171
+ label: facet.selectAllLabel ?? "Select all",
172
+ "data-menu-open": "",
173
+ onSelect: () => setFacet(
174
+ facet,
175
+ // Toggle only the visible set, preserving picks hidden by the filter.
176
+ allOn ? arr.filter((v) => !enabled.includes(v)) : [.../* @__PURE__ */ new Set([...arr, ...enabled])]
177
+ )
178
+ }
179
+ ),
180
+ /* @__PURE__ */ jsx(MenuSeparator, {})
181
+ ] }),
182
+ leaves.map((opt) => optionRow(facet, opt))
183
+ ] });
184
+ };
185
+ const renderFlatResults = () => {
186
+ const groups = facets.filter((f) => f.kind === "single" || f.kind === "multiple").map((facet) => {
187
+ const match = typeof facet.filter === "function" ? facet.filter : defaultMatch;
188
+ return { facet, matched: (leavesByKey.get(facet.key) ?? []).filter((o) => match(o, rootQuery)) };
189
+ }).filter((g) => g.matched.length > 0);
190
+ return groups.map(({ facet, matched }) => /* @__PURE__ */ jsx(MenuGroup, { label: facet.label, children: matched.map((opt) => optionRow(facet, opt, `${facet.key}:`)) }, facet.key));
191
+ };
192
+ const renderText = (facet) => {
193
+ const applied = current[facet.key] ?? "";
194
+ const draft = drafts[facet.key] ?? applied;
195
+ const apply = () => {
196
+ const next = draft.trim() || void 0;
197
+ if (next !== (applied || void 0)) setFacet(facet, next);
198
+ };
199
+ return (
200
+ // `data-menu-open` keeps the menu open through typing; the value commits on
201
+ // Enter / blur, not per keystroke.
202
+ /* @__PURE__ */ jsx("div", { "data-menu-open": "", style: { padding: "4px" }, children: /* @__PURE__ */ jsx(
203
+ Input,
204
+ {
205
+ size: "small",
206
+ value: draft,
207
+ placeholder: facet.placeholder,
208
+ "aria-label": facet.label,
209
+ onInput: (e) => setDrafts((d) => ({ ...d, [facet.key]: e.currentTarget.value })),
210
+ onKeyDown: (e) => {
211
+ if (e.key === "Enter") {
212
+ e.preventDefault();
213
+ apply();
214
+ }
215
+ },
216
+ onBlur: apply
217
+ }
218
+ ) })
219
+ );
220
+ };
221
+ const renderCustom = (facet) => /* @__PURE__ */ jsx("div", { "data-menu-open": "", children: facet.render({
222
+ value: current[facet.key],
223
+ onChange: (next) => setFacet(facet, next),
224
+ close: () => setOpen(false)
225
+ }) });
226
+ const renderEditor = (facet) => {
227
+ const isOptions = facet.kind === "single" || facet.kind === "multiple";
228
+ const body = facet.kind === "single" ? renderSingle(facet) : facet.kind === "multiple" ? renderMultiple(facet) : facet.kind === "text" ? renderText(facet) : renderCustom(facet);
229
+ const hasValue = !isEmpty(current[facet.key]);
230
+ return /* @__PURE__ */ jsxs(Menu, { onactivedescendant: isOptions && facet.filter ? onActive(facet.key) : void 0, children: [
231
+ isOptions && filterHeader(facet),
232
+ body,
233
+ clearable && hasValue && /* @__PURE__ */ jsx("div", { slot: "footer", className: styles.footer, children: /* @__PURE__ */ jsx(
234
+ MenuItem,
235
+ {
236
+ icon: "x",
237
+ label: "Clear",
238
+ "data-menu-open": "",
239
+ onSelect: () => setFacet(facet, void 0)
240
+ }
241
+ ) })
242
+ ] });
243
+ };
244
+ const summaryOf = (facet) => {
245
+ const v = current[facet.key];
246
+ if (isEmpty(v)) return null;
247
+ switch (facet.kind) {
248
+ case "single": {
249
+ const opt = (leavesByKey.get(facet.key) ?? []).find((o) => o.value === v);
250
+ return opt?.label ?? String(v);
251
+ }
252
+ case "multiple":
253
+ return String(v.length);
254
+ case "text":
255
+ return String(v);
256
+ case "custom":
257
+ return facet.summary(v);
258
+ }
259
+ };
260
+ const triggerState = {
261
+ open,
262
+ value: current,
263
+ count: activeCount,
264
+ disabled: !!disabled
265
+ };
266
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
267
+ renderTrigger ? renderTrigger(triggerState) : /* @__PURE__ */ jsx(
268
+ Button,
269
+ {
270
+ icon,
271
+ label,
272
+ priority,
273
+ size,
274
+ disabled,
275
+ "aria-haspopup": "menu",
276
+ "aria-expanded": open ? "true" : "false",
277
+ className,
278
+ style,
279
+ ...rest,
280
+ children: activeCount > 0 && /* @__PURE__ */ jsx(Tag, { size: "small", priority: "primary", tone: "brand", children: String(activeCount) })
281
+ }
282
+ ),
283
+ /* @__PURE__ */ jsxs(
284
+ Menu,
285
+ {
286
+ open,
287
+ onStateChange: (_e, { next }) => {
288
+ setOpen(next);
289
+ if (!next) setRootQuery("");
290
+ },
291
+ onactivedescendant: searchable ? onActive("__root__") : void 0,
292
+ children: [
293
+ searchable && // Pinned global search: flattens all options facets while a query is active.
294
+ /* @__PURE__ */ jsx("div", { slot: "header", "data-menu-open": "", className: styles.search, children: /* @__PURE__ */ jsx(
295
+ Input,
296
+ {
297
+ "data-menu-search": "",
298
+ size: "small",
299
+ value: rootQuery,
300
+ placeholder: searchPlaceholder,
301
+ "aria-label": "Filter all facets",
302
+ "aria-autocomplete": "list",
303
+ "aria-activedescendant": activeIds["__root__"] ?? void 0,
304
+ onInput: (e) => setRootQuery(e.currentTarget.value)
305
+ }
306
+ ) }),
307
+ searchable && rootQuery.trim() ? renderFlatResults() : facets.map((facet) => /* @__PURE__ */ jsxs(MenuItem, { submenu: true, icon: facet.icon, label: facet.label, children: [
308
+ (() => {
309
+ const s = summaryOf(facet);
310
+ return s != null ? /* @__PURE__ */ jsx(Tag, { size: "small", tone: "brand", children: s }) : null;
311
+ })(),
312
+ renderEditor(facet)
313
+ ] }, facet.key)),
314
+ clearable && /* @__PURE__ */ jsx("div", { slot: "footer", className: styles.footer, children: /* @__PURE__ */ jsx(
315
+ MenuItem,
316
+ {
317
+ icon: "filter-x",
318
+ label: clearAllLabel,
319
+ disabled: activeCount === 0,
320
+ "data-menu-open": "",
321
+ onSelect: clearAll
322
+ }
323
+ ) })
324
+ ]
325
+ }
326
+ )
327
+ ] });
328
+ };
329
+ export {
330
+ SelectFaceted
331
+ };
@@ -0,0 +1 @@
1
+ .search{padding:var(--menu-padding, 4px)}.footer{padding:var(--menu-padding, 4px);border-top:1px solid var(--border-4)}
@@ -41,6 +41,12 @@ export interface TabOption {
41
41
  /** Disable just this tab — skipped by keyboard nav and dropped from the tab order
42
42
  * (a disabled-but-selected tab stays reachable, per the ARIA pattern). */
43
43
  disabled?: boolean;
44
+ /** Tooltip for this tab — a string or any node — shown **only when the tab's label
45
+ * is truncated** (tabs ellipsize when the strip overflows), so a clipped tab reveals
46
+ * its full text on hover while a tab that fits shows nothing. Rendered as a
47
+ * `truncatedOnly` `<Tooltip>` anchored to the tab. For an always-visible tooltip or
48
+ * other custom trigger content, use `children` with your own `<Tooltip>` instead. */
49
+ tooltip?: React.ReactNode;
44
50
  }
45
51
  /** Public props for `<Tabs>`. */
46
52
  export interface TabsProps extends Omit<BaseProps, "onChange"> {
@@ -1,6 +1,7 @@
1
1
  import { Fragment, jsx, jsxs } from "@antadesign/anta/jsx-runtime";
2
2
  import { useState } from "../jsx-runtime";
3
3
  import { nativeStateChange, toneStyle, roundStyle, wrapLabel } from "../anta_helpers";
4
+ import { Tooltip } from "./Tooltip";
4
5
  const Tabs = ({
5
6
  children,
6
7
  options,
@@ -88,7 +89,8 @@ const Tabs = ({
88
89
  children: [
89
90
  p.icon && /* @__PURE__ */ jsx("a-icon", { shape: p.icon, "aria-hidden": "true" }),
90
91
  wrapLabel(p.label != null ? p.label : p.children, "a-tab-label"),
91
- p.iconTrailing && /* @__PURE__ */ jsx("a-icon", { shape: p.iconTrailing, "aria-hidden": "true" })
92
+ p.iconTrailing && /* @__PURE__ */ jsx("a-icon", { shape: p.iconTrailing, "aria-hidden": "true" }),
93
+ p.tooltip != null && p.tooltip !== "" ? /* @__PURE__ */ jsx(Tooltip, { truncatedOnly: true, children: p.tooltip }) : null
92
94
  ]
93
95
  },
94
96
  p.value