@overdoser/react-toolkit 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +4 -0
- package/CHANGELOG.md +64 -0
- package/components/Button/Button.js +8 -8
- package/components/Button/Button.module.scss.js +9 -9
- package/components/Dropdown/Dropdown.js +40 -36
- package/components/SplitButton/SplitButton.d.ts +88 -0
- package/components/SplitButton/SplitButton.js +201 -0
- package/components/SplitButton/SplitButton.module.scss.js +57 -0
- package/components/SplitButton/index.d.ts +2 -0
- package/components/inputs/DatePicker/CalendarPanel.d.ts +40 -0
- package/components/inputs/DatePicker/CalendarPanel.js +287 -0
- package/components/inputs/DatePicker/CalendarPanel.module.scss.js +41 -0
- package/components/inputs/DatePicker/DatePicker.d.ts +3 -1
- package/components/inputs/DatePicker/DatePicker.js +93 -186
- package/components/inputs/DatePicker/DatePicker.module.scss.js +20 -40
- package/components/inputs/DateTimePicker/DateTimePicker.d.ts +141 -0
- package/components/inputs/DateTimePicker/DateTimePicker.js +230 -0
- package/components/inputs/DateTimePicker/DateTimePicker.module.scss.js +37 -0
- package/components/inputs/DateTimePicker/DateTimeSegments.d.ts +47 -0
- package/components/inputs/DateTimePicker/DateTimeSegments.js +252 -0
- package/components/inputs/DateTimePicker/TimeField.d.ts +18 -0
- package/components/inputs/DateTimePicker/TimeField.js +135 -0
- package/components/inputs/DateTimePicker/index.d.ts +3 -0
- package/components/inputs/DateTimePicker/timeZoneUtils.d.ts +44 -0
- package/components/inputs/DateTimePicker/timeZoneUtils.js +102 -0
- package/index.css +1 -1
- package/index.d.ts +4 -0
- package/index.js +110 -106
- package/index.layered.css +1 -1
- package/llms.txt +68 -2
- package/manifest.json +210 -1
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -53,6 +53,8 @@ For exhaustive component reference (every prop, every variant, every signature),
|
|
|
53
53
|
|
|
54
54
|
- **Need a menu (Edit / Delete / Archive)?** → `<Dropdown trigger={...}>` with `<DropdownItem>` children.
|
|
55
55
|
|
|
56
|
+
- **Need row actions with one default exposed (table "Operations" column)?** → `<SplitButton actions={[...]} />` — flat list of `{ label, onClick?, href?, danger?, disabled? }`; the first action is the visible button, the rest live behind the chevron. `href` actions render as real anchors. Use `Dropdown` menu mode instead when all actions are equal-weight.
|
|
57
|
+
|
|
56
58
|
- **Need a copy-to-clipboard button?** → `<CopyButton value={text} />` (icon + "Copy"→"Copied" morph), or `<CopyButton value={text} iconOnly aria-label="Copy" />` for icon-only. **Other one-shot actions with success feedback (send, download, delete-with-confirm)?** → `<ActionButton icon label successLabel onAction />` — async `onAction` gets a pending spinner; call `context.setProgress(0–100)` inside it for a determinate % + fill bar (downloads); `confirmLabel` adds a two-step confirm for destructive actions. Use plain `Button` when no phase feedback is needed.
|
|
57
59
|
|
|
58
60
|
- **Need a like/save/bookmark toggle?** → `<ToggleIconButton icon={<HeartIcon />} aria-label="Like" />` — round icon-only toggle with `aria-pressed`, fill + pop on toggle, optional `burst` ring, `activeColor` for semantic colors. Controlled (`pressed` + `onPressedChange`, optimistic) or uncontrolled (`defaultPressed`). Not for text toggles — it's icon-only by design.
|
|
@@ -73,6 +75,8 @@ For exhaustive component reference (every prop, every variant, every signature),
|
|
|
73
75
|
|
|
74
76
|
- **Need a date input?** → `<DatePicker value onChange min max disabledDate />` — pop-up calendar, single date, binds in `FormField` (`value: Date | null`).
|
|
75
77
|
|
|
78
|
+
- **Need a date *and* time?** → `<DateTimePicker value onChange />` — editable segments in the field (click a part, arrows step, digits type) plus a calendar-icon popover with the calendar beside scrollable hour/minute columns (MUI-style); `hourCycle={12|24}`, `showSeconds`, `minuteStep` (default 5). Defaults: `YYYY-MM-DD HH:mm:ss UTC`, 24h, UTC, zone labelled inline after the time. The value is an absolute instant; `timeZone="system"` (or any IANA zone) edits in another wall clock (`… 17:30:00 GMT+03:00`), `fieldFormat="locale"` follows the locale order, `showTimeZone={false}` drops the label. Don't build a time picker from `DatePicker` + `NumberInput`s.
|
|
79
|
+
|
|
76
80
|
- **Need file upload?** → `<Dropzone onFiles accept maxSize multiple />` — drag-drop or click; it emits accepted/rejected files but leaves the file-list UI to you.
|
|
77
81
|
|
|
78
82
|
- **Need a countdown / stopwatch / elapsed display?** → `<Timer mode="countdown|stopwatch" duration={…} variant="digital|ring" label="…" />`. Drive it with `autoStart` + an imperative ref (`start`/`pause`/`reset`/`restart`), or make it display-only with `value`.
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,70 @@ All notable changes to `@overdoser/react-toolkit` are documented here.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
|
|
5
5
|
project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.16.0]
|
|
8
|
+
|
|
9
|
+
A date + time picker, and month/year jumping in the calendar header.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **`DateTimePicker`** — date and time in one field, binding in `FormField`
|
|
14
|
+
like `DatePicker` (`value: Date | null`). The field is a row of editable
|
|
15
|
+
segments: click one, Up/Down steps it (wrapping inside the segment),
|
|
16
|
+
Left/Right moves between segments, digits type with auto-advance,
|
|
17
|
+
Backspace clears; on an empty field the first arrow press fills in "now".
|
|
18
|
+
The calendar icon (or Alt+ArrowDown) opens a popover with the `DatePicker`
|
|
19
|
+
calendar beside scrollable hours / minutes / seconds / AM-PM columns;
|
|
20
|
+
picking a day keeps the time and leaves the popover open, every change
|
|
21
|
+
commits immediately. Defaults: `YYYY-MM-DD HH:mm:ss UTC`, 24-hour clock,
|
|
22
|
+
seconds on, zone badge right after the time. Props: `timeZone` (IANA name,
|
|
23
|
+
`'UTC'`, or `'system'` for the local zone — the value is always an absolute
|
|
24
|
+
instant, only the wall clock shown changes), `showTimeZone`,
|
|
25
|
+
`timeZoneStyle` (`GMT+03:00` by default), `fieldFormat: 'iso' | 'locale'`,
|
|
26
|
+
`hourCycle: 12 | 24`, `showSeconds`, `minuteStep`, `doneLabel`, plus
|
|
27
|
+
`min`/`max` as instants (days outside are disabled, boundary-day times
|
|
28
|
+
clamp). Forwards its ref to the root `<div>`. Exports `DateTimePickerProps`,
|
|
29
|
+
`DateTimePickerClasses`, `TimeZoneNameStyle`.
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- **`DatePicker`** — the month and year in the calendar header are now
|
|
34
|
+
buttons: month opens a 12-month grid, year opens a scrollable year list
|
|
35
|
+
(keyboard-navigable, gated and clipped by `min`/`max`). Props, value
|
|
36
|
+
semantics, and the `DatePickerClasses` shape are unchanged; the month
|
|
37
|
+
label became a visually-hidden live region so month changes are still
|
|
38
|
+
announced.
|
|
39
|
+
|
|
40
|
+
## [0.15.0]
|
|
41
|
+
|
|
42
|
+
A split button for grouped row actions, and a Dropdown positioning fix.
|
|
43
|
+
|
|
44
|
+
### Added
|
|
45
|
+
|
|
46
|
+
- **`SplitButton`** — a primary action button joined to a chevron that opens
|
|
47
|
+
a menu of secondary actions (the classic table-row "Operations" control).
|
|
48
|
+
Takes a flat `actions` list (`{ label, onClick?, href?, target?,
|
|
49
|
+
disabled?, danger? }`); the first entry is the exposed default action, the
|
|
50
|
+
rest live behind the chevron, and a single action renders as a plain
|
|
51
|
+
button with no chevron. `href` actions render as real anchors
|
|
52
|
+
(middle-click / cmd-click work; `_blank` gets `rel="noopener noreferrer"`).
|
|
53
|
+
Segments share `Button`'s variants (`variant`, default `secondary`) and
|
|
54
|
+
sizes. The control sizes itself to its widest action label and the open
|
|
55
|
+
menu sits flush under it at exactly the control's width with the meeting
|
|
56
|
+
corners squared, so button and menu read as one block; the left-aligned
|
|
57
|
+
main label and the menu items share the button's font and per-size
|
|
58
|
+
padding, forming one text column. `maxWidth` caps the growth and clips
|
|
59
|
+
labels with an ellipsis (string labels then get a native `title` tooltip
|
|
60
|
+
with the full text). Menu behavior (portal by default, outside-click/
|
|
61
|
+
Escape dismissal, focus management, `menu`/`menuitem` roles) matches
|
|
62
|
+
`Dropdown`, with `align` defaulting to `right` for end-of-row placement.
|
|
63
|
+
|
|
64
|
+
### Fixed
|
|
65
|
+
|
|
66
|
+
- **Dropdown** — an `align="right"` portaled menu computed its `right`
|
|
67
|
+
offset from `window.innerWidth`, which includes the scrollbar; the menu
|
|
68
|
+
shifted left by the scrollbar width whenever the page had one. Now
|
|
69
|
+
measured against `document.documentElement.clientWidth`.
|
|
70
|
+
|
|
7
71
|
## [0.14.0]
|
|
8
72
|
|
|
9
73
|
Buttons floated over content no longer let it show through their fills.
|
|
@@ -11,34 +11,34 @@ const b = {
|
|
|
11
11
|
variant: s = "primary",
|
|
12
12
|
size: e = "md",
|
|
13
13
|
loading: d = !1,
|
|
14
|
-
loadingStyle:
|
|
15
|
-
fullWidth:
|
|
14
|
+
loadingStyle: n = "dots",
|
|
15
|
+
fullWidth: i = !1,
|
|
16
16
|
iconOnly: l = !1,
|
|
17
17
|
disabled: p,
|
|
18
18
|
classes: t,
|
|
19
19
|
className: f,
|
|
20
20
|
style: c,
|
|
21
21
|
children: h,
|
|
22
|
-
...
|
|
23
|
-
},
|
|
22
|
+
...u
|
|
23
|
+
}, N) => /* @__PURE__ */ m(
|
|
24
24
|
"button",
|
|
25
25
|
{
|
|
26
|
-
ref:
|
|
26
|
+
ref: N,
|
|
27
27
|
className: r(
|
|
28
28
|
o.root,
|
|
29
29
|
o[s],
|
|
30
30
|
o[e],
|
|
31
|
-
|
|
31
|
+
i && o.fullWidth,
|
|
32
32
|
l && o.iconOnly,
|
|
33
33
|
d && o.loading,
|
|
34
|
-
d && b[
|
|
34
|
+
d && b[n],
|
|
35
35
|
t?.root,
|
|
36
36
|
f
|
|
37
37
|
),
|
|
38
38
|
style: c,
|
|
39
39
|
disabled: p || d,
|
|
40
40
|
"aria-busy": d || void 0,
|
|
41
|
-
...
|
|
41
|
+
...u,
|
|
42
42
|
children: [
|
|
43
43
|
/* @__PURE__ */ a("div", { className: r(o.shimmer, t?.shimmer) }),
|
|
44
44
|
/* @__PURE__ */ a("span", { className: r(o.content, t?.content), children: h }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const o = "crk-root-8RX49", n = "crk-loading-QfItr", r = "crk-primary-st6yY", c = "crk-secondary-j-3rj", t = "crk-danger-Hxs5n", s = "crk-ghost-kQ0A8", d = "crk-sm-RXFPY", e = "crk-md-nDnOD", i = "crk-lg-qD-Qh", l = "crk-fullWidth-AHpSl", m = "crk-iconOnly-FNrSu", a = "crk-content-PpYVU", k = "crk-shimmer-8iQSU", g = "crk-loadingShimmer-BVvFw", h = "crk-shimmerSweep-uiZ01",
|
|
1
|
+
const o = "crk-root-8RX49", n = "crk-loading-QfItr", r = "crk-primary-st6yY", c = "crk-secondary-j-3rj", t = "crk-danger-Hxs5n", s = "crk-ghost-kQ0A8", d = "crk-sm-RXFPY", e = "crk-md-nDnOD", i = "crk-lg-qD-Qh", l = "crk-fullWidth-AHpSl", m = "crk-iconOnly-FNrSu", a = "crk-content-PpYVU", k = "crk-shimmer-8iQSU", g = "crk-loadingShimmer-BVvFw", h = "crk-shimmerSweep-uiZ01", S = "crk-dots-U8wss", p = "crk-loadingDots-eKv64", u = "crk-dot-Owuk1", y = "crk-dotBounce-FwdcC", w = "crk-loadingBorder-9ULFw", B = "crk-borderSpin-EJ2gW", D = {
|
|
2
2
|
root: o,
|
|
3
3
|
loading: n,
|
|
4
4
|
primary: r,
|
|
@@ -14,10 +14,10 @@ const o = "crk-root-8RX49", n = "crk-loading-QfItr", r = "crk-primary-st6yY", c
|
|
|
14
14
|
shimmer: k,
|
|
15
15
|
loadingShimmer: g,
|
|
16
16
|
shimmerSweep: h,
|
|
17
|
-
dots:
|
|
18
|
-
loadingDots:
|
|
19
|
-
dot:
|
|
20
|
-
dotBounce:
|
|
17
|
+
dots: S,
|
|
18
|
+
loadingDots: p,
|
|
19
|
+
dot: u,
|
|
20
|
+
dotBounce: y,
|
|
21
21
|
loadingBorder: w,
|
|
22
22
|
borderSpin: B
|
|
23
23
|
};
|
|
@@ -26,16 +26,16 @@ export {
|
|
|
26
26
|
a as content,
|
|
27
27
|
t as danger,
|
|
28
28
|
D as default,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
u as dot,
|
|
30
|
+
y as dotBounce,
|
|
31
|
+
S as dots,
|
|
32
32
|
l as fullWidth,
|
|
33
33
|
s as ghost,
|
|
34
34
|
m as iconOnly,
|
|
35
35
|
i as lg,
|
|
36
36
|
n as loading,
|
|
37
37
|
w as loadingBorder,
|
|
38
|
-
|
|
38
|
+
p as loadingDots,
|
|
39
39
|
g as loadingShimmer,
|
|
40
40
|
e as md,
|
|
41
41
|
r as primary,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef as G, useState as H, useRef as b, useId as J, useEffect as S, useCallback as v } from "react";
|
|
3
3
|
import { createPortal as Q } from "react-dom";
|
|
4
|
-
import
|
|
4
|
+
import o from "clsx";
|
|
5
5
|
import t from "./Dropdown.module.scss.js";
|
|
6
6
|
import { useKeyboard as T } from "../../hooks/useKeyboard.js";
|
|
7
7
|
import { usePortalPosition as U } from "../../hooks/usePortalPosition.js";
|
|
@@ -13,56 +13,56 @@ const V = G(
|
|
|
13
13
|
className: j,
|
|
14
14
|
style: z,
|
|
15
15
|
id: O,
|
|
16
|
-
onOpen:
|
|
16
|
+
onOpen: y,
|
|
17
17
|
onClose: c,
|
|
18
|
-
options:
|
|
18
|
+
options: i,
|
|
19
19
|
placeholder: W = "Select...",
|
|
20
|
-
value:
|
|
20
|
+
value: w,
|
|
21
21
|
onChange: x,
|
|
22
22
|
error: q = !1,
|
|
23
23
|
fullWidth: s = !0,
|
|
24
|
-
portal:
|
|
24
|
+
portal: u = !0,
|
|
25
25
|
classes: n
|
|
26
26
|
}, K) => {
|
|
27
|
-
const [r, N] = H(!1),
|
|
27
|
+
const [r, N] = H(!1), E = b(null), a = b(null), h = b(null), I = J();
|
|
28
28
|
S(() => {
|
|
29
|
-
r &&
|
|
29
|
+
r && a.current && a.current.querySelector('[role="menuitem"]:not(:disabled)')?.focus();
|
|
30
30
|
}, [r]);
|
|
31
|
-
const
|
|
31
|
+
const l = v(() => {
|
|
32
32
|
N(!1), c?.(), h.current?.focus();
|
|
33
33
|
}, [c]), M = v(() => {
|
|
34
34
|
N((e) => {
|
|
35
35
|
const m = !e;
|
|
36
|
-
return m ?
|
|
36
|
+
return m ? y?.() : c?.(), m;
|
|
37
37
|
});
|
|
38
|
-
}, [
|
|
38
|
+
}, [y, c]), A = v(
|
|
39
39
|
(e) => {
|
|
40
|
-
x?.(e),
|
|
40
|
+
x?.(e), l();
|
|
41
41
|
},
|
|
42
|
-
[x,
|
|
42
|
+
[x, l]
|
|
43
43
|
);
|
|
44
44
|
S(() => {
|
|
45
45
|
if (!r) return;
|
|
46
46
|
const e = (m) => {
|
|
47
47
|
const P = m.target;
|
|
48
|
-
|
|
48
|
+
E.current?.contains(P) || a.current?.contains(P) || l();
|
|
49
49
|
};
|
|
50
50
|
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
51
|
-
}, [r,
|
|
51
|
+
}, [r, l]), T(
|
|
52
52
|
{
|
|
53
|
-
Escape: () =>
|
|
53
|
+
Escape: () => l()
|
|
54
54
|
},
|
|
55
55
|
r
|
|
56
56
|
);
|
|
57
|
-
const
|
|
57
|
+
const d = U(h, r && u), L = i?.find((e) => e.value === w)?.label, B = i ? L || W : k, C = i && !L, F = i ? i.map((e) => /* @__PURE__ */ f(
|
|
58
58
|
"button",
|
|
59
59
|
{
|
|
60
60
|
type: "button",
|
|
61
61
|
role: "menuitem",
|
|
62
|
-
className:
|
|
62
|
+
className: o(
|
|
63
63
|
t.item,
|
|
64
64
|
e.disabled && t.itemDisabled,
|
|
65
|
-
e.value ===
|
|
65
|
+
e.value === w && t.itemSelected,
|
|
66
66
|
n?.item
|
|
67
67
|
),
|
|
68
68
|
disabled: e.disabled,
|
|
@@ -70,16 +70,16 @@ const V = G(
|
|
|
70
70
|
children: e.label
|
|
71
71
|
},
|
|
72
72
|
e.value
|
|
73
|
-
)) : D,
|
|
73
|
+
)) : D, R = (e) => /* @__PURE__ */ f(
|
|
74
74
|
"div",
|
|
75
75
|
{
|
|
76
|
-
ref:
|
|
77
|
-
id:
|
|
78
|
-
className:
|
|
76
|
+
ref: a,
|
|
77
|
+
id: I,
|
|
78
|
+
className: o(
|
|
79
79
|
t.menu,
|
|
80
80
|
r && t.menuOpen,
|
|
81
81
|
g === "left" ? t.alignLeft : t.alignRight,
|
|
82
|
-
!
|
|
82
|
+
!u && s && t.fullWidth,
|
|
83
83
|
n?.menu
|
|
84
84
|
),
|
|
85
85
|
style: e,
|
|
@@ -91,17 +91,17 @@ const V = G(
|
|
|
91
91
|
"div",
|
|
92
92
|
{
|
|
93
93
|
ref: K,
|
|
94
|
-
className:
|
|
94
|
+
className: o(t.root, s && t.fullWidth, n?.root, j),
|
|
95
95
|
style: z,
|
|
96
96
|
children: [
|
|
97
|
-
/* @__PURE__ */ p("div", { ref:
|
|
97
|
+
/* @__PURE__ */ p("div", { ref: E, style: s ? { width: "100%" } : void 0, children: [
|
|
98
98
|
/* @__PURE__ */ p(
|
|
99
99
|
"button",
|
|
100
100
|
{
|
|
101
101
|
ref: h,
|
|
102
102
|
id: O,
|
|
103
103
|
type: "button",
|
|
104
|
-
className:
|
|
104
|
+
className: o(
|
|
105
105
|
t.trigger,
|
|
106
106
|
r && t.triggerOpen,
|
|
107
107
|
q && t.triggerError,
|
|
@@ -111,22 +111,26 @@ const V = G(
|
|
|
111
111
|
onClick: M,
|
|
112
112
|
"aria-expanded": r,
|
|
113
113
|
"aria-haspopup": "menu",
|
|
114
|
-
"aria-controls": r ?
|
|
114
|
+
"aria-controls": r ? I : void 0,
|
|
115
115
|
children: [
|
|
116
|
-
/* @__PURE__ */ f("span", { className:
|
|
117
|
-
/* @__PURE__ */ f("span", { className:
|
|
116
|
+
/* @__PURE__ */ f("span", { className: o(t.triggerLabel, C && t.placeholder, n?.triggerLabel), children: B }),
|
|
117
|
+
/* @__PURE__ */ f("span", { className: o(t.chevron, n?.chevron), "aria-hidden": "true" })
|
|
118
118
|
]
|
|
119
119
|
}
|
|
120
120
|
),
|
|
121
|
-
!
|
|
121
|
+
!u && R()
|
|
122
122
|
] }),
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
u && r && typeof document < "u" && Q(
|
|
124
|
+
R({
|
|
125
125
|
position: "fixed",
|
|
126
|
-
top:
|
|
127
|
-
left: g === "right" ? void 0 :
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
top: d.top + 4,
|
|
127
|
+
left: g === "right" ? void 0 : d.left,
|
|
128
|
+
// clientWidth, not innerWidth: `right` on a fixed element is
|
|
129
|
+
// measured from the viewport edge inside the scrollbar, while
|
|
130
|
+
// innerWidth includes it — the menu would shift left by the
|
|
131
|
+
// scrollbar width whenever the page scrolls.
|
|
132
|
+
right: g === "right" ? document.documentElement.clientWidth - (d.left + d.width) : void 0,
|
|
133
|
+
minWidth: d.width,
|
|
130
134
|
zIndex: "var(--crk-z-floating)"
|
|
131
135
|
}),
|
|
132
136
|
document.body
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
export interface SplitButtonAction {
|
|
3
|
+
/** Visible label (main button for the first action, menu item for the rest). */
|
|
4
|
+
label: React.ReactNode;
|
|
5
|
+
/** Click handler. Runs before navigation when `href` is also set. */
|
|
6
|
+
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
|
|
7
|
+
/** Navigation action: renders as a real `<a>` so middle-click/cmd-click work. */
|
|
8
|
+
href?: string;
|
|
9
|
+
/** Anchor target for `href` actions. `_blank` gets `rel="noopener noreferrer"` automatically. */
|
|
10
|
+
target?: React.HTMLAttributeAnchorTarget;
|
|
11
|
+
/** Non-interactive when true. @default false */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Destructive styling — red menu item (only meaningful for menu actions). @default false */
|
|
14
|
+
danger?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface SplitButtonClasses {
|
|
17
|
+
root: string;
|
|
18
|
+
group: string;
|
|
19
|
+
main: string;
|
|
20
|
+
toggle: string;
|
|
21
|
+
chevron: string;
|
|
22
|
+
menu: string;
|
|
23
|
+
item: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SplitButtonProps {
|
|
26
|
+
/**
|
|
27
|
+
* Actions, in display order. The **first** action is the default action,
|
|
28
|
+
* exposed as the main button; the rest collapse into the chevron menu.
|
|
29
|
+
* With a single action no chevron or menu is rendered.
|
|
30
|
+
*/
|
|
31
|
+
actions: SplitButtonAction[];
|
|
32
|
+
/** Visual style of both button segments. @default 'secondary' */
|
|
33
|
+
variant?: 'primary' | 'secondary' | 'danger' | 'ghost';
|
|
34
|
+
/** Button size. @default 'md' */
|
|
35
|
+
size?: 'sm' | 'md' | 'lg';
|
|
36
|
+
/** Disables both segments (the menu can no longer be opened). @default false */
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Menu alignment relative to the control. Defaults to `'right'` because
|
|
40
|
+
* split buttons usually sit at the end of a row/table where a left-aligned
|
|
41
|
+
* menu would overflow.
|
|
42
|
+
* @default 'right'
|
|
43
|
+
*/
|
|
44
|
+
align?: 'left' | 'right';
|
|
45
|
+
/**
|
|
46
|
+
* Render the open menu in a portal at `document.body` so it escapes any
|
|
47
|
+
* `overflow: hidden` ancestor (Modal body, scrollable tables, etc.).
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
portal?: boolean;
|
|
51
|
+
/** Accessible label for the chevron toggle. @default 'More actions' */
|
|
52
|
+
menuLabel?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Maximum width of the control (CSS value; numbers are px). By default the
|
|
55
|
+
* control grows to fit its **widest** action label so the button and the
|
|
56
|
+
* open menu form one equal-width block; past `maxWidth` the main button's
|
|
57
|
+
* label — and any menu item that no longer fits — is clipped with an
|
|
58
|
+
* ellipsis instead.
|
|
59
|
+
*/
|
|
60
|
+
maxWidth?: number | string;
|
|
61
|
+
className?: string;
|
|
62
|
+
style?: CSSProperties;
|
|
63
|
+
/** `id` applied to the main button. */
|
|
64
|
+
id?: string;
|
|
65
|
+
/** Called when the menu opens. */
|
|
66
|
+
onOpen?: () => void;
|
|
67
|
+
/** Called when the menu closes (outside click, Escape, or selection). */
|
|
68
|
+
onClose?: () => void;
|
|
69
|
+
/** Override class names on internal elements. */
|
|
70
|
+
classes?: Partial<SplitButtonClasses>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Split button: a primary action button joined to a chevron that opens a menu
|
|
74
|
+
* of secondary actions — the standard "Operations" control for table rows.
|
|
75
|
+
* Takes a flat `actions` list; the first entry is the exposed default action.
|
|
76
|
+
* Actions can be JS handlers (`onClick`) or navigations (`href`, rendered as
|
|
77
|
+
* real anchors). Closes on outside click and Escape.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* <SplitButton
|
|
81
|
+
* actions={[
|
|
82
|
+
* { label: 'Edit', onClick: () => edit(row) },
|
|
83
|
+
* { label: 'View', href: `/items/${row.id}` },
|
|
84
|
+
* { label: 'Delete', onClick: () => remove(row), danger: true },
|
|
85
|
+
* ]}
|
|
86
|
+
* />
|
|
87
|
+
*/
|
|
88
|
+
export declare const SplitButton: import('react').ForwardRefExoticComponent<SplitButtonProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { jsxs as N, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as X, useState as Y, useRef as S, useId as Z, useEffect as q, useCallback as F } from "react";
|
|
3
|
+
import { createPortal as $ } from "react-dom";
|
|
4
|
+
import i from "clsx";
|
|
5
|
+
import t from "./SplitButton.module.scss.js";
|
|
6
|
+
import h from "../Button/Button.module.scss.js";
|
|
7
|
+
import { useKeyboard as ee } from "../../hooks/useKeyboard.js";
|
|
8
|
+
import { usePortalPosition as te } from "../../hooks/usePortalPosition.js";
|
|
9
|
+
const ne = X(
|
|
10
|
+
({
|
|
11
|
+
actions: g,
|
|
12
|
+
variant: b = "secondary",
|
|
13
|
+
size: O = "md",
|
|
14
|
+
disabled: w = !1,
|
|
15
|
+
align: v = "right",
|
|
16
|
+
portal: k = !0,
|
|
17
|
+
menuLabel: K = "More actions",
|
|
18
|
+
maxWidth: y,
|
|
19
|
+
className: G,
|
|
20
|
+
style: x,
|
|
21
|
+
id: I,
|
|
22
|
+
onOpen: L,
|
|
23
|
+
onClose: c,
|
|
24
|
+
classes: s
|
|
25
|
+
}, H) => {
|
|
26
|
+
const [n, R] = Y(!1), C = S(null), u = S(null), E = S(null), M = Z();
|
|
27
|
+
q(() => {
|
|
28
|
+
n && u.current && u.current.querySelector('[role="menuitem"]:not([disabled])')?.focus();
|
|
29
|
+
}, [n]);
|
|
30
|
+
const f = F(() => {
|
|
31
|
+
R(!1), c?.(), E.current?.focus();
|
|
32
|
+
}, [c]), J = F(() => {
|
|
33
|
+
R((e) => {
|
|
34
|
+
const l = !e;
|
|
35
|
+
return l ? L?.() : c?.(), l;
|
|
36
|
+
});
|
|
37
|
+
}, [L, c]);
|
|
38
|
+
q(() => {
|
|
39
|
+
if (!n) return;
|
|
40
|
+
const e = (l) => {
|
|
41
|
+
const m = l.target;
|
|
42
|
+
C.current?.contains(m) || u.current?.contains(m) || f();
|
|
43
|
+
};
|
|
44
|
+
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
45
|
+
}, [n, f]), ee(
|
|
46
|
+
{
|
|
47
|
+
Escape: () => f()
|
|
48
|
+
},
|
|
49
|
+
n
|
|
50
|
+
);
|
|
51
|
+
const d = te(C, n && k);
|
|
52
|
+
if (g.length === 0) return null;
|
|
53
|
+
const [o, ...z] = g, a = z.length > 0, B = w || o.disabled, P = i(h.root, h[b], h[O]), Q = b === "secondary" ? t.overlapOutline : b === "ghost" ? t.dividerSubtle : t.dividerOnFill, j = i(
|
|
54
|
+
P,
|
|
55
|
+
t.main,
|
|
56
|
+
a && t.mainAttached,
|
|
57
|
+
a && n && t.mainOpen,
|
|
58
|
+
s?.main
|
|
59
|
+
), p = (e) => y !== void 0 && (typeof e == "string" || typeof e == "number") ? String(e) : void 0, D = /* @__PURE__ */ N("span", { className: t.mainContent, children: [
|
|
60
|
+
/* @__PURE__ */ r("span", { className: t.mainLabel, children: o.label }),
|
|
61
|
+
a && /* @__PURE__ */ r("span", { className: t.sizer, "aria-hidden": "true", children: g.map((e, l) => /* @__PURE__ */ r("span", { className: t.sizerItem, children: e.label }, l)) })
|
|
62
|
+
] }), T = o.href && !B ? /* @__PURE__ */ r(
|
|
63
|
+
"a",
|
|
64
|
+
{
|
|
65
|
+
id: I,
|
|
66
|
+
className: j,
|
|
67
|
+
href: o.href,
|
|
68
|
+
target: o.target,
|
|
69
|
+
rel: o.target === "_blank" ? "noopener noreferrer" : void 0,
|
|
70
|
+
title: p(o.label),
|
|
71
|
+
onClick: o.onClick,
|
|
72
|
+
children: D
|
|
73
|
+
}
|
|
74
|
+
) : /* @__PURE__ */ r(
|
|
75
|
+
"button",
|
|
76
|
+
{
|
|
77
|
+
id: I,
|
|
78
|
+
type: "button",
|
|
79
|
+
className: j,
|
|
80
|
+
disabled: B,
|
|
81
|
+
title: p(o.label),
|
|
82
|
+
onClick: o.onClick,
|
|
83
|
+
children: D
|
|
84
|
+
}
|
|
85
|
+
), U = z.map((e, l) => {
|
|
86
|
+
const m = i(
|
|
87
|
+
t.item,
|
|
88
|
+
e.disabled && t.itemDisabled,
|
|
89
|
+
e.danger && t.itemDanger,
|
|
90
|
+
s?.item
|
|
91
|
+
), _ = (W) => {
|
|
92
|
+
e.onClick?.(W), f();
|
|
93
|
+
};
|
|
94
|
+
return e.href && !e.disabled ? /* @__PURE__ */ r(
|
|
95
|
+
"a",
|
|
96
|
+
{
|
|
97
|
+
role: "menuitem",
|
|
98
|
+
className: m,
|
|
99
|
+
href: e.href,
|
|
100
|
+
target: e.target,
|
|
101
|
+
rel: e.target === "_blank" ? "noopener noreferrer" : void 0,
|
|
102
|
+
title: p(e.label),
|
|
103
|
+
onClick: _,
|
|
104
|
+
children: e.label
|
|
105
|
+
},
|
|
106
|
+
l
|
|
107
|
+
) : /* @__PURE__ */ r(
|
|
108
|
+
"button",
|
|
109
|
+
{
|
|
110
|
+
type: "button",
|
|
111
|
+
role: "menuitem",
|
|
112
|
+
className: m,
|
|
113
|
+
disabled: e.disabled,
|
|
114
|
+
title: p(e.label),
|
|
115
|
+
onClick: _,
|
|
116
|
+
children: e.label
|
|
117
|
+
},
|
|
118
|
+
l
|
|
119
|
+
);
|
|
120
|
+
}), V = { sm: t.menuSm, md: t.menuMd, lg: t.menuLg }[O], A = (e) => /* @__PURE__ */ r(
|
|
121
|
+
"div",
|
|
122
|
+
{
|
|
123
|
+
ref: u,
|
|
124
|
+
id: M,
|
|
125
|
+
className: i(
|
|
126
|
+
t.menu,
|
|
127
|
+
V,
|
|
128
|
+
n && t.menuOpen,
|
|
129
|
+
v === "left" ? t.alignLeft : t.alignRight,
|
|
130
|
+
s?.menu
|
|
131
|
+
),
|
|
132
|
+
style: e,
|
|
133
|
+
role: "menu",
|
|
134
|
+
children: U
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
return /* @__PURE__ */ N(
|
|
138
|
+
"div",
|
|
139
|
+
{
|
|
140
|
+
ref: H,
|
|
141
|
+
className: i(t.root, s?.root, G),
|
|
142
|
+
style: y !== void 0 ? { maxWidth: y, ...x } : x,
|
|
143
|
+
children: [
|
|
144
|
+
/* @__PURE__ */ N("div", { ref: C, className: i(t.group, s?.group), children: [
|
|
145
|
+
T,
|
|
146
|
+
a && /* @__PURE__ */ r(
|
|
147
|
+
"button",
|
|
148
|
+
{
|
|
149
|
+
ref: E,
|
|
150
|
+
type: "button",
|
|
151
|
+
className: i(
|
|
152
|
+
P,
|
|
153
|
+
h.iconOnly,
|
|
154
|
+
t.toggle,
|
|
155
|
+
n && t.toggleOpen,
|
|
156
|
+
Q,
|
|
157
|
+
s?.toggle
|
|
158
|
+
),
|
|
159
|
+
disabled: w,
|
|
160
|
+
onClick: J,
|
|
161
|
+
"aria-haspopup": "menu",
|
|
162
|
+
"aria-expanded": n,
|
|
163
|
+
"aria-controls": n ? M : void 0,
|
|
164
|
+
"aria-label": K,
|
|
165
|
+
children: /* @__PURE__ */ r(
|
|
166
|
+
"svg",
|
|
167
|
+
{
|
|
168
|
+
className: i(t.chevron, n && t.chevronOpen, s?.chevron),
|
|
169
|
+
viewBox: "0 0 10 6",
|
|
170
|
+
"aria-hidden": "true",
|
|
171
|
+
children: /* @__PURE__ */ r("path", { d: "M1 1l4 4 4-4", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
)
|
|
176
|
+
] }),
|
|
177
|
+
a && !k && A(),
|
|
178
|
+
a && k && n && typeof document < "u" && $(
|
|
179
|
+
A({
|
|
180
|
+
position: "fixed",
|
|
181
|
+
top: d.top,
|
|
182
|
+
left: v === "right" ? void 0 : d.left,
|
|
183
|
+
// clientWidth, not innerWidth: `right` on a fixed element is
|
|
184
|
+
// measured from the viewport edge inside the scrollbar, while
|
|
185
|
+
// innerWidth includes it — the menu would shift left by the
|
|
186
|
+
// scrollbar width whenever the page scrolls.
|
|
187
|
+
right: v === "right" ? document.documentElement.clientWidth - (d.left + d.width) : void 0,
|
|
188
|
+
width: d.width,
|
|
189
|
+
zIndex: "var(--crk-z-floating)"
|
|
190
|
+
}),
|
|
191
|
+
document.body
|
|
192
|
+
)
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
ne.displayName = "SplitButton";
|
|
199
|
+
export {
|
|
200
|
+
ne as SplitButton
|
|
201
|
+
};
|