@sentry/scraps 0.2.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/dist/button/buttonBar.js +7 -1
- 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/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/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/overlayPositioning.d.ts +10 -1
- package/dist/overlayPositioning.js +15 -2
- 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 +1 -1
- package/dist/text/text.d.ts +7 -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/useOverlay.js +2 -1
- package/package.json +27 -1
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useMemo, useState } from "react";
|
|
2
|
+
import { useResizeObserver } from "@react-aria/utils";
|
|
3
|
+
const NO_ANCESTORS = {
|
|
4
|
+
cell: null,
|
|
5
|
+
table: null
|
|
6
|
+
};
|
|
7
|
+
function setProperty(element, property, value) {
|
|
8
|
+
if (element.style.getPropertyValue(property) !== value) element.style.setProperty(property, value);
|
|
9
|
+
}
|
|
10
|
+
function measureColumn(element, cell, table) {
|
|
11
|
+
setProperty(element, '--column-resizer-height', `${table.clientHeight}px`);
|
|
12
|
+
setProperty(element, '--drag-separator-target-length', `${cell.offsetHeight}px`);
|
|
13
|
+
return {
|
|
14
|
+
max: Math.max(table.clientWidth, cell.offsetWidth),
|
|
15
|
+
width: cell.offsetWidth
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function useObservedColumnSize(elementRef) {
|
|
19
|
+
const [measurements, setMeasurements] = useState({
|
|
20
|
+
max: 0,
|
|
21
|
+
width: 0
|
|
22
|
+
});
|
|
23
|
+
const [{ cell, table }, setAncestors] = useState(NO_ANCESTORS);
|
|
24
|
+
const measure = useCallback((element, target, grid)=>{
|
|
25
|
+
const next = measureColumn(element, target, grid);
|
|
26
|
+
setMeasurements((current)=>current.max === next.max && current.width === next.width ? current : next);
|
|
27
|
+
}, []);
|
|
28
|
+
useLayoutEffect(()=>{
|
|
29
|
+
const element = elementRef.current;
|
|
30
|
+
const foundCell = element?.closest('th') ?? null;
|
|
31
|
+
const foundTable = foundCell?.closest('table') ?? null;
|
|
32
|
+
setAncestors({
|
|
33
|
+
cell: foundCell,
|
|
34
|
+
table: foundTable
|
|
35
|
+
});
|
|
36
|
+
if (element && foundCell && foundTable) measure(element, foundCell, foundTable);
|
|
37
|
+
}, [
|
|
38
|
+
elementRef,
|
|
39
|
+
measure
|
|
40
|
+
]);
|
|
41
|
+
const cellRef = useMemo(()=>({
|
|
42
|
+
current: cell
|
|
43
|
+
}), [
|
|
44
|
+
cell
|
|
45
|
+
]);
|
|
46
|
+
const tableRef = useMemo(()=>({
|
|
47
|
+
current: table
|
|
48
|
+
}), [
|
|
49
|
+
table
|
|
50
|
+
]);
|
|
51
|
+
const onResize = useCallback(()=>{
|
|
52
|
+
const element = elementRef.current;
|
|
53
|
+
if (!element || !cell || !table) return;
|
|
54
|
+
measure(element, cell, table);
|
|
55
|
+
}, [
|
|
56
|
+
cell,
|
|
57
|
+
elementRef,
|
|
58
|
+
measure,
|
|
59
|
+
table
|
|
60
|
+
]);
|
|
61
|
+
useResizeObserver({
|
|
62
|
+
ref: cellRef,
|
|
63
|
+
onResize
|
|
64
|
+
});
|
|
65
|
+
useResizeObserver({
|
|
66
|
+
ref: tableRef,
|
|
67
|
+
onResize
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
cell,
|
|
71
|
+
...measurements
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export { useObservedColumnSize };
|
package/dist/text/heading.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type * as React from 'react';
|
|
|
2
2
|
import { type Responsive } from '../layout/index.js';
|
|
3
3
|
import type { HeadingSize } from '../theme/index.js';
|
|
4
4
|
import { type BaseTextProps } from './text.js';
|
|
5
|
-
type BaseHeadingProps = Omit<BaseTextProps, 'bold' | 'uppercase'>;
|
|
5
|
+
type BaseHeadingProps = Omit<BaseTextProps, 'bold' | 'uppercase' | 'trim'>;
|
|
6
6
|
type ExclusiveHeadingEllipsisProps = {
|
|
7
7
|
ellipsis?: true;
|
|
8
8
|
wrap?: never;
|
package/dist/text/text.d.ts
CHANGED
|
@@ -56,6 +56,13 @@ export interface BaseTextProps {
|
|
|
56
56
|
* @default undefined
|
|
57
57
|
*/
|
|
58
58
|
textWrap?: 'wrap' | 'nowrap' | 'balance' | 'pretty' | 'stable';
|
|
59
|
+
/**
|
|
60
|
+
* Trims the text box to the glyph bounds with `text-box-trim`. Set to false when
|
|
61
|
+
* the content is taller than a line of text, such as a tag or pill, so it isn't
|
|
62
|
+
* clipped when combined with `ellipsis`.
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
trim?: boolean;
|
|
59
66
|
/**
|
|
60
67
|
* Determines how text should be underlined.
|
|
61
68
|
* @default undefined
|
package/dist/text/text.js
CHANGED
|
@@ -49,7 +49,7 @@ const getTextStyles = (p)=>css`
|
|
|
49
49
|
text-transform: ${p.uppercase ? 'uppercase' : void 0};
|
|
50
50
|
|
|
51
51
|
text-box-edge: text text;
|
|
52
|
-
text-box-trim: trim-both;
|
|
52
|
+
text-box-trim: ${false === p.trim ? 'none' : 'trim-both'};
|
|
53
53
|
`;
|
|
54
54
|
const Text = styled((props)=>{
|
|
55
55
|
if ('function' == typeof props.children) return props.children({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TextArea, type TextAreaProps } from './textarea.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TextArea } from "./textarea.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type TextareaAutosizeProps } from 'react-textarea-autosize';
|
|
3
|
+
import { type InputStylesProps } from '../input/inputStyles.js';
|
|
4
|
+
export interface TextAreaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'css' | 'onResize' | 'style'>, InputStylesProps {
|
|
5
|
+
/**
|
|
6
|
+
* Enable autosizing of the textarea.
|
|
7
|
+
*/
|
|
8
|
+
autosize?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Max number of rows to default to.
|
|
11
|
+
*/
|
|
12
|
+
maxRows?: number;
|
|
13
|
+
ref?: React.Ref<HTMLTextAreaElement>;
|
|
14
|
+
/**
|
|
15
|
+
* Number of rows to default to.
|
|
16
|
+
*/
|
|
17
|
+
rows?: number;
|
|
18
|
+
style?: TextareaAutosizeProps['style'];
|
|
19
|
+
}
|
|
20
|
+
export declare const TextArea: import("@emotion/styled").StyledComponent<TextAreaProps & {
|
|
21
|
+
theme?: import("@emotion/react").Theme;
|
|
22
|
+
}, {}, {}>;
|