@sentry/scraps 0.1.0 → 0.3.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/README.md +13 -21
- package/dist/alert/alert.d.ts +25 -0
- package/dist/alert/alert.js +262 -0
- package/dist/alert/alertLink.d.ts +32 -0
- package/dist/alert/alertLink.js +94 -0
- package/dist/alert/index.d.ts +2 -0
- package/dist/alert/index.js +2 -0
- package/dist/backdrop/backdrop.d.ts +9 -0
- package/dist/backdrop/backdrop.js +28 -0
- package/dist/backdrop/index.d.ts +1 -0
- package/dist/backdrop/index.js +1 -0
- package/dist/badge/badge.d.ts +12 -0
- package/dist/badge/badge.js +80 -0
- package/dist/badge/featureBadge.d.ts +6 -0
- package/dist/badge/featureBadge.js +86 -0
- package/dist/badge/index.d.ts +3 -0
- package/dist/badge/index.js +3 -0
- package/dist/badge/tag.d.ts +15 -0
- package/dist/badge/tag.js +119 -0
- package/dist/boundaryContext.d.ts +2 -0
- package/dist/boundaryContext.js +5 -0
- package/dist/button/button.d.ts +3 -0
- package/dist/button/button.js +83 -0
- package/dist/button/buttonBar.d.ts +10 -0
- package/dist/button/buttonBar.js +141 -0
- package/dist/button/index.d.ts +5 -0
- package/dist/button/index.js +4 -0
- package/dist/button/linkButton.d.ts +3 -0
- package/dist/button/linkButton.js +110 -0
- package/dist/button/styles.d.ts +10 -0
- package/dist/button/styles.js +247 -0
- package/dist/button/types.d.ts +77 -0
- package/dist/button/types.js +0 -0
- package/dist/button/useButtonFunctionality.d.ts +5 -0
- package/dist/button/useButtonFunctionality.js +9 -0
- package/dist/checkbox/checkbox.d.ts +20 -0
- package/dist/checkbox/checkbox.js +193 -0
- package/dist/checkbox/index.d.ts +1 -0
- package/dist/checkbox/index.js +1 -0
- package/dist/chip/chip.d.ts +128 -0
- package/dist/chip/chip.js +364 -0
- package/dist/chip/index.d.ts +1 -0
- package/dist/chip/index.js +1 -0
- package/dist/code/inlineCode.d.ts +1 -0
- package/dist/datetime.d.ts +39 -0
- package/dist/datetime.js +20 -0
- package/dist/descriptionList/descriptionList.d.ts +69 -0
- package/dist/descriptionList/descriptionList.js +76 -0
- package/dist/descriptionList/index.d.ts +1 -0
- package/dist/descriptionList/index.js +1 -0
- package/dist/disclosure/disclosure.d.ts +37 -0
- package/dist/disclosure/disclosure.js +155 -0
- package/dist/disclosure/index.d.ts +1 -0
- package/dist/disclosure/index.js +1 -0
- package/dist/dragHandle/dragHandle.d.ts +34 -0
- package/dist/dragHandle/dragHandle.js +115 -0
- package/dist/dragHandle/index.d.ts +4 -0
- package/dist/dragHandle/index.js +4 -0
- package/dist/dragHandle/setDocumentDragging.d.ts +9 -0
- package/dist/dragHandle/setDocumentDragging.js +6 -0
- package/dist/dragHandle/useDragMove.d.ts +244 -0
- package/dist/dragHandle/useDragMove.js +66 -0
- package/dist/dragHandle/useDragSeparator.d.ts +256 -0
- package/dist/dragHandle/useDragSeparator.js +36 -0
- package/dist/emptyState/emptyState.d.ts +10 -0
- package/dist/emptyState/emptyState.js +81 -0
- package/dist/emptyState/index.d.ts +1 -0
- package/dist/emptyState/index.js +1 -0
- package/dist/formPresentation/autoSaveContext.d.ts +23 -0
- package/dist/formPresentation/autoSaveContext.js +13 -0
- package/dist/formPresentation/base.d.ts +11 -0
- package/dist/formPresentation/base.js +37 -0
- package/dist/formPresentation/displayField.d.ts +17 -0
- package/dist/formPresentation/displayField.js +69 -0
- package/dist/formPresentation/fieldIds.d.ts +3 -0
- package/dist/formPresentation/fieldIds.js +14 -0
- package/dist/formPresentation/fieldLayout.d.ts +23 -0
- package/dist/formPresentation/fieldLayout.js +76 -0
- package/dist/formPresentation/formContext.d.ts +4 -0
- package/dist/formPresentation/formContext.js +6 -0
- package/dist/formPresentation/groupContext.d.ts +24 -0
- package/dist/formPresentation/groupContext.js +22 -0
- package/dist/formPresentation/icons.d.ts +11 -0
- package/dist/formPresentation/icons.js +61 -0
- package/dist/formPresentation/index.d.ts +8 -0
- package/dist/formPresentation/index.js +8 -0
- package/dist/formPresentation/meta.d.ts +18 -0
- package/dist/formPresentation/meta.js +88 -0
- package/dist/formPresentation/useStackedLayout.d.ts +1 -0
- package/dist/formPresentation/useStackedLayout.js +9 -0
- package/dist/hotkey/hotkey.d.ts +22 -0
- package/dist/hotkey/hotkey.js +41 -0
- package/dist/hotkey/index.d.ts +4 -0
- package/dist/hotkey/index.js +3 -0
- package/dist/hotkey/kbd.d.ts +1 -0
- package/dist/hotkey/keyMappings.d.ts +23 -0
- package/dist/hotkey/keyMappings.js +223 -0
- package/dist/hotkey/useHotkeys.d.ts +47 -0
- package/dist/hotkey/useHotkeys.js +44 -0
- package/dist/image/image.d.ts +21 -0
- package/dist/image/image.js +20 -0
- package/dist/image/index.d.ts +1 -0
- package/dist/image/index.js +1 -0
- package/dist/info/index.d.ts +2 -0
- package/dist/info/index.js +2 -0
- package/dist/info/infoText.d.ts +15 -0
- package/dist/info/infoText.js +43 -0
- package/dist/info/infoTip.d.ts +10 -0
- package/dist/info/infoTip.js +54 -0
- package/dist/input/index.d.ts +8 -0
- package/dist/input/index.js +6 -0
- package/dist/input/input.d.ts +19 -0
- package/dist/input/input.js +14 -0
- package/dist/input/inputGroup.d.ts +29 -0
- package/dist/input/inputGroup.js +167 -0
- package/dist/input/inputStyles.d.ts +13 -0
- package/dist/input/inputStyles.js +52 -0
- package/dist/input/numberDragInput.d.ts +20 -0
- package/dist/input/numberDragInput.js +97 -0
- package/dist/input/numberInput.d.ts +10 -0
- package/dist/input/numberInput.js +94 -0
- package/dist/input/otpInput.d.ts +28 -0
- package/dist/input/otpInput.js +81 -0
- package/dist/input/useAutosizeInput.d.ts +17 -0
- package/dist/input/useAutosizeInput.js +56 -0
- package/dist/interactionStateLayer/index.d.ts +1 -0
- package/dist/interactionStateLayer/index.js +1 -0
- package/dist/interactionStateLayer/interactionStateLayer.d.ts +23 -0
- package/dist/interactionStateLayer/interactionStateLayer.js +67 -0
- package/dist/layout/flex.d.ts +1 -0
- package/dist/layout/grid.d.ts +1 -0
- package/dist/layout/index.d.ts +1 -1
- package/dist/layout/index.js +1 -1
- package/dist/layout/stack.d.ts +1 -0
- package/dist/layout/styles.d.ts +1 -1
- package/dist/layout/surface.d.ts +1 -0
- package/dist/link/index.d.ts +2 -0
- package/dist/link/index.js +2 -0
- package/dist/link/link.d.ts +43 -0
- package/dist/link/link.js +71 -0
- package/dist/link/linkBehaviorContext.d.ts +14 -0
- package/dist/link/linkBehaviorContext.js +31 -0
- package/dist/loader/indeterminateLoader.d.ts +1 -0
- package/dist/overlay.d.ts +59 -0
- package/dist/overlay.js +113 -0
- package/dist/overlayArrow.d.ts +9 -0
- package/dist/overlayArrow.js +55 -0
- package/dist/overlayPositioning.d.ts +70 -0
- package/dist/overlayPositioning.js +139 -0
- package/dist/panelProvider.d.ts +8 -0
- package/dist/panelProvider.js +20 -0
- package/dist/quote/quote.js +1 -1
- package/dist/radio/index.d.ts +1 -0
- package/dist/radio/index.js +1 -0
- package/dist/radio/radio.d.ts +9 -0
- package/dist/radio/radio.js +77 -0
- package/dist/renderToString.d.ts +2 -0
- package/dist/renderToString.js +25 -0
- package/dist/revealOnHover/index.d.ts +1 -0
- package/dist/revealOnHover/index.js +1 -0
- package/dist/revealOnHover/revealOnHover.d.ts +20 -0
- package/dist/revealOnHover/revealOnHover.js +62 -0
- package/dist/segmentedControl/index.d.ts +1 -0
- package/dist/segmentedControl/index.js +1 -0
- package/dist/segmentedControl/segmentedControl.d.ts +41 -0
- package/dist/segmentedControl/segmentedControl.js +217 -0
- package/dist/separator/separator.d.ts +4 -3
- package/dist/separator/separator.js +1 -1
- package/dist/sizeContext.d.ts +9 -0
- package/dist/sizeContext.js +13 -0
- package/dist/slider/index.d.ts +1 -0
- package/dist/slider/index.js +1 -0
- package/dist/slider/slider.d.ts +41 -0
- package/dist/slider/slider.js +386 -0
- package/dist/slot/index.d.ts +1 -0
- package/dist/slot/index.js +1 -0
- package/dist/slot/knownContexts.d.ts +1 -0
- package/dist/slot/knownContexts.js +7 -0
- package/dist/slot/slot.d.ts +26 -0
- package/dist/slot/slot.js +274 -0
- package/dist/statusIndicator/index.d.ts +1 -0
- package/dist/statusIndicator/index.js +1 -0
- package/dist/statusIndicator/statusIndicator.d.ts +24 -0
- package/dist/statusIndicator/statusIndicator.js +130 -0
- package/dist/switch/index.d.ts +1 -0
- package/dist/switch/index.js +1 -0
- package/dist/switch/switch.d.ts +6 -0
- package/dist/switch/switch.js +172 -0
- package/dist/table/index.d.ts +3 -0
- package/dist/table/index.js +3 -0
- package/dist/table/sortableHeaderCell.d.ts +36 -0
- package/dist/table/sortableHeaderCell.js +99 -0
- package/dist/table/styles.d.ts +46 -0
- package/dist/table/styles.js +93 -0
- package/dist/table/table.d.ts +64 -0
- package/dist/table/table.js +228 -0
- package/dist/table/useColumnResize.d.ts +27 -0
- package/dist/table/useColumnResize.js +62 -0
- package/dist/table/useObservedColumnSize.d.ts +12 -0
- package/dist/table/useObservedColumnSize.js +74 -0
- package/dist/text/heading.d.ts +2 -1
- package/dist/text/index.d.ts +1 -0
- package/dist/text/index.js +1 -0
- package/dist/text/prose.d.ts +8 -0
- package/dist/text/prose.js +45 -0
- package/dist/text/text.d.ts +8 -0
- package/dist/text/text.js +1 -1
- package/dist/textarea/index.d.ts +1 -0
- package/dist/textarea/index.js +1 -0
- package/dist/textarea/textarea.d.ts +22 -0
- package/dist/textarea/textarea.js +77 -0
- package/dist/theme/dark.d.ts +129 -10
- package/dist/theme/dark.js +41 -13
- package/dist/theme/index.d.ts +3 -12
- package/dist/theme/index.js +2 -2
- package/dist/theme/light.d.ts +129 -10
- package/dist/theme/light.js +42 -14
- package/dist/theme/swatch.d.ts +27 -0
- package/dist/theme/swatch.js +37 -0
- package/dist/theme/theme.d.ts +648 -0
- package/dist/theme/theme.js +780 -0
- package/dist/theme/types.d.ts +1 -0
- package/dist/theme/useInvertedTheme.d.ts +1 -0
- package/dist/theme/useInvertedTheme.js +7 -0
- package/dist/tooltip/index.d.ts +2 -0
- package/dist/tooltip/index.js +2 -0
- package/dist/tooltip/tooltip.d.ts +166 -0
- package/dist/tooltip/tooltip.js +181 -0
- package/dist/tooltip/useDisabledTooltip.d.ts +22 -0
- package/dist/tooltip/useDisabledTooltip.js +24 -0
- package/dist/trackingContext.d.ts +34 -0
- package/dist/trackingContext.js +29 -0
- package/dist/translation/index.d.ts +4 -0
- package/dist/translation/index.js +4 -0
- package/dist/translation/translationContext.d.ts +6 -0
- package/dist/translation/translationContext.js +6 -0
- package/dist/translation/useTranslation.d.ts +1 -0
- package/dist/translation/useTranslation.js +6 -0
- package/dist/unreachable.d.ts +1 -0
- package/dist/unreachable.js +4 -0
- package/dist/useHoverOverlay.d.ts +113 -0
- package/dist/useHoverOverlay.js +370 -0
- package/dist/useIsInsideInteractiveElement.d.ts +6 -0
- package/dist/useIsInsideInteractiveElement.js +31 -0
- package/dist/useOverlay.d.ts +82 -0
- package/dist/useOverlay.js +217 -0
- package/dist/useScrollLock.d.ts +5 -0
- package/dist/useScrollLock.js +100 -0
- package/dist/useStableMergeRef.d.ts +9 -0
- package/dist/useStableMergeRef.js +18 -0
- package/package.json +219 -11
- package/dist/index.d.ts +0 -9
- package/dist/index.js +0 -9
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import is_prop_valid from "@emotion/is-prop-valid";
|
|
3
|
+
import { css } from "@emotion/react";
|
|
4
|
+
import styled from "@emotion/styled";
|
|
5
|
+
import { IconArrow } from "@sentry/icons/arrow";
|
|
6
|
+
import { FLEX_JUSTIFY_CONTENT } from "../layout/index.js";
|
|
7
|
+
import { Link } from "../link/index.js";
|
|
8
|
+
import { Tooltip } from "../tooltip/index.js";
|
|
9
|
+
function getAriaSort(direction) {
|
|
10
|
+
switch(direction){
|
|
11
|
+
case 'asc':
|
|
12
|
+
return 'ascending';
|
|
13
|
+
case 'desc':
|
|
14
|
+
return 'descending';
|
|
15
|
+
default:
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const COLUMN_ALIGN_JUSTIFY = {
|
|
20
|
+
center: 'center',
|
|
21
|
+
left: 'start',
|
|
22
|
+
right: 'end'
|
|
23
|
+
};
|
|
24
|
+
function SortableHeaderCell({ align, children, direction, onSort, overlays, replace, to, ...props }) {
|
|
25
|
+
return /*#__PURE__*/ jsxs(HeaderCellContent, {
|
|
26
|
+
...props,
|
|
27
|
+
align: align,
|
|
28
|
+
as: to ? Link : onSort ? 'button' : 'div',
|
|
29
|
+
onClick: onSort,
|
|
30
|
+
replace: to ? replace : void 0,
|
|
31
|
+
to: to,
|
|
32
|
+
type: !to && onSort ? 'button' : void 0,
|
|
33
|
+
children: [
|
|
34
|
+
overlays,
|
|
35
|
+
/*#__PURE__*/ jsx(Tooltip, {
|
|
36
|
+
showOnlyOnOverflow: true,
|
|
37
|
+
skipWrapper: true,
|
|
38
|
+
title: children,
|
|
39
|
+
children: /*#__PURE__*/ jsx(Label, {
|
|
40
|
+
align: align,
|
|
41
|
+
grow: !direction,
|
|
42
|
+
children: children
|
|
43
|
+
})
|
|
44
|
+
}),
|
|
45
|
+
direction && /*#__PURE__*/ jsx(IconArrow, {
|
|
46
|
+
"aria-hidden": true,
|
|
47
|
+
direction: 'desc' === direction ? 'down' : 'up',
|
|
48
|
+
size: "xs"
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const Label = styled('div', {
|
|
54
|
+
shouldForwardProp: (prop)=>'align' !== prop && 'grow' !== prop
|
|
55
|
+
})`
|
|
56
|
+
margin: -${(p)=>p.theme.space['2xs']};
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
padding: ${(p)=>p.theme.space['2xs']};
|
|
59
|
+
text-overflow: ellipsis;
|
|
60
|
+
white-space: nowrap;
|
|
61
|
+
|
|
62
|
+
/* Without a sort arrow beside it, the label fills the cell so that content
|
|
63
|
+
aligning itself, such as a right-aligned column label, has room to. */
|
|
64
|
+
${(p)=>p.grow && css`
|
|
65
|
+
flex: 1;
|
|
66
|
+
text-align: ${p.align ?? 'left'};
|
|
67
|
+
`}
|
|
68
|
+
`;
|
|
69
|
+
const HeaderCellContent = styled('div', {
|
|
70
|
+
shouldForwardProp: (prop)=>'align' !== prop && ('to' === prop || 'replace' === prop || is_prop_valid(prop))
|
|
71
|
+
})`
|
|
72
|
+
align-items: center;
|
|
73
|
+
background: none;
|
|
74
|
+
border: 0;
|
|
75
|
+
color: inherit;
|
|
76
|
+
cursor: ${(p)=>p.onClick || p.to ? 'pointer' : 'default'};
|
|
77
|
+
display: flex;
|
|
78
|
+
flex: 1;
|
|
79
|
+
font: inherit;
|
|
80
|
+
gap: ${(p)=>p.theme.space.xs};
|
|
81
|
+
margin: -${(p)=>p.theme.space['2xs']};
|
|
82
|
+
min-width: 0;
|
|
83
|
+
overflow: hidden;
|
|
84
|
+
padding: ${(p)=>p.theme.space['2xs']};
|
|
85
|
+
text-align: inherit;
|
|
86
|
+
text-transform: inherit;
|
|
87
|
+
|
|
88
|
+
${(p)=>p.align && css`
|
|
89
|
+
justify-content: ${FLEX_JUSTIFY_CONTENT[COLUMN_ALIGN_JUSTIFY[p.align]]};
|
|
90
|
+
`}
|
|
91
|
+
|
|
92
|
+
&:hover,
|
|
93
|
+
&:active,
|
|
94
|
+
&:focus,
|
|
95
|
+
&:visited {
|
|
96
|
+
color: inherit;
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
export { COLUMN_ALIGN_JUSTIFY, HeaderCellContent, SortableHeaderCell, getAriaSort };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Theme } from '@emotion/react';
|
|
2
|
+
import { type FlexProps } from '../layout/index.js';
|
|
3
|
+
interface TableGridProps {
|
|
4
|
+
hiddenColumnIndexes?: number[];
|
|
5
|
+
}
|
|
6
|
+
export declare const TableGrid: import("@emotion/styled").StyledComponent<{
|
|
7
|
+
theme?: Theme;
|
|
8
|
+
as?: React.ElementType;
|
|
9
|
+
} & TableGridProps, import("react").DetailedHTMLProps<import("react").TableHTMLAttributes<HTMLTableElement>, HTMLTableElement>, {}>;
|
|
10
|
+
export declare const TableHead: import("@emotion/styled").StyledComponent<{
|
|
11
|
+
theme?: Theme;
|
|
12
|
+
as?: React.ElementType;
|
|
13
|
+
} & {
|
|
14
|
+
sticky?: boolean;
|
|
15
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, {}>;
|
|
16
|
+
export declare const TableBody: import("@emotion/styled").StyledComponent<{
|
|
17
|
+
theme?: Theme;
|
|
18
|
+
as?: React.ElementType;
|
|
19
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, {}>;
|
|
20
|
+
export declare const TableRow: import("@emotion/styled").StyledComponent<{
|
|
21
|
+
theme?: Theme;
|
|
22
|
+
as?: React.ElementType;
|
|
23
|
+
} & {
|
|
24
|
+
divider?: boolean;
|
|
25
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>, {}>;
|
|
26
|
+
export declare function TableHeadCell(props: FlexProps<'th'>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
27
|
+
export declare const TableCell: import("@emotion/styled").StyledComponent<{
|
|
28
|
+
theme?: Theme;
|
|
29
|
+
as?: React.ElementType;
|
|
30
|
+
}, import("react").DetailedHTMLProps<import("react").TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>, {}>;
|
|
31
|
+
export declare const TableStatusCell: import("@emotion/styled").StyledComponent<{
|
|
32
|
+
theme?: Theme;
|
|
33
|
+
as?: React.ElementType;
|
|
34
|
+
}, import("react").DetailedHTMLProps<import("react").TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>, {}>;
|
|
35
|
+
export declare const fullWidthCellStyle: import("@emotion/react").SerializedStyles;
|
|
36
|
+
export declare const statusCellStyle: (p: {
|
|
37
|
+
theme: Theme;
|
|
38
|
+
}) => import("@emotion/react").SerializedStyles;
|
|
39
|
+
export declare const emptyCellStyle: (p: {
|
|
40
|
+
theme: Theme;
|
|
41
|
+
}) => import("@emotion/react").SerializedStyles;
|
|
42
|
+
export declare const TableResizer: import("@emotion/styled").StyledComponent<{
|
|
43
|
+
theme?: Theme;
|
|
44
|
+
as?: React.ElementType;
|
|
45
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import is_prop_valid from "@emotion/is-prop-valid";
|
|
3
|
+
import { css } from "@emotion/react";
|
|
4
|
+
import styled from "@emotion/styled";
|
|
5
|
+
import { Flex } from "../layout/index.js";
|
|
6
|
+
const TABLE_HEAD_ROW_HEIGHT = 45;
|
|
7
|
+
const Z_INDEX_RESIZER = 1;
|
|
8
|
+
const Z_INDEX_STICKY_HEAD = 2;
|
|
9
|
+
const TableGrid = styled('table')`
|
|
10
|
+
position: inherit;
|
|
11
|
+
display: grid;
|
|
12
|
+
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
border-collapse: collapse;
|
|
15
|
+
margin: 0;
|
|
16
|
+
|
|
17
|
+
${(p)=>p.hiddenColumnIndexes?.map((index)=>css`
|
|
18
|
+
tr > *:nth-child(${index + 1} of [role='cell'], [role='columnheader']):not(:only-child) {
|
|
19
|
+
display: none;
|
|
20
|
+
}
|
|
21
|
+
`)}
|
|
22
|
+
`;
|
|
23
|
+
const subgrid = css`
|
|
24
|
+
display: grid;
|
|
25
|
+
grid-template-columns: subgrid;
|
|
26
|
+
grid-column: 1 / -1;
|
|
27
|
+
`;
|
|
28
|
+
const TableHead = styled('thead')`
|
|
29
|
+
${subgrid}
|
|
30
|
+
|
|
31
|
+
${(p)=>p.sticky && css`
|
|
32
|
+
position: sticky;
|
|
33
|
+
top: 0;
|
|
34
|
+
z-index: ${Z_INDEX_STICKY_HEAD};
|
|
35
|
+
`}
|
|
36
|
+
`;
|
|
37
|
+
const TableBody = styled('tbody')`
|
|
38
|
+
${subgrid}
|
|
39
|
+
`;
|
|
40
|
+
const TableRow = styled('tr', {
|
|
41
|
+
shouldForwardProp: (prop)=>'divider' !== prop && is_prop_valid(prop)
|
|
42
|
+
})`
|
|
43
|
+
${subgrid}
|
|
44
|
+
position: relative;
|
|
45
|
+
|
|
46
|
+
${(p)=>p.divider && css`
|
|
47
|
+
&:not(:last-child) {
|
|
48
|
+
border-bottom: 1px solid ${p.theme.tokens.border.secondary};
|
|
49
|
+
}
|
|
50
|
+
`}
|
|
51
|
+
`;
|
|
52
|
+
function TableHeadCell(props) {
|
|
53
|
+
return /*#__PURE__*/ jsx(Flex, {
|
|
54
|
+
as: "th",
|
|
55
|
+
position: "relative",
|
|
56
|
+
minWidth: 0,
|
|
57
|
+
...props
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const TableCell = styled('td')`
|
|
61
|
+
min-width: 0;
|
|
62
|
+
`;
|
|
63
|
+
const TableStatusCell = styled('td')`
|
|
64
|
+
grid-column: 1 / -1;
|
|
65
|
+
width: 100%;
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
`;
|
|
70
|
+
const fullWidthCellStyle = css`
|
|
71
|
+
align-items: stretch;
|
|
72
|
+
flex-direction: column;
|
|
73
|
+
padding: 0;
|
|
74
|
+
`;
|
|
75
|
+
const statusCellStyle = (p)=>css`
|
|
76
|
+
min-height: 200px;
|
|
77
|
+
padding: ${p.theme.space.xl};
|
|
78
|
+
`;
|
|
79
|
+
const emptyCellStyle = (p)=>css`
|
|
80
|
+
${statusCellStyle(p)}
|
|
81
|
+
color: ${p.theme.tokens.content.secondary};
|
|
82
|
+
font-size: ${p.theme.font.size.md};
|
|
83
|
+
`;
|
|
84
|
+
const TableResizer = styled('div')`
|
|
85
|
+
position: absolute;
|
|
86
|
+
top: 0;
|
|
87
|
+
right: 0;
|
|
88
|
+
display: flex;
|
|
89
|
+
height: var(--column-resizer-height, ${TABLE_HEAD_ROW_HEIGHT}px);
|
|
90
|
+
pointer-events: none;
|
|
91
|
+
z-index: ${Z_INDEX_RESIZER};
|
|
92
|
+
`;
|
|
93
|
+
export { TableBody, TableCell, TableGrid, TableHead, TableHeadCell, TableResizer, TableRow, TableStatusCell, emptyCellStyle, fullWidthCellStyle, statusCellStyle };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { ComponentProps, HTMLAttributes, ReactNode, Ref, RefObject, TdHTMLAttributes, ThHTMLAttributes } from 'react';
|
|
3
|
+
import { type Responsive } from '../layout/index.js';
|
|
4
|
+
import type { LinkProps } from '../link/index.js';
|
|
5
|
+
import { type ColumnAlign, type SortDirection } from './sortableHeaderCell.js';
|
|
6
|
+
import { TableBody, TableCell, TableHead, TableRow } from './styles.js';
|
|
7
|
+
export declare const COL_WIDTH_UNDEFINED = -1;
|
|
8
|
+
export declare const COL_WIDTH_MINIMUM = 90;
|
|
9
|
+
export interface TableColumnConfig {
|
|
10
|
+
key: string;
|
|
11
|
+
resizable?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the column takes part in the layout, defaulting to `true`. A
|
|
14
|
+
* responsive value drops the column's track from the grid template and hides
|
|
15
|
+
* the cells in that position as the container crosses a breakpoint, and starts
|
|
16
|
+
* out hidden: `{'3xl': true}` is the same as `{zero: false, '3xl': true}`.
|
|
17
|
+
*
|
|
18
|
+
* Cells are matched to columns by position, so every column a row renders a
|
|
19
|
+
* cell for needs an entry here, in the order the cells are rendered.
|
|
20
|
+
*/
|
|
21
|
+
visible?: Responsive<boolean>;
|
|
22
|
+
width?: Responsive<number | string>;
|
|
23
|
+
}
|
|
24
|
+
export declare function useTableElement(): React.RefObject<HTMLTableElement | null>;
|
|
25
|
+
export interface TableProps extends Omit<HTMLAttributes<HTMLTableElement>, 'children' | 'onResize'> {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
columns?: TableColumnConfig[];
|
|
28
|
+
flexibleLastColumn?: boolean;
|
|
29
|
+
minimumColumnWidth?: number;
|
|
30
|
+
onColumnResize?: (index: number, width: number) => void;
|
|
31
|
+
prependColumnWidths?: string[];
|
|
32
|
+
ref?: RefObject<HTMLTableElement | null>;
|
|
33
|
+
}
|
|
34
|
+
export declare function Table({ children, columns, flexibleLastColumn, minimumColumnWidth, onColumnResize, prependColumnWidths, ref, ...props }: TableProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
35
|
+
export declare namespace Table {
|
|
36
|
+
var Body: (props: ComponentProps<typeof TableBody>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
37
|
+
var Cell: (props: ComponentProps<typeof TableCell>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
38
|
+
var Head: (props: ComponentProps<typeof TableHead>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
39
|
+
var HeadCell: ({ align, children, columnIndex, onSort, overlays, ref, replace, sort, to, ...props }: HeadCellProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
40
|
+
var Row: (props: ComponentProps<typeof TableRow>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
41
|
+
var Status: ({ children, ...props }: TdHTMLAttributes<HTMLTableCellElement>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
42
|
+
var StatusBody: (props: TdHTMLAttributes<HTMLTableCellElement>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
43
|
+
}
|
|
44
|
+
interface HeadCellProps extends Omit<ThHTMLAttributes<HTMLTableCellElement>, 'align'> {
|
|
45
|
+
align?: ColumnAlign;
|
|
46
|
+
/**
|
|
47
|
+
* The head cell's position in `columns`, which a resizable table passes so the
|
|
48
|
+
* handle knows which column it drags.
|
|
49
|
+
*/
|
|
50
|
+
columnIndex?: number;
|
|
51
|
+
onSort?: (event: React.MouseEvent) => void;
|
|
52
|
+
overlays?: ReactNode;
|
|
53
|
+
ref?: Ref<HTMLTableCellElement>;
|
|
54
|
+
/**
|
|
55
|
+
* Whether `to` should replace the history entry rather than pushing a new one.
|
|
56
|
+
*/
|
|
57
|
+
replace?: boolean;
|
|
58
|
+
sort?: SortDirection;
|
|
59
|
+
/**
|
|
60
|
+
* Sort destination to navigate to on sort.
|
|
61
|
+
*/
|
|
62
|
+
to?: LinkProps['to'];
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Fragment, createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { DragHandle } from "../dragHandle/index.js";
|
|
4
|
+
import { useResponsivePropResolver } from "../layout/index.js";
|
|
5
|
+
import { useStableMergeRef } from "../useStableMergeRef.js";
|
|
6
|
+
import { COLUMN_ALIGN_JUSTIFY, SortableHeaderCell, getAriaSort } from "./sortableHeaderCell.js";
|
|
7
|
+
import { TableBody, TableCell, TableGrid, TableHead, TableHeadCell, TableResizer, TableRow, TableStatusCell } from "./styles.js";
|
|
8
|
+
import { useColumnResize } from "./useColumnResize.js";
|
|
9
|
+
import { useObservedColumnSize } from "./useObservedColumnSize.js";
|
|
10
|
+
const COL_WIDTH_UNDEFINED = -1;
|
|
11
|
+
const COL_WIDTH_MINIMUM = 90;
|
|
12
|
+
function withHiddenBase(visible) {
|
|
13
|
+
if (void 0 === visible || 'boolean' == typeof visible) return visible ?? true;
|
|
14
|
+
return {
|
|
15
|
+
zero: false,
|
|
16
|
+
...visible
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function getDefaultColumnTrack(width, { flexible, minimumColumnWidth }) {
|
|
20
|
+
if ('string' == typeof width) return width;
|
|
21
|
+
if (void 0 === width || width === COL_WIDTH_UNDEFINED) return `minmax(${minimumColumnWidth}px, auto)`;
|
|
22
|
+
if (width > minimumColumnWidth) return flexible ? `minmax(${width}px, auto)` : `${width}px`;
|
|
23
|
+
return flexible ? `minmax(${minimumColumnWidth}px, auto)` : `${minimumColumnWidth}px`;
|
|
24
|
+
}
|
|
25
|
+
const TableContext = /*#__PURE__*/ createContext(null);
|
|
26
|
+
function useTableContext() {
|
|
27
|
+
return useContext(TableContext);
|
|
28
|
+
}
|
|
29
|
+
const DETACHED_TABLE_REF = {
|
|
30
|
+
current: null
|
|
31
|
+
};
|
|
32
|
+
function useTableElement() {
|
|
33
|
+
return useTableContext()?.tableRef ?? DETACHED_TABLE_REF;
|
|
34
|
+
}
|
|
35
|
+
const EMPTY_COLUMNS = [];
|
|
36
|
+
function Table({ children, columns = EMPTY_COLUMNS, flexibleLastColumn = true, minimumColumnWidth = COL_WIDTH_MINIMUM, onColumnResize, prependColumnWidths, ref, ...props }) {
|
|
37
|
+
const internalRef = useRef(null);
|
|
38
|
+
const gridRef = ref ?? internalRef;
|
|
39
|
+
const [internalWidths, setInternalWidths] = useState({});
|
|
40
|
+
const isControlled = !!onColumnResize;
|
|
41
|
+
const resolveResponsiveProp = useResponsivePropResolver();
|
|
42
|
+
const resolvedColumns = [];
|
|
43
|
+
const visibleColumns = [];
|
|
44
|
+
for (const { visible, width, ...column } of columns){
|
|
45
|
+
const resolved = {
|
|
46
|
+
...column,
|
|
47
|
+
hidden: !resolveResponsiveProp(withHiddenBase(visible)),
|
|
48
|
+
width: resolveResponsiveProp(width)
|
|
49
|
+
};
|
|
50
|
+
resolvedColumns.push(resolved);
|
|
51
|
+
if (!resolved.hidden) visibleColumns.push(resolved);
|
|
52
|
+
}
|
|
53
|
+
const lastVisibleIndex = resolvedColumns.findLastIndex((column)=>!column.hidden);
|
|
54
|
+
const trackIndexes = resolvedColumns.map((_, index)=>resolvedColumns.slice(0, index).filter((column)=>!column.hidden).length);
|
|
55
|
+
const resolveWidth = (column)=>isControlled ? column.width : internalWidths[column.key] ?? column.width;
|
|
56
|
+
const buildTemplate = (overrideIndex, overrideWidth)=>{
|
|
57
|
+
const overrideTrack = void 0 === overrideIndex ? void 0 : trackIndexes[overrideIndex];
|
|
58
|
+
const tracks = visibleColumns.map((column, index)=>getDefaultColumnTrack(index === overrideTrack ? overrideWidth : resolveWidth(column), {
|
|
59
|
+
flexible: flexibleLastColumn && index === visibleColumns.length - 1,
|
|
60
|
+
minimumColumnWidth
|
|
61
|
+
}));
|
|
62
|
+
if (!tracks.length) return '';
|
|
63
|
+
return [
|
|
64
|
+
...prependColumnWidths ?? [],
|
|
65
|
+
...tracks
|
|
66
|
+
].join(' ');
|
|
67
|
+
};
|
|
68
|
+
const commitWidth = (index, width)=>{
|
|
69
|
+
const key = resolvedColumns[index]?.key;
|
|
70
|
+
if (onColumnResize) onColumnResize(index, width);
|
|
71
|
+
else if (key) setInternalWidths((current)=>({
|
|
72
|
+
...current,
|
|
73
|
+
[key]: width
|
|
74
|
+
}));
|
|
75
|
+
};
|
|
76
|
+
const { applyTemplate, onResizeEnd, onResizeMove, onResizeStart } = useColumnResize({
|
|
77
|
+
gridRef,
|
|
78
|
+
getResizeTemplate: (index, newWidth)=>buildTemplate(index, Math.max(newWidth, minimumColumnWidth)),
|
|
79
|
+
onColumnResizeEnd: (index, newWidth)=>commitWidth(index, Math.max(newWidth, minimumColumnWidth))
|
|
80
|
+
});
|
|
81
|
+
const template = buildTemplate();
|
|
82
|
+
const redraw = useCallback(()=>{
|
|
83
|
+
if (template) applyTemplate(template);
|
|
84
|
+
}, [
|
|
85
|
+
applyTemplate,
|
|
86
|
+
template
|
|
87
|
+
]);
|
|
88
|
+
useLayoutEffect(()=>{
|
|
89
|
+
redraw();
|
|
90
|
+
}, [
|
|
91
|
+
redraw
|
|
92
|
+
]);
|
|
93
|
+
useEffect(()=>{
|
|
94
|
+
window.addEventListener('resize', redraw);
|
|
95
|
+
return ()=>window.removeEventListener('resize', redraw);
|
|
96
|
+
}, [
|
|
97
|
+
redraw
|
|
98
|
+
]);
|
|
99
|
+
const contextValue = {
|
|
100
|
+
lastColumnIndex: lastVisibleIndex,
|
|
101
|
+
minimumColumnWidth,
|
|
102
|
+
onResetColumnSize: (event, index)=>{
|
|
103
|
+
event.stopPropagation();
|
|
104
|
+
applyTemplate(buildTemplate(index, COL_WIDTH_UNDEFINED));
|
|
105
|
+
commitWidth(index, COL_WIDTH_UNDEFINED);
|
|
106
|
+
},
|
|
107
|
+
onResizeEnd,
|
|
108
|
+
onResizeMove,
|
|
109
|
+
onResizeStart,
|
|
110
|
+
resizableByIndex: resolvedColumns.map((column)=>!column.hidden && false !== column.resizable),
|
|
111
|
+
tableRef: gridRef
|
|
112
|
+
};
|
|
113
|
+
return /*#__PURE__*/ jsx(TableContext, {
|
|
114
|
+
value: contextValue,
|
|
115
|
+
children: /*#__PURE__*/ jsx(TableGrid, {
|
|
116
|
+
role: "table",
|
|
117
|
+
...props,
|
|
118
|
+
hiddenColumnIndexes: resolvedColumns.flatMap((column, index)=>column.hidden ? [
|
|
119
|
+
index
|
|
120
|
+
] : []),
|
|
121
|
+
ref: gridRef,
|
|
122
|
+
style: template ? {
|
|
123
|
+
...props.style,
|
|
124
|
+
gridTemplateColumns: template
|
|
125
|
+
} : props.style,
|
|
126
|
+
children: children
|
|
127
|
+
})
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function Head(props) {
|
|
131
|
+
return /*#__PURE__*/ jsx(TableHead, {
|
|
132
|
+
role: "rowgroup",
|
|
133
|
+
...props
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function Body(props) {
|
|
137
|
+
return /*#__PURE__*/ jsx(TableBody, {
|
|
138
|
+
role: "rowgroup",
|
|
139
|
+
...props
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function Row(props) {
|
|
143
|
+
return /*#__PURE__*/ jsx(TableRow, {
|
|
144
|
+
role: "row",
|
|
145
|
+
...props
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function Cell(props) {
|
|
149
|
+
return /*#__PURE__*/ jsx(TableCell, {
|
|
150
|
+
role: "cell",
|
|
151
|
+
...props
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function HeadCell({ align, children, columnIndex, onSort, overlays, ref, replace, sort, to, ...props }) {
|
|
155
|
+
const context = useTableContext();
|
|
156
|
+
const index = columnIndex;
|
|
157
|
+
const showResizer = null !== context && void 0 !== index && index !== context.lastColumnIndex && true === context.resizableByIndex[index];
|
|
158
|
+
const sortable = !!onSort || !!sort || !!overlays || !!to;
|
|
159
|
+
const cellRef = useRef(null);
|
|
160
|
+
const getMergedRef = useStableMergeRef(cellRef);
|
|
161
|
+
const { max, width } = useObservedColumnSize(cellRef);
|
|
162
|
+
const fallbackId = useId();
|
|
163
|
+
const cellId = props.id || fallbackId;
|
|
164
|
+
return /*#__PURE__*/ jsxs(TableHeadCell, {
|
|
165
|
+
"aria-sort": getAriaSort(sort),
|
|
166
|
+
...props,
|
|
167
|
+
id: cellId,
|
|
168
|
+
justify: align && COLUMN_ALIGN_JUSTIFY[align],
|
|
169
|
+
ref: getMergedRef(ref),
|
|
170
|
+
role: "columnheader",
|
|
171
|
+
children: [
|
|
172
|
+
sortable ? /*#__PURE__*/ jsx(SortableHeaderCell, {
|
|
173
|
+
align: align,
|
|
174
|
+
direction: sort,
|
|
175
|
+
onSort: onSort,
|
|
176
|
+
overlays: overlays,
|
|
177
|
+
replace: replace,
|
|
178
|
+
to: to,
|
|
179
|
+
children: children
|
|
180
|
+
}) : /*#__PURE__*/ jsxs(Fragment, {
|
|
181
|
+
children: [
|
|
182
|
+
overlays,
|
|
183
|
+
children
|
|
184
|
+
]
|
|
185
|
+
}),
|
|
186
|
+
showResizer && /*#__PURE__*/ jsx(TableResizer, {
|
|
187
|
+
onContextMenu: (event)=>event.preventDefault(),
|
|
188
|
+
children: /*#__PURE__*/ jsx(DragHandle, {
|
|
189
|
+
"aria-labelledby": cellId,
|
|
190
|
+
isSizedFirst: true,
|
|
191
|
+
max: Math.max(max, context.minimumColumnWidth),
|
|
192
|
+
min: context.minimumColumnWidth,
|
|
193
|
+
orientation: "horizontal",
|
|
194
|
+
value: Math.max(width, context.minimumColumnWidth),
|
|
195
|
+
variant: "ghost",
|
|
196
|
+
onDoubleClick: (event)=>context.onResetColumnSize(event, index),
|
|
197
|
+
onMove: context.onResizeMove,
|
|
198
|
+
onMoveEnd: context.onResizeEnd,
|
|
199
|
+
onMoveStart: ()=>context.onResizeStart(index, cellRef.current)
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
]
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function Status({ children, ...props }) {
|
|
206
|
+
return /*#__PURE__*/ jsx(Row, {
|
|
207
|
+
children: /*#__PURE__*/ jsx(TableStatusCell, {
|
|
208
|
+
...props,
|
|
209
|
+
role: "cell",
|
|
210
|
+
children: children
|
|
211
|
+
})
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function StatusBody(props) {
|
|
215
|
+
return /*#__PURE__*/ jsx(Body, {
|
|
216
|
+
children: /*#__PURE__*/ jsx(Status, {
|
|
217
|
+
...props
|
|
218
|
+
})
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
Table.Body = Body;
|
|
222
|
+
Table.Cell = Cell;
|
|
223
|
+
Table.Head = Head;
|
|
224
|
+
Table.HeadCell = HeadCell;
|
|
225
|
+
Table.Row = Row;
|
|
226
|
+
Table.Status = Status;
|
|
227
|
+
Table.StatusBody = StatusBody;
|
|
228
|
+
export { COL_WIDTH_MINIMUM, COL_WIDTH_UNDEFINED, Table, useTableElement };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
interface UseColumnResizeOptions<T extends HTMLElement> {
|
|
3
|
+
/**
|
|
4
|
+
* Build the `gridTemplateColumns` string while `columnIndex` is being resized to `newWidth`.
|
|
5
|
+
*/
|
|
6
|
+
getResizeTemplate: (columnIndex: number, newWidth: number) => string;
|
|
7
|
+
/**
|
|
8
|
+
* The grid element whose `gridTemplateColumns` is mutated during a resize.
|
|
9
|
+
*/
|
|
10
|
+
gridRef: React.RefObject<T | null>;
|
|
11
|
+
/**
|
|
12
|
+
* Persist the finalized width once the resize ends.
|
|
13
|
+
*/
|
|
14
|
+
onColumnResizeEnd?: (columnIndex: number, newWidth: number) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Shared column-resize mechanic for the sanctioned table shells. Owns the width
|
|
18
|
+
* accumulation and the imperative write to the grid's `gridTemplateColumns`; the
|
|
19
|
+
* handles themselves own the interaction and report movement as a delta.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useColumnResize<T extends HTMLElement>({ gridRef, getResizeTemplate, onColumnResizeEnd, }: UseColumnResizeOptions<T>): {
|
|
22
|
+
applyTemplate: (template: string) => void;
|
|
23
|
+
onResizeEnd: () => void;
|
|
24
|
+
onResizeMove: (delta: number) => void;
|
|
25
|
+
onResizeStart: (columnIndex: number, cell: HTMLElement | null) => void;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
function useColumnResize({ gridRef, getResizeTemplate, onColumnResizeEnd }) {
|
|
3
|
+
const resizeStateRef = useRef(null);
|
|
4
|
+
const frameRef = useRef(null);
|
|
5
|
+
const cancelPendingFrame = useCallback(()=>{
|
|
6
|
+
if (null !== frameRef.current) {
|
|
7
|
+
window.cancelAnimationFrame(frameRef.current);
|
|
8
|
+
frameRef.current = null;
|
|
9
|
+
}
|
|
10
|
+
}, []);
|
|
11
|
+
const applyTemplate = useCallback((template)=>{
|
|
12
|
+
const grid = gridRef.current;
|
|
13
|
+
if (!grid) return;
|
|
14
|
+
grid.style.gridTemplateColumns = template;
|
|
15
|
+
}, [
|
|
16
|
+
gridRef
|
|
17
|
+
]);
|
|
18
|
+
const onResizeStart = useCallback((columnIndex, cell)=>{
|
|
19
|
+
resizeStateRef.current = {
|
|
20
|
+
columnIndex,
|
|
21
|
+
moved: false,
|
|
22
|
+
width: cell?.offsetWidth ?? 0
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
const onResizeMove = useCallback((delta)=>{
|
|
26
|
+
const state = resizeStateRef.current;
|
|
27
|
+
if (!state) return;
|
|
28
|
+
state.width += delta;
|
|
29
|
+
state.moved = true;
|
|
30
|
+
cancelPendingFrame();
|
|
31
|
+
frameRef.current = window.requestAnimationFrame(()=>{
|
|
32
|
+
frameRef.current = null;
|
|
33
|
+
applyTemplate(getResizeTemplate(state.columnIndex, Math.round(state.width)));
|
|
34
|
+
});
|
|
35
|
+
}, [
|
|
36
|
+
applyTemplate,
|
|
37
|
+
cancelPendingFrame,
|
|
38
|
+
getResizeTemplate
|
|
39
|
+
]);
|
|
40
|
+
const onResizeEnd = useCallback(()=>{
|
|
41
|
+
const state = resizeStateRef.current;
|
|
42
|
+
if (!state) return;
|
|
43
|
+
cancelPendingFrame();
|
|
44
|
+
resizeStateRef.current = null;
|
|
45
|
+
if (!state.moved) return;
|
|
46
|
+
const width = Math.round(state.width);
|
|
47
|
+
applyTemplate(getResizeTemplate(state.columnIndex, width));
|
|
48
|
+
onColumnResizeEnd?.(state.columnIndex, width);
|
|
49
|
+
}, [
|
|
50
|
+
applyTemplate,
|
|
51
|
+
cancelPendingFrame,
|
|
52
|
+
getResizeTemplate,
|
|
53
|
+
onColumnResizeEnd
|
|
54
|
+
]);
|
|
55
|
+
return {
|
|
56
|
+
applyTemplate,
|
|
57
|
+
onResizeEnd,
|
|
58
|
+
onResizeMove,
|
|
59
|
+
onResizeStart
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export { useColumnResize };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Measures the column a resize handle belongs to, for the values the handle
|
|
4
|
+
* announces, the height it should span as `--column-resizer-height`, and the
|
|
5
|
+
* header row height its pointer target is capped to as
|
|
6
|
+
* `--drag-separator-target-length`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useObservedColumnSize(elementRef: React.RefObject<HTMLElement | null>): {
|
|
9
|
+
max: number;
|
|
10
|
+
width: number;
|
|
11
|
+
cell: HTMLTableCellElement | null;
|
|
12
|
+
};
|