@mohirlab/react 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/combobox/combobox.d.ts +34 -0
- package/dist/components/combobox/combobox.d.ts.map +1 -0
- package/dist/components/combobox/combobox.js +265 -0
- package/dist/components/combobox/combobox.js.map +1 -0
- package/dist/components/combobox/combobox.styles.js +42 -0
- package/dist/components/combobox/combobox.styles.js.map +1 -0
- package/dist/components/combobox/index.d.ts +3 -0
- package/dist/components/feedback/feedback.css.d.ts +39 -0
- package/dist/components/feedback/feedback.css.d.ts.map +1 -0
- package/dist/components/feedback/feedback.d.ts +41 -0
- package/dist/components/feedback/feedback.d.ts.map +1 -0
- package/dist/components/feedback/feedback.js +70 -0
- package/dist/components/feedback/feedback.js.map +1 -0
- package/dist/components/feedback/feedback.styles.js +40 -0
- package/dist/components/feedback/feedback.styles.js.map +1 -0
- package/dist/components/feedback/index.d.ts +3 -0
- package/dist/components/input/input.css.d.ts.map +1 -1
- package/dist/components/menu/index.d.ts +3 -0
- package/dist/components/menu/menu.d.ts +48 -0
- package/dist/components/menu/menu.d.ts.map +1 -0
- package/dist/components/menu/menu.js +188 -0
- package/dist/components/menu/menu.js.map +1 -0
- package/dist/components/menu/menu.styles.js +28 -0
- package/dist/components/menu/menu.styles.js.map +1 -0
- package/dist/components/navigation/index.d.ts +2 -1
- package/dist/components/navigation/pagination.d.ts +34 -0
- package/dist/components/navigation/pagination.d.ts.map +1 -0
- package/dist/components/navigation/pagination.js +109 -0
- package/dist/components/navigation/pagination.js.map +1 -0
- package/dist/components/navigation/pagination.styles.js +11 -0
- package/dist/components/navigation/pagination.styles.js.map +1 -0
- package/dist/components/popover/popover.js +1 -1
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/visually-hidden/index.d.ts +3 -0
- package/dist/components/visually-hidden/visually-hidden.d.ts +13 -0
- package/dist/components/visually-hidden/visually-hidden.d.ts.map +1 -0
- package/dist/components/visually-hidden/visually-hidden.js +19 -0
- package/dist/components/visually-hidden/visually-hidden.js.map +1 -0
- package/dist/components/visually-hidden/visually-hidden.styles.js +7 -0
- package/dist/components/visually-hidden/visually-hidden.styles.js.map +1 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +8 -3
- package/dist/styles.css +640 -166
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
import { InputVariants } from "../input/input.css.js";
|
|
4
|
+
export interface ComboboxOption {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
/** A second, quieter line. Also searched. */
|
|
8
|
+
description?: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const defaultFilter: (option: ComboboxOption, query: string) => boolean;
|
|
12
|
+
export interface ComboboxProps extends Omit<ComponentPropsWithRef<'input'>, 'size' | 'value' | 'defaultValue' | 'onChange' | 'children'> {
|
|
13
|
+
options: ComboboxOption[];
|
|
14
|
+
/** The chosen option's value; `''` for none. */
|
|
15
|
+
value?: string;
|
|
16
|
+
defaultValue?: string;
|
|
17
|
+
onValueChange?: (value: string) => void;
|
|
18
|
+
size?: InputVariants['size'];
|
|
19
|
+
invalid?: boolean;
|
|
20
|
+
/** Shown when nothing matches. */
|
|
21
|
+
emptyText?: ReactNode;
|
|
22
|
+
/** Decide which options match what was typed. Default: label or description contains it. */
|
|
23
|
+
filter?: (option: ComboboxOption, query: string) => boolean;
|
|
24
|
+
/** Accessible name of the open/close button. */
|
|
25
|
+
toggleLabel?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A select you can type into: for long lists such as countries, people or tags.
|
|
29
|
+
* Follows the WAI-ARIA combobox pattern (list autocomplete): focus stays in the field,
|
|
30
|
+
* arrows move through the matches, Enter chooses, Escape closes. With `name` it submits
|
|
31
|
+
* the chosen value, not the typed text. For short lists, prefer `Select`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function Combobox({ options, value: valueProp, defaultValue, onValueChange, size, invalid, emptyText, filter, toggleLabel, name, placeholder, className, style, id, required, disabled, onKeyDown, onBlur, ...rest }: ComboboxProps): import("react").JSX.Element;
|
|
34
|
+
//# sourceMappingURL=combobox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combobox.d.ts","names":[],"sources":["../../../src/components/combobox/combobox.tsx"],"mappings":";;;iBAmBiB;EACf;EACA;;EAEA;EACA;;qBAUW,gBAAa,QAAY,gBAAc;iBA8BnC,sBAAsB,KACrC;EAGA,SAAS;;EAET;EACA;EACA,iBAAiB;EACjB,OAAO;EACP;;EAEA,YAAY;;EAEZ,UAAU,QAAQ,gBAAgB;;EAElC;;;;;;;;wBASc,WACd,SACA,OAAO,WACP,cACA,eACA,MACA,SACA,WACA,QACA,aACA,MACA,aACA,WACA,OACA,IACA,UACA,UACA,WACA,WACG,QACF,gCAAa,IAAA"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { iconCheck, iconChevronDown } from "@mohirlab/icons";
|
|
4
|
+
import { cx } from "../../utils/cx.js";
|
|
5
|
+
import { useFieldControl } from "../field/use-field-control.js";
|
|
6
|
+
import { Icon } from "../icon/icon.js";
|
|
7
|
+
import { useAnchorName } from "../popover/popover.js";
|
|
8
|
+
import { check, empty, field, input, listbox, match, option, optionText, panel, popover, toggle, wrap } from "./combobox.styles.js";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
// src/components/combobox/combobox.tsx
|
|
11
|
+
/** Case- and accent-insensitive, so "o'zbek" finds "Oʻzbek" and "e" finds "é". */
|
|
12
|
+
const fold = (text) => text.normalize("NFD").replace(/[̀-ͯʻʼ'’`]/g, "").toLowerCase();
|
|
13
|
+
const defaultFilter = (option, query) => {
|
|
14
|
+
const q = fold(query.trim());
|
|
15
|
+
return !q || fold(option.label).includes(q) || fold(option.description ?? "").includes(q);
|
|
16
|
+
};
|
|
17
|
+
/** The label with the first match of the query marked. */
|
|
18
|
+
function Highlight({ text, query }) {
|
|
19
|
+
const q = fold(query.trim());
|
|
20
|
+
if (!q) return /* @__PURE__ */ jsx(Fragment, { children: text });
|
|
21
|
+
const folded = [...text].map((c) => fold(c));
|
|
22
|
+
let start = -1;
|
|
23
|
+
for (let i = 0; i < folded.length && start < 0; i++) {
|
|
24
|
+
let joined = "";
|
|
25
|
+
for (let j = i; j < folded.length && joined.length < q.length; j++) joined += folded[j];
|
|
26
|
+
if (joined.startsWith(q)) start = i;
|
|
27
|
+
}
|
|
28
|
+
if (start < 0) return /* @__PURE__ */ jsx(Fragment, { children: text });
|
|
29
|
+
const chars = [...text];
|
|
30
|
+
let end = start;
|
|
31
|
+
for (let length = 0; end < chars.length && length < q.length; end++) length += folded[end].length;
|
|
32
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
33
|
+
chars.slice(0, start).join(""),
|
|
34
|
+
/* @__PURE__ */ jsx("mark", {
|
|
35
|
+
className: match,
|
|
36
|
+
children: chars.slice(start, end).join("")
|
|
37
|
+
}),
|
|
38
|
+
chars.slice(end).join("")
|
|
39
|
+
] });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A select you can type into: for long lists such as countries, people or tags.
|
|
43
|
+
* Follows the WAI-ARIA combobox pattern (list autocomplete): focus stays in the field,
|
|
44
|
+
* arrows move through the matches, Enter chooses, Escape closes. With `name` it submits
|
|
45
|
+
* the chosen value, not the typed text. For short lists, prefer `Select`.
|
|
46
|
+
*/
|
|
47
|
+
function Combobox({ options, value: valueProp, defaultValue = "", onValueChange, size, invalid, emptyText = "No matches", filter = defaultFilter, toggleLabel = "Show options", name, placeholder, className, style, id, required, disabled, onKeyDown, onBlur, ...rest }) {
|
|
48
|
+
const control = useFieldControl({
|
|
49
|
+
id,
|
|
50
|
+
required,
|
|
51
|
+
disabled,
|
|
52
|
+
invalid,
|
|
53
|
+
"aria-describedby": rest["aria-describedby"]
|
|
54
|
+
});
|
|
55
|
+
const listId = useId();
|
|
56
|
+
const optionId = useId();
|
|
57
|
+
const anchor = useAnchorName();
|
|
58
|
+
const panelRef = useRef(null);
|
|
59
|
+
const inputRef = useRef(null);
|
|
60
|
+
const [innerValue, setInnerValue] = useState(defaultValue);
|
|
61
|
+
const value = valueProp ?? innerValue;
|
|
62
|
+
const selected = options.find((o) => o.value === value);
|
|
63
|
+
const [query, setQuery] = useState(selected?.label ?? "");
|
|
64
|
+
/** False right after opening: show every option, not only those matching the current label. */
|
|
65
|
+
const [filtering, setFiltering] = useState(false);
|
|
66
|
+
const [open, setOpen] = useState(false);
|
|
67
|
+
const [active, setActive] = useState(-1);
|
|
68
|
+
const [shownValue, setShownValue] = useState(value);
|
|
69
|
+
if (shownValue !== value) {
|
|
70
|
+
setShownValue(value);
|
|
71
|
+
setQuery(selected?.label ?? "");
|
|
72
|
+
}
|
|
73
|
+
const visible = useMemo(() => filtering ? options.filter((o) => filter(o, query)) : options, [
|
|
74
|
+
options,
|
|
75
|
+
filter,
|
|
76
|
+
query,
|
|
77
|
+
filtering
|
|
78
|
+
]);
|
|
79
|
+
const enabled = (index) => index >= 0 && index < visible.length && !visible[index].disabled;
|
|
80
|
+
const firstEnabled = (from, step) => {
|
|
81
|
+
for (let i = from; i >= 0 && i < visible.length; i += step) if (enabled(i)) return i;
|
|
82
|
+
return -1;
|
|
83
|
+
};
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const panel = panelRef.current;
|
|
86
|
+
if (!panel || panel.matches(":popover-open") === open) return;
|
|
87
|
+
if (open) panel.showPopover();
|
|
88
|
+
else panel.hidePopover();
|
|
89
|
+
}, [open]);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (active < 0) return;
|
|
92
|
+
document.getElementById(`${optionId}-${active}`)?.scrollIntoView?.({ block: "nearest" });
|
|
93
|
+
}, [active, optionId]);
|
|
94
|
+
const show = (at = "selected") => {
|
|
95
|
+
setFiltering(false);
|
|
96
|
+
setOpen(true);
|
|
97
|
+
const current = options.findIndex((o) => o.value === value);
|
|
98
|
+
if (at === "last") setActive(lastEnabledOf(options));
|
|
99
|
+
else setActive(at === "selected" && current >= 0 ? current : firstEnabledOf(options));
|
|
100
|
+
};
|
|
101
|
+
const hide = () => {
|
|
102
|
+
setOpen(false);
|
|
103
|
+
setActive(-1);
|
|
104
|
+
};
|
|
105
|
+
const choose = (option) => {
|
|
106
|
+
if (option.disabled) return;
|
|
107
|
+
if (valueProp === void 0) setInnerValue(option.value);
|
|
108
|
+
setShownValue(option.value);
|
|
109
|
+
setQuery(option.label);
|
|
110
|
+
if (option.value !== value) onValueChange?.(option.value);
|
|
111
|
+
hide();
|
|
112
|
+
};
|
|
113
|
+
/** Leaving the field: an exact label match counts as a choice, anything else is undone. */
|
|
114
|
+
const settle = () => {
|
|
115
|
+
const exact = options.find((o) => !o.disabled && fold(o.label) === fold(query.trim()));
|
|
116
|
+
if (exact) choose(exact);
|
|
117
|
+
else if (!query.trim() && value) {
|
|
118
|
+
if (valueProp === void 0) setInnerValue("");
|
|
119
|
+
setShownValue("");
|
|
120
|
+
onValueChange?.("");
|
|
121
|
+
} else setQuery(selected?.label ?? "");
|
|
122
|
+
hide();
|
|
123
|
+
};
|
|
124
|
+
const onFieldKeyDown = (event) => {
|
|
125
|
+
onKeyDown?.(event);
|
|
126
|
+
if (event.defaultPrevented) return;
|
|
127
|
+
switch (event.key) {
|
|
128
|
+
case "ArrowDown":
|
|
129
|
+
if (event.altKey || !open) show(event.altKey ? "selected" : "first");
|
|
130
|
+
else setActive((i) => firstEnabled(i + 1, 1) >= 0 ? firstEnabled(i + 1, 1) : firstEnabled(0, 1));
|
|
131
|
+
break;
|
|
132
|
+
case "ArrowUp":
|
|
133
|
+
if (!open) show("last");
|
|
134
|
+
else setActive((i) => firstEnabled(i - 1, -1) >= 0 ? firstEnabled(i - 1, -1) : firstEnabled(visible.length - 1, -1));
|
|
135
|
+
break;
|
|
136
|
+
case "Enter":
|
|
137
|
+
if (!open) return;
|
|
138
|
+
if (enabled(active)) choose(visible[active]);
|
|
139
|
+
break;
|
|
140
|
+
case "Escape":
|
|
141
|
+
if (open) {
|
|
142
|
+
setQuery(selected?.label ?? "");
|
|
143
|
+
hide();
|
|
144
|
+
} else if (query) setQuery("");
|
|
145
|
+
else return;
|
|
146
|
+
break;
|
|
147
|
+
case "Home":
|
|
148
|
+
case "End": return;
|
|
149
|
+
default: return;
|
|
150
|
+
}
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
};
|
|
153
|
+
const activeId = open && active >= 0 ? `${optionId}-${active}` : void 0;
|
|
154
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
155
|
+
className: cx(wrap, className),
|
|
156
|
+
style,
|
|
157
|
+
children: [
|
|
158
|
+
/* @__PURE__ */ jsx("input", {
|
|
159
|
+
...rest,
|
|
160
|
+
...control,
|
|
161
|
+
ref: inputRef,
|
|
162
|
+
type: "text",
|
|
163
|
+
role: "combobox",
|
|
164
|
+
autoComplete: "off",
|
|
165
|
+
"aria-autocomplete": "list",
|
|
166
|
+
"aria-expanded": open,
|
|
167
|
+
"aria-controls": listId,
|
|
168
|
+
"aria-activedescendant": activeId,
|
|
169
|
+
placeholder,
|
|
170
|
+
value: query,
|
|
171
|
+
className: cx(input({ size }), field),
|
|
172
|
+
style: { anchorName: anchor },
|
|
173
|
+
onChange: (event) => {
|
|
174
|
+
setQuery(event.target.value);
|
|
175
|
+
setFiltering(true);
|
|
176
|
+
setOpen(true);
|
|
177
|
+
const matches = options.filter((o) => filter(o, event.target.value));
|
|
178
|
+
setActive(firstEnabledOf(matches));
|
|
179
|
+
},
|
|
180
|
+
onKeyDown: onFieldKeyDown,
|
|
181
|
+
onBlur: (event) => {
|
|
182
|
+
onBlur?.(event);
|
|
183
|
+
settle();
|
|
184
|
+
},
|
|
185
|
+
onClick: () => !open && show()
|
|
186
|
+
}),
|
|
187
|
+
/* @__PURE__ */ jsx("button", {
|
|
188
|
+
type: "button",
|
|
189
|
+
tabIndex: -1,
|
|
190
|
+
"aria-label": toggleLabel,
|
|
191
|
+
"aria-expanded": open,
|
|
192
|
+
"aria-controls": listId,
|
|
193
|
+
className: toggle,
|
|
194
|
+
disabled: control.disabled,
|
|
195
|
+
onPointerDown: (event) => event.preventDefault(),
|
|
196
|
+
onClick: () => {
|
|
197
|
+
if (open) hide();
|
|
198
|
+
else show();
|
|
199
|
+
inputRef.current?.focus();
|
|
200
|
+
},
|
|
201
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
202
|
+
icon: iconChevronDown,
|
|
203
|
+
size: 18
|
|
204
|
+
})
|
|
205
|
+
}),
|
|
206
|
+
name && /* @__PURE__ */ jsx("input", {
|
|
207
|
+
type: "hidden",
|
|
208
|
+
name,
|
|
209
|
+
value
|
|
210
|
+
}),
|
|
211
|
+
/* @__PURE__ */ jsxs("div", {
|
|
212
|
+
ref: panelRef,
|
|
213
|
+
popover: "manual",
|
|
214
|
+
className: cx(popover({ placement: "bottom-start" }), panel),
|
|
215
|
+
style: { positionAnchor: anchor },
|
|
216
|
+
onPointerDown: (event) => event.preventDefault(),
|
|
217
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
218
|
+
id: listId,
|
|
219
|
+
role: "listbox",
|
|
220
|
+
className: listbox,
|
|
221
|
+
"aria-label": rest["aria-label"],
|
|
222
|
+
children: visible.map((option$1, index) => /* @__PURE__ */ jsxs("div", {
|
|
223
|
+
id: `${optionId}-${index}`,
|
|
224
|
+
role: "option",
|
|
225
|
+
"aria-selected": option$1.value === value,
|
|
226
|
+
"aria-disabled": option$1.disabled || void 0,
|
|
227
|
+
"data-active": index === active ? "" : void 0,
|
|
228
|
+
className: option,
|
|
229
|
+
onPointerMove: () => enabled(index) && index !== active && setActive(index),
|
|
230
|
+
onClick: () => choose(option$1),
|
|
231
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
232
|
+
className: optionText,
|
|
233
|
+
children: [/* @__PURE__ */ jsx("span", { children: filtering ? /* @__PURE__ */ jsx(Highlight, {
|
|
234
|
+
text: option$1.label,
|
|
235
|
+
query
|
|
236
|
+
}) : option$1.label }), option$1.description && /* @__PURE__ */ jsx("span", {
|
|
237
|
+
className: "ml_1ouolxs7",
|
|
238
|
+
children: filtering ? /* @__PURE__ */ jsx(Highlight, {
|
|
239
|
+
text: option$1.description,
|
|
240
|
+
query
|
|
241
|
+
}) : option$1.description
|
|
242
|
+
})]
|
|
243
|
+
}), /* @__PURE__ */ jsx(Icon, {
|
|
244
|
+
icon: iconCheck,
|
|
245
|
+
size: 16,
|
|
246
|
+
className: check
|
|
247
|
+
})]
|
|
248
|
+
}, option$1.value))
|
|
249
|
+
}), /* @__PURE__ */ jsx("output", {
|
|
250
|
+
className: empty,
|
|
251
|
+
children: visible.length === 0 ? emptyText : null
|
|
252
|
+
})]
|
|
253
|
+
})
|
|
254
|
+
]
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function firstEnabledOf(list) {
|
|
258
|
+
return list.findIndex((o) => !o.disabled);
|
|
259
|
+
}
|
|
260
|
+
function lastEnabledOf(list) {
|
|
261
|
+
return list.findLastIndex((o) => !o.disabled);
|
|
262
|
+
}
|
|
263
|
+
export { Combobox, defaultFilter };
|
|
264
|
+
|
|
265
|
+
//# sourceMappingURL=combobox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combobox.js","names":["styles.match","styles.wrap","styles.input","styles.field","styles.toggle","styles.popover","styles.panel","styles.listbox","option","styles.option","styles.optionText","styles.check","styles.empty"],"sources":["../../../src/components/combobox/combobox.tsx"],"sourcesContent":["import {\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type ComponentPropsWithRef,\n type CSSProperties,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\nimport { iconCheck, iconChevronDown } from '@mohirlab/icons';\nimport { cx } from '../../utils/cx';\nimport { useFieldControl } from '../field/use-field-control';\nimport { Icon } from '../icon';\nimport type { InputVariants } from '../input/input.css';\nimport { useAnchorName } from '../popover/popover';\nimport * as styles from './combobox.css';\n\nexport interface ComboboxOption {\n value: string;\n label: string;\n /** A second, quieter line. Also searched. */\n description?: string;\n disabled?: boolean;\n}\n\n/** Case- and accent-insensitive, so \"o'zbek\" finds \"Oʻzbek\" and \"e\" finds \"é\". */\nconst fold = (text: string) =>\n text\n .normalize('NFD')\n .replace(/[̀-ͯʻʼ'’`]/g, '')\n .toLowerCase();\n\nexport const defaultFilter = (option: ComboboxOption, query: string) => {\n const q = fold(query.trim());\n return !q || fold(option.label).includes(q) || fold(option.description ?? '').includes(q);\n};\n\n/** The label with the first match of the query marked. */\nfunction Highlight({ text, query }: { text: string; query: string }) {\n const q = fold(query.trim());\n if (!q) return <>{text}</>;\n // fold() can change lengths (combining marks), so map positions character by character.\n const folded = [...text].map((c) => fold(c));\n let start = -1;\n for (let i = 0; i < folded.length && start < 0; i++) {\n let joined = '';\n for (let j = i; j < folded.length && joined.length < q.length; j++) joined += folded[j];\n if (joined.startsWith(q)) start = i;\n }\n if (start < 0) return <>{text}</>;\n const chars = [...text];\n let end = start;\n for (let length = 0; end < chars.length && length < q.length; end++) length += folded[end]!.length;\n return (\n <>\n {chars.slice(0, start).join('')}\n <mark className={styles.match}>{chars.slice(start, end).join('')}</mark>\n {chars.slice(end).join('')}\n </>\n );\n}\n\nexport interface ComboboxProps extends Omit<\n ComponentPropsWithRef<'input'>,\n 'size' | 'value' | 'defaultValue' | 'onChange' | 'children'\n> {\n options: ComboboxOption[];\n /** The chosen option's value; `''` for none. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n size?: InputVariants['size'];\n invalid?: boolean;\n /** Shown when nothing matches. */\n emptyText?: ReactNode;\n /** Decide which options match what was typed. Default: label or description contains it. */\n filter?: (option: ComboboxOption, query: string) => boolean;\n /** Accessible name of the open/close button. */\n toggleLabel?: string;\n}\n\n/**\n * A select you can type into: for long lists such as countries, people or tags.\n * Follows the WAI-ARIA combobox pattern (list autocomplete): focus stays in the field,\n * arrows move through the matches, Enter chooses, Escape closes. With `name` it submits\n * the chosen value, not the typed text. For short lists, prefer `Select`.\n */\nexport function Combobox({\n options,\n value: valueProp,\n defaultValue = '',\n onValueChange,\n size,\n invalid,\n emptyText = 'No matches',\n filter = defaultFilter,\n toggleLabel = 'Show options',\n name,\n placeholder,\n className,\n style,\n id,\n required,\n disabled,\n onKeyDown,\n onBlur,\n ...rest\n}: ComboboxProps) {\n const control = useFieldControl({\n id,\n required,\n disabled,\n invalid,\n 'aria-describedby': rest['aria-describedby'],\n });\n const listId = useId();\n const optionId = useId();\n const anchor = useAnchorName();\n const panelRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n\n const [innerValue, setInnerValue] = useState(defaultValue);\n const value = valueProp ?? innerValue;\n const selected = options.find((o) => o.value === value);\n const [query, setQuery] = useState(selected?.label ?? '');\n /** False right after opening: show every option, not only those matching the current label. */\n const [filtering, setFiltering] = useState(false);\n const [open, setOpen] = useState(false);\n const [active, setActive] = useState(-1);\n\n // Keep the text in step when the value changes from outside.\n const [shownValue, setShownValue] = useState(value);\n if (shownValue !== value) {\n setShownValue(value);\n setQuery(selected?.label ?? '');\n }\n\n const visible = useMemo(\n () => (filtering ? options.filter((o) => filter(o, query)) : options),\n [options, filter, query, filtering],\n );\n const enabled = (index: number) => index >= 0 && index < visible.length && !visible[index]!.disabled;\n const firstEnabled = (from: number, step: 1 | -1) => {\n for (let i = from; i >= 0 && i < visible.length; i += step) if (enabled(i)) return i;\n return -1;\n };\n\n useEffect(() => {\n const panel = panelRef.current;\n if (!panel || panel.matches(':popover-open') === open) return;\n if (open) panel.showPopover();\n else panel.hidePopover();\n }, [open]);\n\n useEffect(() => {\n if (active < 0) return;\n document.getElementById(`${optionId}-${active}`)?.scrollIntoView?.({ block: 'nearest' });\n }, [active, optionId]);\n\n const show = (at: 'selected' | 'first' | 'last' = 'selected') => {\n setFiltering(false);\n setOpen(true);\n const current = options.findIndex((o) => o.value === value);\n if (at === 'last') setActive(lastEnabledOf(options));\n else setActive(at === 'selected' && current >= 0 ? current : firstEnabledOf(options));\n };\n const hide = () => {\n setOpen(false);\n setActive(-1);\n };\n const choose = (option: ComboboxOption) => {\n if (option.disabled) return;\n if (valueProp === undefined) setInnerValue(option.value);\n setShownValue(option.value);\n setQuery(option.label);\n if (option.value !== value) onValueChange?.(option.value);\n hide();\n };\n /** Leaving the field: an exact label match counts as a choice, anything else is undone. */\n const settle = () => {\n const exact = options.find((o) => !o.disabled && fold(o.label) === fold(query.trim()));\n if (exact) choose(exact);\n else if (!query.trim() && value) {\n if (valueProp === undefined) setInnerValue('');\n setShownValue('');\n onValueChange?.('');\n } else setQuery(selected?.label ?? '');\n hide();\n };\n\n const onFieldKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(event);\n if (event.defaultPrevented) return;\n switch (event.key) {\n case 'ArrowDown':\n if (event.altKey || !open) show(event.altKey ? 'selected' : 'first');\n else setActive((i) => (firstEnabled(i + 1, 1) >= 0 ? firstEnabled(i + 1, 1) : firstEnabled(0, 1)));\n break;\n case 'ArrowUp':\n if (!open) show('last');\n else\n setActive((i) =>\n firstEnabled(i - 1, -1) >= 0 ? firstEnabled(i - 1, -1) : firstEnabled(visible.length - 1, -1),\n );\n break;\n case 'Enter':\n if (!open) return;\n if (enabled(active)) choose(visible[active]!);\n break;\n case 'Escape':\n if (open) {\n setQuery(selected?.label ?? '');\n hide();\n } else if (query) {\n setQuery('');\n } else return;\n break;\n case 'Home':\n case 'End':\n // In the text field these move the caret, as users expect.\n return;\n default:\n return;\n }\n event.preventDefault();\n };\n\n const activeId = open && active >= 0 ? `${optionId}-${active}` : undefined;\n\n return (\n <span className={cx(styles.wrap, className)} style={style}>\n <input\n {...rest}\n {...control}\n ref={inputRef}\n type=\"text\"\n role=\"combobox\"\n autoComplete=\"off\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={listId}\n aria-activedescendant={activeId}\n placeholder={placeholder}\n value={query}\n className={cx(styles.input({ size }), styles.field)}\n style={{ anchorName: anchor } as CSSProperties}\n onChange={(event) => {\n setQuery(event.target.value);\n setFiltering(true);\n setOpen(true);\n const matches = options.filter((o) => filter(o, event.target.value));\n setActive(firstEnabledOf(matches));\n }}\n onKeyDown={onFieldKeyDown}\n onBlur={(event) => {\n onBlur?.(event);\n settle();\n }}\n onClick={() => !open && show()}\n />\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={toggleLabel}\n aria-expanded={open}\n aria-controls={listId}\n className={styles.toggle}\n disabled={control.disabled}\n // Keep focus in the field.\n onPointerDown={(event) => event.preventDefault()}\n onClick={() => {\n if (open) hide();\n else show();\n inputRef.current?.focus();\n }}\n >\n <Icon icon={iconChevronDown} size={18} />\n </button>\n {name && <input type=\"hidden\" name={name} value={value} />}\n <div\n ref={panelRef}\n popover=\"manual\"\n className={cx(styles.popover({ placement: 'bottom-start' }), styles.panel)}\n style={{ positionAnchor: anchor } as CSSProperties}\n // Clicks inside must not blur the field.\n onPointerDown={(event) => event.preventDefault()}\n >\n {/* The combobox pattern needs ARIA listbox and option roles: focus stays in the field\n and aria-activedescendant points at the active option. A native <select> or\n <datalist> can be neither styled nor filtered like this. */}\n {/* oxlint-disable-next-line jsx-a11y/prefer-tag-over-role */}\n <div id={listId} role=\"listbox\" className={styles.listbox} aria-label={rest['aria-label']}>\n {visible.map((option, index) => (\n // Options are chosen with the keyboard from the field (see onFieldKeyDown), so they\n // take no focus and no key handlers of their own.\n // oxlint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/interactive-supports-focus\n <div\n key={option.value}\n id={`${optionId}-${index}`}\n // oxlint-disable-next-line jsx-a11y/prefer-tag-over-role\n role=\"option\"\n aria-selected={option.value === value}\n aria-disabled={option.disabled || undefined}\n data-active={index === active ? '' : undefined}\n className={styles.option}\n onPointerMove={() => enabled(index) && index !== active && setActive(index)}\n onClick={() => choose(option)}\n >\n <span className={styles.optionText}>\n <span>{filtering ? <Highlight text={option.label} query={query} /> : option.label}</span>\n {option.description && (\n <span className={styles.optionDescription}>\n {filtering ? <Highlight text={option.description} query={query} /> : option.description}\n </span>\n )}\n </span>\n <Icon icon={iconCheck} size={16} className={styles.check} />\n </div>\n ))}\n </div>\n {/* Always present, so screen readers announce the text when it appears. */}\n <output className={styles.empty}>{visible.length === 0 ? emptyText : null}</output>\n </div>\n </span>\n );\n}\n\nfunction firstEnabledOf(list: ComboboxOption[]) {\n return list.findIndex((o) => !o.disabled);\n}\nfunction lastEnabledOf(list: ComboboxOption[]) {\n return list.findLastIndex((o) => !o.disabled);\n}\n"],"mappings":";;;;;;;;;;;AA4BA,MAAM,QAAQ,SACZ,KACG,UAAU,KAAK,CAAC,CAChB,QAAQ,eAAe,EAAE,CAAC,CAC1B,YAAY;AAEjB,MAAa,iBAAiB,QAAwB,UAAkB;CACtE,MAAM,IAAI,KAAK,MAAM,KAAK,CAAC;CAC3B,OAAO,CAAC,KAAK,KAAK,OAAO,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,KAAK,OAAO,eAAe,EAAE,CAAC,CAAC,SAAS,CAAC;AAC1F;;AAGA,SAAS,UAAU,EAAE,MAAM,SAA0C;CACnE,MAAM,IAAI,KAAK,MAAM,KAAK,CAAC;CAC3B,IAAI,CAAC,GAAG,OAAO,oBAAA,UAAA,EAAA,UAAG,KAAO,CAAA;CAEzB,MAAM,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC;CAC3C,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,UAAU,QAAQ,GAAG,KAAK;EACnD,IAAI,SAAS;EACb,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,UAAU,OAAO,SAAS,EAAE,QAAQ,KAAK,UAAU,OAAO;EACrF,IAAI,OAAO,WAAW,CAAC,GAAG,QAAQ;CACp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qBAAC,OAAD;MAEE,IAAI,GAAG,SAAS,GAAG;MAEnB,MAAK;MACL,iBAAeA,SAAO,UAAU;MAChC,iBAAeA,SAAO,YAAY,KAAA;MAClC,eAAa,UAAU,SAAS,KAAK,KAAA;MACrC,WAAWC;MACX,qBAAqB,QAAQ,KAAK,KAAK,UAAU,UAAU,UAAU,KAAK;MAC1E,eAAe,OAAOD,QAAM;MAV9B,UAAA,CAYE,qBAAC,QAAD;OAAM,WAAWE;OAAjB,UAAA,CACE,oBAAC,QAAD,EAAA,UAAO,YAAY,oBAAC,WAAD;QAAW,MAAMF,SAAO;QAAc;OAAQ,CAAA,IAAIA,SAAO,MAAY,CAAA,GACvFA,SAAO,eACN,oBAAC,QAAD;QAAM,WAAW;QACd,UAAA,YAAY,oBAAC,WAAD;SAAW,MAAMA,SAAO;SAAoB;QAAQ,CAAA,IAAIA,SAAO;OACxE,CAAA,CAEJ;MACN,CAAA,GAAA,oBAAC,MAAD;OAAM,MAAM;OAAW,MAAM;OAAI,WAAWG;MAAe,CAAA,CACxD;KApBEH,GAAAA,SAAO,KAoBT,CACN;IACE,CAAA,GAEL,oBAAC,UAAD;KAAQ,WAAWI;KAAe,UAAA,QAAQ,WAAW,IAAI,YAAY;IAAa,CAAA,CAC/E;;EACD;;AAEV;AAEA,SAAS,eAAe,MAAwB;CAC9C,OAAO,KAAK,WAAW,MAAM,CAAC,EAAE,QAAQ;AAC1C;AACA,SAAS,cAAc,MAAwB;CAC7C,OAAO,KAAK,eAAe,MAAM,CAAC,EAAE,QAAQ;AAC9C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
3
|
+
// src/components/combobox/combobox.css.ts
|
|
4
|
+
var check = "ml_1ouolxs8";
|
|
5
|
+
var empty = "ml_1ouolxsa";
|
|
6
|
+
var field = "ml_1ouolxs1";
|
|
7
|
+
var input = createRuntimeFn({
|
|
8
|
+
defaultClassName: "ml_18bh0930",
|
|
9
|
+
variantClassNames: { size: {
|
|
10
|
+
sm: "ml_size_sm_18bh0931",
|
|
11
|
+
md: "ml_size_md_18bh0932",
|
|
12
|
+
lg: "ml_size_lg_18bh0933"
|
|
13
|
+
} },
|
|
14
|
+
defaultVariants: { size: "md" },
|
|
15
|
+
compoundVariants: []
|
|
16
|
+
});
|
|
17
|
+
var listbox = "ml_1ouolxs4";
|
|
18
|
+
var match = "ml_1ouolxs9";
|
|
19
|
+
var option = "ml_1ouolxs5";
|
|
20
|
+
var optionDescription = "ml_1ouolxs7";
|
|
21
|
+
var optionText = "ml_1ouolxs6";
|
|
22
|
+
var panel = "ml_1ouolxs3";
|
|
23
|
+
var popover = createRuntimeFn({
|
|
24
|
+
defaultClassName: "ml_12557yp0",
|
|
25
|
+
variantClassNames: { placement: {
|
|
26
|
+
top: "ml_placement_top_12557yp1",
|
|
27
|
+
"top-start": "ml_placement_top-start_12557yp2",
|
|
28
|
+
"top-end": "ml_placement_top-end_12557yp3",
|
|
29
|
+
bottom: "ml_placement_bottom_12557yp4",
|
|
30
|
+
"bottom-start": "ml_placement_bottom-start_12557yp5",
|
|
31
|
+
"bottom-end": "ml_placement_bottom-end_12557yp6",
|
|
32
|
+
start: "ml_placement_start_12557yp7",
|
|
33
|
+
end: "ml_placement_end_12557yp8"
|
|
34
|
+
} },
|
|
35
|
+
defaultVariants: { placement: "bottom-start" },
|
|
36
|
+
compoundVariants: []
|
|
37
|
+
});
|
|
38
|
+
var toggle = "ml_1ouolxs2";
|
|
39
|
+
var wrap = "ml_1ouolxs0";
|
|
40
|
+
export { check, empty, field, input, listbox, match, option, optionDescription, optionText, panel, popover, toggle, wrap };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=combobox.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combobox.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
import { RecipeVariants } from "@vanilla-extract/recipes";
|
|
3
|
+
export declare const skeleton: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
4
|
+
shape: {
|
|
5
|
+
text: {
|
|
6
|
+
height: "0.75em";
|
|
7
|
+
marginBlock: "0.375em";
|
|
8
|
+
borderRadius: `var(--${string})`;
|
|
9
|
+
};
|
|
10
|
+
circle: {
|
|
11
|
+
borderRadius: `var(--${string})`;
|
|
12
|
+
aspectRatio: "1";
|
|
13
|
+
};
|
|
14
|
+
block: {
|
|
15
|
+
borderRadius: `var(--${string})`;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
export type SkeletonVariants = NonNullable<RecipeVariants<typeof skeleton>>;
|
|
20
|
+
export declare const empty: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
21
|
+
size: {
|
|
22
|
+
sm: {
|
|
23
|
+
paddingBlock: `var(--${string})`;
|
|
24
|
+
};
|
|
25
|
+
md: {
|
|
26
|
+
paddingBlock: `var(--${string})`;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** A dashed paper edge, for drop zones and empty panels inside a page. */
|
|
30
|
+
framed: {
|
|
31
|
+
true: {
|
|
32
|
+
border: `1px dashed var(--${string})`;
|
|
33
|
+
borderRadius: `var(--${string})`;
|
|
34
|
+
};
|
|
35
|
+
false: {};
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
export type EmptyStateVariants = NonNullable<RecipeVariants<typeof empty>>;
|
|
39
|
+
//# sourceMappingURL=feedback.css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback.css.d.ts","names":[],"sources":["../../../src/components/feedback/feedback.css.ts"],"mappings":";;qBAYa,6CAAQ;;;;;;;;;;;;MAcN;;;;YAMH,mBAAmB,YAAY,sBAAsB;qBAOpD,0CAAK;;IAYZ;MAAM;;IACN;MAAM;;;;;;;;;;;;YAWA,qBAAqB,YAAY,sBAAsB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
import { IconData } from "@mohirlab/icons";
|
|
4
|
+
import { EmptyStateVariants, SkeletonVariants } from "./feedback.css.js";
|
|
5
|
+
type Length = number | string;
|
|
6
|
+
export interface SkeletonProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {
|
|
7
|
+
/** `text` follows the font size, `circle` is for avatars, `block` for images and cards. */
|
|
8
|
+
shape?: SkeletonVariants['shape'];
|
|
9
|
+
/** For `text`: how many lines. The last one is shorter. Default 1. */
|
|
10
|
+
lines?: number;
|
|
11
|
+
width?: Length;
|
|
12
|
+
/** For `block`. */
|
|
13
|
+
height?: Length;
|
|
14
|
+
/** For `circle`: the diameter. */
|
|
15
|
+
size?: Length;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A placeholder in the shape of content that is still loading. It is hidden from
|
|
19
|
+
* assistive technology: mark the loading region with `aria-busy="true"` and give it a
|
|
20
|
+
* name or a status message, so screen reader users hear that something is loading.
|
|
21
|
+
*/
|
|
22
|
+
export declare function Skeleton({ shape, lines, width, height, size, className, style, ...rest }: SkeletonProps): import("react").JSX.Element;
|
|
23
|
+
export interface EmptyStateProps extends Omit<ComponentPropsWithRef<'div'>, 'title'> {
|
|
24
|
+
/** Shown in the seal tile above the title. */
|
|
25
|
+
icon?: IconData;
|
|
26
|
+
title: ReactNode;
|
|
27
|
+
/** One or two sentences: why it is empty and what to do next. */
|
|
28
|
+
description?: ReactNode;
|
|
29
|
+
/** Usually one primary `Button`, maybe a secondary one. */
|
|
30
|
+
actions?: ReactNode;
|
|
31
|
+
/** `sm` inside panels and cards, `md` for a whole page or table. */
|
|
32
|
+
size?: EmptyStateVariants['size'];
|
|
33
|
+
/** Dashed edge: for empty panels inside a page and drop zones. */
|
|
34
|
+
framed?: boolean;
|
|
35
|
+
/** Heading level of the title. Default 2. */
|
|
36
|
+
level?: 2 | 3 | 4;
|
|
37
|
+
}
|
|
38
|
+
/** What a list, table or page shows when there is nothing in it yet, or no results. */
|
|
39
|
+
export declare function EmptyState({ icon, title, description, actions, size, framed, level, className, children, ...rest }: EmptyStateProps): import("react").JSX.Element;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=feedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback.d.ts","names":["styles.SkeletonVariants","styles.EmptyStateVariants"],"sources":["../../../src/components/feedback/feedback.tsx"],"mappings":";;;;KAMK;iBAGY,sBAAsB,KAAK;;EAE1C,QAAQA;;EAER;EACA,QAAQ;;EAER,SAAS;;EAET,OAAO;;;;;;;wBAQO,WACd,OACA,OACA,OACA,QACA,MACA,WACA,UACG,QACF,gCAAa,IAAA;iBAsBC,wBAAwB,KAAK;;EAE5C,OAAO;EACP,OAAO;;EAEP,cAAc;;EAEd,UAAU;;EAEV,OAAOC;;EAEP;;EAEA;;;wBAIc,aACd,MACA,OACA,aACA,SACA,MACA,QACA,OACA,WACA,aACG,QACF,kCAAe,IAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../../utils/cx.js";
|
|
3
|
+
import { Icon } from "../icon/icon.js";
|
|
4
|
+
import { empty, emptyTitle, skeleton, skeletonLines } from "./feedback.styles.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/components/feedback/feedback.tsx
|
|
7
|
+
const toLength = (value) => typeof value === "number" ? `${value}px` : value;
|
|
8
|
+
/**
|
|
9
|
+
* A placeholder in the shape of content that is still loading. It is hidden from
|
|
10
|
+
* assistive technology: mark the loading region with `aria-busy="true"` and give it a
|
|
11
|
+
* name or a status message, so screen reader users hear that something is loading.
|
|
12
|
+
*/
|
|
13
|
+
function Skeleton({ shape = "text", lines = 1, width, height, size, className, style, ...rest }) {
|
|
14
|
+
const box = {
|
|
15
|
+
width: toLength(shape === "circle" ? size : width),
|
|
16
|
+
height: toLength(shape === "circle" ? void 0 : height),
|
|
17
|
+
...style
|
|
18
|
+
};
|
|
19
|
+
if (shape === "circle" && box.width === void 0) box.width = "2.5rem";
|
|
20
|
+
if (shape === "text" && lines > 1) return /* @__PURE__ */ jsx("span", {
|
|
21
|
+
...rest,
|
|
22
|
+
"aria-hidden": "true",
|
|
23
|
+
className: cx(skeletonLines, className),
|
|
24
|
+
style: box,
|
|
25
|
+
children: Array.from({ length: lines }, (_, i) => /* @__PURE__ */ jsx("span", { className: cx(skeleton({ shape }), i === lines - 1 && "ml_5ga6w26") }, i))
|
|
26
|
+
});
|
|
27
|
+
return /* @__PURE__ */ jsx("span", {
|
|
28
|
+
...rest,
|
|
29
|
+
"aria-hidden": "true",
|
|
30
|
+
className: cx(skeleton({ shape }), className),
|
|
31
|
+
style: box
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** What a list, table or page shows when there is nothing in it yet, or no results. */
|
|
35
|
+
function EmptyState({ icon, title, description, actions, size, framed, level = 2, className, children, ...rest }) {
|
|
36
|
+
const Heading = `h${level}`;
|
|
37
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
38
|
+
...rest,
|
|
39
|
+
className: cx(empty({
|
|
40
|
+
size,
|
|
41
|
+
framed
|
|
42
|
+
}), className),
|
|
43
|
+
children: [
|
|
44
|
+
icon && /* @__PURE__ */ jsx("span", {
|
|
45
|
+
className: "ml_5ga6w2c",
|
|
46
|
+
"aria-hidden": "true",
|
|
47
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
48
|
+
icon,
|
|
49
|
+
size: 22
|
|
50
|
+
})
|
|
51
|
+
}),
|
|
52
|
+
/* @__PURE__ */ jsx(Heading, {
|
|
53
|
+
className: emptyTitle,
|
|
54
|
+
children: title
|
|
55
|
+
}),
|
|
56
|
+
description && /* @__PURE__ */ jsx("p", {
|
|
57
|
+
className: "ml_5ga6w2e",
|
|
58
|
+
children: description
|
|
59
|
+
}),
|
|
60
|
+
children,
|
|
61
|
+
actions && /* @__PURE__ */ jsx("div", {
|
|
62
|
+
className: "ml_5ga6w2f",
|
|
63
|
+
children: actions
|
|
64
|
+
})
|
|
65
|
+
]
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export { EmptyState, Skeleton };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=feedback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback.js","names":["styles.skeletonLines","styles.skeleton","styles.empty","styles.emptyTitle"],"sources":["../../../src/components/feedback/feedback.tsx"],"sourcesContent":["import type { ComponentPropsWithRef, CSSProperties, ReactNode } from 'react';\nimport type { IconData } from '@mohirlab/icons';\nimport { cx } from '../../utils/cx';\nimport { Icon } from '../icon';\nimport * as styles from './feedback.css';\n\ntype Length = number | string;\nconst toLength = (value: Length | undefined) => (typeof value === 'number' ? `${value}px` : value);\n\nexport interface SkeletonProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /** `text` follows the font size, `circle` is for avatars, `block` for images and cards. */\n shape?: styles.SkeletonVariants['shape'];\n /** For `text`: how many lines. The last one is shorter. Default 1. */\n lines?: number;\n width?: Length;\n /** For `block`. */\n height?: Length;\n /** For `circle`: the diameter. */\n size?: Length;\n}\n\n/**\n * A placeholder in the shape of content that is still loading. It is hidden from\n * assistive technology: mark the loading region with `aria-busy=\"true\"` and give it a\n * name or a status message, so screen reader users hear that something is loading.\n */\nexport function Skeleton({\n shape = 'text',\n lines = 1,\n width,\n height,\n size,\n className,\n style,\n ...rest\n}: SkeletonProps) {\n const box: CSSProperties = {\n width: toLength(shape === 'circle' ? size : width),\n height: toLength(shape === 'circle' ? undefined : height),\n ...style,\n };\n if (shape === 'circle' && box.width === undefined) box.width = '2.5rem';\n\n if (shape === 'text' && lines > 1) {\n return (\n <span {...rest} aria-hidden=\"true\" className={cx(styles.skeletonLines, className)} style={box}>\n {Array.from({ length: lines }, (_, i) => (\n <span key={i} className={cx(styles.skeleton({ shape }), i === lines - 1 && styles.lastLine)} />\n ))}\n </span>\n );\n }\n return (\n <span {...rest} aria-hidden=\"true\" className={cx(styles.skeleton({ shape }), className)} style={box} />\n );\n}\n\nexport interface EmptyStateProps extends Omit<ComponentPropsWithRef<'div'>, 'title'> {\n /** Shown in the seal tile above the title. */\n icon?: IconData;\n title: ReactNode;\n /** One or two sentences: why it is empty and what to do next. */\n description?: ReactNode;\n /** Usually one primary `Button`, maybe a secondary one. */\n actions?: ReactNode;\n /** `sm` inside panels and cards, `md` for a whole page or table. */\n size?: styles.EmptyStateVariants['size'];\n /** Dashed edge: for empty panels inside a page and drop zones. */\n framed?: boolean;\n /** Heading level of the title. Default 2. */\n level?: 2 | 3 | 4;\n}\n\n/** What a list, table or page shows when there is nothing in it yet, or no results. */\nexport function EmptyState({\n icon,\n title,\n description,\n actions,\n size,\n framed,\n level = 2,\n className,\n children,\n ...rest\n}: EmptyStateProps) {\n const Heading = `h${level}` as const;\n return (\n <div {...rest} className={cx(styles.empty({ size, framed }), className)}>\n {icon && (\n <span className={styles.emptyMark} aria-hidden=\"true\">\n <Icon icon={icon} size={22} />\n </span>\n )}\n <Heading className={styles.emptyTitle}>{title}</Heading>\n {description && <p className={styles.emptyText}>{description}</p>}\n {children}\n {actions && <div className={styles.emptyActions}>{actions}</div>}\n </div>\n );\n}\n"],"mappings":";;;;;;AAOA,MAAM,YAAY,UAA+B,OAAO,UAAU,WAAW,GAAG,MAAM,MAAM;;;;;;AAmB5F,SAAgB,SAAS,EACvB,QAAQ,QACR,QAAQ,GACR,OACA,QACA,MACA,WACA,OACA,GAAG,QACa;CAChB,MAAM,MAAqB;EACzB,OAAO,SAAS,UAAU,WAAW,OAAO,KAAK;EACjD,QAAQ,SAAS,UAAU,WAAW,KAAA,IAAY,MAAM;EACxD,GAAG;CACL;CACA,IAAI,UAAU,YAAY,IAAI,UAAU,KAAA,GAAW,IAAI,QAAQ;CAE/D,IAAI,UAAU,UAAU,QAAQ,GAC9B,OACE,oBAAC,QAAD;EAAM,GAAI;EAAM,eAAY;EAAO,WAAW,GAAGA,eAAsB,SAAS;EAAG,OAAO;EACvF,UAAA,MAAM,KAAK,EAAE,QAAQ,MAAM,IAAI,GAAG,MACjC,oBAAC,QAAD,EAAc,WAAW,GAAGC,SAAgB,EAAE,MAAM,CAAC,GAAG,MAAM,QAAQ,KAAK,YAAe,EAAI,GAAnF,CAAmF,CAC/F;CACG,CAAA;CAGV,OACE,oBAAC,QAAD;EAAM,GAAI;EAAM,eAAY;EAAO,WAAW,GAAGA,SAAgB,EAAE,MAAM,CAAC,GAAG,SAAS;EAAG,OAAO;CAAM,CAAA;AAE1G;;AAmBA,SAAgB,WAAW,EACzB,MACA,OACA,aACA,SACA,MACA,QACA,QAAQ,GACR,WACA,UACA,GAAG,QACe;CAClB,MAAM,UAAU,IAAI;CACpB,OACE,qBAAC,OAAD;EAAK,GAAI;EAAM,WAAW,GAAGC,MAAa;GAAE;GAAM;EAAO,CAAC,GAAG,SAAS;EAAtE,UAAA;GACG,QACC,oBAAC,QAAD;IAAM,WAAW;IAAkB,eAAY;IAC7C,UAAA,oBAAC,MAAD;KAAY;KAAM,MAAM;IAAK,CAAA;GACzB,CAAA;GAER,oBAAC,SAAD;IAAS,WAAWC;IAAoB,UAAA;GAAe,CAAA;GACtD,eAAe,oBAAC,KAAD;IAAG,WAAW;IAAmB,UAAA;GAAe,CAAA;GAC/D;GACA,WAAW,oBAAC,OAAD;IAAK,WAAW;IAAsB,UAAA;GAAa,CAAA;EAC5D;;AAET"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
3
|
+
// src/components/feedback/feedback.css.ts
|
|
4
|
+
var empty = createRuntimeFn({
|
|
5
|
+
defaultClassName: "ml_5ga6w27",
|
|
6
|
+
variantClassNames: {
|
|
7
|
+
size: {
|
|
8
|
+
sm: "ml_size_sm_5ga6w28",
|
|
9
|
+
md: "ml_size_md_5ga6w29"
|
|
10
|
+
},
|
|
11
|
+
framed: {
|
|
12
|
+
true: "ml_framed_true_5ga6w2a",
|
|
13
|
+
false: "ml_framed_false_5ga6w2b"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
defaultVariants: {
|
|
17
|
+
size: "md",
|
|
18
|
+
framed: false
|
|
19
|
+
},
|
|
20
|
+
compoundVariants: []
|
|
21
|
+
});
|
|
22
|
+
var emptyActions = "ml_5ga6w2f";
|
|
23
|
+
var emptyMark = "ml_5ga6w2c";
|
|
24
|
+
var emptyText = "ml_5ga6w2e";
|
|
25
|
+
var emptyTitle = "ml_5ga6w2d";
|
|
26
|
+
var lastLine = "ml_5ga6w26";
|
|
27
|
+
var skeleton = createRuntimeFn({
|
|
28
|
+
defaultClassName: "ml_5ga6w21",
|
|
29
|
+
variantClassNames: { shape: {
|
|
30
|
+
text: "ml_shape_text_5ga6w22",
|
|
31
|
+
circle: "ml_shape_circle_5ga6w23",
|
|
32
|
+
block: "ml_shape_block_5ga6w24"
|
|
33
|
+
} },
|
|
34
|
+
defaultVariants: { shape: "text" },
|
|
35
|
+
compoundVariants: []
|
|
36
|
+
});
|
|
37
|
+
var skeletonLines = "ml_5ga6w25";
|
|
38
|
+
export { empty, emptyActions, emptyMark, emptyText, emptyTitle, lastLine, skeleton, skeletonLines };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=feedback.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.css.d.ts","names":[],"sources":["../../../src/components/input/input.css.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"input.css.d.ts","names":[],"sources":["../../../src/components/input/input.css.ts"],"mappings":";;;;;;qBAyBa,0CAAK;;IAqCZ,mCAAE;IAIF,mCAAE;IACF,mCAAE;;;YAMI,gBAAgB,YAAY,sBAAsB"}
|