@overdoser/react-toolkit 0.18.0 → 0.20.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/AGENTS.md +51 -7
- package/CHANGELOG.md +162 -0
- package/components/Accordion/Accordion.d.ts +94 -0
- package/components/Accordion/Accordion.js +180 -0
- package/components/Accordion/Accordion.module.scss.js +36 -0
- package/components/Accordion/index.d.ts +2 -0
- package/components/Alert/Alert.d.ts +29 -1
- package/components/Alert/Alert.js +44 -30
- package/components/Alert/Alert.module.scss.js +24 -16
- package/components/Alert/index.d.ts +1 -1
- package/components/Card/Card.d.ts +86 -0
- package/components/Card/Card.js +132 -0
- package/components/Card/Card.module.scss.js +60 -0
- package/components/Card/index.d.ts +2 -0
- package/components/Chip/Chip.d.ts +86 -0
- package/components/Chip/Chip.js +141 -0
- package/components/Chip/Chip.module.scss.js +59 -0
- package/components/Chip/index.d.ts +2 -0
- package/components/CodeBlock/CodeBlock.d.ts +78 -0
- package/components/CodeBlock/CodeBlock.js +120 -0
- package/components/CodeBlock/CodeBlock.module.scss.js +43 -0
- package/components/CodeBlock/index.d.ts +2 -0
- package/components/CommandPalette/CommandPalette.d.ts +141 -0
- package/components/CommandPalette/CommandPalette.js +397 -0
- package/components/CommandPalette/CommandPalette.module.scss.js +49 -0
- package/components/CommandPalette/index.d.ts +2 -0
- package/components/ConfirmDialog/ConfirmDialog.d.ts +119 -0
- package/components/ConfirmDialog/ConfirmDialog.js +201 -0
- package/components/ConfirmDialog/ConfirmDialog.module.scss.js +21 -0
- package/components/ConfirmDialog/index.d.ts +2 -0
- package/components/Drawer/Drawer.d.ts +1 -0
- package/components/Drawer/Drawer.js +35 -36
- package/components/Drawer/Drawer.module.scss.js +20 -18
- package/components/Dropdown/Dropdown.d.ts +47 -7
- package/components/Dropdown/Dropdown.js +174 -81
- package/components/Dropdown/Dropdown.module.scss.js +40 -22
- package/components/Dropdown/DropdownItem.d.ts +31 -2
- package/components/Dropdown/DropdownItem.js +54 -27
- package/components/Dropdown/DropdownLabel.d.ts +11 -0
- package/components/Dropdown/DropdownLabel.js +11 -0
- package/components/Dropdown/DropdownSeparator.d.ts +12 -0
- package/components/Dropdown/DropdownSeparator.js +11 -0
- package/components/Dropdown/dropdownContext.d.ts +6 -0
- package/components/Dropdown/dropdownContext.js +5 -0
- package/components/Dropdown/index.d.ts +8 -2
- package/components/Dropdown/useContextMenu.d.ts +32 -0
- package/components/Dropdown/useContextMenu.js +18 -0
- package/components/EmptyState/EmptyState.d.ts +53 -0
- package/components/EmptyState/EmptyState.js +55 -0
- package/components/EmptyState/EmptyState.module.scss.js +25 -0
- package/components/EmptyState/index.d.ts +2 -0
- package/components/Form/FormField.js +25 -24
- package/components/ImageViewer/ImageViewer.d.ts +105 -0
- package/components/ImageViewer/ImageViewer.js +201 -0
- package/components/ImageViewer/ImageViewer.module.scss.js +47 -0
- package/components/ImageViewer/index.d.ts +4 -0
- package/components/ImageViewer/useZoomPan.d.ts +94 -0
- package/components/ImageViewer/useZoomPan.js +141 -0
- package/components/Kbd/Kbd.d.ts +26 -0
- package/components/Kbd/Kbd.js +22 -0
- package/components/Kbd/Kbd.module.scss.js +17 -0
- package/components/Kbd/index.d.ts +2 -0
- package/components/KeyValueList/KeyValueList.d.ts +84 -0
- package/components/KeyValueList/KeyValueList.js +127 -0
- package/components/KeyValueList/KeyValueList.module.scss.js +43 -0
- package/components/KeyValueList/index.d.ts +2 -0
- package/components/Modal/Modal.d.ts +1 -0
- package/components/Modal/Modal.js +40 -41
- package/components/Modal/Modal.module.scss.js +18 -16
- package/components/PageHeader/PageHeader.d.ts +61 -0
- package/components/PageHeader/PageHeader.js +73 -0
- package/components/PageHeader/PageHeader.module.scss.js +43 -0
- package/components/PageHeader/index.d.ts +2 -0
- package/components/ProgressBar/ProgressBar.d.ts +74 -0
- package/components/ProgressBar/ProgressBar.js +90 -0
- package/components/ProgressBar/ProgressBar.module.scss.js +51 -0
- package/components/ProgressBar/index.d.ts +2 -0
- package/components/RelativeTime/RelativeTime.d.ts +45 -0
- package/components/RelativeTime/RelativeTime.js +43 -0
- package/components/RelativeTime/RelativeTime.module.scss.js +7 -0
- package/components/RelativeTime/index.d.ts +2 -0
- package/components/SegmentedControl/SegmentedControl.d.ts +84 -0
- package/components/SegmentedControl/SegmentedControl.js +131 -0
- package/components/SegmentedControl/SegmentedControl.module.scss.js +39 -0
- package/components/SegmentedControl/index.d.ts +2 -0
- package/components/SplitPane/SplitPane.d.ts +61 -0
- package/components/SplitPane/SplitPane.js +171 -0
- package/components/SplitPane/SplitPane.module.scss.js +25 -0
- package/components/SplitPane/index.d.ts +2 -0
- package/components/StatCard/StatCard.d.ts +105 -0
- package/components/StatCard/StatCard.js +127 -0
- package/components/StatCard/StatCard.module.scss.js +72 -0
- package/components/StatCard/index.d.ts +2 -0
- package/components/StatusDot/StatusDot.d.ts +33 -0
- package/components/StatusDot/StatusDot.js +39 -0
- package/components/StatusDot/StatusDot.module.scss.js +32 -0
- package/components/StatusDot/index.d.ts +2 -0
- package/components/Table/Table.d.ts +140 -17
- package/components/Table/Table.js +382 -210
- package/components/Table/Table.module.scss.js +68 -46
- package/components/Table/index.d.ts +1 -1
- package/components/Table/useTableSort.d.ts +1 -1
- package/components/ThemeToggle/ThemeToggle.d.ts +40 -0
- package/components/ThemeToggle/ThemeToggle.js +98 -0
- package/components/ThemeToggle/ThemeToggle.module.scss.js +23 -0
- package/components/ThemeToggle/index.d.ts +2 -0
- package/components/inputs/Checkbox/Checkbox.d.ts +2 -0
- package/components/inputs/Checkbox/Checkbox.js +29 -28
- package/components/inputs/Checkbox/Checkbox.module.scss.js +8 -6
- package/components/inputs/Input/Input.d.ts +33 -1
- package/components/inputs/Input/Input.js +94 -35
- package/components/inputs/Input/Input.module.scss.js +14 -12
- package/components/inputs/Radio/Radio.d.ts +5 -4
- package/components/inputs/Radio/Radio.js +55 -50
- package/components/inputs/Radio/Radio.module.scss.js +12 -10
- package/components/inputs/SearchInput/SearchInput.d.ts +57 -0
- package/components/inputs/SearchInput/SearchInput.js +116 -0
- package/components/inputs/SearchInput/SearchInput.module.scss.js +13 -0
- package/components/inputs/SearchInput/index.d.ts +2 -0
- package/components/inputs/Select/Select.d.ts +52 -0
- package/components/inputs/Select/Select.js +494 -385
- package/components/inputs/Select/Select.module.scss.js +34 -30
- package/components/inputs/Switch/Switch.d.ts +15 -0
- package/components/inputs/Switch/Switch.js +8 -0
- package/components/inputs/Switch/index.d.ts +2 -0
- package/hooks/useDebouncedValue.d.ts +15 -0
- package/hooks/useDebouncedValue.js +15 -0
- package/hooks/useElementSize.d.ts +20 -0
- package/hooks/useElementSize.js +23 -0
- package/hooks/useKeyboard.d.ts +49 -5
- package/hooks/useKeyboard.js +66 -16
- package/hooks/useMediaQuery.d.ts +14 -0
- package/hooks/useMediaQuery.js +16 -0
- package/hooks/useNow.d.ts +14 -0
- package/hooks/useNow.js +35 -0
- package/hooks/usePersistedState.d.ts +30 -0
- package/hooks/usePersistedState.js +99 -0
- package/hooks/useResizable.d.ts +66 -0
- package/hooks/useResizable.js +105 -0
- package/hooks/useTheme.d.ts +33 -0
- package/hooks/useTheme.js +25 -0
- package/index.css +1 -1
- package/index.d.ts +58 -4
- package/index.js +208 -132
- package/index.layered.css +1 -1
- package/llms.txt +620 -26
- package/manifest.json +1795 -99
- package/package.json +1 -1
- package/recipes/confirm-modal.tsx +65 -53
- package/recipes/floating-copy-button.tsx +32 -28
- package/utils/formatBytes.d.ts +21 -0
- package/utils/formatBytes.js +14 -0
- package/utils/index.d.ts +6 -0
- package/utils/themeScript.d.ts +19 -0
- package/utils/themeScript.js +9 -0
- package/utils/timeAgo.d.ts +33 -0
- package/utils/timeAgo.js +37 -0
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
const r = "crk-root-rSgdy", s = "crk-wrapper-GHy8V", c = "crk-sm-DptM5",
|
|
1
|
+
const r = "crk-root-rSgdy", s = "crk-wrapper-GHy8V", c = "crk-sm-DptM5", o = "crk-md-F4B0G", t = "crk-lg-pBxwX", f = "crk-error-fucxe", e = "crk-prefix-w53Md", n = "crk-suffix-fcNgR", i = "crk-hasPrefix--bqPD", x = "crk-hasSuffix-zO0nX", p = "crk-sideButton-H3GC-", a = {
|
|
2
2
|
root: r,
|
|
3
3
|
wrapper: s,
|
|
4
4
|
sm: c,
|
|
5
|
-
md:
|
|
6
|
-
lg:
|
|
7
|
-
error:
|
|
5
|
+
md: o,
|
|
6
|
+
lg: t,
|
|
7
|
+
error: f,
|
|
8
8
|
prefix: e,
|
|
9
|
-
suffix:
|
|
9
|
+
suffix: n,
|
|
10
10
|
hasPrefix: i,
|
|
11
|
-
hasSuffix:
|
|
11
|
+
hasSuffix: x,
|
|
12
|
+
sideButton: p
|
|
12
13
|
};
|
|
13
14
|
export {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
a as default,
|
|
16
|
+
f as error,
|
|
16
17
|
i as hasPrefix,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
x as hasSuffix,
|
|
19
|
+
t as lg,
|
|
20
|
+
o as md,
|
|
20
21
|
e as prefix,
|
|
21
22
|
r as root,
|
|
23
|
+
p as sideButton,
|
|
22
24
|
c as sm,
|
|
23
|
-
|
|
25
|
+
n as suffix,
|
|
24
26
|
s as wrapper
|
|
25
27
|
};
|
|
@@ -15,6 +15,8 @@ export interface RadioGroupProps {
|
|
|
15
15
|
'aria-labelledby'?: string;
|
|
16
16
|
/** Marks the group as required (`aria-required`). */
|
|
17
17
|
required?: boolean;
|
|
18
|
+
/** Apply error styling to every `Radio` in the group (set automatically by `FormField` when the field is invalid). @default false */
|
|
19
|
+
error?: boolean;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* Manages selection state and `name` attribute for a group of `<Radio>`s via context.
|
|
@@ -26,10 +28,7 @@ export interface RadioGroupProps {
|
|
|
26
28
|
* <Radio value="pro" label="Pro" />
|
|
27
29
|
* </RadioGroup>
|
|
28
30
|
*/
|
|
29
|
-
export declare const RadioGroup:
|
|
30
|
-
({ name, value, onChange, className, style, children, id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, required, }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
31
|
-
displayName: string;
|
|
32
|
-
};
|
|
31
|
+
export declare const RadioGroup: import('react').ForwardRefExoticComponent<RadioGroupProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
33
32
|
export interface RadioClasses {
|
|
34
33
|
root: string;
|
|
35
34
|
input: string;
|
|
@@ -40,6 +39,8 @@ export interface RadioProps extends Omit<ComponentPropsWithRef<'input'>, 'type'>
|
|
|
40
39
|
label?: ReactNode;
|
|
41
40
|
/** Value of this option. Required (used to identify the radio in the group). */
|
|
42
41
|
value: string;
|
|
42
|
+
/** Apply error styling (set automatically by `FormField` when the field is invalid). @default false */
|
|
43
|
+
error?: boolean;
|
|
43
44
|
/** Override class names on internal elements. */
|
|
44
45
|
classes?: Partial<RadioClasses>;
|
|
45
46
|
}
|
|
@@ -1,68 +1,73 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
children: s,
|
|
12
|
-
id: p,
|
|
13
|
-
"aria-label": c,
|
|
14
|
-
"aria-labelledby": m,
|
|
15
|
-
required: u
|
|
16
|
-
}) => /* @__PURE__ */ t(b.Provider, { value: { name: o, value: e, onChange: a }, children: /* @__PURE__ */ t(
|
|
17
|
-
"div",
|
|
18
|
-
{
|
|
19
|
-
id: p,
|
|
20
|
-
className: l(n.group, i),
|
|
1
|
+
import { jsxs as y, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as h, useContext as R, createContext as G } from "react";
|
|
3
|
+
import n from "clsx";
|
|
4
|
+
import a from "./Radio.module.scss.js";
|
|
5
|
+
const f = G(null), j = h(
|
|
6
|
+
({
|
|
7
|
+
name: l,
|
|
8
|
+
value: r,
|
|
9
|
+
onChange: o,
|
|
10
|
+
className: i,
|
|
21
11
|
style: d,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"aria-label":
|
|
12
|
+
children: s,
|
|
13
|
+
id: c,
|
|
14
|
+
"aria-label": p,
|
|
25
15
|
"aria-labelledby": m,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
required: u,
|
|
17
|
+
error: b = !1
|
|
18
|
+
}, e) => /* @__PURE__ */ t(f.Provider, { value: { name: l, value: r, onChange: o, error: b }, children: /* @__PURE__ */ t(
|
|
19
|
+
"div",
|
|
20
|
+
{
|
|
21
|
+
ref: e,
|
|
22
|
+
id: c,
|
|
23
|
+
className: n(a.group, i),
|
|
24
|
+
style: d,
|
|
25
|
+
role: "radiogroup",
|
|
26
|
+
tabIndex: -1,
|
|
27
|
+
"aria-label": p,
|
|
28
|
+
"aria-labelledby": m,
|
|
29
|
+
"aria-required": u || void 0,
|
|
30
|
+
children: s
|
|
31
|
+
}
|
|
32
|
+
) })
|
|
33
|
+
);
|
|
34
|
+
j.displayName = "RadioGroup";
|
|
35
|
+
const k = h(
|
|
32
36
|
({
|
|
33
|
-
label:
|
|
34
|
-
value:
|
|
35
|
-
classes:
|
|
37
|
+
label: l,
|
|
38
|
+
value: r,
|
|
39
|
+
classes: o,
|
|
36
40
|
className: i,
|
|
37
41
|
style: d,
|
|
38
42
|
onChange: s,
|
|
39
|
-
checked:
|
|
40
|
-
name:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
checked: c,
|
|
44
|
+
name: p,
|
|
45
|
+
error: m = !1,
|
|
46
|
+
...u
|
|
47
|
+
}, b) => {
|
|
48
|
+
const e = R(f), x = e?.name ?? p, C = e ? e.value === r : c, N = m || !!e?.error, g = (v) => {
|
|
49
|
+
e?.onChange?.(r), s?.(v);
|
|
45
50
|
};
|
|
46
|
-
return /* @__PURE__ */
|
|
51
|
+
return /* @__PURE__ */ y("label", { className: n(a.root, o?.root, i), style: d, children: [
|
|
47
52
|
/* @__PURE__ */ t(
|
|
48
53
|
"input",
|
|
49
54
|
{
|
|
50
|
-
ref:
|
|
55
|
+
ref: b,
|
|
51
56
|
type: "radio",
|
|
52
|
-
className:
|
|
53
|
-
name:
|
|
54
|
-
value:
|
|
55
|
-
checked:
|
|
56
|
-
onChange:
|
|
57
|
-
...
|
|
57
|
+
className: n(a.input, N && a.error, o?.input),
|
|
58
|
+
name: x,
|
|
59
|
+
value: r,
|
|
60
|
+
checked: C,
|
|
61
|
+
onChange: g,
|
|
62
|
+
...u
|
|
58
63
|
}
|
|
59
64
|
),
|
|
60
|
-
|
|
65
|
+
l && /* @__PURE__ */ t("span", { className: n(a.label, o?.label), children: l })
|
|
61
66
|
] });
|
|
62
67
|
}
|
|
63
68
|
);
|
|
64
|
-
|
|
69
|
+
k.displayName = "Radio";
|
|
65
70
|
export {
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
k as Radio,
|
|
72
|
+
j as RadioGroup
|
|
68
73
|
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
const
|
|
2
|
-
group:
|
|
3
|
-
root:
|
|
4
|
-
input:
|
|
5
|
-
|
|
1
|
+
const r = "crk-group-NNwCD", o = "crk-root-7fGik", t = "crk-input-43PQW", c = "crk-error-Xb8Jc", e = "crk-label-aW30x", n = {
|
|
2
|
+
group: r,
|
|
3
|
+
root: o,
|
|
4
|
+
input: t,
|
|
5
|
+
error: c,
|
|
6
|
+
label: e
|
|
6
7
|
};
|
|
7
8
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
r as
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
n as default,
|
|
10
|
+
c as error,
|
|
11
|
+
r as group,
|
|
12
|
+
t as input,
|
|
13
|
+
e as label,
|
|
14
|
+
o as root
|
|
13
15
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { InputClasses, InputProps } from '../Input/Input';
|
|
2
|
+
export interface SearchInputClasses extends InputClasses {
|
|
3
|
+
/** The leading magnifier icon. */
|
|
4
|
+
icon: string;
|
|
5
|
+
/** The `loading` spinner. */
|
|
6
|
+
spinner: string;
|
|
7
|
+
/** The hotkey hint (`<Kbd>`). */
|
|
8
|
+
hint: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SearchInputProps extends Omit<InputProps, 'prefix' | 'type' | 'clearable' | 'classes'> {
|
|
11
|
+
/** Fires with the text on every keystroke and with `''` on clear/Escape-clear. */
|
|
12
|
+
onValueChange?: (value: string) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Fires with the *debounced* text once it has been quiet for `debounce` ms,
|
|
15
|
+
* immediately on Enter, and with `''` on clear. Never fires on mount, and
|
|
16
|
+
* never twice in a row with the same value.
|
|
17
|
+
*/
|
|
18
|
+
onSearch?: (value: string) => void;
|
|
19
|
+
/** Quiet period before `onSearch` fires, in ms. `0` fires on every change. @default 300 */
|
|
20
|
+
debounce?: number;
|
|
21
|
+
/** Show a small spinner in the field while results load. @default false */
|
|
22
|
+
loading?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Global shortcut that focuses the field (`'/'`, `'mod+k'`…, any
|
|
25
|
+
* `useKeyboard` chord). A key-cap hint is shown while the field is empty
|
|
26
|
+
* and unfocused. @default false
|
|
27
|
+
*/
|
|
28
|
+
hotkey?: string | false;
|
|
29
|
+
/** Render the `hotkey` hint in the field. @default true */
|
|
30
|
+
showHotkeyHint?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* What Escape does inside the field: `'clear'` clears the text when there is
|
|
33
|
+
* any (and blurs when already empty), `'blur'` always blurs, `'none'` leaves
|
|
34
|
+
* it to your `onKeyDown`. @default 'clear'
|
|
35
|
+
*/
|
|
36
|
+
onEscape?: 'clear' | 'blur' | 'none';
|
|
37
|
+
/** `aria-label` used unless you pass `aria-label` / `aria-labelledby`. @default 'Search' */
|
|
38
|
+
searchLabel?: string;
|
|
39
|
+
/** Override class names on internal elements. */
|
|
40
|
+
classes?: Partial<SearchInputClasses>;
|
|
41
|
+
}
|
|
42
|
+
/** `'mod+k'` → `'⌘K'` on macOS, `'Ctrl K'` elsewhere; `'/'` → `'/'`. */
|
|
43
|
+
export declare function formatHotkey(chord: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Search field: magnifier icon, clear button, debounced `onSearch`, optional
|
|
46
|
+
* loading spinner and a global focus hotkey with an in-field key-cap hint.
|
|
47
|
+
* The forwarded ref is the `<input>`, so `ref.current.focus()` works.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* <SearchInput
|
|
51
|
+
* placeholder="Search projects…"
|
|
52
|
+
* hotkey="/"
|
|
53
|
+
* loading={isFetching}
|
|
54
|
+
* onSearch={(q) => setQuery(q)}
|
|
55
|
+
* />
|
|
56
|
+
*/
|
|
57
|
+
export declare const SearchInput: import('react').ForwardRefExoticComponent<Omit<SearchInputProps, "ref"> & import('react').RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { jsxs as F, Fragment as X, jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as Y, useRef as g, useCallback as S, useState as B, useEffect as Z } from "react";
|
|
3
|
+
import m from "clsx";
|
|
4
|
+
import d from "./SearchInput.module.scss.js";
|
|
5
|
+
import { Input as _ } from "../Input/Input.js";
|
|
6
|
+
import { Spinner as $ } from "../../Spinner/Spinner.js";
|
|
7
|
+
import { Kbd as V } from "../../Kbd/Kbd.js";
|
|
8
|
+
import { useDebouncedValue as q } from "../../../hooks/useDebouncedValue.js";
|
|
9
|
+
import { useKeyboard as ee } from "../../../hooks/useKeyboard.js";
|
|
10
|
+
const te = ({ className: o }) => /* @__PURE__ */ F(
|
|
11
|
+
"svg",
|
|
12
|
+
{
|
|
13
|
+
className: o,
|
|
14
|
+
viewBox: "0 0 20 20",
|
|
15
|
+
fill: "none",
|
|
16
|
+
stroke: "currentColor",
|
|
17
|
+
strokeWidth: "1.8",
|
|
18
|
+
"aria-hidden": "true",
|
|
19
|
+
children: [
|
|
20
|
+
/* @__PURE__ */ c("circle", { cx: "8.5", cy: "8.5", r: "5.5" }),
|
|
21
|
+
/* @__PURE__ */ c("path", { d: "M12.8 12.8L17 17", strokeLinecap: "round" })
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
), re = () => typeof navigator < "u" && /Mac|iPhone|iPad|iPod/i.test(navigator.platform ?? "");
|
|
25
|
+
function ne(o) {
|
|
26
|
+
const n = re(), i = o.split("+").map((r) => r.trim()).filter(Boolean);
|
|
27
|
+
return o.endsWith("+") && i.push("+"), i.map((r) => {
|
|
28
|
+
const t = r.toLowerCase();
|
|
29
|
+
return t === "mod" ? n ? "⌘" : "Ctrl" : t === "meta" || t === "cmd" || t === "command" ? n ? "⌘" : "Win" : t === "ctrl" || t === "control" ? n ? "⌃" : "Ctrl" : t === "alt" || t === "option" ? n ? "⌥" : "Alt" : t === "shift" ? n ? "⇧" : "Shift" : t === "esc" || t === "escape" ? "Esc" : t === "space" ? "Space" : r.length === 1 ? r.toUpperCase() : r;
|
|
30
|
+
}).join(n ? "" : " ");
|
|
31
|
+
}
|
|
32
|
+
const oe = Y(
|
|
33
|
+
({
|
|
34
|
+
onValueChange: o,
|
|
35
|
+
onSearch: n,
|
|
36
|
+
debounce: i = 300,
|
|
37
|
+
loading: h = !1,
|
|
38
|
+
hotkey: r = !1,
|
|
39
|
+
showHotkeyHint: t = !0,
|
|
40
|
+
onEscape: y = "clear",
|
|
41
|
+
searchLabel: L = "Search",
|
|
42
|
+
classes: l,
|
|
43
|
+
suffix: C,
|
|
44
|
+
value: u,
|
|
45
|
+
defaultValue: b,
|
|
46
|
+
onChange: P,
|
|
47
|
+
onClear: R,
|
|
48
|
+
onKeyDown: j,
|
|
49
|
+
onFocus: K,
|
|
50
|
+
onBlur: M,
|
|
51
|
+
...f
|
|
52
|
+
}, a) => {
|
|
53
|
+
const p = g(null), T = S(
|
|
54
|
+
(e) => {
|
|
55
|
+
p.current = e, typeof a == "function" ? a(e) : a && (a.current = e);
|
|
56
|
+
},
|
|
57
|
+
[a]
|
|
58
|
+
), [k, H] = B(() => b == null ? "" : String(b)), x = u != null, v = x ? String(u) : k, D = g(v), w = g(n);
|
|
59
|
+
w.current = n;
|
|
60
|
+
const s = S((e) => {
|
|
61
|
+
D.current !== e && (D.current = e, w.current?.(e));
|
|
62
|
+
}, []), E = q(v, i);
|
|
63
|
+
Z(() => {
|
|
64
|
+
s(E);
|
|
65
|
+
}, [E, s]);
|
|
66
|
+
const [O, I] = B(!1), W = (e) => {
|
|
67
|
+
x || H(e.target.value), P?.(e), o?.(e.target.value);
|
|
68
|
+
}, z = () => {
|
|
69
|
+
s(""), R?.();
|
|
70
|
+
}, A = () => {
|
|
71
|
+
const e = p.current;
|
|
72
|
+
if (!e) return;
|
|
73
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set?.call(e, ""), e.dispatchEvent(new Event("input", { bubbles: !0 })), s("");
|
|
74
|
+
}, U = (e) => {
|
|
75
|
+
j?.(e), !e.defaultPrevented && (e.key === "Enter" ? (e.preventDefault(), s(e.currentTarget.value)) : e.key === "Escape" && y !== "none" && (y === "clear" && e.currentTarget.value.length > 0 ? (e.preventDefault(), A()) : e.currentTarget.blur()));
|
|
76
|
+
}, G = S(() => {
|
|
77
|
+
p.current?.focus(), p.current?.select();
|
|
78
|
+
}, []);
|
|
79
|
+
ee(r ? { [r]: G } : {}, { active: !!r, preventDefault: !0 });
|
|
80
|
+
const N = !!r && t && v.length === 0 && !O, J = h || N || C ? /* @__PURE__ */ F(X, { children: [
|
|
81
|
+
h && /* @__PURE__ */ c($, { size: "sm", label: "Searching", className: m(d.spinner, l?.spinner) }),
|
|
82
|
+
N && /* @__PURE__ */ c(V, { size: "sm", className: m(d.hint, l?.hint), "aria-hidden": "true", children: ne(r) }),
|
|
83
|
+
C
|
|
84
|
+
] }) : void 0, Q = f["aria-label"] !== void 0 || f["aria-labelledby"] !== void 0;
|
|
85
|
+
return /* @__PURE__ */ c(
|
|
86
|
+
_,
|
|
87
|
+
{
|
|
88
|
+
ref: T,
|
|
89
|
+
type: "search",
|
|
90
|
+
clearable: !0,
|
|
91
|
+
prefix: /* @__PURE__ */ c(te, { className: m(d.icon, l?.icon) }),
|
|
92
|
+
suffix: J,
|
|
93
|
+
value: u,
|
|
94
|
+
defaultValue: b,
|
|
95
|
+
onChange: W,
|
|
96
|
+
onClear: z,
|
|
97
|
+
onKeyDown: U,
|
|
98
|
+
onFocus: (e) => {
|
|
99
|
+
I(!0), K?.(e);
|
|
100
|
+
},
|
|
101
|
+
onBlur: (e) => {
|
|
102
|
+
I(!1), M?.(e);
|
|
103
|
+
},
|
|
104
|
+
"aria-label": Q ? void 0 : L,
|
|
105
|
+
classes: l,
|
|
106
|
+
...f,
|
|
107
|
+
className: m(d.root, f.className)
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
oe.displayName = "SearchInput";
|
|
113
|
+
export {
|
|
114
|
+
oe as SearchInput,
|
|
115
|
+
ne as formatHotkey
|
|
116
|
+
};
|
|
@@ -18,6 +18,12 @@ export interface SelectClasses {
|
|
|
18
18
|
item: string;
|
|
19
19
|
chip: string;
|
|
20
20
|
chipRemove: string;
|
|
21
|
+
/** Spinner shown in the control while `loading`. */
|
|
22
|
+
spinner: string;
|
|
23
|
+
/** `<mark>` around the matched substring when `highlightMatches` is set. */
|
|
24
|
+
match: string;
|
|
25
|
+
/** Non-option rows in the menu: "No results", "Loading…", the search prompt. */
|
|
26
|
+
message: string;
|
|
21
27
|
}
|
|
22
28
|
export interface SelectProps extends Omit<ComponentPropsWithRef<'select'>, 'onChange' | 'value'> {
|
|
23
29
|
/** Toolkit size scale (independent of the native `size` HTML attribute). @default 'md' */
|
|
@@ -70,6 +76,44 @@ export interface SelectProps extends Omit<ComponentPropsWithRef<'select'>, 'onCh
|
|
|
70
76
|
* @default (q) => `Create "${q}"`
|
|
71
77
|
*/
|
|
72
78
|
createLabel?: (query: string) => React.ReactNode;
|
|
79
|
+
/**
|
|
80
|
+
* Searchable / multi modes. **Remote mode**: when set, the Select stops
|
|
81
|
+
* filtering `options` itself and instead calls `onSearch` with the
|
|
82
|
+
* debounced query (and with `''` when the menu opens empty, so defaults can
|
|
83
|
+
* be loaded). You fetch and pass the matching `options`. Never called twice
|
|
84
|
+
* in a row with the same query.
|
|
85
|
+
*/
|
|
86
|
+
onSearch?: (query: string) => void;
|
|
87
|
+
/** Remote mode: quiet period before `onSearch` fires; `0` = every keystroke. @default 250 */
|
|
88
|
+
searchDebounce?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Remote mode: queries shorter than this don't call `onSearch`; the menu
|
|
91
|
+
* shows `searchPrompt` instead. @default 0
|
|
92
|
+
*/
|
|
93
|
+
minSearchLength?: number;
|
|
94
|
+
/** Row shown while the query is shorter than `minSearchLength`. @default 'Type to search' */
|
|
95
|
+
searchPrompt?: React.ReactNode;
|
|
96
|
+
/**
|
|
97
|
+
* Searchable / multi modes: show a spinner in the control and a
|
|
98
|
+
* `loadingMessage` row in the menu (instead of "No results"). @default false
|
|
99
|
+
*/
|
|
100
|
+
loading?: boolean;
|
|
101
|
+
/** Menu row while `loading`. @default 'Loading…' */
|
|
102
|
+
loadingMessage?: React.ReactNode;
|
|
103
|
+
/** Menu row when nothing matches. @default 'No results' */
|
|
104
|
+
noResultsMessage?: React.ReactNode;
|
|
105
|
+
/**
|
|
106
|
+
* Local filter mode: wrap the matched substring of each string `label` in a
|
|
107
|
+
* `<mark>` (semibold, inherits colour). Options with `content` are left as
|
|
108
|
+
* is. @default false
|
|
109
|
+
*/
|
|
110
|
+
highlightMatches?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Fallback labels for selected values whose option is not in the current
|
|
113
|
+
* `options` — remote search results that moved on, or values created via
|
|
114
|
+
* `allowCreate`. Falls back to the raw value when missing.
|
|
115
|
+
*/
|
|
116
|
+
selectedLabels?: Record<string, React.ReactNode>;
|
|
73
117
|
/**
|
|
74
118
|
* Render the open menu in a portal at `document.body` so it escapes
|
|
75
119
|
* `overflow: hidden` ancestors (Modal body, scroll containers, etc.).
|
|
@@ -86,6 +130,13 @@ export interface SelectProps extends Omit<ComponentPropsWithRef<'select'>, 'onCh
|
|
|
86
130
|
* - **Searchable**: set `searchable`. Custom dropdown with text filter.
|
|
87
131
|
* - **Multi**: set `multiple`. Chip-based multi-select with text filter.
|
|
88
132
|
*
|
|
133
|
+
* The searchable and multi modes filter `options` locally by default. Pass
|
|
134
|
+
* `onSearch` for **remote** search: the query (debounced by `searchDebounce`)
|
|
135
|
+
* is handed to you, you fetch and pass back `options`, and `loading` shows a
|
|
136
|
+
* spinner + a "Loading…" row meanwhile. `selectedLabels` keeps chips / the
|
|
137
|
+
* trigger labelled for values whose option is no longer in `options`;
|
|
138
|
+
* `minSearchLength` + `searchPrompt` gate short queries.
|
|
139
|
+
*
|
|
89
140
|
* In the searchable and multi modes `name` / `form` go to a hidden native
|
|
90
141
|
* `<select>` (so the value is submitted with `FormData`), `aria-*` / `data-*`
|
|
91
142
|
* go to the visible control, `required` becomes `aria-required`, and
|
|
@@ -94,5 +145,6 @@ export interface SelectProps extends Omit<ComponentPropsWithRef<'select'>, 'onCh
|
|
|
94
145
|
* @example Native: <Select options={[{ value: 'a', label: 'A' }]} onValueChange={setValue} />
|
|
95
146
|
* @example Searchable: <Select searchable options={users} value={id} onValueChange={setId} />
|
|
96
147
|
* @example Multi: <Select multiple options={tags} value={selected} onValuesChange={setSelected} />
|
|
148
|
+
* @example Remote: <Select searchable options={results} loading={isFetching} onSearch={fetchUsers} value={id} onValueChange={setId} selectedLabels={{ [id]: name }} />
|
|
97
149
|
*/
|
|
98
150
|
export declare const Select: import('react').ForwardRefExoticComponent<Omit<SelectProps, "ref"> & import('react').RefAttributes<HTMLSelectElement>>;
|