@box-kite/react 0.0.1 → 2.0.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/.claude/rules/box-kite-rules.md +65 -0
- package/.claude/skills/box-kite/SKILL.md +138 -0
- package/.claude/skills/box-kite/references/components.md +235 -0
- package/.claude/skills/box-kite/references/extending.md +42 -0
- package/.claude/skills/box-kite/references/patterns.md +27 -0
- package/.claude/skills/box-kite/references/styling.md +222 -0
- package/.cursor/rules/box-kite.mdc +73 -0
- package/AGENTS.md +102 -0
- package/BOX_AI_CONTEXT.md +2804 -0
- package/BOX_KITE_AI_CONTEXT.md +2804 -0
- package/LICENSE +21 -0
- package/README.md +744 -7
- package/a11y.cjs +1 -0
- package/a11y.d.ts +15 -0
- package/a11y.mjs +4 -0
- package/anchor.cjs +1 -0
- package/anchor.d.ts +14 -0
- package/anchor.mjs +3 -0
- package/behavior.cjs +1 -0
- package/behavior.mjs +277 -0
- package/box.cjs +1 -0
- package/box.d.ts +46 -0
- package/box.mjs +23 -0
- package/client.cjs +1 -0
- package/client.mjs +164 -0
- package/components/accordion.cjs +1 -0
- package/components/accordion.d.ts +114 -0
- package/components/accordion.mjs +251 -0
- package/components/baseSvg.cjs +1 -0
- package/components/baseSvg.d.ts +5 -0
- package/components/baseSvg.mjs +21 -0
- package/components/button.cjs +1 -0
- package/components/button.d.ts +19 -0
- package/components/button.mjs +19 -0
- package/components/chart.cjs +1 -0
- package/components/chart.d.ts +83 -0
- package/components/chart.mjs +236 -0
- package/components/checkbox.cjs +1 -0
- package/components/checkbox.d.ts +36 -0
- package/components/checkbox.mjs +38 -0
- package/components/combobox/comboboxChips.d.ts +21 -0
- package/components/combobox/comboboxListbox.d.ts +47 -0
- package/components/combobox.cjs +1 -0
- package/components/combobox.d.ts +121 -0
- package/components/combobox.mjs +563 -0
- package/components/dataGrid/components/dataGridAggregateValue.d.ts +10 -0
- package/components/dataGrid/components/dataGridBody.d.ts +7 -0
- package/components/dataGrid/components/dataGridBottomBar.d.ts +6 -0
- package/components/dataGrid/components/dataGridCell.d.ts +16 -0
- package/components/dataGrid/components/dataGridCellEditor.d.ts +15 -0
- package/components/dataGrid/components/dataGridCellPlaceholder.d.ts +14 -0
- package/components/dataGrid/components/dataGridCellRowDetail.d.ts +6 -0
- package/components/dataGrid/components/dataGridCellRowSelection.d.ts +6 -0
- package/components/dataGrid/components/dataGridCellText.d.ts +6 -0
- package/components/dataGrid/components/dataGridCellTree.d.ts +16 -0
- package/components/dataGrid/components/dataGridColumnFilter.d.ts +9 -0
- package/components/dataGrid/components/dataGridColumnGroups.d.ts +7 -0
- package/components/dataGrid/components/dataGridContent.d.ts +6 -0
- package/components/dataGrid/components/dataGridDataSourceError.d.ts +12 -0
- package/components/dataGrid/components/dataGridDetailRow.d.ts +8 -0
- package/components/dataGrid/components/dataGridEmptyColumns.d.ts +6 -0
- package/components/dataGrid/components/dataGridExport.d.ts +10 -0
- package/components/dataGrid/components/dataGridFilterCell.d.ts +11 -0
- package/components/dataGrid/components/dataGridFilterRow.d.ts +6 -0
- package/components/dataGrid/components/dataGridFooter.d.ts +11 -0
- package/components/dataGrid/components/dataGridGlobalFilter.d.ts +6 -0
- package/components/dataGrid/components/dataGridGroupRow.d.ts +8 -0
- package/components/dataGrid/components/dataGridHeader.d.ts +6 -0
- package/components/dataGrid/components/dataGridHeaderCell.d.ts +9 -0
- package/components/dataGrid/components/dataGridHeaderCellContextMenu.d.ts +11 -0
- package/components/dataGrid/components/dataGridHeaderCellResizer.d.ts +14 -0
- package/components/dataGrid/components/dataGridLoader.d.ts +11 -0
- package/components/dataGrid/components/dataGridPagination.d.ts +6 -0
- package/components/dataGrid/components/dataGridRow.d.ts +8 -0
- package/components/dataGrid/components/dataGridTopBar.d.ts +6 -0
- package/components/dataGrid/components/dataGridTopBarContextMenu.d.ts +6 -0
- package/components/dataGrid/contracts/dataGridContract.d.ts +671 -0
- package/components/dataGrid/export/gridExport.d.ts +10 -0
- package/components/dataGrid/gridNavigationContext.d.ts +32 -0
- package/components/dataGrid/models/aggregateCellModel.d.ts +34 -0
- package/components/dataGrid/models/aggregationModel.d.ts +32 -0
- package/components/dataGrid/models/cellKeys.d.ts +11 -0
- package/components/dataGrid/models/cellModel.d.ts +44 -0
- package/components/dataGrid/models/columnModel.d.ts +160 -0
- package/components/dataGrid/models/columnVisibilityModel.d.ts +24 -0
- package/components/dataGrid/models/dataSourceModel.d.ts +177 -0
- package/components/dataGrid/models/detailRowModel.d.ts +22 -0
- package/components/dataGrid/models/editModel.d.ts +77 -0
- package/components/dataGrid/models/exportModel.d.ts +51 -0
- package/components/dataGrid/models/filterModel.d.ts +22 -0
- package/components/dataGrid/models/gridModel.d.ts +293 -0
- package/components/dataGrid/models/groupRowCellModel.d.ts +34 -0
- package/components/dataGrid/models/groupRowModel.d.ts +68 -0
- package/components/dataGrid/models/headerCellModel.d.ts +83 -0
- package/components/dataGrid/models/paginationModel.d.ts +32 -0
- package/components/dataGrid/models/rowModel.d.ts +46 -0
- package/components/dataGrid/models/sourceGroupRowModel.d.ts +45 -0
- package/components/dataGrid/models/sourceLevel.d.ts +71 -0
- package/components/dataGrid/models/sourceRowModel.d.ts +29 -0
- package/components/dataGrid/models/sourceTreeRowModel.d.ts +23 -0
- package/components/dataGrid/models/treeModel.d.ts +94 -0
- package/components/dataGrid/models/treeRow.d.ts +22 -0
- package/components/dataGrid/models/treeRowModel.d.ts +50 -0
- package/components/dataGrid/models/viewportModel.d.ts +44 -0
- package/components/dataGrid/useGrid.d.ts +8 -0
- package/components/dataGrid/useGridNavigation.d.ts +21 -0
- package/components/dataGrid.cjs +1 -0
- package/components/dataGrid.d.ts +4 -0
- package/components/dataGrid.mjs +4907 -0
- package/components/dialog.cjs +1 -0
- package/components/dialog.d.ts +151 -0
- package/components/dialog.mjs +223 -0
- package/components/dropdown/dropdownContext.d.ts +44 -0
- package/components/dropdown/dropdownItems.d.ts +22 -0
- package/components/dropdown/dropdownRowRenderer.d.ts +8 -0
- package/components/dropdown/dropdownSearch.d.ts +21 -0
- package/components/dropdown/utils.d.ts +1 -0
- package/components/dropdown.cjs +1 -0
- package/components/dropdown.d.ts +77 -0
- package/components/dropdown.mjs +491 -0
- package/components/flex.cjs +1 -0
- package/components/flex.d.ts +6 -0
- package/components/flex.mjs +16 -0
- package/components/form.cjs +1 -0
- package/components/form.d.ts +10 -0
- package/components/form.mjs +58 -0
- package/components/grid.cjs +1 -0
- package/components/grid.d.ts +6 -0
- package/components/grid.mjs +16 -0
- package/components/icon.cjs +1 -0
- package/components/icon.d.ts +37 -0
- package/components/icon.mjs +41 -0
- package/components/menu.cjs +1 -0
- package/components/menu.d.ts +234 -0
- package/components/menu.mjs +422 -0
- package/components/overlay.cjs +1 -0
- package/components/overlay.d.ts +47 -0
- package/components/overlay.mjs +52 -0
- package/components/popover.cjs +1 -0
- package/components/popover.d.ts +100 -0
- package/components/popover.mjs +69 -0
- package/components/presence.cjs +1 -0
- package/components/presence.d.ts +36 -0
- package/components/presence.mjs +11 -0
- package/components/progress.cjs +1 -0
- package/components/progress.d.ts +47 -0
- package/components/progress.mjs +28 -0
- package/components/radioButton.cjs +1 -0
- package/components/radioButton.d.ts +32 -0
- package/components/radioButton.mjs +32 -0
- package/components/radioGroup.cjs +1 -0
- package/components/radioGroup.d.ts +51 -0
- package/components/radioGroup.mjs +83 -0
- package/components/select.cjs +1 -0
- package/components/select.d.ts +51 -0
- package/components/select.mjs +36 -0
- package/components/semantics.cjs +1 -0
- package/components/semantics.d.ts +39 -0
- package/components/semantics.mjs +17 -0
- package/components/slider.cjs +1 -0
- package/components/slider.d.ts +98 -0
- package/components/slider.mjs +250 -0
- package/components/svg.cjs +1 -0
- package/components/svg.d.ts +65 -0
- package/components/svg.mjs +141 -0
- package/components/switch.cjs +1 -0
- package/components/switch.d.ts +29 -0
- package/components/switch.mjs +25 -0
- package/components/tabs.cjs +1 -0
- package/components/tabs.d.ts +87 -0
- package/components/tabs.mjs +324 -0
- package/components/textarea.cjs +1 -0
- package/components/textarea.d.ts +41 -0
- package/components/textarea.mjs +33 -0
- package/components/textbox.cjs +1 -0
- package/components/textbox.d.ts +38 -0
- package/components/textbox.mjs +33 -0
- package/components/toaster.cjs +1 -0
- package/components/toaster.d.ts +106 -0
- package/components/toaster.mjs +295 -0
- package/components/tooltip.cjs +1 -0
- package/components/tooltip.d.ts +98 -0
- package/components/tooltip.mjs +110 -0
- package/components/visuallyHidden.cjs +1 -0
- package/components/visuallyHidden.d.ts +6 -0
- package/components/visuallyHidden.mjs +23 -0
- package/docs/a11y.md +199 -0
- package/docs/anchor.md +139 -0
- package/docs/components.md +48 -0
- package/docs/index.md +11 -0
- package/docs/props.md +1777 -0
- package/effects.cjs +1 -0
- package/effects.mjs +6 -0
- package/forms.cjs +1 -0
- package/forms.mjs +21 -0
- package/gridExport.cjs +2 -0
- package/gridExport.mjs +244 -0
- package/icons/dotsIcon.d.ts +2 -0
- package/icons/expandIcon.d.ts +2 -0
- package/icons/groupingIcon.d.ts +2 -0
- package/icons/pinIcon.d.ts +2 -0
- package/icons/searchIcon.d.ts +2 -0
- package/icons/sortIcon.d.ts +2 -0
- package/identity.cjs +1 -0
- package/identity.mjs +12 -0
- package/keyboard.cjs +1 -0
- package/keyboard.mjs +30 -0
- package/layer.cjs +1 -0
- package/layer.mjs +127 -0
- package/motion.cjs +1 -0
- package/motion.mjs +66 -0
- package/package.json +327 -7
- package/placement.cjs +1 -0
- package/placement.mjs +180 -0
- package/platform.cjs +1 -0
- package/platform.mjs +45 -0
- package/react/a11y/callbacks.d.ts +12 -0
- package/react/a11y/useControllableState.d.ts +25 -0
- package/react/a11y/useDismiss.d.ts +25 -0
- package/react/a11y/useFocusReturn.d.ts +18 -0
- package/react/a11y/useRovingFocus.d.ts +84 -0
- package/react/anchor/useAnchorPosition.d.ts +79 -0
- package/react/animation/usePresence.d.ts +32 -0
- package/react/boxClassNames.d.ts +25 -0
- package/react/boxProps.d.ts +49 -0
- package/react/boxTagProps.d.ts +7 -0
- package/react/clientRuntime.d.ts +11 -0
- package/react/dialog/useScrollLock.d.ts +12 -0
- package/react/effects.d.ts +10 -0
- package/react/forms/labelledControl.d.ts +17 -0
- package/react/forms/placeholderProp.d.ts +13 -0
- package/react/hooks/usePortalContainer.d.ts +6 -0
- package/react/hooks/useVirtualization.d.ts +32 -0
- package/react/hooks/useVisibility.d.ts +9 -0
- package/react/identity/useIdentifier.d.ts +17 -0
- package/react/popover/usePopoverLayer.d.ts +87 -0
- package/react/reactTypes.d.ts +10 -0
- package/react/resolveStyles.d.ts +18 -0
- package/react/styleElements.d.ts +3 -0
- package/react/svg/attributesInProps.d.ts +4 -0
- package/react/svg/svgNaming.d.ts +15 -0
- package/react/theme/theme.d.ts +26 -0
- package/react/theme/themeContext.d.ts +7 -0
- package/react/useStyles.d.ts +22 -0
- package/react-shared.cjs +1 -0
- package/react-shared.mjs +122 -0
- package/rolldown-runtime.cjs +1 -0
- package/rsc.cjs +1 -0
- package/rsc.d.ts +27 -0
- package/rsc.mjs +18 -0
- package/ssg.cjs +1 -0
- package/ssg.d.ts +24 -0
- package/ssg.mjs +25 -0
- package/utils/accordion/accordionUtils.d.ts +48 -0
- package/utils/anchor/anchorUtils.d.ts +79 -0
- package/utils/animation/animationUtils.d.ts +29 -0
- package/utils/array/arrayUtils.d.ts +15 -0
- package/utils/array/lazyList.d.ts +10 -0
- package/utils/box/boxUtils.d.ts +5 -0
- package/utils/chart/chartPalette.d.ts +15 -0
- package/utils/chart/chartUtils.d.ts +92 -0
- package/utils/combobox/comboboxUtils.d.ts +89 -0
- package/utils/dom/domUtils.d.ts +32 -0
- package/utils/environment/environmentUtils.d.ts +28 -0
- package/utils/export/csvUtils.d.ts +23 -0
- package/utils/export/downloadUtils.d.ts +12 -0
- package/utils/export/xlsxUtils.d.ts +56 -0
- package/utils/export/zipUtils.d.ts +26 -0
- package/utils/fn/fnUtils.d.ts +4 -0
- package/utils/form/formUtils.d.ts +8 -0
- package/utils/keyboard/typeaheadUtils.d.ts +31 -0
- package/utils/memo.d.ts +10 -0
- package/utils/menu/menuUtils.d.ts +25 -0
- package/utils/object/objectUtils.d.ts +13 -0
- package/utils/slider/sliderUtils.d.ts +67 -0
- package/utils/string/fuzzySearch.d.ts +27 -0
- package/utils/string/stringUtils.d.ts +4 -0
- package/utils/tabs/tabsUtils.d.ts +75 -0
- package/utils/toast/toastStore.d.ts +73 -0
- package/utils/virtual/virtualUtils.d.ts +47 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { u as e } from "../platform.mjs";
|
|
3
|
+
import { n as t } from "../effects.mjs";
|
|
4
|
+
import n from "../box.mjs";
|
|
5
|
+
import { a as r, i } from "../behavior.mjs";
|
|
6
|
+
import { t as a } from "../identity.mjs";
|
|
7
|
+
import { n as o } from "../motion.mjs";
|
|
8
|
+
import { createContext as s, useContext as c, useMemo as l, useRef as u, useState as d } from "react";
|
|
9
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
10
|
+
//#region src/utils/tabs/tabsUtils.ts
|
|
11
|
+
var m;
|
|
12
|
+
(function(e) {
|
|
13
|
+
let t = e.TAB_SELECTOR = "[role=\"tab\"]", n = e.LIST_SELECTOR = "[role=\"tablist\"]", r = e.PANEL_SELECTOR = "[role=\"tabpanel\"]";
|
|
14
|
+
function i(e, t) {
|
|
15
|
+
return t instanceof Element && t.closest(n) === e;
|
|
16
|
+
}
|
|
17
|
+
e.owns = i;
|
|
18
|
+
function a(e) {
|
|
19
|
+
return e ? [...e.querySelectorAll(t)].filter((t) => i(e, t)) : [];
|
|
20
|
+
}
|
|
21
|
+
e.tabs = a;
|
|
22
|
+
function o(e) {
|
|
23
|
+
return e.hasAttribute("disabled") || e.getAttribute("aria-disabled") === "true";
|
|
24
|
+
}
|
|
25
|
+
e.isDisabled = o;
|
|
26
|
+
function s(e) {
|
|
27
|
+
return e.dataset.value;
|
|
28
|
+
}
|
|
29
|
+
e.valueOf = s;
|
|
30
|
+
function c(e) {
|
|
31
|
+
return e.replace(/[^A-Za-z0-9-]/g, (e) => `_${e.codePointAt(0).toString(36)}_`);
|
|
32
|
+
}
|
|
33
|
+
e.token = c;
|
|
34
|
+
function l(e, t, n, r) {
|
|
35
|
+
let i = e.length;
|
|
36
|
+
if (i === 0) return;
|
|
37
|
+
let a = t < 0 || t >= i ? n > 0 ? -1 : i : t;
|
|
38
|
+
for (let t = 0; t < i; t++) {
|
|
39
|
+
if (a += n, a < 0 || a >= i) {
|
|
40
|
+
if (!r) return;
|
|
41
|
+
a = (a % i + i) % i;
|
|
42
|
+
}
|
|
43
|
+
if (!o(e[a])) return e[a];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
e.step = l;
|
|
47
|
+
function u(e, t) {
|
|
48
|
+
return l(e, t === 1 ? -1 : e.length, t, !1);
|
|
49
|
+
}
|
|
50
|
+
e.edge = u;
|
|
51
|
+
function d(e, t) {
|
|
52
|
+
return t instanceof HTMLElement ? e.indexOf(t) : -1;
|
|
53
|
+
}
|
|
54
|
+
e.indexOf = d;
|
|
55
|
+
function f(e, t, n = !1) {
|
|
56
|
+
if (e === "Home") return {
|
|
57
|
+
kind: "edge",
|
|
58
|
+
delta: 1
|
|
59
|
+
};
|
|
60
|
+
if (e === "End") return {
|
|
61
|
+
kind: "edge",
|
|
62
|
+
delta: -1
|
|
63
|
+
};
|
|
64
|
+
let r = t === "vertical", i = r ? "ArrowDown" : n ? "ArrowLeft" : "ArrowRight", a = r ? "ArrowUp" : n ? "ArrowRight" : "ArrowLeft";
|
|
65
|
+
if (e === i) return {
|
|
66
|
+
kind: "step",
|
|
67
|
+
delta: 1
|
|
68
|
+
};
|
|
69
|
+
if (e === a) return {
|
|
70
|
+
kind: "step",
|
|
71
|
+
delta: -1
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
e.moveFor = f;
|
|
75
|
+
function p(e, t, n, r) {
|
|
76
|
+
return n.kind === "edge" ? u(e, n.delta) : l(e, t, n.delta, r);
|
|
77
|
+
}
|
|
78
|
+
e.target = p;
|
|
79
|
+
function m(e) {
|
|
80
|
+
if (e) return a(e).find((e) => e.getAttribute("aria-selected") === "true");
|
|
81
|
+
}
|
|
82
|
+
e.selectedTab = m;
|
|
83
|
+
function h(e, t, n) {
|
|
84
|
+
let r = e.getBoundingClientRect(), i = t.getBoundingClientRect();
|
|
85
|
+
return n === "vertical" ? {
|
|
86
|
+
start: i.top - r.top + e.scrollTop,
|
|
87
|
+
size: i.height
|
|
88
|
+
} : {
|
|
89
|
+
start: i.left - r.left + e.scrollLeft,
|
|
90
|
+
size: i.width
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
e.bounds = h;
|
|
94
|
+
function g(e, t) {
|
|
95
|
+
return !e || !t ? e === t : e.start === t.start && e.size === t.size;
|
|
96
|
+
}
|
|
97
|
+
e.sameBounds = g;
|
|
98
|
+
function _(e) {
|
|
99
|
+
if (e) return [...e.querySelectorAll(r)].find((e) => !e.hasAttribute("hidden"));
|
|
100
|
+
}
|
|
101
|
+
e.visiblePanel = _;
|
|
102
|
+
})(m ||= {});
|
|
103
|
+
var h = m, g = s(null);
|
|
104
|
+
function _(e) {
|
|
105
|
+
let t = c(g);
|
|
106
|
+
if (!t) throw Error(`<${e}> has to be rendered inside a <Tabs>.`);
|
|
107
|
+
return t;
|
|
108
|
+
}
|
|
109
|
+
function v(e) {
|
|
110
|
+
let { children: r, value: o, defaultValue: s, onValueChange: c, orientation: u = "horizontal", activation: p = "automatic", loop: m = !0, keepMounted: _ = !1, indicator: v = "static", props: y, ...b } = e, x = a("tabs"), [S, C] = i({
|
|
111
|
+
value: o,
|
|
112
|
+
defaultValue: s,
|
|
113
|
+
onChange: c
|
|
114
|
+
}), [w, T] = d(), [E, D] = d(!1);
|
|
115
|
+
t(() => {
|
|
116
|
+
S !== void 0 && T(S);
|
|
117
|
+
}, [S]);
|
|
118
|
+
let O = l(() => ({
|
|
119
|
+
identifier: x,
|
|
120
|
+
value: S,
|
|
121
|
+
orientation: u,
|
|
122
|
+
activation: p,
|
|
123
|
+
loop: m,
|
|
124
|
+
keepMounted: _,
|
|
125
|
+
indicator: v,
|
|
126
|
+
indicatorLive: E,
|
|
127
|
+
setIndicatorLive: D,
|
|
128
|
+
tabStop: w ?? S,
|
|
129
|
+
setTabStop: T,
|
|
130
|
+
select: C,
|
|
131
|
+
tabId: (e) => `${x}-tab-${h.token(e)}`,
|
|
132
|
+
panelId: (e) => `${x}-panel-${h.token(e)}`
|
|
133
|
+
}), [
|
|
134
|
+
x,
|
|
135
|
+
S,
|
|
136
|
+
u,
|
|
137
|
+
p,
|
|
138
|
+
m,
|
|
139
|
+
_,
|
|
140
|
+
v,
|
|
141
|
+
E,
|
|
142
|
+
w,
|
|
143
|
+
C
|
|
144
|
+
]);
|
|
145
|
+
return /* @__PURE__ */ f(g.Provider, {
|
|
146
|
+
value: O,
|
|
147
|
+
children: /* @__PURE__ */ f(n, {
|
|
148
|
+
component: "tabs",
|
|
149
|
+
...b,
|
|
150
|
+
variant: [b.variant, { vertical: u === "vertical" }],
|
|
151
|
+
props: y,
|
|
152
|
+
children: r
|
|
153
|
+
})
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function y(i) {
|
|
157
|
+
let { children: a, label: o, labelledBy: s, props: c, ...l } = i, { value: m, orientation: g, activation: v, loop: y, indicator: b, tabStop: x, setTabStop: S, setIndicatorLive: C, select: w } = _("Tabs.List"), T = u(null), [E, D] = d(), O = b === "sliding";
|
|
158
|
+
t(() => {
|
|
159
|
+
let e = T.current;
|
|
160
|
+
if (!O || !e) return;
|
|
161
|
+
let t = () => {
|
|
162
|
+
let t = h.selectedTab(e), n = t && h.bounds(e, t, g);
|
|
163
|
+
D((e) => h.sameBounds(e, n) ? e : n);
|
|
164
|
+
};
|
|
165
|
+
if (t(), typeof ResizeObserver > "u") return;
|
|
166
|
+
let n = new ResizeObserver(t);
|
|
167
|
+
n.observe(e);
|
|
168
|
+
for (let t of h.tabs(e)) n.observe(t);
|
|
169
|
+
return () => n.disconnect();
|
|
170
|
+
}, [
|
|
171
|
+
O,
|
|
172
|
+
g,
|
|
173
|
+
m
|
|
174
|
+
]);
|
|
175
|
+
let k = O && E && E.size > 0 ? E : void 0;
|
|
176
|
+
t(() => {
|
|
177
|
+
C(k !== void 0);
|
|
178
|
+
}, [k, C]), t(() => {
|
|
179
|
+
if (x !== void 0) return;
|
|
180
|
+
let e = h.edge(h.tabs(T.current), 1), t = e && h.valueOf(e);
|
|
181
|
+
t !== void 0 && S(t);
|
|
182
|
+
}, [x, S]);
|
|
183
|
+
let A = r((t) => {
|
|
184
|
+
let n = T.current;
|
|
185
|
+
if (!n || t.defaultPrevented || !h.owns(n, t.target)) return;
|
|
186
|
+
let r = h.tabs(n), i = h.indexOf(r, t.target);
|
|
187
|
+
if (i === -1) return;
|
|
188
|
+
if (v === "manual" && (t.key === "Enter" || t.key === " ")) {
|
|
189
|
+
let e = h.valueOf(r[i]);
|
|
190
|
+
if (e === void 0) return;
|
|
191
|
+
t.preventDefault(), w(e, {
|
|
192
|
+
reason: "keyboard",
|
|
193
|
+
event: t
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
let a = h.moveFor(t.key, g, e(n));
|
|
198
|
+
if (!a) return;
|
|
199
|
+
let o = h.target(r, i, a, y);
|
|
200
|
+
if (!o) return;
|
|
201
|
+
t.preventDefault(), o.focus();
|
|
202
|
+
let s = h.valueOf(o);
|
|
203
|
+
v === "automatic" && s !== void 0 && w(s, {
|
|
204
|
+
reason: "keyboard",
|
|
205
|
+
event: t
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
return /* @__PURE__ */ p(n, {
|
|
209
|
+
ref: T,
|
|
210
|
+
component: "tabs.list",
|
|
211
|
+
...l,
|
|
212
|
+
variant: [l.variant, {
|
|
213
|
+
vertical: g === "vertical",
|
|
214
|
+
sliding: O
|
|
215
|
+
}],
|
|
216
|
+
props: {
|
|
217
|
+
role: "tablist",
|
|
218
|
+
"aria-label": o,
|
|
219
|
+
"aria-labelledby": s,
|
|
220
|
+
"aria-orientation": g,
|
|
221
|
+
...c,
|
|
222
|
+
onKeyDown: A
|
|
223
|
+
},
|
|
224
|
+
children: [a, k && /* @__PURE__ */ f(n, {
|
|
225
|
+
tag: "span",
|
|
226
|
+
component: "tabs.indicator",
|
|
227
|
+
variant: { vertical: g === "vertical" },
|
|
228
|
+
style: g === "vertical" ? {
|
|
229
|
+
top: `${k.start}px`,
|
|
230
|
+
height: `${k.size}px`
|
|
231
|
+
} : {
|
|
232
|
+
left: `${k.start}px`,
|
|
233
|
+
width: `${k.size}px`
|
|
234
|
+
},
|
|
235
|
+
props: { "aria-hidden": !0 }
|
|
236
|
+
})]
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
y.displayName = "Tabs.List";
|
|
240
|
+
function b(e) {
|
|
241
|
+
let { value: t, children: i, disabled: a, props: o, ...s } = e, { value: c, orientation: l, keepMounted: u, indicatorLive: d, tabStop: p, setTabStop: m, select: h, tabId: g, panelId: v } = _("Tabs.Tab"), y = c === t, b = r((e) => h(t, {
|
|
242
|
+
reason: "click",
|
|
243
|
+
event: e
|
|
244
|
+
})), x = r(() => m(t));
|
|
245
|
+
return /* @__PURE__ */ f(n, {
|
|
246
|
+
tag: "button",
|
|
247
|
+
component: "tabs.tab",
|
|
248
|
+
...s,
|
|
249
|
+
variant: [s.variant, {
|
|
250
|
+
vertical: l === "vertical",
|
|
251
|
+
underline: !d
|
|
252
|
+
}],
|
|
253
|
+
disabled: a,
|
|
254
|
+
id: g(t),
|
|
255
|
+
props: {
|
|
256
|
+
type: "button",
|
|
257
|
+
role: "tab",
|
|
258
|
+
"aria-selected": y,
|
|
259
|
+
"aria-controls": y || u ? v(t) : void 0,
|
|
260
|
+
tabIndex: p === t ? 0 : -1,
|
|
261
|
+
"data-value": t,
|
|
262
|
+
...o,
|
|
263
|
+
onClick: b,
|
|
264
|
+
onFocus: x
|
|
265
|
+
},
|
|
266
|
+
children: i
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
b.displayName = "Tabs.Tab";
|
|
270
|
+
function x(e) {
|
|
271
|
+
let { children: i, props: a, ...s } = e, { value: c } = _("Tabs.Panels"), l = u(null), [p, m] = d(), [g, v] = d(!1), y = r(() => {
|
|
272
|
+
let e = l.current;
|
|
273
|
+
if (!e) return;
|
|
274
|
+
let t = h.visiblePanel(e)?.offsetHeight;
|
|
275
|
+
t !== p && (p !== void 0 && t !== void 0 && v(!0), m(t));
|
|
276
|
+
});
|
|
277
|
+
return t(() => {
|
|
278
|
+
let e = l.current;
|
|
279
|
+
if (!e || (y(), typeof ResizeObserver > "u")) return;
|
|
280
|
+
let t = h.visiblePanel(e);
|
|
281
|
+
if (!t) return;
|
|
282
|
+
let n = new ResizeObserver(y);
|
|
283
|
+
return n.observe(t), () => n.disconnect();
|
|
284
|
+
}, [c, y]), t(() => {
|
|
285
|
+
let e = l.current;
|
|
286
|
+
if (!e || !g) return;
|
|
287
|
+
let t = setTimeout(() => v(!1), o.activeDuration(getComputedStyle(e)) + o.SETTLE_FRAME);
|
|
288
|
+
return () => clearTimeout(t);
|
|
289
|
+
}, [g, p]), /* @__PURE__ */ f(n, {
|
|
290
|
+
ref: l,
|
|
291
|
+
component: "tabs.panels",
|
|
292
|
+
...s,
|
|
293
|
+
variant: [s.variant, { resizing: g }],
|
|
294
|
+
style: {
|
|
295
|
+
height: p === void 0 ? void 0 : `${p}px`,
|
|
296
|
+
...s.style
|
|
297
|
+
},
|
|
298
|
+
props: a,
|
|
299
|
+
children: i
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
x.displayName = "Tabs.Panels";
|
|
303
|
+
function S(e) {
|
|
304
|
+
let { value: t, children: r, props: i, ...a } = e, { value: o, keepMounted: s, tabId: c, panelId: l } = _("Tabs.Panel"), u = o === t;
|
|
305
|
+
return !u && !s ? null : /* @__PURE__ */ f(n, {
|
|
306
|
+
component: "tabs.panel",
|
|
307
|
+
...a,
|
|
308
|
+
variant: [a.variant, { hidden: !u }],
|
|
309
|
+
id: l(t),
|
|
310
|
+
props: {
|
|
311
|
+
role: "tabpanel",
|
|
312
|
+
"aria-labelledby": c(t),
|
|
313
|
+
hidden: !u || void 0,
|
|
314
|
+
tabIndex: 0,
|
|
315
|
+
...i
|
|
316
|
+
},
|
|
317
|
+
children: r
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
S.displayName = "Tabs.Panel";
|
|
321
|
+
var C = v;
|
|
322
|
+
C.List = y, C.Tab = b, C.Panels = x, C.Panel = S, C.displayName = "Tabs";
|
|
323
|
+
//#endregion
|
|
324
|
+
export { C as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../rolldown-runtime.cjs"),t=require("../react-shared.cjs"),n=require("../forms.cjs");let r=require("react"),i=require("react/jsx-runtime"),a=require("@box-kite/react");a=e.t(a,1);var o=[`name`,`onInput`,`onChange`,`value`,`defaultValue`,`rows`,`cols`,`autoFocus`,`maxLength`,`minLength`,`readOnly`];function s(e,r){let{placeholder:s,...c}=e,{text:l,styles:u}=n.t(s),d=t.i.buildProps(c,o,l===void 0?void 0:{placeholder:l});return(0,i.jsx)(a.default,{ref:r,tag:`textarea`,component:`textarea`,...d,placeholder:u})}var c=(0,r.forwardRef)(s);c.displayName=`Textarea`,exports.default=c;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RefAttributes } from 'react';
|
|
2
|
+
import { BoxProps, BoxTagProps } from '../box';
|
|
3
|
+
import { OmitTagProps } from '../react/boxProps';
|
|
4
|
+
import { PlaceholderProp } from '../react/forms/placeholderProp';
|
|
5
|
+
import { ComponentsAndVariants } from '@box-kite/core/types';
|
|
6
|
+
declare const tagProps: readonly ["name", "onInput", "onChange", "value", "defaultValue", "rows", "cols", "autoFocus", "maxLength", "minLength", "readOnly"];
|
|
7
|
+
type TagPropsType = (typeof tagProps)[number];
|
|
8
|
+
type TextareaProps<TKey extends keyof ComponentsAndVariants> = Omit<BoxProps<'textarea', TKey>, 'tag' | 'props' | 'placeholder'>;
|
|
9
|
+
type TextareaTagProps = OmitTagProps<BoxTagProps<'textarea'>, TagPropsType | 'type'>;
|
|
10
|
+
interface Props<TKey extends keyof ComponentsAndVariants> extends TextareaProps<TKey> {
|
|
11
|
+
/** What the field submits under, and what a `<label htmlFor>` of your own would point at. */
|
|
12
|
+
name?: string;
|
|
13
|
+
/** Attributes for the `<textarea>` itself — an `id`, an `aria-label`, `autoComplete`, `wrap`. */
|
|
14
|
+
props?: TextareaTagProps;
|
|
15
|
+
/** Fires on every keystroke. `onChange` is React's alias for the same event. */
|
|
16
|
+
onInput?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
17
|
+
/** Fires on every keystroke too — React's `onChange` is the DOM's `input`, not its `change`. */
|
|
18
|
+
onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
19
|
+
/** A string is the attribute; an object is `::placeholder` styles. Neither one names the field. */
|
|
20
|
+
placeholder?: PlaceholderProp;
|
|
21
|
+
/** Controlled value. Pair it with `onChange`, or the field cannot be typed into. */
|
|
22
|
+
value?: string;
|
|
23
|
+
/** The value it starts with when the field owns its own state. */
|
|
24
|
+
defaultValue?: string;
|
|
25
|
+
/** How many lines tall it starts. `height` is the Box prop for the size it stays. */
|
|
26
|
+
rows?: number;
|
|
27
|
+
/** How many characters wide it starts — `width` is the prop to reach for instead. */
|
|
28
|
+
cols?: number;
|
|
29
|
+
/** Focus it on mount. One per page at most — a stolen focus is a lost place in the document. */
|
|
30
|
+
autoFocus?: boolean;
|
|
31
|
+
/** The most characters the field accepts. The browser both enforces and announces it. */
|
|
32
|
+
maxLength?: number;
|
|
33
|
+
/** The fewest characters that count as valid. Checked when the form is submitted. */
|
|
34
|
+
minLength?: number;
|
|
35
|
+
/** Editable to nobody, but still focusable, still read out and still submitted. */
|
|
36
|
+
readOnly?: boolean;
|
|
37
|
+
/** The form will not submit while it is empty, and a screen reader says so. */
|
|
38
|
+
required?: boolean;
|
|
39
|
+
}
|
|
40
|
+
declare const _default: <TKey extends keyof ComponentsAndVariants = "textarea">(props: Props<TKey> & RefAttributes<HTMLTextAreaElement>) => React.ReactNode;
|
|
41
|
+
export default _default;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { i as e } from "../react-shared.mjs";
|
|
2
|
+
import { t } from "../forms.mjs";
|
|
3
|
+
import { forwardRef as n } from "react";
|
|
4
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
5
|
+
import i from "@box-kite/react";
|
|
6
|
+
//#region src/components/textarea.tsx
|
|
7
|
+
var a = [
|
|
8
|
+
"name",
|
|
9
|
+
"onInput",
|
|
10
|
+
"onChange",
|
|
11
|
+
"value",
|
|
12
|
+
"defaultValue",
|
|
13
|
+
"rows",
|
|
14
|
+
"cols",
|
|
15
|
+
"autoFocus",
|
|
16
|
+
"maxLength",
|
|
17
|
+
"minLength",
|
|
18
|
+
"readOnly"
|
|
19
|
+
];
|
|
20
|
+
function o(n, o) {
|
|
21
|
+
let { placeholder: s, ...c } = n, { text: l, styles: u } = t(s), d = e.buildProps(c, a, l === void 0 ? void 0 : { placeholder: l });
|
|
22
|
+
return /* @__PURE__ */ r(i, {
|
|
23
|
+
ref: o,
|
|
24
|
+
tag: "textarea",
|
|
25
|
+
component: "textarea",
|
|
26
|
+
...d,
|
|
27
|
+
placeholder: u
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
var s = n(o);
|
|
31
|
+
s.displayName = "Textarea";
|
|
32
|
+
//#endregion
|
|
33
|
+
export { s as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../rolldown-runtime.cjs"),t=require("../react-shared.cjs"),n=require("../forms.cjs");let r=require("react"),i=require("react/jsx-runtime"),a=require("@box-kite/react");a=e.t(a,1);var o=[`name`,`onInput`,`onChange`,`type`,`step`,`defaultValue`,`autoFocus`,`readOnly`,`required`,`value`,`pattern`];function s(e,r){let{placeholder:s,...c}=e,{text:l,styles:u}=n.t(s),d=t.i.buildProps(c,o,l===void 0?void 0:{placeholder:l});return(0,i.jsx)(a.default,{ref:r,tag:`input`,component:`textbox`,...d,placeholder:u})}var c=(0,r.forwardRef)(s);c.displayName=`Textbox`,exports.default=c;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RefAttributes } from 'react';
|
|
2
|
+
import { BoxProps, BoxTagProps } from '../box';
|
|
3
|
+
import { OmitTagProps } from '../react/boxProps';
|
|
4
|
+
import { PlaceholderProp } from '../react/forms/placeholderProp';
|
|
5
|
+
import { ComponentsAndVariants } from '@box-kite/core/types';
|
|
6
|
+
declare const tagProps: readonly ["name", "onInput", "onChange", "type", "step", "defaultValue", "autoFocus", "readOnly", "required", "value", "pattern"];
|
|
7
|
+
type TagPropsType = (typeof tagProps)[number];
|
|
8
|
+
type TextareaProps<TKey extends keyof ComponentsAndVariants> = Omit<BoxProps<'input', TKey>, 'tag' | 'props' | 'placeholder'>;
|
|
9
|
+
type TextboxTagProps = OmitTagProps<BoxTagProps<'input'>, TagPropsType>;
|
|
10
|
+
type TextboxType = 'date' | 'datetime-local' | 'email' | 'hidden' | 'month' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'time' | 'url' | 'week';
|
|
11
|
+
interface Props<TKey extends keyof ComponentsAndVariants> extends TextareaProps<TKey> {
|
|
12
|
+
/** What the field submits under, and what a `<label htmlFor>` of your own would point at. */
|
|
13
|
+
name?: string;
|
|
14
|
+
/** Attributes for the `<input>` itself — an `id`, an `aria-label`, `inputMode`, `autoComplete`. */
|
|
15
|
+
props?: TextboxTagProps;
|
|
16
|
+
/** Fires on every keystroke. `onChange` is React's alias for the same event. */
|
|
17
|
+
onInput?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
18
|
+
/** Fires on every keystroke too — React's `onChange` is the DOM's `input`, not its `change`. */
|
|
19
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
20
|
+
/** Which text input this is. It decides the validation, the mobile keyboard and the spinner. */
|
|
21
|
+
type?: TextboxType;
|
|
22
|
+
/** A string is the attribute; an object is `::placeholder` styles. Neither one names the field. */
|
|
23
|
+
placeholder?: PlaceholderProp;
|
|
24
|
+
/** Controlled value. Pair it with `onChange`, or the field cannot be typed into. */
|
|
25
|
+
value?: string | number;
|
|
26
|
+
/** The value it starts with when the field owns its own state. */
|
|
27
|
+
defaultValue?: string | number;
|
|
28
|
+
/** A regular expression the value has to match for the form to be valid. */
|
|
29
|
+
pattern?: string;
|
|
30
|
+
/** Focus it on mount. One per page at most — a stolen focus is a lost place in the document. */
|
|
31
|
+
autoFocus?: boolean;
|
|
32
|
+
/** Editable to nobody, but still focusable, still read out and still submitted. */
|
|
33
|
+
readOnly?: boolean;
|
|
34
|
+
/** How far a `number` field's spinner and arrow keys move. */
|
|
35
|
+
step?: number | string;
|
|
36
|
+
}
|
|
37
|
+
declare const _default: <TKey extends keyof ComponentsAndVariants = "textbox">(props: Props<TKey> & RefAttributes<HTMLInputElement>) => React.ReactNode;
|
|
38
|
+
export default _default;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { i as e } from "../react-shared.mjs";
|
|
2
|
+
import { t } from "../forms.mjs";
|
|
3
|
+
import { forwardRef as n } from "react";
|
|
4
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
5
|
+
import i from "@box-kite/react";
|
|
6
|
+
//#region src/components/textbox.tsx
|
|
7
|
+
var a = [
|
|
8
|
+
"name",
|
|
9
|
+
"onInput",
|
|
10
|
+
"onChange",
|
|
11
|
+
"type",
|
|
12
|
+
"step",
|
|
13
|
+
"defaultValue",
|
|
14
|
+
"autoFocus",
|
|
15
|
+
"readOnly",
|
|
16
|
+
"required",
|
|
17
|
+
"value",
|
|
18
|
+
"pattern"
|
|
19
|
+
];
|
|
20
|
+
function o(n, o) {
|
|
21
|
+
let { placeholder: s, ...c } = n, { text: l, styles: u } = t(s), d = e.buildProps(c, a, l === void 0 ? void 0 : { placeholder: l });
|
|
22
|
+
return /* @__PURE__ */ r(i, {
|
|
23
|
+
ref: o,
|
|
24
|
+
tag: "input",
|
|
25
|
+
component: "textbox",
|
|
26
|
+
...d,
|
|
27
|
+
placeholder: u
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
var s = n(o);
|
|
31
|
+
s.displayName = "Textbox";
|
|
32
|
+
//#endregion
|
|
33
|
+
export { s as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../platform.cjs"),t=require("../client.cjs"),n=require("../effects.cjs"),r=require("../box.cjs"),i=require("../motion.cjs");let a=require("react"),o=require("react/jsx-runtime"),s=require("react-dom"),c=require("use-sync-external-store/shim");var l={toasts:[],overflow:0},u=0;function d(){return u+=1,`toast-${u}`}function f(e){let t=[],n=l,r=e?.limit??3,i=e?.duration??5e3,a=!1,o=new Set,s=new Map,c=e=>{let t=s.get(e);t?.handle&&clearTimeout(t.handle),s.delete(e)},u=()=>{let e=0;t=t.map(t=>{let n=!t.open||e++<r;return t.visible===n?t:{...t,visible:n}}),n={toasts:t,overflow:Math.max(0,e-r)},f(),o.forEach(e=>e())};function f(){let e=new Set;for(let n of t){if(!n.open||!n.visible||!Number.isFinite(n.duration))continue;e.add(n.id);let t=s.get(n.id)??{handle:null,remaining:n.duration,startedAt:0};s.set(n.id,t),!(a||t.handle)&&(t.startedAt=Date.now(),t.handle=setTimeout(()=>{s.delete(n.id),m(n.id,`timeout`)},t.remaining))}for(let t of[...s.keys()])e.has(t)||c(t)}let p=(e,t)=>t??(e===`loading`?1/0:i);function m(e,n=`imperative`){let r=[];t=t.map(t=>!t.open||e!==void 0&&t.id!==e?t:(r.push(t),c(t.id),{...t,open:!1})),r.length&&(u(),r.forEach(e=>e.onDismiss?.(n)))}function h(e,n,r){let i=!1;t=t.map(t=>{if(t.id!==e)return t;i=!0,c(e);let a=r?.kind??t.kind;return{...t,...r,id:e,message:n,kind:a,duration:r?.duration??(r?.kind?p(a):t.duration),open:!0}}),i&&u()}function g(e,n){let r=n?.id??d();if(n?.id&&t.some(e=>e.id===r))return h(r,e,n),r;let i=n?.kind??`default`;return t=[...t,{id:r,kind:i,message:e,description:n?.description,duration:p(i,n?.duration),action:n?.action,dismissible:n?.dismissible??!0,onDismiss:n?.onDismiss,open:!0,visible:!1}],u(),r}return{subscribe(e){return o.add(e),()=>o.delete(e)},getSnapshot:()=>n,getServerSnapshot:()=>l,add:g,update:h,dismiss:m,remove(e){let n=t.filter(t=>t.id!==e);n.length!==t.length&&(c(e),t=n,u())},setLimit(e){e!==r&&(r=e,u())},setDefaultDuration(e){i=e},pause(){if(!a){a=!0;for(let e of s.values())e.handle&&(clearTimeout(e.handle),e.handle=null,e.remaining=Math.max(0,e.remaining-(Date.now()-e.startedAt)))}},resume(){a&&(a=!1,f())},reset(){for(let e of[...s.keys()])c(e);t=[],n=l,o.forEach(e=>e())}}}var p=f(),m=e=>(t,n)=>p.add(t,{...n,kind:e}),h=Object.assign((e,t)=>p.add(e,t),{success:m(`success`),error:m(`error`),warning:m(`warning`),info:m(`info`),loading:m(`loading`),update:(e,t,n)=>p.update(e,t,n),dismiss:e=>p.dismiss(e,`imperative`),promise(e,t,n){let r=p.add(t.loading,{...n,id:n?.id,kind:`loading`}),i=(e,t)=>typeof e==`function`?e(t):e;return e.then(e=>p.update(r,i(t.success,e),{kind:`success`}),e=>p.update(r,i(t.error,e),{kind:`error`})),e}}),g={"top-start":`topStart`,"top-center":`topCenter`,"top-end":`topEnd`,"bottom-start":`bottomStart`,"bottom-center":`bottomCenter`,"bottom-end":`bottomEnd`};function _(e,t){let n=t.toLowerCase().split(`+`),r=n[n.length-1],i=new Set(n.slice(0,-1));return e.key.toLowerCase()===r&&e.altKey===i.has(`alt`)&&e.ctrlKey===i.has(`ctrl`)&&e.shiftKey===i.has(`shift`)&&e.metaKey===i.has(`meta`)}function v(e){let{toast:t,store:a,fromTop:s,closeLabel:c}=e,{mounted:l,ref:u,props:d}=i.t({present:t.open});if(n.n(()=>{l||a.remove(t.id)},[l,a,t.id]),!l)return null;let f=t.action,p=()=>{f?.onClick(),f?.closeOnClick!==!1&&a.dismiss(t.id,`action`)};return(0,o.jsxs)(r.default,{ref:u,component:`toaster.toast`,variant:{[t.kind]:t.kind!=="default",fromTop:s},props:{...t.kind===`error`?{role:`alert`}:{},"data-toast-id":t.id,...d},children:[(0,o.jsx)(r.default,{component:`toaster.message`,children:t.message}),t.description!==void 0&&(0,o.jsx)(r.default,{component:`toaster.description`,children:t.description}),f&&(0,o.jsx)(r.default,{tag:`button`,component:`toaster.action`,props:{type:`button`,onClick:p},children:f.label}),t.dismissible&&(0,o.jsx)(r.default,{tag:`button`,component:`toaster.close`,props:{type:`button`,"aria-label":c,onClick:()=>a.dismiss(t.id,`close`)}})]})}function y(i){let{position:l=`bottom-end`,limit:u=3,duration:d=5e3,label:f=`Notifications`,closeLabel:m=`Close`,overflowLabel:h=e=>`+${e} more`,hotkey:y=`F6`,store:b=p,props:x,...S}=i,C=(0,c.useSyncExternalStore)(b.subscribe,b.getSnapshot,b.getServerSnapshot),[w,T]=(0,a.useState)(!0),E=t.t(!w),D=(0,a.useRef)(null),O=(0,a.useRef)(null),k=(0,a.useRef)({hovered:!1,focused:!1,hidden:!1}),A=(0,a.useCallback)(()=>{let{hovered:e,focused:t,hidden:n}=k.current;e||t||n?b.pause():b.resume()},[b]);n.n(()=>{e.a()||T(!1)},[]),n.n(()=>b.setLimit(u),[b,u]),n.n(()=>b.setDefaultDuration(d),[b,d]),n.n(()=>{let t=D.current;!w||!e.a()||!t||!t.isConnected||t.matches(`:popover-open`)||t.showPopover()}),n.n(()=>{let t=e.t();if(!t)return;let n=new AbortController;return t.addEventListener(`visibilitychange`,()=>{k.current.hidden=t.hidden,A()},{signal:n.signal}),()=>n.abort()},[A]),n.n(()=>{let t=e.t();if(!y||!t)return;let n=new AbortController;return t.addEventListener(`keydown`,e=>{!_(e,y)||!D.current||(e.preventDefault(),O.current=t.activeElement,D.current.focus())},{signal:n.signal}),()=>n.abort()},[y]);let j=e=>!!e&&!!D.current?.contains(e),M=()=>{k.current.hovered=!0,A()},N=e=>{j(e.relatedTarget)||(k.current.hovered=!1,A())},P=e=>{k.current.focused=!0,A(),j(e.relatedTarget)||(O.current=e.relatedTarget)},F=e=>{j(e.relatedTarget)||(k.current.focused=!1,A())},I=e=>{if(e.key!==`Escape`)return;let t=(e.target.closest?.(`[data-toast-id]`))?.getAttribute(`data-toast-id`);t&&b.dismiss(t,`close`),b.getSnapshot().toasts.some(e=>e.open)?D.current?.focus():O.current?.focus()},L=l.startsWith(`top`),R=C.toasts.filter(e=>e.visible),z=L?[...R].reverse():R,B=C.overflow>0&&(0,o.jsx)(r.default,{component:`toaster.overflow`,children:h(C.overflow)}),V=(0,o.jsxs)(r.default,{tag:`section`,ref:D,component:`toaster`,...S,variant:[S.variant,{[g[l]]:!0}],props:{...w?{popover:`manual`}:{},"aria-live":`polite`,"aria-atomic":`false`,"aria-relevant":`additions text`,"aria-label":f,tabIndex:-1,...x,onPointerOver:M,onPointerOut:N,onFocus:P,onBlur:F,onKeyDown:I},children:[!L&&B,z.map(e=>(0,o.jsx)(v,{toast:e,store:b,fromTop:L,closeLabel:m},e.id)),L&&B]});return w?V:E?(0,s.createPortal)(V,E):null}var b=y;b.displayName=`Toaster`,exports.createToastStore=f,exports.default=b,exports.defaultToastStore=p,exports.toast=h;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { BoxProps } from '../box';
|
|
2
|
+
import { ComponentsAndVariants } from '@box-kite/core/types';
|
|
3
|
+
import { Toast, ToastAction, ToastDismissReason, ToastKind, ToastOptions, ToastStore } from '../utils/toast/toastStore';
|
|
4
|
+
export { default as createToastStore } from '../utils/toast/toastStore';
|
|
5
|
+
export type { Toast, ToastAction, ToastDismissReason, ToastKind, ToastOptions, ToastStore };
|
|
6
|
+
/** Which corner the stack is pinned to. The inline half is logical, so `start` mirrors with the page. */
|
|
7
|
+
export type ToastPosition = 'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end';
|
|
8
|
+
/** What `toast.promise` is told to say at each of the three moments. A function is handed the result. */
|
|
9
|
+
export interface ToastPromiseMessages<TValue> {
|
|
10
|
+
loading: React.ReactNode;
|
|
11
|
+
success: React.ReactNode | ((value: TValue) => React.ReactNode);
|
|
12
|
+
error: React.ReactNode | ((error: unknown) => React.ReactNode);
|
|
13
|
+
}
|
|
14
|
+
type Content = React.ReactNode;
|
|
15
|
+
type Options = ToastOptions<Content>;
|
|
16
|
+
/** The store `toast()` writes to, and the one `<Toaster>` reads when it is given none of its own. */
|
|
17
|
+
export declare const defaultToastStore: ToastStore<Content>;
|
|
18
|
+
/**
|
|
19
|
+
* Puts a message on screen, from anywhere — an event handler, a fetch, a module with no React in it. It
|
|
20
|
+
* returns the id, which is what `toast.dismiss` and a second `toast()` naming the same id act on.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* toast.success('Saved', { description: 'Your changes are live.' });
|
|
24
|
+
* toast.error('Could not save', { action: { label: 'Retry', onClick: save } });
|
|
25
|
+
* toast.promise(save(), { loading: 'Saving…', success: 'Saved', error: 'Could not save' });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Nothing is shown until a `<Toaster>` is on the page; a call made before one mounts is queued rather
|
|
29
|
+
* than lost, because the store holds the toasts and the viewport only draws them.
|
|
30
|
+
*/
|
|
31
|
+
export declare const toast: ((message: Content, options?: Options) => string) & {
|
|
32
|
+
success: (message: Content, options?: Options) => string;
|
|
33
|
+
error: (message: Content, options?: Options) => string;
|
|
34
|
+
warning: (message: Content, options?: Options) => string;
|
|
35
|
+
info: (message: Content, options?: Options) => string;
|
|
36
|
+
/** Stays until something dismisses it — a spinner that timed out would leave its work unreported. */
|
|
37
|
+
loading: (message: Content, options?: Options) => string;
|
|
38
|
+
/** Changes a toast already on screen. An id that is not there is ignored. */
|
|
39
|
+
update: (id: string, message: Content, options?: Options) => void;
|
|
40
|
+
/** Starts the exit for one toast, or for every one of them when given no id. */
|
|
41
|
+
dismiss: (id?: string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* One toast for the whole of an async call: a spinner while it runs, then the result in its place.
|
|
44
|
+
* The promise is handed back untouched, so it can still be awaited.
|
|
45
|
+
*/
|
|
46
|
+
promise<TValue>(promise: Promise<TValue>, messages: ToastPromiseMessages<TValue>, options?: Options): Promise<TValue>;
|
|
47
|
+
};
|
|
48
|
+
export interface ToasterProps<TKey extends keyof ComponentsAndVariants = 'toaster'> extends Omit<BoxProps<'div', TKey>, 'position'> {
|
|
49
|
+
/** Which corner the stack is pinned to. Default `'bottom-end'`. */
|
|
50
|
+
position?: ToastPosition;
|
|
51
|
+
/** How many toasts are on screen at once. The rest wait their turn, timers and all. Default `3`. */
|
|
52
|
+
limit?: number;
|
|
53
|
+
/** Milliseconds a toast that names no duration of its own stays. Default `5000`. */
|
|
54
|
+
duration?: number;
|
|
55
|
+
/** The region's accessible name. `role="region"` has none of its own, and this one is never labelled visually. */
|
|
56
|
+
label?: string;
|
|
57
|
+
/** The close button's accessible name. */
|
|
58
|
+
closeLabel?: string;
|
|
59
|
+
/** What the counter at the end of the stack says when the limit is holding toasts back. */
|
|
60
|
+
overflowLabel?(count: number): React.ReactNode;
|
|
61
|
+
/**
|
|
62
|
+
* A key that moves focus to the stack from anywhere on the page, since toasts steal none. Default
|
|
63
|
+
* `'F6'`; `'alt+t'` and the like also work, and `false` turns it off.
|
|
64
|
+
*/
|
|
65
|
+
hotkey?: string | false;
|
|
66
|
+
/** A store of your own — for a second, independent stack, or for a test that must not share state. */
|
|
67
|
+
store?: ToastStore<Content>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The viewport every toast is drawn in, and the live region they are announced from. Render one, once,
|
|
71
|
+
* near the root of the app; everything after that is `toast()`, from wherever the message comes from.
|
|
72
|
+
*
|
|
73
|
+
* ```tsx
|
|
74
|
+
* <Toaster position="bottom-end" />
|
|
75
|
+
* // anywhere at all, React or not:
|
|
76
|
+
* toast.success('Saved');
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* **It is in the top layer and there is no portal.** The viewport carries `popover="manual"` and is shown
|
|
80
|
+
* as soon as it mounts, so it paints over every stacking context and out of every clipped or transformed
|
|
81
|
+
* ancestor — and because it stays where it was declared, it inherits the theme, the custom properties and
|
|
82
|
+
* the text direction around it. `manual` rather than `auto` because a stack of messages owns no dismissal:
|
|
83
|
+
* a press outside must reach the page, not close the toasts.
|
|
84
|
+
*
|
|
85
|
+
* **A press in the gaps goes through to the page.** The viewport is a corner-sized box that would
|
|
86
|
+
* otherwise swallow every click in it, so it takes no pointer events at all and the toasts take them back.
|
|
87
|
+
*
|
|
88
|
+
* **The limit is a queue, not a cap.** A toast past it waits with its timer unstarted, so nothing expires
|
|
89
|
+
* that was never on screen, and the counter at the end of the stack says how many are waiting.
|
|
90
|
+
*
|
|
91
|
+
* @a11y The viewport is a polite live region that exists from the moment it mounts, **before there is
|
|
92
|
+
* anything in it** — an `aria-live` element inserted together with its content is not reliably announced.
|
|
93
|
+
* @a11y An error toast is `role="alert"`, which is assertive; every other kind is announced politely by
|
|
94
|
+
* the region around it. A toast is never focused on arrival, so nothing is taken away from the keyboard.
|
|
95
|
+
* @a11y Timers stop while the pointer is over the stack, while anything in it has focus, and while the
|
|
96
|
+
* tab is in the background — WCAG 2.2.1, and the reason a toast may carry a control at all.
|
|
97
|
+
* @a11y The accent bar says the kind a second time; it is never the only signal, since the message itself
|
|
98
|
+
* is what says what happened.
|
|
99
|
+
* @keyboard F6 — Moves focus to the stack from anywhere on the page. Configurable through `hotkey`.
|
|
100
|
+
* @keyboard Tab — Through the toasts and their controls, in the order they are on screen.
|
|
101
|
+
* @keyboard Escape — Dismisses the toast focus is in, and hands focus back to where it came from once
|
|
102
|
+
* the stack is empty.
|
|
103
|
+
*/
|
|
104
|
+
declare function ToasterImpl<TKey extends keyof ComponentsAndVariants = 'toaster'>(props: ToasterProps<TKey>): import("react").JSX.Element | null;
|
|
105
|
+
declare const Toaster: typeof ToasterImpl;
|
|
106
|
+
export default Toaster;
|