@dbcdk/react-components 0.0.207 → 0.0.209
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.cjs +10 -0
- package/dist/client.d.ts +4 -0
- package/dist/client.js +2 -0
- package/dist/components/listbox/Listbox.cjs +153 -0
- package/dist/components/listbox/Listbox.d.ts +22 -0
- package/dist/components/listbox/Listbox.js +146 -0
- package/dist/components/listbox/Listbox.module.css +97 -0
- package/dist/components/menu/Menu.cjs +7 -24
- package/dist/components/menu/Menu.js +7 -24
- package/dist/components/overlay/side-panel/SidePanel.cjs +80 -2
- package/dist/components/overlay/side-panel/SidePanel.js +80 -2
- package/dist/components/split-pane/SplitPane.cjs +22 -7
- package/dist/components/split-pane/SplitPane.d.ts +5 -2
- package/dist/components/split-pane/SplitPane.js +22 -7
- package/dist/components/split-pane/SplitPane.module.css +9 -0
- package/dist/components/split-pane/provider/SplitPaneContext.cjs +5 -2
- package/dist/components/split-pane/provider/SplitPaneContext.d.ts +3 -1
- package/dist/components/split-pane/provider/SplitPaneContext.js +5 -2
- package/dist/components/status-text/StatusText.cjs +27 -0
- package/dist/components/status-text/StatusText.d.ts +7 -0
- package/dist/components/status-text/StatusText.js +21 -0
- package/dist/components/status-text/StatusText.module.css +41 -0
- package/dist/components/tree-view/TreeNodeRow.cjs +70 -30
- package/dist/components/tree-view/TreeNodeRow.d.ts +6 -1
- package/dist/components/tree-view/TreeNodeRow.js +70 -30
- package/dist/components/tree-view/TreeView.cjs +107 -19
- package/dist/components/tree-view/TreeView.d.ts +1 -1
- package/dist/components/tree-view/TreeView.js +107 -19
- package/dist/components/tree-view/TreeView.module.css +47 -3
- package/dist/components/tree-view/types.d.ts +6 -0
- package/dist/hooks/useRovingFocus.cjs +45 -0
- package/dist/hooks/useRovingFocus.d.ts +10 -0
- package/dist/hooks/useRovingFocus.js +43 -0
- package/dist/index.css +2 -0
- package/dist/styles/css-helper-classes/typography.css +4 -0
- package/package.json +1 -1
|
@@ -13,6 +13,36 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
13
13
|
|
|
14
14
|
var styles__default = /*#__PURE__*/_interopDefault(styles);
|
|
15
15
|
|
|
16
|
+
function getFocusable(container) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const selector = [
|
|
19
|
+
'a[href]:not([aria-disabled="true"])',
|
|
20
|
+
"button:not([disabled])",
|
|
21
|
+
"input:not([disabled])",
|
|
22
|
+
"select:not([disabled])",
|
|
23
|
+
"textarea:not([disabled])",
|
|
24
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
25
|
+
].join(",");
|
|
26
|
+
const focusables = [];
|
|
27
|
+
const addFocusableContent = (root) => {
|
|
28
|
+
const candidates = root.querySelectorAll(selector);
|
|
29
|
+
for (const element of candidates) {
|
|
30
|
+
if (element.hasAttribute("hidden") || element.getAttribute("aria-hidden") === "true" || element.getAttribute("aria-disabled") === "true") {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (!focusables.includes(element)) focusables.push(element);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
addFocusableContent(container);
|
|
37
|
+
for (const trigger of container.querySelectorAll("[aria-controls]")) {
|
|
38
|
+
const controlledIds = (_b = (_a = trigger.getAttribute("aria-controls")) == null ? void 0 : _a.split(/\s+/)) != null ? _b : [];
|
|
39
|
+
for (const controlledId of controlledIds) {
|
|
40
|
+
const controlledContent = document.getElementById(controlledId);
|
|
41
|
+
if (controlledContent) addFocusableContent(controlledContent);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return focusables;
|
|
45
|
+
}
|
|
16
46
|
function SidePanel({
|
|
17
47
|
isOpen,
|
|
18
48
|
onClose,
|
|
@@ -36,23 +66,70 @@ function SidePanel({
|
|
|
36
66
|
const [shouldRender, setShouldRender] = react.useState(isOpen);
|
|
37
67
|
const [isActive, setIsActive] = react.useState(false);
|
|
38
68
|
const panelRef = react.useRef(null);
|
|
69
|
+
const returnFocusRef = react.useRef(null);
|
|
70
|
+
const wasOpenRef = react.useRef(false);
|
|
39
71
|
react.useEffect(() => setMounted(true), []);
|
|
40
72
|
react.useEffect(() => {
|
|
41
73
|
if (isOpen) setShouldRender(true);
|
|
42
74
|
}, [isOpen]);
|
|
43
75
|
react.useEffect(() => {
|
|
44
|
-
if (!isOpen) return;
|
|
76
|
+
if (!isOpen || !shouldRender || !mounted) return;
|
|
77
|
+
if (!wasOpenRef.current) {
|
|
78
|
+
const activeElement = document.activeElement;
|
|
79
|
+
returnFocusRef.current = activeElement instanceof HTMLElement ? activeElement : null;
|
|
80
|
+
wasOpenRef.current = true;
|
|
81
|
+
}
|
|
82
|
+
const focusInitial = () => {
|
|
83
|
+
var _a;
|
|
84
|
+
const panel = panelRef.current;
|
|
85
|
+
if (!panel) return;
|
|
86
|
+
const closeButton = panel.querySelector(
|
|
87
|
+
'[data-cy="side-panel-close-button"]'
|
|
88
|
+
);
|
|
89
|
+
const focusables = getFocusable(panel);
|
|
90
|
+
((_a = closeButton != null ? closeButton : focusables[0]) != null ? _a : panel).focus();
|
|
91
|
+
};
|
|
92
|
+
focusInitial();
|
|
93
|
+
const frame = requestAnimationFrame(focusInitial);
|
|
45
94
|
const handleKeyDown = (e) => {
|
|
46
95
|
if (e.key === "Escape") {
|
|
47
96
|
e.stopPropagation();
|
|
48
97
|
onClose();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (e.key !== "Tab") return;
|
|
101
|
+
const panel = panelRef.current;
|
|
102
|
+
if (!panel) return;
|
|
103
|
+
const focusables = getFocusable(panel);
|
|
104
|
+
if (focusables.length === 0) {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
panel.focus();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const first = focusables[0];
|
|
110
|
+
const last = focusables[focusables.length - 1];
|
|
111
|
+
const active = document.activeElement;
|
|
112
|
+
if (e.shiftKey && (active === first || !panel.contains(active))) {
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
last.focus();
|
|
115
|
+
} else if (!e.shiftKey && (active === last || !panel.contains(active))) {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
first.focus();
|
|
49
118
|
}
|
|
50
119
|
};
|
|
51
120
|
document.addEventListener("keydown", handleKeyDown);
|
|
52
121
|
return () => {
|
|
122
|
+
cancelAnimationFrame(frame);
|
|
53
123
|
document.removeEventListener("keydown", handleKeyDown);
|
|
54
124
|
};
|
|
55
|
-
}, [isOpen, onClose]);
|
|
125
|
+
}, [isOpen, mounted, onClose, shouldRender]);
|
|
126
|
+
react.useEffect(() => {
|
|
127
|
+
var _a;
|
|
128
|
+
if (isOpen || !wasOpenRef.current) return;
|
|
129
|
+
wasOpenRef.current = false;
|
|
130
|
+
(_a = returnFocusRef.current) == null ? void 0 : _a.focus();
|
|
131
|
+
returnFocusRef.current = null;
|
|
132
|
+
}, [isOpen]);
|
|
56
133
|
react.useEffect(() => {
|
|
57
134
|
if (!shouldRender) return;
|
|
58
135
|
if (!isOpen) {
|
|
@@ -103,6 +180,7 @@ function SidePanel({
|
|
|
103
180
|
"data-cy": "details-panel",
|
|
104
181
|
role: "dialog",
|
|
105
182
|
"aria-modal": "true",
|
|
183
|
+
tabIndex: -1,
|
|
106
184
|
children: [
|
|
107
185
|
hasDetails ? /* @__PURE__ */ jsxRuntime.jsxs("aside", { className: styles__default.default.detailsCol, "data-cy": "details-panel-details", children: [
|
|
108
186
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles__default.default.detailsHeader, children: [
|
|
@@ -7,6 +7,36 @@ import { Headline } from '../../../components/headline/Headline';
|
|
|
7
7
|
import { MOTION_MS } from '../../../styles/animation';
|
|
8
8
|
import styles from './SidePanel.module.css';
|
|
9
9
|
|
|
10
|
+
function getFocusable(container) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const selector = [
|
|
13
|
+
'a[href]:not([aria-disabled="true"])',
|
|
14
|
+
"button:not([disabled])",
|
|
15
|
+
"input:not([disabled])",
|
|
16
|
+
"select:not([disabled])",
|
|
17
|
+
"textarea:not([disabled])",
|
|
18
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
19
|
+
].join(",");
|
|
20
|
+
const focusables = [];
|
|
21
|
+
const addFocusableContent = (root) => {
|
|
22
|
+
const candidates = root.querySelectorAll(selector);
|
|
23
|
+
for (const element of candidates) {
|
|
24
|
+
if (element.hasAttribute("hidden") || element.getAttribute("aria-hidden") === "true" || element.getAttribute("aria-disabled") === "true") {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (!focusables.includes(element)) focusables.push(element);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
addFocusableContent(container);
|
|
31
|
+
for (const trigger of container.querySelectorAll("[aria-controls]")) {
|
|
32
|
+
const controlledIds = (_b = (_a = trigger.getAttribute("aria-controls")) == null ? void 0 : _a.split(/\s+/)) != null ? _b : [];
|
|
33
|
+
for (const controlledId of controlledIds) {
|
|
34
|
+
const controlledContent = document.getElementById(controlledId);
|
|
35
|
+
if (controlledContent) addFocusableContent(controlledContent);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return focusables;
|
|
39
|
+
}
|
|
10
40
|
function SidePanel({
|
|
11
41
|
isOpen,
|
|
12
42
|
onClose,
|
|
@@ -30,23 +60,70 @@ function SidePanel({
|
|
|
30
60
|
const [shouldRender, setShouldRender] = useState(isOpen);
|
|
31
61
|
const [isActive, setIsActive] = useState(false);
|
|
32
62
|
const panelRef = useRef(null);
|
|
63
|
+
const returnFocusRef = useRef(null);
|
|
64
|
+
const wasOpenRef = useRef(false);
|
|
33
65
|
useEffect(() => setMounted(true), []);
|
|
34
66
|
useEffect(() => {
|
|
35
67
|
if (isOpen) setShouldRender(true);
|
|
36
68
|
}, [isOpen]);
|
|
37
69
|
useEffect(() => {
|
|
38
|
-
if (!isOpen) return;
|
|
70
|
+
if (!isOpen || !shouldRender || !mounted) return;
|
|
71
|
+
if (!wasOpenRef.current) {
|
|
72
|
+
const activeElement = document.activeElement;
|
|
73
|
+
returnFocusRef.current = activeElement instanceof HTMLElement ? activeElement : null;
|
|
74
|
+
wasOpenRef.current = true;
|
|
75
|
+
}
|
|
76
|
+
const focusInitial = () => {
|
|
77
|
+
var _a;
|
|
78
|
+
const panel = panelRef.current;
|
|
79
|
+
if (!panel) return;
|
|
80
|
+
const closeButton = panel.querySelector(
|
|
81
|
+
'[data-cy="side-panel-close-button"]'
|
|
82
|
+
);
|
|
83
|
+
const focusables = getFocusable(panel);
|
|
84
|
+
((_a = closeButton != null ? closeButton : focusables[0]) != null ? _a : panel).focus();
|
|
85
|
+
};
|
|
86
|
+
focusInitial();
|
|
87
|
+
const frame = requestAnimationFrame(focusInitial);
|
|
39
88
|
const handleKeyDown = (e) => {
|
|
40
89
|
if (e.key === "Escape") {
|
|
41
90
|
e.stopPropagation();
|
|
42
91
|
onClose();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (e.key !== "Tab") return;
|
|
95
|
+
const panel = panelRef.current;
|
|
96
|
+
if (!panel) return;
|
|
97
|
+
const focusables = getFocusable(panel);
|
|
98
|
+
if (focusables.length === 0) {
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
panel.focus();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const first = focusables[0];
|
|
104
|
+
const last = focusables[focusables.length - 1];
|
|
105
|
+
const active = document.activeElement;
|
|
106
|
+
if (e.shiftKey && (active === first || !panel.contains(active))) {
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
last.focus();
|
|
109
|
+
} else if (!e.shiftKey && (active === last || !panel.contains(active))) {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
first.focus();
|
|
43
112
|
}
|
|
44
113
|
};
|
|
45
114
|
document.addEventListener("keydown", handleKeyDown);
|
|
46
115
|
return () => {
|
|
116
|
+
cancelAnimationFrame(frame);
|
|
47
117
|
document.removeEventListener("keydown", handleKeyDown);
|
|
48
118
|
};
|
|
49
|
-
}, [isOpen, onClose]);
|
|
119
|
+
}, [isOpen, mounted, onClose, shouldRender]);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
var _a;
|
|
122
|
+
if (isOpen || !wasOpenRef.current) return;
|
|
123
|
+
wasOpenRef.current = false;
|
|
124
|
+
(_a = returnFocusRef.current) == null ? void 0 : _a.focus();
|
|
125
|
+
returnFocusRef.current = null;
|
|
126
|
+
}, [isOpen]);
|
|
50
127
|
useEffect(() => {
|
|
51
128
|
if (!shouldRender) return;
|
|
52
129
|
if (!isOpen) {
|
|
@@ -97,6 +174,7 @@ function SidePanel({
|
|
|
97
174
|
"data-cy": "details-panel",
|
|
98
175
|
role: "dialog",
|
|
99
176
|
"aria-modal": "true",
|
|
177
|
+
tabIndex: -1,
|
|
100
178
|
children: [
|
|
101
179
|
hasDetails ? /* @__PURE__ */ jsxs("aside", { className: styles.detailsCol, "data-cy": "details-panel-details", children: [
|
|
102
180
|
/* @__PURE__ */ jsxs("div", { className: styles.detailsHeader, children: [
|
|
@@ -22,7 +22,8 @@ function SplitPane({
|
|
|
22
22
|
showDivider = "hover",
|
|
23
23
|
gutterSize = 16,
|
|
24
24
|
storageKey,
|
|
25
|
-
fillViewport = false
|
|
25
|
+
fillViewport = false,
|
|
26
|
+
secondaryVisible = true
|
|
26
27
|
}) {
|
|
27
28
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
28
29
|
SplitPaneContext.SplitPaneProvider,
|
|
@@ -31,6 +32,7 @@ function SplitPane({
|
|
|
31
32
|
initialPrimarySize,
|
|
32
33
|
minPrimarySize,
|
|
33
34
|
minSecondarySize,
|
|
35
|
+
gutterSize,
|
|
34
36
|
storageKey,
|
|
35
37
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
36
38
|
SplitPaneContainer,
|
|
@@ -38,6 +40,7 @@ function SplitPane({
|
|
|
38
40
|
showDivider,
|
|
39
41
|
gutterSize,
|
|
40
42
|
fillViewport,
|
|
43
|
+
secondaryVisible,
|
|
41
44
|
children
|
|
42
45
|
}
|
|
43
46
|
)
|
|
@@ -48,7 +51,8 @@ function SplitPaneContainer({
|
|
|
48
51
|
children,
|
|
49
52
|
showDivider,
|
|
50
53
|
gutterSize,
|
|
51
|
-
fillViewport
|
|
54
|
+
fillViewport,
|
|
55
|
+
secondaryVisible
|
|
52
56
|
}) {
|
|
53
57
|
const { direction, primarySize, containerRef } = SplitPaneContext.useSplitPaneContext();
|
|
54
58
|
const style = react.useMemo(
|
|
@@ -66,6 +70,7 @@ function SplitPaneContainer({
|
|
|
66
70
|
"data-direction": direction,
|
|
67
71
|
"data-divider": showDivider,
|
|
68
72
|
"data-fill-viewport": fillViewport,
|
|
73
|
+
"data-secondary-visible": secondaryVisible,
|
|
69
74
|
style,
|
|
70
75
|
children
|
|
71
76
|
}
|
|
@@ -77,13 +82,14 @@ function SplitPanePrimary({ children }) {
|
|
|
77
82
|
function SplitPaneSecondary({ children }) {
|
|
78
83
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.secondary, children });
|
|
79
84
|
}
|
|
80
|
-
function SplitPaneGutter() {
|
|
85
|
+
function SplitPaneGutter({ label = "Resize panes" }) {
|
|
81
86
|
const {
|
|
82
87
|
direction,
|
|
83
88
|
primarySize,
|
|
84
89
|
setPrimarySize,
|
|
85
90
|
minPrimarySize,
|
|
86
91
|
minSecondarySize,
|
|
92
|
+
gutterSize,
|
|
87
93
|
containerRef,
|
|
88
94
|
resetDefault
|
|
89
95
|
} = SplitPaneContext.useSplitPaneContext();
|
|
@@ -101,9 +107,10 @@ function SplitPaneGutter() {
|
|
|
101
107
|
if (!el) return { maxPrimary: Infinity, total: 0 };
|
|
102
108
|
const rect = el.getBoundingClientRect();
|
|
103
109
|
const total = direction === "horizontal" ? rect.width : rect.height;
|
|
104
|
-
|
|
110
|
+
if (!Number.isFinite(total) || total <= 0) return { maxPrimary: Infinity, total };
|
|
111
|
+
const maxPrimary2 = Math.max(minPrimarySize, total - minSecondarySize - gutterSize);
|
|
105
112
|
return { maxPrimary: maxPrimary2, total };
|
|
106
|
-
}, [containerRef, direction, minPrimarySize, minSecondarySize]);
|
|
113
|
+
}, [containerRef, direction, gutterSize, minPrimarySize, minSecondarySize]);
|
|
107
114
|
const onPointerDown = react.useCallback(
|
|
108
115
|
(e) => {
|
|
109
116
|
const el = containerRef.current;
|
|
@@ -163,13 +170,21 @@ function SplitPaneGutter() {
|
|
|
163
170
|
const ariaOrientation = direction === "horizontal" ? "vertical" : "horizontal";
|
|
164
171
|
const [maxPrimary, setMaxPrimary] = react.useState(Infinity);
|
|
165
172
|
react.useEffect(() => {
|
|
166
|
-
|
|
167
|
-
|
|
173
|
+
const container = containerRef.current;
|
|
174
|
+
if (!container) return;
|
|
175
|
+
const updateMax = () => setMaxPrimary(computeClamp().maxPrimary);
|
|
176
|
+
updateMax();
|
|
177
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
178
|
+
const observer = new ResizeObserver(updateMax);
|
|
179
|
+
observer.observe(container);
|
|
180
|
+
return () => observer.disconnect();
|
|
181
|
+
}, [computeClamp, containerRef]);
|
|
168
182
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.gutter, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
169
183
|
"div",
|
|
170
184
|
{
|
|
171
185
|
className: styles__default.default.resizer,
|
|
172
186
|
role: "separator",
|
|
187
|
+
"aria-label": label,
|
|
173
188
|
"aria-orientation": ariaOrientation,
|
|
174
189
|
"aria-valuemin": Math.round(minPrimarySize),
|
|
175
190
|
"aria-valuemax": Number.isFinite(maxPrimary) ? Math.round(maxPrimary) : void 0,
|
|
@@ -10,12 +10,15 @@ export interface SplitPaneProps {
|
|
|
10
10
|
gutterSize?: number;
|
|
11
11
|
storageKey?: string;
|
|
12
12
|
fillViewport?: boolean;
|
|
13
|
+
secondaryVisible?: boolean;
|
|
13
14
|
}
|
|
14
|
-
export declare function SplitPane({ children, initialPrimarySize, minPrimarySize, minSecondarySize, direction, showDivider, gutterSize, storageKey, fillViewport, }: SplitPaneProps): JSX.Element;
|
|
15
|
+
export declare function SplitPane({ children, initialPrimarySize, minPrimarySize, minSecondarySize, direction, showDivider, gutterSize, storageKey, fillViewport, secondaryVisible, }: SplitPaneProps): JSX.Element;
|
|
15
16
|
export declare function SplitPanePrimary({ children }: {
|
|
16
17
|
children: ReactNode;
|
|
17
18
|
}): JSX.Element;
|
|
18
19
|
export declare function SplitPaneSecondary({ children }: {
|
|
19
20
|
children: ReactNode;
|
|
20
21
|
}): JSX.Element;
|
|
21
|
-
export declare function SplitPaneGutter(
|
|
22
|
+
export declare function SplitPaneGutter({ label }: {
|
|
23
|
+
label?: string;
|
|
24
|
+
}): JSX.Element;
|
|
@@ -16,7 +16,8 @@ function SplitPane({
|
|
|
16
16
|
showDivider = "hover",
|
|
17
17
|
gutterSize = 16,
|
|
18
18
|
storageKey,
|
|
19
|
-
fillViewport = false
|
|
19
|
+
fillViewport = false,
|
|
20
|
+
secondaryVisible = true
|
|
20
21
|
}) {
|
|
21
22
|
return /* @__PURE__ */ jsx(
|
|
22
23
|
SplitPaneProvider,
|
|
@@ -25,6 +26,7 @@ function SplitPane({
|
|
|
25
26
|
initialPrimarySize,
|
|
26
27
|
minPrimarySize,
|
|
27
28
|
minSecondarySize,
|
|
29
|
+
gutterSize,
|
|
28
30
|
storageKey,
|
|
29
31
|
children: /* @__PURE__ */ jsx(
|
|
30
32
|
SplitPaneContainer,
|
|
@@ -32,6 +34,7 @@ function SplitPane({
|
|
|
32
34
|
showDivider,
|
|
33
35
|
gutterSize,
|
|
34
36
|
fillViewport,
|
|
37
|
+
secondaryVisible,
|
|
35
38
|
children
|
|
36
39
|
}
|
|
37
40
|
)
|
|
@@ -42,7 +45,8 @@ function SplitPaneContainer({
|
|
|
42
45
|
children,
|
|
43
46
|
showDivider,
|
|
44
47
|
gutterSize,
|
|
45
|
-
fillViewport
|
|
48
|
+
fillViewport,
|
|
49
|
+
secondaryVisible
|
|
46
50
|
}) {
|
|
47
51
|
const { direction, primarySize, containerRef } = useSplitPaneContext();
|
|
48
52
|
const style = useMemo(
|
|
@@ -60,6 +64,7 @@ function SplitPaneContainer({
|
|
|
60
64
|
"data-direction": direction,
|
|
61
65
|
"data-divider": showDivider,
|
|
62
66
|
"data-fill-viewport": fillViewport,
|
|
67
|
+
"data-secondary-visible": secondaryVisible,
|
|
63
68
|
style,
|
|
64
69
|
children
|
|
65
70
|
}
|
|
@@ -71,13 +76,14 @@ function SplitPanePrimary({ children }) {
|
|
|
71
76
|
function SplitPaneSecondary({ children }) {
|
|
72
77
|
return /* @__PURE__ */ jsx("div", { className: styles.secondary, children });
|
|
73
78
|
}
|
|
74
|
-
function SplitPaneGutter() {
|
|
79
|
+
function SplitPaneGutter({ label = "Resize panes" }) {
|
|
75
80
|
const {
|
|
76
81
|
direction,
|
|
77
82
|
primarySize,
|
|
78
83
|
setPrimarySize,
|
|
79
84
|
minPrimarySize,
|
|
80
85
|
minSecondarySize,
|
|
86
|
+
gutterSize,
|
|
81
87
|
containerRef,
|
|
82
88
|
resetDefault
|
|
83
89
|
} = useSplitPaneContext();
|
|
@@ -95,9 +101,10 @@ function SplitPaneGutter() {
|
|
|
95
101
|
if (!el) return { maxPrimary: Infinity, total: 0 };
|
|
96
102
|
const rect = el.getBoundingClientRect();
|
|
97
103
|
const total = direction === "horizontal" ? rect.width : rect.height;
|
|
98
|
-
|
|
104
|
+
if (!Number.isFinite(total) || total <= 0) return { maxPrimary: Infinity, total };
|
|
105
|
+
const maxPrimary2 = Math.max(minPrimarySize, total - minSecondarySize - gutterSize);
|
|
99
106
|
return { maxPrimary: maxPrimary2, total };
|
|
100
|
-
}, [containerRef, direction, minPrimarySize, minSecondarySize]);
|
|
107
|
+
}, [containerRef, direction, gutterSize, minPrimarySize, minSecondarySize]);
|
|
101
108
|
const onPointerDown = useCallback(
|
|
102
109
|
(e) => {
|
|
103
110
|
const el = containerRef.current;
|
|
@@ -157,13 +164,21 @@ function SplitPaneGutter() {
|
|
|
157
164
|
const ariaOrientation = direction === "horizontal" ? "vertical" : "horizontal";
|
|
158
165
|
const [maxPrimary, setMaxPrimary] = useState(Infinity);
|
|
159
166
|
useEffect(() => {
|
|
160
|
-
|
|
161
|
-
|
|
167
|
+
const container = containerRef.current;
|
|
168
|
+
if (!container) return;
|
|
169
|
+
const updateMax = () => setMaxPrimary(computeClamp().maxPrimary);
|
|
170
|
+
updateMax();
|
|
171
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
172
|
+
const observer = new ResizeObserver(updateMax);
|
|
173
|
+
observer.observe(container);
|
|
174
|
+
return () => observer.disconnect();
|
|
175
|
+
}, [computeClamp, containerRef]);
|
|
162
176
|
return /* @__PURE__ */ jsx("div", { className: styles.gutter, children: /* @__PURE__ */ jsx(
|
|
163
177
|
"div",
|
|
164
178
|
{
|
|
165
179
|
className: styles.resizer,
|
|
166
180
|
role: "separator",
|
|
181
|
+
"aria-label": label,
|
|
167
182
|
"aria-orientation": ariaOrientation,
|
|
168
183
|
"aria-valuemin": Math.round(minPrimarySize),
|
|
169
184
|
"aria-valuemax": Number.isFinite(maxPrimary) ? Math.round(maxPrimary) : void 0,
|
|
@@ -13,6 +13,15 @@
|
|
|
13
13
|
max-height: 100%;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
.container[data-secondary-visible='false'] > .primary {
|
|
17
|
+
flex: 1 1 auto;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.container[data-secondary-visible='false'] > .gutter,
|
|
21
|
+
.container[data-secondary-visible='false'] > .secondary {
|
|
22
|
+
display: none;
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
.container[data-direction='horizontal'] {
|
|
17
26
|
flex-direction: row;
|
|
18
27
|
}
|
|
@@ -44,6 +44,7 @@ function SplitPaneProvider({
|
|
|
44
44
|
initialPrimarySize,
|
|
45
45
|
minPrimarySize,
|
|
46
46
|
minSecondarySize,
|
|
47
|
+
gutterSize,
|
|
47
48
|
storageKey
|
|
48
49
|
}) {
|
|
49
50
|
const containerRef = React.useRef(null);
|
|
@@ -55,8 +56,8 @@ function SplitPaneProvider({
|
|
|
55
56
|
const rect = el.getBoundingClientRect();
|
|
56
57
|
const total = direction === "horizontal" ? rect.width : rect.height;
|
|
57
58
|
if (!Number.isFinite(total) || total <= 0) return null;
|
|
58
|
-
return Math.max(minPrimarySize, total - minSecondarySize);
|
|
59
|
-
}, [direction, minPrimarySize, minSecondarySize]);
|
|
59
|
+
return Math.max(minPrimarySize, total - minSecondarySize - gutterSize);
|
|
60
|
+
}, [direction, gutterSize, minPrimarySize, minSecondarySize]);
|
|
60
61
|
React.useEffect(() => {
|
|
61
62
|
if (!storageKey) return;
|
|
62
63
|
const stored = readStoredSize(storageKey);
|
|
@@ -108,6 +109,7 @@ function SplitPaneProvider({
|
|
|
108
109
|
resetDefault,
|
|
109
110
|
minPrimarySize,
|
|
110
111
|
minSecondarySize,
|
|
112
|
+
gutterSize,
|
|
111
113
|
containerRef,
|
|
112
114
|
storageKey
|
|
113
115
|
}),
|
|
@@ -118,6 +120,7 @@ function SplitPaneProvider({
|
|
|
118
120
|
resetDefault,
|
|
119
121
|
minPrimarySize,
|
|
120
122
|
minSecondarySize,
|
|
123
|
+
gutterSize,
|
|
121
124
|
storageKey
|
|
122
125
|
]
|
|
123
126
|
);
|
|
@@ -6,6 +6,7 @@ export interface SplitPaneContextValue {
|
|
|
6
6
|
setPrimarySize: (newSize: number) => void;
|
|
7
7
|
minPrimarySize: number;
|
|
8
8
|
minSecondarySize: number;
|
|
9
|
+
gutterSize: number;
|
|
9
10
|
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
10
11
|
storageKey?: string;
|
|
11
12
|
resetDefault: () => void;
|
|
@@ -18,7 +19,8 @@ type SplitPaneProviderProps = {
|
|
|
18
19
|
initialPrimarySize: number;
|
|
19
20
|
minPrimarySize: number;
|
|
20
21
|
minSecondarySize: number;
|
|
22
|
+
gutterSize: number;
|
|
21
23
|
storageKey?: string;
|
|
22
24
|
};
|
|
23
|
-
export declare function SplitPaneProvider({ children, direction, initialPrimarySize, minPrimarySize, minSecondarySize, storageKey, }: SplitPaneProviderProps): React.ReactNode;
|
|
25
|
+
export declare function SplitPaneProvider({ children, direction, initialPrimarySize, minPrimarySize, minSecondarySize, gutterSize, storageKey, }: SplitPaneProviderProps): React.ReactNode;
|
|
24
26
|
export {};
|
|
@@ -38,6 +38,7 @@ function SplitPaneProvider({
|
|
|
38
38
|
initialPrimarySize,
|
|
39
39
|
minPrimarySize,
|
|
40
40
|
minSecondarySize,
|
|
41
|
+
gutterSize,
|
|
41
42
|
storageKey
|
|
42
43
|
}) {
|
|
43
44
|
const containerRef = useRef(null);
|
|
@@ -49,8 +50,8 @@ function SplitPaneProvider({
|
|
|
49
50
|
const rect = el.getBoundingClientRect();
|
|
50
51
|
const total = direction === "horizontal" ? rect.width : rect.height;
|
|
51
52
|
if (!Number.isFinite(total) || total <= 0) return null;
|
|
52
|
-
return Math.max(minPrimarySize, total - minSecondarySize);
|
|
53
|
-
}, [direction, minPrimarySize, minSecondarySize]);
|
|
53
|
+
return Math.max(minPrimarySize, total - minSecondarySize - gutterSize);
|
|
54
|
+
}, [direction, gutterSize, minPrimarySize, minSecondarySize]);
|
|
54
55
|
useEffect(() => {
|
|
55
56
|
if (!storageKey) return;
|
|
56
57
|
const stored = readStoredSize(storageKey);
|
|
@@ -102,6 +103,7 @@ function SplitPaneProvider({
|
|
|
102
103
|
resetDefault,
|
|
103
104
|
minPrimarySize,
|
|
104
105
|
minSecondarySize,
|
|
106
|
+
gutterSize,
|
|
105
107
|
containerRef,
|
|
106
108
|
storageKey
|
|
107
109
|
}),
|
|
@@ -112,6 +114,7 @@ function SplitPaneProvider({
|
|
|
112
114
|
resetDefault,
|
|
113
115
|
minPrimarySize,
|
|
114
116
|
minSecondarySize,
|
|
117
|
+
gutterSize,
|
|
115
118
|
storageKey
|
|
116
119
|
]
|
|
117
120
|
);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var styles = require('./StatusText.module.css');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var styles__default = /*#__PURE__*/_interopDefault(styles);
|
|
10
|
+
|
|
11
|
+
function StatusText({
|
|
12
|
+
children,
|
|
13
|
+
severity = "neutral",
|
|
14
|
+
className,
|
|
15
|
+
...props
|
|
16
|
+
}) {
|
|
17
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
18
|
+
"span",
|
|
19
|
+
{
|
|
20
|
+
...props,
|
|
21
|
+
className: [styles__default.default.statusText, styles__default.default[severity], className].filter(Boolean).join(" "),
|
|
22
|
+
children
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.StatusText = StatusText;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import type { Severity } from '../../constants/severity.types';
|
|
3
|
+
export interface StatusTextProps extends HTMLAttributes<HTMLSpanElement> {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
severity?: Severity;
|
|
6
|
+
}
|
|
7
|
+
export declare function StatusText({ children, severity, className, ...props }: Readonly<StatusTextProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import styles from './StatusText.module.css';
|
|
4
|
+
|
|
5
|
+
function StatusText({
|
|
6
|
+
children,
|
|
7
|
+
severity = "neutral",
|
|
8
|
+
className,
|
|
9
|
+
...props
|
|
10
|
+
}) {
|
|
11
|
+
return /* @__PURE__ */ jsx(
|
|
12
|
+
"span",
|
|
13
|
+
{
|
|
14
|
+
...props,
|
|
15
|
+
className: [styles.statusText, styles[severity], className].filter(Boolean).join(" "),
|
|
16
|
+
children
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { StatusText };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
.statusText {
|
|
2
|
+
background: var(--status-text-bg);
|
|
3
|
+
color: var(--status-text-fg);
|
|
4
|
+
-webkit-box-decoration-break: clone;
|
|
5
|
+
box-decoration-break: clone;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.neutral {
|
|
9
|
+
--status-text-bg: var(--color-bg-surface-subtle);
|
|
10
|
+
--status-text-fg: var(--color-fg-default);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.brand {
|
|
14
|
+
--status-text-bg: color-mix(in srgb, var(--color-brand) 12%, var(--color-bg-surface));
|
|
15
|
+
--status-text-fg: var(--color-brand);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.accent {
|
|
19
|
+
--status-text-bg: var(--color-accent-bg-soft);
|
|
20
|
+
--status-text-fg: var(--color-accent-fg-soft);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.success {
|
|
24
|
+
--status-text-bg: var(--color-status-success-bg);
|
|
25
|
+
--status-text-fg: var(--color-status-success-fg);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.error {
|
|
29
|
+
--status-text-bg: var(--color-status-error-bg);
|
|
30
|
+
--status-text-fg: var(--color-status-error-fg);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.info {
|
|
34
|
+
--status-text-bg: var(--color-status-info-bg);
|
|
35
|
+
--status-text-fg: var(--color-status-info-fg);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.warning {
|
|
39
|
+
--status-text-bg: var(--color-status-warning-bg);
|
|
40
|
+
--status-text-fg: var(--color-status-warning-fg);
|
|
41
|
+
}
|