@dbcdk/react-components 0.0.4 → 0.0.5
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/assets/logo.cjs +10 -10
- package/dist/assets/logo.js +10 -10
- package/dist/components/__stories__/story-components/Colors.cjs +159 -0
- package/dist/components/__stories__/story-components/Colors.d.ts +10 -0
- package/dist/components/__stories__/story-components/Colors.js +151 -0
- package/dist/components/__stories__/story-components/Colors.module.css +27 -0
- package/dist/components/__stories__/story-components/Spacing.cjs +190 -0
- package/dist/components/__stories__/story-components/Spacing.d.ts +1 -0
- package/dist/components/__stories__/story-components/Spacing.js +184 -0
- package/dist/components/__stories__/story-components/Spacing.module.css +154 -0
- package/dist/components/app-header/AppHeader.module.css +10 -15
- package/dist/components/attribute-chip/AttributeChip.cjs +22 -0
- package/dist/components/attribute-chip/AttributeChip.d.ts +8 -0
- package/dist/components/attribute-chip/AttributeChip.js +16 -0
- package/dist/components/attribute-chip/AttributeChip.module.css +65 -0
- package/dist/components/avatar/Avatar.cjs +38 -4
- package/dist/components/avatar/Avatar.d.ts +4 -2
- package/dist/components/avatar/Avatar.js +39 -5
- package/dist/components/avatar/Avatar.module.css +27 -0
- package/dist/components/breadcrumbs/Breadcrumbs.cjs +1 -2
- package/dist/components/breadcrumbs/Breadcrumbs.js +1 -2
- package/dist/components/breadcrumbs/Breadcrumbs.module.css +19 -22
- package/dist/components/button/Button.cjs +20 -12
- package/dist/components/button/Button.d.ts +4 -1
- package/dist/components/button/Button.js +20 -12
- package/dist/components/button/Button.module.css +118 -55
- package/dist/components/card/Card.cjs +53 -13
- package/dist/components/card/Card.d.ts +21 -6
- package/dist/components/card/Card.js +54 -14
- package/dist/components/card/Card.module.css +148 -44
- package/dist/components/card-container/CardContainer.cjs +6 -5
- package/dist/components/card-container/CardContainer.d.ts +5 -2
- package/dist/components/card-container/CardContainer.js +6 -5
- package/dist/components/card-container/CardContainer.module.css +40 -0
- package/dist/components/checkbox/Checkbox.cjs +3 -4
- package/dist/components/checkbox/Checkbox.d.ts +1 -1
- package/dist/components/checkbox/Checkbox.js +3 -4
- package/dist/components/checkbox/Checkbox.module.css +10 -10
- package/dist/components/chip/Chip.cjs +2 -1
- package/dist/components/chip/Chip.d.ts +2 -1
- package/dist/components/chip/Chip.js +2 -1
- package/dist/components/chip/Chip.module.css +42 -27
- package/dist/components/circle/Circle.module.css +11 -11
- package/dist/components/clear-button/ClearButton.cjs +3 -3
- package/dist/components/clear-button/ClearButton.js +3 -3
- package/dist/components/clear-button/ClearButton.module.css +8 -7
- package/dist/components/code-block/CodeBlock.cjs +18 -0
- package/dist/components/code-block/CodeBlock.d.ts +6 -0
- package/dist/components/code-block/CodeBlock.js +12 -0
- package/dist/components/code-block/CodeBlock.module.css +60 -0
- package/dist/components/copy-button/CopyButton.cjs +35 -0
- package/dist/components/copy-button/CopyButton.d.ts +9 -0
- package/dist/components/copy-button/CopyButton.js +29 -0
- package/dist/components/copy-button/CopyButton.module.css +6 -0
- package/dist/components/datetime-picker/DateTimePicker.cjs +504 -0
- package/dist/components/datetime-picker/DateTimePicker.d.ts +39 -0
- package/dist/components/datetime-picker/DateTimePicker.js +498 -0
- package/dist/components/datetime-picker/DateTimePicker.module.css +144 -0
- package/dist/components/filter-field/FilterField.cjs +34 -19
- package/dist/components/filter-field/FilterField.d.ts +2 -2
- package/dist/components/filter-field/FilterField.js +35 -20
- package/dist/components/filter-field/FilterField.module.css +14 -20
- package/dist/components/headline/Headline.cjs +10 -4
- package/dist/components/headline/Headline.d.ts +9 -1
- package/dist/components/headline/Headline.js +10 -4
- package/dist/components/headline/Headline.module.css +32 -7
- package/dist/components/icon/Icon.module.css +10 -9
- package/dist/components/input/Input.cjs +60 -19
- package/dist/components/input/Input.d.ts +7 -2
- package/dist/components/input/Input.js +60 -19
- package/dist/components/input/Input.module.css +90 -43
- package/dist/components/link/Link.cjs +46 -0
- package/dist/components/link/Link.d.ts +9 -0
- package/dist/components/link/Link.js +21 -0
- package/dist/components/link/Link.module.css +32 -0
- package/dist/components/menu/Menu.module.css +10 -32
- package/dist/components/meta-bar/MetaBar.cjs +29 -0
- package/dist/components/meta-bar/MetaBar.d.ts +11 -0
- package/dist/components/meta-bar/MetaBar.js +22 -0
- package/dist/components/meta-bar/MetaBar.module.css +12 -0
- package/dist/components/modal/Modal.cjs +134 -0
- package/dist/components/modal/Modal.d.ts +21 -0
- package/dist/components/modal/Modal.js +128 -0
- package/dist/components/modal/Modal.module.css +66 -0
- package/dist/components/modal/provider/ModalProvider.cjs +80 -0
- package/dist/components/modal/provider/ModalProvider.d.ts +21 -0
- package/dist/components/modal/provider/ModalProvider.js +77 -0
- package/dist/components/multi-select/MultiSelect.cjs +12 -1
- package/dist/components/multi-select/MultiSelect.js +12 -1
- package/dist/components/nav-bar/NavBar.module.css +11 -16
- package/dist/components/page/Page.module.css +2 -2
- package/dist/components/page-layout/PageLayout.cjs +5 -22
- package/dist/components/page-layout/PageLayout.d.ts +1 -8
- package/dist/components/page-layout/PageLayout.js +5 -22
- package/dist/components/page-layout/PageLayout.module.css +4 -80
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.cjs +32 -0
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.d.ts +11 -0
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.js +25 -0
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.module.css +84 -0
- package/dist/components/pagination/Pagination.cjs +83 -67
- package/dist/components/pagination/Pagination.d.ts +3 -1
- package/dist/components/pagination/Pagination.js +84 -68
- package/dist/components/pagination/Pagination.module.css +11 -3
- package/dist/components/panel/Panel.module.css +5 -7
- package/dist/components/popover/Popover.cjs +25 -8
- package/dist/components/popover/Popover.d.ts +2 -1
- package/dist/components/popover/Popover.js +25 -8
- package/dist/components/popover/Popover.module.css +4 -6
- package/dist/components/search-box/SearchBox.cjs +50 -37
- package/dist/components/search-box/SearchBox.d.ts +10 -7
- package/dist/components/search-box/SearchBox.js +50 -37
- package/dist/components/search-box/SearchBox.module.css +0 -1
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.cjs +12 -6
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.js +12 -6
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.module.css +5 -1
- package/dist/components/select/Select.cjs +82 -13
- package/dist/components/select/Select.d.ts +2 -1
- package/dist/components/select/Select.js +83 -14
- package/dist/components/sidebar/Sidebar.cjs +3 -30
- package/dist/components/sidebar/Sidebar.d.ts +2 -1
- package/dist/components/sidebar/Sidebar.js +4 -26
- package/dist/components/sidebar/components/SidebarItem.cjs +3 -1
- package/dist/components/sidebar/components/SidebarItem.js +3 -1
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.cjs +40 -14
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.d.ts +3 -1
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +40 -14
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.module.css +9 -38
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.cjs +50 -0
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.d.ts +8 -0
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.js +43 -0
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.module.css +155 -0
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.cjs +16 -9
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.d.ts +2 -1
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.js +16 -9
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.module.css +25 -12
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.cjs +2 -1
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.d.ts +1 -1
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.js +2 -1
- package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.cjs +29 -2
- package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.js +25 -2
- package/dist/components/sidebar/providers/SidebarProvider.cjs +108 -10
- package/dist/components/sidebar/providers/SidebarProvider.d.ts +7 -3
- package/dist/components/sidebar/providers/SidebarProvider.js +109 -11
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.cjs +1 -1
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.js +1 -1
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.module.css +0 -12
- package/dist/components/split-pane/SplitPane.cjs +123 -0
- package/dist/components/split-pane/SplitPane.d.ts +34 -0
- package/dist/components/split-pane/SplitPane.js +114 -0
- package/dist/components/split-pane/SplitPane.module.css +106 -0
- package/dist/components/split-pane/provider/SplitPaneContext.cjs +87 -0
- package/dist/components/split-pane/provider/SplitPaneContext.d.ts +23 -0
- package/dist/components/split-pane/provider/SplitPaneContext.js +79 -0
- package/dist/components/table/Table.cjs +180 -112
- package/dist/components/table/Table.d.ts +22 -6
- package/dist/components/table/Table.js +181 -113
- package/dist/components/table/Table.module.css +74 -47
- package/dist/components/table/components/empty-state/EmptyState.cjs +52 -0
- package/dist/components/table/components/empty-state/EmptyState.d.ts +40 -0
- package/dist/components/table/components/empty-state/EmptyState.js +46 -0
- package/dist/components/table/components/empty-state/EmptyState.module.css +16 -0
- package/dist/components/table/components/table-settings/TableSettings.cjs +32 -0
- package/dist/components/table/components/table-settings/TableSettings.d.ts +7 -0
- package/dist/components/table/components/table-settings/TableSettings.js +30 -0
- package/dist/{tanstack.cjs → components/table/tanstack.cjs} +61 -99
- package/dist/components/table/tanstack.d.ts +14 -0
- package/dist/{tanstack.js → components/table/tanstack.js} +61 -99
- package/dist/components/tabs/Tabs.cjs +33 -17
- package/dist/components/tabs/Tabs.d.ts +6 -3
- package/dist/components/tabs/Tabs.js +33 -17
- package/dist/components/tabs/Tabs.module.css +9 -9
- package/dist/components/toast/Toast.cjs +47 -0
- package/dist/components/toast/Toast.d.ts +14 -0
- package/dist/components/toast/Toast.js +41 -0
- package/dist/components/toast/Toast.module.css +101 -0
- package/dist/components/toast/provider/ToastProvider.cjs +98 -0
- package/dist/components/toast/provider/ToastProvider.d.ts +23 -0
- package/dist/components/toast/provider/ToastProvider.js +91 -0
- package/dist/components/tooltip/Tooltip.cjs +134 -29
- package/dist/components/tooltip/Tooltip.js +135 -30
- package/dist/components/tooltip/Tooltip.module.css +25 -43
- package/dist/components/user-display/UserDisplay.module.css +2 -2
- package/dist/constants/severity.cjs +12 -12
- package/dist/constants/severity.js +12 -12
- package/dist/constants/sizes.cjs +1 -0
- package/dist/constants/sizes.d.ts +1 -1
- package/dist/constants/sizes.js +1 -0
- package/dist/hooks/usePagination.cjs +88 -0
- package/dist/hooks/usePagination.d.ts +33 -0
- package/dist/hooks/usePagination.js +86 -0
- package/dist/hooks/useSorting.cjs +118 -0
- package/dist/hooks/useSorting.d.ts +49 -0
- package/dist/hooks/useSorting.js +116 -0
- package/dist/hooks/useTableData.cjs +52 -0
- package/dist/hooks/useTableData.d.ts +40 -0
- package/dist/hooks/useTableData.js +50 -0
- package/dist/hooks/useTableSelection.cjs +130 -0
- package/dist/hooks/useTableSelection.d.ts +25 -0
- package/dist/hooks/useTableSelection.js +128 -0
- package/dist/hooks/useTableSettings.cjs +28 -0
- package/dist/hooks/useTableSettings.d.ts +7 -0
- package/dist/hooks/useTableSettings.js +26 -0
- package/dist/hooks/useTimeDuration.cjs +39 -0
- package/dist/hooks/useTimeDuration.d.ts +22 -0
- package/dist/hooks/useTimeDuration.js +37 -0
- package/dist/hooks/useViewportFill.js +1 -1
- package/dist/index.cjs +119 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +17 -0
- package/dist/src/styles/styles.css +101 -8
- package/dist/styles/css-helper-classes/flex.css +97 -0
- package/dist/styles/css-helper-classes/typography.css +7 -0
- package/dist/styles/styles.css +101 -8
- package/dist/styles/themes/dbc/dark.css +206 -99
- package/dist/styles/themes/dbc/light.css +183 -89
- package/dist/types/sizes.types.d.ts +2 -2
- package/package.json +17 -11
- package/dist/components/data-summary/DataSummary.cjs +0 -49
- package/dist/components/data-summary/DataSummary.d.ts +0 -19
- package/dist/components/data-summary/DataSummary.js +0 -43
- package/dist/components/data-summary/DataSummary.module.css +0 -51
- package/dist/components/sidebar/Sidebar.module.css +0 -66
- package/dist/tanstack.d.ts +0 -25
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var styles = require('./SplitPane.module.css');
|
|
6
|
+
var SplitPaneContext = require('./provider/SplitPaneContext');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var styles__default = /*#__PURE__*/_interopDefault(styles);
|
|
11
|
+
|
|
12
|
+
function clamp(n, min, max) {
|
|
13
|
+
return Math.max(min, Math.min(max, n));
|
|
14
|
+
}
|
|
15
|
+
function SplitPane({
|
|
16
|
+
children,
|
|
17
|
+
initialPrimarySize = 300,
|
|
18
|
+
minPrimarySize = 160,
|
|
19
|
+
minSecondarySize = 160,
|
|
20
|
+
direction = "horizontal",
|
|
21
|
+
showDivider = "hover",
|
|
22
|
+
gutterSize = 8,
|
|
23
|
+
storageKey
|
|
24
|
+
}) {
|
|
25
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
26
|
+
SplitPaneContext.SplitPaneProvider,
|
|
27
|
+
{
|
|
28
|
+
direction,
|
|
29
|
+
initialPrimarySize,
|
|
30
|
+
minPrimarySize,
|
|
31
|
+
minSecondarySize,
|
|
32
|
+
storageKey,
|
|
33
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SplitPaneContainer, { showDivider, gutterSize, children })
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
function SplitPaneContainer({
|
|
38
|
+
children,
|
|
39
|
+
showDivider,
|
|
40
|
+
gutterSize
|
|
41
|
+
}) {
|
|
42
|
+
const { direction, primarySize, containerRef } = SplitPaneContext.useSplitPaneContext();
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
"div",
|
|
45
|
+
{
|
|
46
|
+
ref: containerRef,
|
|
47
|
+
className: styles__default.default.container,
|
|
48
|
+
"data-direction": direction,
|
|
49
|
+
"data-divider": showDivider,
|
|
50
|
+
style: {
|
|
51
|
+
"--split-pane-primary-size": `${primarySize}px`,
|
|
52
|
+
"--split-pane-gutter": `${gutterSize}px`
|
|
53
|
+
},
|
|
54
|
+
children
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
function SplitPanePrimary({ children }) {
|
|
59
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.primary, children });
|
|
60
|
+
}
|
|
61
|
+
function SplitPaneGutter() {
|
|
62
|
+
const { direction, primarySize, setPrimarySize, minPrimarySize, minSecondarySize, containerRef } = SplitPaneContext.useSplitPaneContext();
|
|
63
|
+
const isDraggingRef = react.useRef(false);
|
|
64
|
+
const startPosRef = react.useRef(0);
|
|
65
|
+
const startSizeRef = react.useRef(primarySize);
|
|
66
|
+
react.useEffect(() => {
|
|
67
|
+
if (!window) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const onMove = (e) => {
|
|
71
|
+
if (!isDraggingRef.current) return;
|
|
72
|
+
const el = containerRef.current;
|
|
73
|
+
if (!el) return;
|
|
74
|
+
const rect = el.getBoundingClientRect();
|
|
75
|
+
const total = direction === "horizontal" ? rect.width : rect.height;
|
|
76
|
+
const clientPos = direction === "horizontal" ? e.clientX : e.clientY;
|
|
77
|
+
const delta = clientPos - startPosRef.current;
|
|
78
|
+
const next = startSizeRef.current + delta;
|
|
79
|
+
const maxPrimary = Math.max(minPrimarySize, total - minSecondarySize);
|
|
80
|
+
setPrimarySize(clamp(next, minPrimarySize, maxPrimary));
|
|
81
|
+
};
|
|
82
|
+
const onUp = () => {
|
|
83
|
+
if (!isDraggingRef.current) return;
|
|
84
|
+
isDraggingRef.current = false;
|
|
85
|
+
document.body.style.cursor = "";
|
|
86
|
+
document.body.style.userSelect = "";
|
|
87
|
+
};
|
|
88
|
+
window.addEventListener("mousemove", onMove);
|
|
89
|
+
window.addEventListener("mouseup", onUp);
|
|
90
|
+
return () => {
|
|
91
|
+
if (window) {
|
|
92
|
+
window.removeEventListener("mousemove", onMove);
|
|
93
|
+
window.removeEventListener("mouseup", onUp);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}, [containerRef, direction, minPrimarySize, minSecondarySize, setPrimarySize]);
|
|
97
|
+
const handleMouseDown = (event) => {
|
|
98
|
+
isDraggingRef.current = true;
|
|
99
|
+
startPosRef.current = direction === "horizontal" ? event.clientX : event.clientY;
|
|
100
|
+
startSizeRef.current = primarySize;
|
|
101
|
+
document.body.style.cursor = direction === "horizontal" ? "col-resize" : "row-resize";
|
|
102
|
+
document.body.style.userSelect = "none";
|
|
103
|
+
};
|
|
104
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.gutter, "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
105
|
+
"span",
|
|
106
|
+
{
|
|
107
|
+
className: styles__default.default.resizer,
|
|
108
|
+
onMouseDown: handleMouseDown,
|
|
109
|
+
role: "separator",
|
|
110
|
+
"aria-orientation": direction === "horizontal" ? "vertical" : "horizontal",
|
|
111
|
+
"aria-valuenow": Math.round(primarySize),
|
|
112
|
+
tabIndex: 0
|
|
113
|
+
}
|
|
114
|
+
) });
|
|
115
|
+
}
|
|
116
|
+
function SplitPaneSecondary({ children }) {
|
|
117
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.secondary, children });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
exports.SplitPane = SplitPane;
|
|
121
|
+
exports.SplitPaneGutter = SplitPaneGutter;
|
|
122
|
+
exports.SplitPanePrimary = SplitPanePrimary;
|
|
123
|
+
exports.SplitPaneSecondary = SplitPaneSecondary;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SplitDirection } from './provider/SplitPaneContext';
|
|
3
|
+
interface SplitPaneProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
initialPrimarySize?: number;
|
|
6
|
+
minPrimarySize?: number;
|
|
7
|
+
minSecondarySize?: number;
|
|
8
|
+
direction?: SplitDirection;
|
|
9
|
+
showDivider?: 'hover' | 'always' | 'never';
|
|
10
|
+
/**
|
|
11
|
+
* Gutter size (px). This is the space between panes and contains the resizer hit area.
|
|
12
|
+
* Example: 8 => 4px breathing room on each side if the divider line is centered.
|
|
13
|
+
*/
|
|
14
|
+
gutterSize?: number;
|
|
15
|
+
/**
|
|
16
|
+
* If provided, primary size is persisted per key in localStorage.
|
|
17
|
+
* Only SplitPanes sharing the same key will share size.
|
|
18
|
+
*/
|
|
19
|
+
storageKey?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function SplitPane({ children, initialPrimarySize, minPrimarySize, minSecondarySize, direction, showDivider, gutterSize, storageKey, }: SplitPaneProps): React.ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* IMPORTANT:
|
|
24
|
+
* This component now renders ONLY the primary content (scrollable).
|
|
25
|
+
* The resizer lives in a dedicated <SplitPaneGutter /> so it never overlaps scrollbars.
|
|
26
|
+
*/
|
|
27
|
+
export declare function SplitPanePrimary({ children }: {
|
|
28
|
+
children: React.ReactNode;
|
|
29
|
+
}): React.ReactNode;
|
|
30
|
+
export declare function SplitPaneGutter(): React.ReactNode;
|
|
31
|
+
export declare function SplitPaneSecondary({ children }: {
|
|
32
|
+
children: React.ReactNode;
|
|
33
|
+
}): React.ReactNode;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useEffect } from 'react';
|
|
3
|
+
import styles from './SplitPane.module.css';
|
|
4
|
+
import { SplitPaneProvider, useSplitPaneContext } from './provider/SplitPaneContext';
|
|
5
|
+
|
|
6
|
+
function clamp(n, min, max) {
|
|
7
|
+
return Math.max(min, Math.min(max, n));
|
|
8
|
+
}
|
|
9
|
+
function SplitPane({
|
|
10
|
+
children,
|
|
11
|
+
initialPrimarySize = 300,
|
|
12
|
+
minPrimarySize = 160,
|
|
13
|
+
minSecondarySize = 160,
|
|
14
|
+
direction = "horizontal",
|
|
15
|
+
showDivider = "hover",
|
|
16
|
+
gutterSize = 8,
|
|
17
|
+
storageKey
|
|
18
|
+
}) {
|
|
19
|
+
return /* @__PURE__ */ jsx(
|
|
20
|
+
SplitPaneProvider,
|
|
21
|
+
{
|
|
22
|
+
direction,
|
|
23
|
+
initialPrimarySize,
|
|
24
|
+
minPrimarySize,
|
|
25
|
+
minSecondarySize,
|
|
26
|
+
storageKey,
|
|
27
|
+
children: /* @__PURE__ */ jsx(SplitPaneContainer, { showDivider, gutterSize, children })
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
function SplitPaneContainer({
|
|
32
|
+
children,
|
|
33
|
+
showDivider,
|
|
34
|
+
gutterSize
|
|
35
|
+
}) {
|
|
36
|
+
const { direction, primarySize, containerRef } = useSplitPaneContext();
|
|
37
|
+
return /* @__PURE__ */ jsx(
|
|
38
|
+
"div",
|
|
39
|
+
{
|
|
40
|
+
ref: containerRef,
|
|
41
|
+
className: styles.container,
|
|
42
|
+
"data-direction": direction,
|
|
43
|
+
"data-divider": showDivider,
|
|
44
|
+
style: {
|
|
45
|
+
"--split-pane-primary-size": `${primarySize}px`,
|
|
46
|
+
"--split-pane-gutter": `${gutterSize}px`
|
|
47
|
+
},
|
|
48
|
+
children
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
function SplitPanePrimary({ children }) {
|
|
53
|
+
return /* @__PURE__ */ jsx("div", { className: styles.primary, children });
|
|
54
|
+
}
|
|
55
|
+
function SplitPaneGutter() {
|
|
56
|
+
const { direction, primarySize, setPrimarySize, minPrimarySize, minSecondarySize, containerRef } = useSplitPaneContext();
|
|
57
|
+
const isDraggingRef = useRef(false);
|
|
58
|
+
const startPosRef = useRef(0);
|
|
59
|
+
const startSizeRef = useRef(primarySize);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!window) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const onMove = (e) => {
|
|
65
|
+
if (!isDraggingRef.current) return;
|
|
66
|
+
const el = containerRef.current;
|
|
67
|
+
if (!el) return;
|
|
68
|
+
const rect = el.getBoundingClientRect();
|
|
69
|
+
const total = direction === "horizontal" ? rect.width : rect.height;
|
|
70
|
+
const clientPos = direction === "horizontal" ? e.clientX : e.clientY;
|
|
71
|
+
const delta = clientPos - startPosRef.current;
|
|
72
|
+
const next = startSizeRef.current + delta;
|
|
73
|
+
const maxPrimary = Math.max(minPrimarySize, total - minSecondarySize);
|
|
74
|
+
setPrimarySize(clamp(next, minPrimarySize, maxPrimary));
|
|
75
|
+
};
|
|
76
|
+
const onUp = () => {
|
|
77
|
+
if (!isDraggingRef.current) return;
|
|
78
|
+
isDraggingRef.current = false;
|
|
79
|
+
document.body.style.cursor = "";
|
|
80
|
+
document.body.style.userSelect = "";
|
|
81
|
+
};
|
|
82
|
+
window.addEventListener("mousemove", onMove);
|
|
83
|
+
window.addEventListener("mouseup", onUp);
|
|
84
|
+
return () => {
|
|
85
|
+
if (window) {
|
|
86
|
+
window.removeEventListener("mousemove", onMove);
|
|
87
|
+
window.removeEventListener("mouseup", onUp);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}, [containerRef, direction, minPrimarySize, minSecondarySize, setPrimarySize]);
|
|
91
|
+
const handleMouseDown = (event) => {
|
|
92
|
+
isDraggingRef.current = true;
|
|
93
|
+
startPosRef.current = direction === "horizontal" ? event.clientX : event.clientY;
|
|
94
|
+
startSizeRef.current = primarySize;
|
|
95
|
+
document.body.style.cursor = direction === "horizontal" ? "col-resize" : "row-resize";
|
|
96
|
+
document.body.style.userSelect = "none";
|
|
97
|
+
};
|
|
98
|
+
return /* @__PURE__ */ jsx("div", { className: styles.gutter, "aria-hidden": "true", children: /* @__PURE__ */ jsx(
|
|
99
|
+
"span",
|
|
100
|
+
{
|
|
101
|
+
className: styles.resizer,
|
|
102
|
+
onMouseDown: handleMouseDown,
|
|
103
|
+
role: "separator",
|
|
104
|
+
"aria-orientation": direction === "horizontal" ? "vertical" : "horizontal",
|
|
105
|
+
"aria-valuenow": Math.round(primarySize),
|
|
106
|
+
tabIndex: 0
|
|
107
|
+
}
|
|
108
|
+
) });
|
|
109
|
+
}
|
|
110
|
+
function SplitPaneSecondary({ children }) {
|
|
111
|
+
return /* @__PURE__ */ jsx("div", { className: styles.secondary, children });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { SplitPane, SplitPaneGutter, SplitPanePrimary, SplitPaneSecondary };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
display: flex;
|
|
3
|
+
inline-size: 100%;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
min-inline-size: 0;
|
|
6
|
+
min-block-size: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.container[data-direction='horizontal'] {
|
|
10
|
+
flex-direction: row;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.container[data-direction='vertical'] {
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* ===== Primary pane ===== */
|
|
18
|
+
.primary {
|
|
19
|
+
flex: 0 0 var(--split-pane-primary-size, 300px);
|
|
20
|
+
min-inline-size: 0;
|
|
21
|
+
min-block-size: 0;
|
|
22
|
+
overflow: auto;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
display: flex;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* ===== Secondary pane ===== */
|
|
28
|
+
.secondary {
|
|
29
|
+
flex: 1 1 auto;
|
|
30
|
+
min-inline-size: 0;
|
|
31
|
+
min-block-size: 0;
|
|
32
|
+
overflow: auto;
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* ===== Gutter (spacing + hit area) ===== */
|
|
38
|
+
.gutter {
|
|
39
|
+
position: relative;
|
|
40
|
+
flex: 0 0 var(--split-pane-gutter, 8px);
|
|
41
|
+
background: transparent;
|
|
42
|
+
z-index: 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Vertical mode gutter */
|
|
46
|
+
.container[data-direction='vertical'] .gutter {
|
|
47
|
+
inline-size: 100%;
|
|
48
|
+
block-size: var(--split-pane-gutter, 8px);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* ===== Resizer (interaction only) ===== */
|
|
52
|
+
.resizer {
|
|
53
|
+
position: absolute;
|
|
54
|
+
inset: 0;
|
|
55
|
+
cursor: col-resize;
|
|
56
|
+
user-select: none;
|
|
57
|
+
touch-action: none;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.container[data-direction='vertical'] .resizer {
|
|
61
|
+
cursor: row-resize;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* ===== Divider line ===== */
|
|
65
|
+
.resizer::after {
|
|
66
|
+
content: '';
|
|
67
|
+
position: absolute;
|
|
68
|
+
inset-block: 0;
|
|
69
|
+
inset-inline: 50%;
|
|
70
|
+
inline-size: var(--border-width-hairline);
|
|
71
|
+
background-color: var(--color-border-subtle);
|
|
72
|
+
opacity: 0;
|
|
73
|
+
transform: translateX(-50%);
|
|
74
|
+
transition:
|
|
75
|
+
opacity var(--transition-fast) var(--ease-standard),
|
|
76
|
+
background-color var(--transition-fast) var(--ease-standard);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Vertical divider */
|
|
80
|
+
.container[data-direction='vertical'] .resizer::after {
|
|
81
|
+
inset-inline: 0;
|
|
82
|
+
inset-block: 50%;
|
|
83
|
+
inline-size: 100%;
|
|
84
|
+
block-size: var(--border-width-hairline);
|
|
85
|
+
transform: translateY(-50%);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* ===== Divider visibility modes ===== */
|
|
89
|
+
.container[data-divider='hover'] .resizer:hover::after,
|
|
90
|
+
.container[data-divider='hover'] .resizer:active::after {
|
|
91
|
+
opacity: 1;
|
|
92
|
+
background-color: var(--color-border-strong);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.container[data-divider='always'] .resizer::after {
|
|
96
|
+
opacity: 1;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.container[data-divider='never'] .resizer::after {
|
|
100
|
+
display: none;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.container[data-divider='hover'] .resizer:active::after,
|
|
104
|
+
.container[data-divider='always'] .resizer:active::after {
|
|
105
|
+
background-color: var(--color-brand);
|
|
106
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
9
|
+
|
|
10
|
+
const SplitPaneContext = React__default.default.createContext(null);
|
|
11
|
+
function clamp(n, min, max) {
|
|
12
|
+
return Math.max(min, Math.min(max, n));
|
|
13
|
+
}
|
|
14
|
+
function readStoredSize(key) {
|
|
15
|
+
try {
|
|
16
|
+
const raw = localStorage.getItem(key);
|
|
17
|
+
if (!raw) return null;
|
|
18
|
+
const num = Number(raw);
|
|
19
|
+
return Number.isFinite(num) ? num : null;
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function writeStoredSize(key, value) {
|
|
25
|
+
try {
|
|
26
|
+
localStorage.setItem(key, String(Math.round(value)));
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function useSplitPaneContext() {
|
|
31
|
+
const ctx = React__default.default.useContext(SplitPaneContext);
|
|
32
|
+
if (!ctx) throw new Error("SplitPane components must be used within <SplitPane />");
|
|
33
|
+
return ctx;
|
|
34
|
+
}
|
|
35
|
+
function SplitPaneProvider({
|
|
36
|
+
children,
|
|
37
|
+
direction,
|
|
38
|
+
initialPrimarySize,
|
|
39
|
+
minPrimarySize,
|
|
40
|
+
minSecondarySize,
|
|
41
|
+
storageKey
|
|
42
|
+
}) {
|
|
43
|
+
const containerRef = React.useRef(null);
|
|
44
|
+
const [primarySize, setPrimarySize] = React.useState(initialPrimarySize);
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
if (!storageKey) return;
|
|
47
|
+
const stored = readStoredSize(storageKey);
|
|
48
|
+
if (stored === null) return;
|
|
49
|
+
setPrimarySize(stored);
|
|
50
|
+
}, [storageKey]);
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
const el = containerRef.current;
|
|
53
|
+
if (!el) return;
|
|
54
|
+
const clampToContainer = () => {
|
|
55
|
+
const rect = el.getBoundingClientRect();
|
|
56
|
+
const total = direction === "horizontal" ? rect.width : rect.height;
|
|
57
|
+
if (!Number.isFinite(total) || total <= 0) return;
|
|
58
|
+
const maxPrimary = Math.max(minPrimarySize, total - minSecondarySize);
|
|
59
|
+
setPrimarySize((prev) => clamp(prev, minPrimarySize, maxPrimary));
|
|
60
|
+
};
|
|
61
|
+
clampToContainer();
|
|
62
|
+
const ro = new ResizeObserver(() => clampToContainer());
|
|
63
|
+
ro.observe(el);
|
|
64
|
+
return () => ro.disconnect();
|
|
65
|
+
}, [direction, minPrimarySize, minSecondarySize]);
|
|
66
|
+
React.useEffect(() => {
|
|
67
|
+
if (!storageKey) return;
|
|
68
|
+
writeStoredSize(storageKey, primarySize);
|
|
69
|
+
}, [storageKey, primarySize]);
|
|
70
|
+
const value = React.useMemo(
|
|
71
|
+
() => ({
|
|
72
|
+
direction,
|
|
73
|
+
primarySize,
|
|
74
|
+
setPrimarySize,
|
|
75
|
+
minPrimarySize,
|
|
76
|
+
minSecondarySize,
|
|
77
|
+
containerRef,
|
|
78
|
+
storageKey
|
|
79
|
+
}),
|
|
80
|
+
[direction, primarySize, minPrimarySize, minSecondarySize, storageKey]
|
|
81
|
+
);
|
|
82
|
+
return /* @__PURE__ */ jsxRuntime.jsx(SplitPaneContext.Provider, { value, children });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.SplitPaneContext = SplitPaneContext;
|
|
86
|
+
exports.SplitPaneProvider = SplitPaneProvider;
|
|
87
|
+
exports.useSplitPaneContext = useSplitPaneContext;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type SplitDirection = 'horizontal' | 'vertical';
|
|
3
|
+
export interface SplitPaneContextValue {
|
|
4
|
+
direction: SplitDirection;
|
|
5
|
+
primarySize: number;
|
|
6
|
+
setPrimarySize: React.Dispatch<React.SetStateAction<number>>;
|
|
7
|
+
minPrimarySize: number;
|
|
8
|
+
minSecondarySize: number;
|
|
9
|
+
containerRef: React.RefObject<HTMLDivElement>;
|
|
10
|
+
storageKey?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const SplitPaneContext: React.Context<SplitPaneContextValue | null>;
|
|
13
|
+
export declare function useSplitPaneContext(): SplitPaneContextValue;
|
|
14
|
+
type SplitPaneProviderProps = {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
direction: SplitDirection;
|
|
17
|
+
initialPrimarySize: number;
|
|
18
|
+
minPrimarySize: number;
|
|
19
|
+
minSecondarySize: number;
|
|
20
|
+
storageKey?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function SplitPaneProvider({ children, direction, initialPrimarySize, minPrimarySize, minSecondarySize, storageKey, }: SplitPaneProviderProps): React.ReactNode;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import React, { useRef, useState, useEffect, useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
const SplitPaneContext = React.createContext(null);
|
|
5
|
+
function clamp(n, min, max) {
|
|
6
|
+
return Math.max(min, Math.min(max, n));
|
|
7
|
+
}
|
|
8
|
+
function readStoredSize(key) {
|
|
9
|
+
try {
|
|
10
|
+
const raw = localStorage.getItem(key);
|
|
11
|
+
if (!raw) return null;
|
|
12
|
+
const num = Number(raw);
|
|
13
|
+
return Number.isFinite(num) ? num : null;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function writeStoredSize(key, value) {
|
|
19
|
+
try {
|
|
20
|
+
localStorage.setItem(key, String(Math.round(value)));
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function useSplitPaneContext() {
|
|
25
|
+
const ctx = React.useContext(SplitPaneContext);
|
|
26
|
+
if (!ctx) throw new Error("SplitPane components must be used within <SplitPane />");
|
|
27
|
+
return ctx;
|
|
28
|
+
}
|
|
29
|
+
function SplitPaneProvider({
|
|
30
|
+
children,
|
|
31
|
+
direction,
|
|
32
|
+
initialPrimarySize,
|
|
33
|
+
minPrimarySize,
|
|
34
|
+
minSecondarySize,
|
|
35
|
+
storageKey
|
|
36
|
+
}) {
|
|
37
|
+
const containerRef = useRef(null);
|
|
38
|
+
const [primarySize, setPrimarySize] = useState(initialPrimarySize);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!storageKey) return;
|
|
41
|
+
const stored = readStoredSize(storageKey);
|
|
42
|
+
if (stored === null) return;
|
|
43
|
+
setPrimarySize(stored);
|
|
44
|
+
}, [storageKey]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const el = containerRef.current;
|
|
47
|
+
if (!el) return;
|
|
48
|
+
const clampToContainer = () => {
|
|
49
|
+
const rect = el.getBoundingClientRect();
|
|
50
|
+
const total = direction === "horizontal" ? rect.width : rect.height;
|
|
51
|
+
if (!Number.isFinite(total) || total <= 0) return;
|
|
52
|
+
const maxPrimary = Math.max(minPrimarySize, total - minSecondarySize);
|
|
53
|
+
setPrimarySize((prev) => clamp(prev, minPrimarySize, maxPrimary));
|
|
54
|
+
};
|
|
55
|
+
clampToContainer();
|
|
56
|
+
const ro = new ResizeObserver(() => clampToContainer());
|
|
57
|
+
ro.observe(el);
|
|
58
|
+
return () => ro.disconnect();
|
|
59
|
+
}, [direction, minPrimarySize, minSecondarySize]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!storageKey) return;
|
|
62
|
+
writeStoredSize(storageKey, primarySize);
|
|
63
|
+
}, [storageKey, primarySize]);
|
|
64
|
+
const value = useMemo(
|
|
65
|
+
() => ({
|
|
66
|
+
direction,
|
|
67
|
+
primarySize,
|
|
68
|
+
setPrimarySize,
|
|
69
|
+
minPrimarySize,
|
|
70
|
+
minSecondarySize,
|
|
71
|
+
containerRef,
|
|
72
|
+
storageKey
|
|
73
|
+
}),
|
|
74
|
+
[direction, primarySize, minPrimarySize, minSecondarySize, storageKey]
|
|
75
|
+
);
|
|
76
|
+
return /* @__PURE__ */ jsx(SplitPaneContext.Provider, { value, children });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { SplitPaneContext, SplitPaneProvider, useSplitPaneContext };
|