@wallarm-org/design-system 1.20.4 → 1.22.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/components/AppShell/story-content/_storySearchModal.js +3 -3
- package/dist/components/CodeSnippet/CodeSnippetCopyButton.d.ts +1 -1
- package/dist/components/CodeSnippet/CodeSnippetCopyButton.js +14 -7
- package/dist/components/CodeSnippet/InlineCodeSnippet.js +7 -25
- package/dist/components/Copyable/Copyable.d.ts +39 -0
- package/dist/components/Copyable/Copyable.js +85 -0
- package/dist/components/Copyable/CopyableContext.d.ts +11 -0
- package/dist/components/Copyable/CopyableContext.js +9 -0
- package/dist/components/Copyable/CopyableIcon.d.ts +9 -0
- package/dist/components/Copyable/CopyableIcon.js +13 -0
- package/dist/components/Copyable/CopyableLabel.d.ts +18 -0
- package/dist/components/Copyable/CopyableLabel.js +24 -0
- package/dist/components/Copyable/index.d.ts +4 -0
- package/dist/components/Copyable/index.js +4 -0
- package/dist/components/SearchInput/SearchInput.d.ts +18 -0
- package/dist/components/SearchInput/SearchInput.js +54 -0
- package/dist/components/SearchInput/index.d.ts +1 -0
- package/dist/components/SearchInput/index.js +1 -0
- package/dist/components/SearchModal/SearchModalInput.js +16 -3
- package/dist/components/SegmentedControl/classes.js +1 -1
- package/dist/components/Select/Select.d.ts +3 -1
- package/dist/components/Select/Select.js +6 -3
- package/dist/components/Select/SelectSearchInput.js +6 -19
- package/dist/components/SettingsHeader/SettingsHeader.d.ts +7 -0
- package/dist/components/SettingsHeader/SettingsHeader.js +16 -0
- package/dist/components/SettingsHeader/SettingsHeaderActions.d.ts +6 -0
- package/dist/components/SettingsHeader/SettingsHeaderActions.js +16 -0
- package/dist/components/SettingsHeader/SettingsHeaderBreadcrumbs.d.ts +6 -0
- package/dist/components/SettingsHeader/SettingsHeaderBreadcrumbs.js +16 -0
- package/dist/components/SettingsHeader/SettingsHeaderDescription.d.ts +5 -0
- package/dist/components/SettingsHeader/SettingsHeaderDescription.js +16 -0
- package/dist/components/SettingsHeader/SettingsHeaderFilters.d.ts +6 -0
- package/dist/components/SettingsHeader/SettingsHeaderFilters.js +16 -0
- package/dist/components/SettingsHeader/SettingsHeaderHeading.d.ts +6 -0
- package/dist/components/SettingsHeader/SettingsHeaderHeading.js +16 -0
- package/dist/components/SettingsHeader/SettingsHeaderTitle.d.ts +5 -0
- package/dist/components/SettingsHeader/SettingsHeaderTitle.js +16 -0
- package/dist/components/SettingsHeader/index.d.ts +7 -0
- package/dist/components/SettingsHeader/index.js +7 -0
- package/dist/components/Table/EditableCell/EditableSelectCell.d.ts +1 -1
- package/dist/components/Table/EditableCell/EditableSelectCell.js +12 -1
- package/dist/components/Table/StickyGroupParent.js +7 -8
- package/dist/components/Table/TableBody/TableBodyCell.d.ts +3 -1
- package/dist/components/Table/TableBody/TableBodyCell.js +6 -2
- package/dist/components/Table/TableBody/TableBodyRowDndContext.d.ts +5 -0
- package/dist/components/Table/TableBody/TableBodyRowDndContext.js +65 -21
- package/dist/components/Table/TableBody/TableRowOverlay.js +2 -1
- package/dist/components/Table/TableColGroup.js +20 -17
- package/dist/components/Table/TableContext/TableProvider.js +3 -1
- package/dist/components/Table/TableContext/types.d.ts +1 -0
- package/dist/components/Table/TableHead.js +13 -8
- package/dist/components/Table/TableLoadingState.js +19 -13
- package/dist/components/Table/TableMasterCellActions.js +2 -5
- package/dist/components/Table/TableRow.js +42 -12
- package/dist/components/Table/TableRowExpanded.js +3 -2
- package/dist/components/Table/classes.d.ts +5 -0
- package/dist/components/Table/classes.js +2 -1
- package/dist/components/Table/hooks/useStickyGroupParent.js +3 -1
- package/dist/components/Table/lib/constants.d.ts +1 -1
- package/dist/components/Table/lib/constants.js +1 -1
- package/dist/components/Table/lib/createDragHandleColumn.js +3 -3
- package/dist/components/Table/lib/useRowDnd.js +3 -13
- package/dist/components/Table/types.d.ts +8 -0
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +0 -1
- package/dist/hooks/useCopyToClipboard.d.ts +9 -10
- package/dist/hooks/useCopyToClipboard.js +6 -18
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/metadata/components.json +12502 -9142
- package/package.json +1 -1
- package/dist/components/CopyButton/CopyButton.d.ts +0 -16
- package/dist/components/CopyButton/CopyButton.js +0 -63
- package/dist/components/CopyButton/index.d.ts +0 -1
- package/dist/components/CopyButton/index.js +0 -1
- package/dist/hooks/useCopyTooltip.d.ts +0 -12
- package/dist/hooks/useCopyTooltip.js +0 -63
|
@@ -2,9 +2,11 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { memo, useCallback } from "react";
|
|
3
3
|
import { cn } from "../../utils/cn.js";
|
|
4
4
|
import { useTestId } from "../../utils/testId.js";
|
|
5
|
+
import { DROP_INDICATOR_BASE } from "./classes.js";
|
|
5
6
|
import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID, useRowDnd } from "./lib/index.js";
|
|
6
7
|
import { Td, Tr } from "./primitives/index.js";
|
|
7
8
|
import { TableBodyCell } from "./TableBody/TableBodyCell.js";
|
|
9
|
+
import { useRowDndIndicator } from "./TableBody/TableBodyRowDndContext.js";
|
|
8
10
|
import { useTableContext } from "./TableContext/index.js";
|
|
9
11
|
import { TableRowExpanded } from "./TableRowExpanded.js";
|
|
10
12
|
const SYSTEM_COLUMN_IDS = new Set([
|
|
@@ -13,9 +15,10 @@ const SYSTEM_COLUMN_IDS = new Set([
|
|
|
13
15
|
TABLE_DRAG_HANDLE_COLUMN_ID
|
|
14
16
|
]);
|
|
15
17
|
const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
|
|
16
|
-
const { table, expandingEnabled, activeRowId, isLoading, renderExpandedRow } = useTableContext();
|
|
18
|
+
const { table, expandingEnabled, activeRowId, isLoading, renderExpandedRow, stretch, hasSubRowGrouping, allLeafColumns } = useTableContext();
|
|
17
19
|
const testId = useTestId('row');
|
|
18
20
|
const { canDnd, isDragging, setNodeRef, style: dndStyle, attributes, listeners } = useRowDnd(row);
|
|
21
|
+
const { activeId, overId } = useRowDndIndicator();
|
|
19
22
|
const isGroupParent = row.subRows.length > 0;
|
|
20
23
|
const isSelected = isGroupParent ? row.getIsAllSubRowsSelected() : row.getIsSelected();
|
|
21
24
|
const isPreviewActive = activeRowId === row.id;
|
|
@@ -38,6 +41,11 @@ const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
|
|
|
38
41
|
const systemCells = cells.filter((c)=>SYSTEM_COLUMN_IDS.has(c.column.id));
|
|
39
42
|
const dataCells = cells.filter((c)=>!SYSTEM_COLUMN_IDS.has(c.column.id));
|
|
40
43
|
const firstDataCell = dataCells[0];
|
|
44
|
+
const stickyStyle = hasSubRowGrouping && row.getIsExpanded() ? {
|
|
45
|
+
position: 'sticky',
|
|
46
|
+
top: allLeafColumns.some((c)=>c.columnDef.meta?.description?.type === 'text') ? 48 : 32,
|
|
47
|
+
zIndex: 20
|
|
48
|
+
} : void 0;
|
|
41
49
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
42
50
|
children: [
|
|
43
51
|
/*#__PURE__*/ jsxs(Tr, {
|
|
@@ -49,6 +57,7 @@ const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
|
|
|
49
57
|
"data-selected": isSelected || void 0,
|
|
50
58
|
"data-preview-active": isPreviewActive || void 0,
|
|
51
59
|
"aria-selected": isSelected || void 0,
|
|
60
|
+
style: stickyStyle,
|
|
52
61
|
children: [
|
|
53
62
|
systemCells.map((cell)=>/*#__PURE__*/ jsx(TableBodyCell, {
|
|
54
63
|
cell: cell,
|
|
@@ -67,7 +76,11 @@ const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
|
|
|
67
76
|
width: cell.column.getSize()
|
|
68
77
|
},
|
|
69
78
|
"aria-hidden": "true"
|
|
70
|
-
}, cell.id))
|
|
79
|
+
}, cell.id)),
|
|
80
|
+
!stretch && /*#__PURE__*/ jsx(Td, {
|
|
81
|
+
pinned: false,
|
|
82
|
+
"aria-hidden": true
|
|
83
|
+
})
|
|
71
84
|
]
|
|
72
85
|
}),
|
|
73
86
|
expandingEnabled && /*#__PURE__*/ jsx(TableRowExpanded, {
|
|
@@ -77,9 +90,15 @@ const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
|
|
|
77
90
|
]
|
|
78
91
|
});
|
|
79
92
|
}
|
|
93
|
+
let dropIndicator;
|
|
94
|
+
if (overId === row.id && null != activeId && activeId !== row.id) {
|
|
95
|
+
const activeIndex = flatRows.findIndex((r)=>r.id === activeId);
|
|
96
|
+
const overIndex = flatRows.findIndex((r)=>r.id === row.id);
|
|
97
|
+
if (-1 !== activeIndex && -1 !== overIndex) dropIndicator = activeIndex < overIndex ? 'below' : 'above';
|
|
98
|
+
}
|
|
80
99
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
81
100
|
children: [
|
|
82
|
-
/*#__PURE__*/
|
|
101
|
+
/*#__PURE__*/ jsxs(Tr, {
|
|
83
102
|
ref: composedRef,
|
|
84
103
|
"data-index": dataIndex,
|
|
85
104
|
"data-row-id": row.id,
|
|
@@ -91,15 +110,26 @@ const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
|
|
|
91
110
|
"aria-selected": isSelected || void 0,
|
|
92
111
|
"data-depth": row.depth > 0 ? row.depth : void 0,
|
|
93
112
|
style: dndStyle,
|
|
94
|
-
children:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
children: [
|
|
114
|
+
row.getVisibleCells().map((cell)=>{
|
|
115
|
+
const isDragHandle = cell.column.id === TABLE_DRAG_HANDLE_COLUMN_ID;
|
|
116
|
+
return /*#__PURE__*/ jsx(TableBodyCell, {
|
|
117
|
+
cell: cell,
|
|
118
|
+
dragListeners: isDragHandle ? listeners : void 0,
|
|
119
|
+
dragAttributes: isDragHandle ? attributes : void 0,
|
|
120
|
+
lastRow: isLastRow,
|
|
121
|
+
dropIndicator: dropIndicator
|
|
122
|
+
}, cell.id);
|
|
123
|
+
}),
|
|
124
|
+
!stretch && /*#__PURE__*/ jsx(Td, {
|
|
125
|
+
pinned: false,
|
|
126
|
+
"aria-hidden": true,
|
|
127
|
+
className: cn(dropIndicator && DROP_INDICATOR_BASE, 'above' === dropIndicator && 'after:top-0', 'below' === dropIndicator && 'after:-bottom-px'),
|
|
128
|
+
style: dropIndicator ? {
|
|
129
|
+
overflow: 'visible'
|
|
130
|
+
} : void 0
|
|
131
|
+
})
|
|
132
|
+
]
|
|
103
133
|
}),
|
|
104
134
|
expandingEnabled && /*#__PURE__*/ jsx(TableRowExpanded, {
|
|
105
135
|
row: row,
|
|
@@ -5,12 +5,13 @@ import { TABLE_EXPAND_COLUMN_ID } from "./lib/index.js";
|
|
|
5
5
|
import { Td, Tr } from "./primitives/index.js";
|
|
6
6
|
import { useTableContext } from "./TableContext/index.js";
|
|
7
7
|
const TableRowExpanded = ({ row, dndStyle, lastRow })=>{
|
|
8
|
-
const { table, renderExpandedRow } = useTableContext();
|
|
8
|
+
const { table, stretch, renderExpandedRow } = useTableContext();
|
|
9
9
|
const testId = useTestId('row-expanded');
|
|
10
10
|
if (!row.getIsExpanded() || !renderExpandedRow) return null;
|
|
11
11
|
const visibleColumns = table.getVisibleLeafColumns();
|
|
12
12
|
const hasExpandColumn = visibleColumns.some((col)=>col.id === TABLE_EXPAND_COLUMN_ID);
|
|
13
|
-
const
|
|
13
|
+
const fillerOffset = stretch ? 0 : 1;
|
|
14
|
+
const contentColSpan = (hasExpandColumn ? visibleColumns.length - 1 : visibleColumns.length) + fillerOffset;
|
|
14
15
|
return /*#__PURE__*/ jsxs(Tr, {
|
|
15
16
|
"data-testid": testId,
|
|
16
17
|
style: dndStyle,
|
|
@@ -16,5 +16,10 @@ export declare const tableContainerVariants: (props?: ({
|
|
|
16
16
|
virtualized?: "container" | "window" | null | undefined;
|
|
17
17
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
18
18
|
export declare const tableRowVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Drop-indicator ::after pseudo-element (shared by TableBodyCell & filler Td).
|
|
21
|
+
* Positioned above borders so the line is uninterrupted across columns.
|
|
22
|
+
*/
|
|
23
|
+
export declare const DROP_INDICATOR_BASE = "after:content-[''] after:absolute after:left-0 after:-right-px after:h-[2px] after:bg-[var(--color-border-strong-brand)] after:pointer-events-none after:z-[1]";
|
|
19
24
|
/** Small icon button used in table header (sort, scroll, menu triggers) */
|
|
20
25
|
export declare const tableHeaderButtonClass: string;
|
|
@@ -73,5 +73,6 @@ const tableContainerVariants = cva('rounded-12 border border-border-primary-ligh
|
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
75
|
const tableRowVariants = cva('transition-colors');
|
|
76
|
+
const DROP_INDICATOR_BASE = "after:content-[''] after:absolute after:left-0 after:-right-px after:h-[2px] after:bg-[var(--color-border-strong-brand)] after:pointer-events-none after:z-[1]";
|
|
76
77
|
const tableHeaderButtonClass = cn('w-16 h-16 shrink-0 hover:text-text-primary', 'focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-focus-primary rounded-2', 'transition-colors cursor-pointer', 'inline-flex items-center justify-center bg-transparent border-0 p-0');
|
|
77
|
-
export { tableBodyCellVariants, tableContainerVariants, tableHeadCellVariants, tableHeaderButtonClass, tableRowVariants };
|
|
78
|
+
export { DROP_INDICATOR_BASE, tableBodyCellVariants, tableContainerVariants, tableHeadCellVariants, tableHeaderButtonClass, tableRowVariants };
|
|
@@ -55,6 +55,7 @@ const useStickyGroupParent = (options)=>{
|
|
|
55
55
|
const [pushUpOffset, setPushUpOffset] = useState(0);
|
|
56
56
|
const rafRef = useRef(0);
|
|
57
57
|
const prevStickyRowIdRef = useRef(null);
|
|
58
|
+
const prevOffsetRef = useRef(0);
|
|
58
59
|
const compute = useCallback(()=>{
|
|
59
60
|
if (!enabled) {
|
|
60
61
|
if (null !== prevStickyRowIdRef.current) {
|
|
@@ -98,8 +99,9 @@ const useStickyGroupParent = (options)=>{
|
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
const newId = foundRow?.id ?? null;
|
|
101
|
-
if (newId !== prevStickyRowIdRef.current ||
|
|
102
|
+
if (newId !== prevStickyRowIdRef.current || offset !== prevOffsetRef.current) {
|
|
102
103
|
prevStickyRowIdRef.current = newId;
|
|
104
|
+
prevOffsetRef.current = offset;
|
|
103
105
|
setStickyRow(foundRow);
|
|
104
106
|
setPushUpOffset(offset);
|
|
105
107
|
}
|
|
@@ -8,7 +8,7 @@ export declare const TABLE_SELECT_COLUMN_WIDTH = 33;
|
|
|
8
8
|
export declare const TABLE_EXPAND_COLUMN_ID = "_expand";
|
|
9
9
|
export declare const TABLE_EXPAND_COLUMN_WIDTH = 33;
|
|
10
10
|
export declare const TABLE_DRAG_HANDLE_COLUMN_ID = "_dragHandle";
|
|
11
|
-
export declare const TABLE_DRAG_HANDLE_COLUMN_WIDTH =
|
|
11
|
+
export declare const TABLE_DRAG_HANDLE_COLUMN_WIDTH = 24;
|
|
12
12
|
export declare const TABLE_END_REACHED_THRESHOLD = 200;
|
|
13
13
|
export declare const TABLE_START_REACHED_THRESHOLD = 200;
|
|
14
14
|
/** Minimum time (ms) between successive edge-reached callbacks. */
|
|
@@ -7,7 +7,7 @@ const TABLE_SELECT_COLUMN_WIDTH = 33;
|
|
|
7
7
|
const TABLE_EXPAND_COLUMN_ID = '_expand';
|
|
8
8
|
const TABLE_EXPAND_COLUMN_WIDTH = 33;
|
|
9
9
|
const TABLE_DRAG_HANDLE_COLUMN_ID = '_dragHandle';
|
|
10
|
-
const TABLE_DRAG_HANDLE_COLUMN_WIDTH =
|
|
10
|
+
const TABLE_DRAG_HANDLE_COLUMN_WIDTH = 24;
|
|
11
11
|
const TABLE_END_REACHED_THRESHOLD = 200;
|
|
12
12
|
const TABLE_START_REACHED_THRESHOLD = 200;
|
|
13
13
|
const SCROLL_EDGE_COOLDOWN_MS = 200;
|
|
@@ -11,13 +11,13 @@ const createDragHandleColumn = ()=>({
|
|
|
11
11
|
enableHiding: false,
|
|
12
12
|
enablePinning: false,
|
|
13
13
|
meta: {
|
|
14
|
-
headerClassName: 'px-
|
|
15
|
-
cellClassName: 'px-
|
|
14
|
+
headerClassName: 'px-4 py-4',
|
|
15
|
+
cellClassName: 'px-4 py-8 align-middle text-center'
|
|
16
16
|
},
|
|
17
17
|
header: ()=>null,
|
|
18
18
|
cell: ()=>/*#__PURE__*/ jsx(GripVertical, {
|
|
19
19
|
size: "sm",
|
|
20
|
-
className: "text-text-
|
|
20
|
+
className: "text-text-secondary"
|
|
21
21
|
})
|
|
22
22
|
});
|
|
23
23
|
export { createDragHandleColumn };
|
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
import { useSortable } from "@dnd-kit/sortable";
|
|
2
|
-
import { CSS } from "@dnd-kit/utilities";
|
|
3
2
|
import { useTableContext } from "../TableContext/useTableContext.js";
|
|
4
3
|
const useRowDnd = (row)=>{
|
|
5
4
|
const { rowDndEnabled } = useTableContext();
|
|
6
5
|
const canDnd = rowDndEnabled && 0 === row.subRows.length;
|
|
7
|
-
const { attributes, listeners, setNodeRef,
|
|
6
|
+
const { attributes, listeners, setNodeRef, isDragging } = useSortable({
|
|
8
7
|
id: row.id,
|
|
9
8
|
disabled: !canDnd
|
|
10
9
|
});
|
|
11
|
-
const style = canDnd ? {
|
|
12
|
-
|
|
13
|
-
...transform,
|
|
14
|
-
x: 0
|
|
15
|
-
} : null),
|
|
16
|
-
transition,
|
|
17
|
-
...isDragging && {
|
|
18
|
-
opacity: 0.5,
|
|
19
|
-
position: 'relative',
|
|
20
|
-
zIndex: 100
|
|
21
|
-
}
|
|
10
|
+
const style = canDnd && isDragging ? {
|
|
11
|
+
opacity: 0.4
|
|
22
12
|
} : {};
|
|
23
13
|
return {
|
|
24
14
|
canDnd,
|
|
@@ -247,6 +247,14 @@ export interface TableProps<T> extends TestableProps {
|
|
|
247
247
|
onSettingsOpenChange?: (open: boolean) => void;
|
|
248
248
|
/** Enable row virtualization. `'container'` virtualizes within the scroll container; `'window'` virtualizes against the browser window. */
|
|
249
249
|
virtualized?: TableVirtualized;
|
|
250
|
+
/**
|
|
251
|
+
* Whether columns stretch proportionally to fill the container width.
|
|
252
|
+
* When `false`, columns use their defined sizes and the table may be
|
|
253
|
+
* narrower than its container.
|
|
254
|
+
*
|
|
255
|
+
* Default: `true`.
|
|
256
|
+
*/
|
|
257
|
+
stretch?: boolean;
|
|
250
258
|
estimateRowHeight?: (index: number) => number;
|
|
251
259
|
overscan?: number;
|
|
252
260
|
/** Callback fired when the user scrolls near the end (bottom) of the table */
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { useArrowNav } from './useArrowNav';
|
|
2
2
|
export { useControlled } from './useControlled';
|
|
3
3
|
export { useCopyToClipboard } from './useCopyToClipboard';
|
|
4
|
-
export { useCopyTooltip } from './useCopyTooltip';
|
|
5
4
|
export { useIsKeyPressed } from './useIsKeyPressed';
|
|
6
5
|
export { type UseOverflowItemsOptions, type UseOverflowItemsResult, useOverflowItems, } from './useOverflowItems';
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { useArrowNav } from "./useArrowNav.js";
|
|
2
2
|
export { useControlled } from "./useControlled.js";
|
|
3
3
|
export { useCopyToClipboard } from "./useCopyToClipboard.js";
|
|
4
|
-
export { useCopyTooltip } from "./useCopyTooltip.js";
|
|
5
4
|
export { useIsKeyPressed } from "./useIsKeyPressed.js";
|
|
6
5
|
export { useOverflowItems } from "./useOverflowItems.js";
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hook for copying text to clipboard with status tracking.
|
|
3
3
|
*
|
|
4
|
+
* Uses the Clipboard API with an `execCommand` fallback for older browsers.
|
|
5
|
+
* The `copied` flag auto-resets after `resetDelay` ms.
|
|
6
|
+
*
|
|
4
7
|
* @param resetDelay - Time in ms before `copied` resets to false (default: 2000)
|
|
5
|
-
* @returns
|
|
8
|
+
* @returns `{ copied, copy }` — `copied` is `true` while the feedback window is active
|
|
6
9
|
*
|
|
7
10
|
* @example
|
|
8
11
|
* ```tsx
|
|
9
|
-
* const { copied, copy
|
|
12
|
+
* const { copied, copy } = useCopyToClipboard();
|
|
10
13
|
*
|
|
11
|
-
* {
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* </button>
|
|
15
|
-
* )}
|
|
14
|
+
* <button onClick={() => copy('text to copy')}>
|
|
15
|
+
* {copied ? 'Copied!' : 'Copy'}
|
|
16
|
+
* </button>
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
19
|
export declare function useCopyToClipboard(resetDelay?: number): {
|
|
19
20
|
copied: boolean;
|
|
20
|
-
copy: (text: string) =>
|
|
21
|
-
reset: () => void;
|
|
22
|
-
isSupported: boolean;
|
|
21
|
+
copy: (text: string) => void;
|
|
23
22
|
};
|
|
@@ -1,31 +1,19 @@
|
|
|
1
1
|
import { useCallback, useRef, useState } from "react";
|
|
2
|
-
|
|
2
|
+
import { copyText } from "../utils/copyText.js";
|
|
3
3
|
function useCopyToClipboard(resetDelay = 2000) {
|
|
4
4
|
const [copied, setCopied] = useState(false);
|
|
5
5
|
const timeoutRef = useRef(void 0);
|
|
6
|
-
const
|
|
6
|
+
const copy = useCallback((text)=>{
|
|
7
|
+
copyText(text);
|
|
8
|
+
setCopied(true);
|
|
7
9
|
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
8
|
-
setCopied(false);
|
|
9
|
-
}, []);
|
|
10
|
-
const copy = useCallback(async (text)=>{
|
|
11
|
-
if (!isClipboardSupported) return false;
|
|
12
|
-
try {
|
|
13
|
-
await navigator.clipboard.writeText(text);
|
|
14
|
-
setCopied(true);
|
|
15
|
-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
16
|
-
timeoutRef.current = setTimeout(()=>setCopied(false), resetDelay);
|
|
17
|
-
return true;
|
|
18
|
-
} catch {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
10
|
+
timeoutRef.current = setTimeout(()=>setCopied(false), resetDelay);
|
|
21
11
|
}, [
|
|
22
12
|
resetDelay
|
|
23
13
|
]);
|
|
24
14
|
return {
|
|
25
15
|
copied,
|
|
26
|
-
copy
|
|
27
|
-
reset,
|
|
28
|
-
isSupported: isClipboardSupported
|
|
16
|
+
copy
|
|
29
17
|
};
|
|
30
18
|
}
|
|
31
19
|
export { useCopyToClipboard };
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export { Calendar, CalendarApplyButton, type CalendarApplyButtonProps, CalendarB
|
|
|
25
25
|
export { Card, CardContent, type CardContentProps, CardFooter, type CardFooterProps, CardHeader, type CardHeaderProps, type CardProps, CardTitle, type CardTitleProps, cardVariants, } from './components/Card';
|
|
26
26
|
export { Checkbox, CheckboxDescription, type CheckboxDescriptionProps, CheckboxGroup, type CheckboxGroupProps, CheckboxIndicator, CheckboxLabel, type CheckboxLabelProps, type CheckboxProps, } from './components/Checkbox';
|
|
27
27
|
export { Code, type CodeProps } from './components/Code';
|
|
28
|
-
export {
|
|
28
|
+
export { Copyable, CopyableIcon, type CopyableIconProps, CopyableLabel, type CopyableLabelProps, type CopyableProps, useCopyable, } from './components/Copyable';
|
|
29
29
|
export { Country, CountryFlag, type CountryFlagProps, CountryName, type CountryNameProps, type CountryProps, } from './components/Country';
|
|
30
30
|
export { type DateFormatContextValue, DateFormatProvider, type DateFormatProviderProps, type DateOrder, useDateFormat, } from './components/DateFormatProvider';
|
|
31
31
|
export { DateInput, type DateInputProps } from './components/DateInput';
|
|
@@ -68,12 +68,14 @@ export { type BreadcrumbSegment, findFirstLinkPath, type NavConfig, type NavConf
|
|
|
68
68
|
export { ResizableHandle, type ResizableHandleProps, ResizablePanel, ResizablePanelGroup, type ResizablePanelGroupProps, type ResizablePanelProps, } from './components/Resizable';
|
|
69
69
|
export { getResponseCodeCategory, RESPONSE_CODE_COLOR, ResponseCode, type ResponseCodeCategory, type ResponseCodeProps, } from './components/ResponseCode';
|
|
70
70
|
export { ScrollArea, ScrollAreaContent, type ScrollAreaContentProps, ScrollAreaCorner, type ScrollAreaCornerProps, type ScrollAreaProps, ScrollAreaScrollbar, type ScrollAreaScrollbarProps, ScrollAreaViewport, type ScrollAreaViewportProps, } from './components/ScrollArea';
|
|
71
|
+
export { SearchInput, type SearchInputProps } from './components/SearchInput';
|
|
71
72
|
export { SearchModal, SearchModalBody, type SearchModalBodyProps, SearchModalContent, type SearchModalContentProps, SearchModalEmpty, type SearchModalEmptyProps, SearchModalFooter, type SearchModalFooterProps, SearchModalGroup, SearchModalGroupLabel, type SearchModalGroupLabelProps, type SearchModalGroupProps, SearchModalInput, type SearchModalInputProps, SearchModalItem, type SearchModalItemProps, type SearchModalProps, SearchModalTrigger, type SearchModalTriggerProps, useSearchModalContext, } from './components/SearchModal';
|
|
72
73
|
export { SegmentedControl, SegmentedControlButton, type SegmentedControlButtonProps, SegmentedControlItem, type SegmentedControlItemProps, type SegmentedControlProps, SegmentedControlSeparator, type SegmentedControlSeparatorProps, } from './components/SegmentedControl';
|
|
73
74
|
export { SegmentedTabs, SegmentedTabsButton, SegmentedTabsContent, SegmentedTabsList, SegmentedTabsSeparator, SegmentedTabsTrigger, SegmentedTabsTriggerButton, } from './components/SegmentedTabs';
|
|
74
75
|
export { createListCollection, Select, SelectButton, SelectClearTrigger, SelectContent, type SelectDataItem, SelectEmptyState, type SelectEmptyStateProps, SelectFooter, SelectGroup, SelectGroupLabel, SelectHeader, SelectInput, SelectOption, SelectOptionDescription, SelectOptionIndicator, SelectOptionText, SelectPositioner, SelectSearchInput, SelectSeparator, type UseSelectSearchOptions, type UseSelectSearchResult, useSelectSearch, } from './components/Select';
|
|
75
76
|
export { Selection, SelectionAll, type SelectionAllProps, SelectionBulkBar, type SelectionBulkBarPlacement, type SelectionBulkBarProps, type SelectionContextValue, SelectionItem, type SelectionItemProps, type SelectionProps, useSelectionContext, } from './components/Selection';
|
|
76
77
|
export { Separator, type SeparatorProps } from './components/Separator';
|
|
78
|
+
export { SettingsHeader, SettingsHeaderActions, type SettingsHeaderActionsProps, SettingsHeaderBreadcrumbs, type SettingsHeaderBreadcrumbsProps, SettingsHeaderDescription, type SettingsHeaderDescriptionProps, SettingsHeaderFilters, type SettingsHeaderFiltersProps, SettingsHeaderHeading, type SettingsHeaderHeadingProps, type SettingsHeaderProps, SettingsHeaderTitle, type SettingsHeaderTitleProps, } from './components/SettingsHeader';
|
|
77
79
|
export { Skeleton, type SkeletonProps } from './components/Skeleton';
|
|
78
80
|
export { Slider, SliderControl, type SliderControlProps, SliderInput, type SliderInputProps, type SliderMark, SliderMarks, type SliderMarksProps, type SliderProps, SliderThumb, type SliderThumbProps, SliderValue, type SliderValueProps, } from './components/Slider';
|
|
79
81
|
export { SplashScreen, type SplashScreenProps } from './components/SplashScreen';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export { Calendar, CalendarApplyButton, CalendarBody, CalendarContent, CalendarD
|
|
|
14
14
|
export { Card, CardContent, CardFooter, CardHeader, CardTitle, cardVariants } from "./components/Card/index.js";
|
|
15
15
|
export { Checkbox, CheckboxDescription, CheckboxGroup, CheckboxIndicator, CheckboxLabel } from "./components/Checkbox/index.js";
|
|
16
16
|
export { Code } from "./components/Code/index.js";
|
|
17
|
-
export {
|
|
17
|
+
export { Copyable, CopyableIcon, CopyableLabel, useCopyable } from "./components/Copyable/index.js";
|
|
18
18
|
export { Country, CountryFlag, CountryName } from "./components/Country/index.js";
|
|
19
19
|
export { DateFormatProvider, useDateFormat } from "./components/DateFormatProvider/index.js";
|
|
20
20
|
export { DateInput } from "./components/DateInput/index.js";
|
|
@@ -57,12 +57,14 @@ export { RemoteShell, RemoteShellBreadcrumb, RemoteShellContent, RemoteShellPane
|
|
|
57
57
|
export { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "./components/Resizable/index.js";
|
|
58
58
|
export { RESPONSE_CODE_COLOR, ResponseCode, getResponseCodeCategory } from "./components/ResponseCode/index.js";
|
|
59
59
|
export { ScrollArea, ScrollAreaContent, ScrollAreaCorner, ScrollAreaScrollbar, ScrollAreaViewport } from "./components/ScrollArea/index.js";
|
|
60
|
+
export { SearchInput } from "./components/SearchInput/index.js";
|
|
60
61
|
export { SearchModal, SearchModalBody, SearchModalContent, SearchModalEmpty, SearchModalFooter, SearchModalGroup, SearchModalGroupLabel, SearchModalInput, SearchModalItem, SearchModalTrigger, useSearchModalContext } from "./components/SearchModal/index.js";
|
|
61
62
|
export { SegmentedControl, SegmentedControlButton, SegmentedControlItem, SegmentedControlSeparator } from "./components/SegmentedControl/index.js";
|
|
62
63
|
export { SegmentedTabs, SegmentedTabsButton, SegmentedTabsContent, SegmentedTabsList, SegmentedTabsSeparator, SegmentedTabsTrigger, SegmentedTabsTriggerButton } from "./components/SegmentedTabs/index.js";
|
|
63
64
|
export { Select, SelectButton, SelectClearTrigger, SelectContent, SelectEmptyState, SelectFooter, SelectGroup, SelectGroupLabel, SelectHeader, SelectInput, SelectOption, SelectOptionDescription, SelectOptionIndicator, SelectOptionText, SelectPositioner, SelectSearchInput, SelectSeparator, createListCollection, useSelectSearch } from "./components/Select/index.js";
|
|
64
65
|
export { Selection, SelectionAll, SelectionBulkBar, SelectionItem, useSelectionContext } from "./components/Selection/index.js";
|
|
65
66
|
export { Separator } from "./components/Separator/index.js";
|
|
67
|
+
export { SettingsHeader, SettingsHeaderActions, SettingsHeaderBreadcrumbs, SettingsHeaderDescription, SettingsHeaderFilters, SettingsHeaderHeading, SettingsHeaderTitle } from "./components/SettingsHeader/index.js";
|
|
66
68
|
export { Skeleton } from "./components/Skeleton/index.js";
|
|
67
69
|
export { Slider, SliderControl, SliderInput, SliderMarks, SliderThumb, SliderValue } from "./components/Slider/index.js";
|
|
68
70
|
export { SplashScreen } from "./components/SplashScreen/index.js";
|