@vesture/react 0.2.5 → 0.2.7
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/index.css +20 -6
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +19 -3
- package/dist/index.js +71 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ButtonHTMLAttributes, LabelHTMLAttributes, InputHTMLAttributes, TextareaHTMLAttributes, SelectHTMLAttributes, ReactNode, HTMLAttributes, ReactElement, MutableRefObject, AnchorHTMLAttributes, CSSProperties } from 'react';
|
|
2
|
+
import { ButtonHTMLAttributes, LabelHTMLAttributes, InputHTMLAttributes, TextareaHTMLAttributes, SelectHTMLAttributes, ReactNode, HTMLAttributes, ReactElement, MutableRefObject, AnchorHTMLAttributes, MouseEvent, ForwardedRef, CSSProperties } from 'react';
|
|
3
3
|
import { Placement } from '@floating-ui/react';
|
|
4
4
|
export { defaultThemeClass, defaultThemeVars, vars } from '@vesture/tokens';
|
|
5
5
|
|
|
@@ -295,6 +295,8 @@ interface DataGridColumn<T> {
|
|
|
295
295
|
filterType?: "text" | "select";
|
|
296
296
|
accessor?: (row: T) => string | number;
|
|
297
297
|
render?: (row: T) => ReactNode;
|
|
298
|
+
/** Value used when exporting this column; falls back to accessor, then the raw row value. Not derived from render, since render returns a ReactNode. */
|
|
299
|
+
exportValue?: (row: T) => string | number;
|
|
298
300
|
}
|
|
299
301
|
type SortDirection = "asc" | "desc" | null;
|
|
300
302
|
interface SortState {
|
|
@@ -332,8 +334,22 @@ interface DataGridProps<T> {
|
|
|
332
334
|
page?: number;
|
|
333
335
|
pageSize?: number;
|
|
334
336
|
onPageChange?: (page: number) => void;
|
|
337
|
+
/** Renders an "Export" button in the grid's toolbar that exports the current view to Excel. */
|
|
338
|
+
enableExport?: boolean;
|
|
339
|
+
onRowClick?: (row: T, event: MouseEvent<HTMLDivElement>) => void;
|
|
340
|
+
onRowDoubleClick?: (row: T, event: MouseEvent<HTMLDivElement>) => void;
|
|
341
|
+
onCellClick?: (row: T, column: DataGridColumn<T>, event: MouseEvent<HTMLDivElement>) => void;
|
|
335
342
|
}
|
|
336
|
-
|
|
343
|
+
interface DataGridExportOptions {
|
|
344
|
+
filename?: string;
|
|
345
|
+
sheetName?: string;
|
|
346
|
+
}
|
|
347
|
+
interface DataGridHandle<T> {
|
|
348
|
+
exportToExcel: (options?: DataGridExportOptions) => Promise<void>;
|
|
349
|
+
}
|
|
350
|
+
declare const DataGrid: <T>(props: DataGridProps<T> & {
|
|
351
|
+
ref?: ForwardedRef<DataGridHandle<T>>;
|
|
352
|
+
}) => ReactElement;
|
|
337
353
|
|
|
338
354
|
interface CalendarProps {
|
|
339
355
|
/** Controlled selected date. Pass `null` for "controlled, nothing selected". */
|
|
@@ -506,4 +522,4 @@ interface TreeViewProps<T = unknown> {
|
|
|
506
522
|
|
|
507
523
|
declare function TreeView<T = unknown>({ nodes, expanded: controlledExpanded, defaultExpanded, onExpandedChange, selected: controlledSelected, defaultSelected, onSelectedChange, selectable, onLoadChildren, height, rowHeight, }: TreeViewProps<T>): ReactElement;
|
|
508
524
|
|
|
509
|
-
export { Accordion, AccordionContent, type AccordionContentProps, AccordionItem, type AccordionItemProps, type AccordionProps, AccordionTrigger, type AccordionTriggerProps, Alert, type AlertProps, type AlertVariant, Avatar, type AvatarProps, type AvatarSize, type AvatarStatus, Badge, type BadgeProps, type BadgeVariant, Breadcrumbs, BreadcrumbsItem, type BreadcrumbsItemProps, type BreadcrumbsProps, Button, type ButtonProps, type ButtonVariant, Calendar, type CalendarProps, Card, type CardElevation, type CardProps, Checkbox, type CheckboxProps, Combobox, type ComboboxOption, type ComboboxProps, DataGrid, type DataGridColumn, type DataGridProps, DatePicker, type DatePickerProps, type DateRange, DateRangePicker, type DateRangePickerProps, Divider, type DividerOrientation, type DividerProps, DropdownMenu, DropdownMenuItem, type DropdownMenuItemProps, type DropdownMenuProps, Input, type InputProps, Label, type LabelProps, Modal, type ModalProps, NumberInput, type NumberInputProps, Pagination, type PaginationProps, Popover, type PopoverProps, Progress, type ProgressProps, Radio, type RadioProps, Select, type SelectProps, Slider, type SliderProps, type SliderValue, type SortDirection, type SortState, Spinner, type SpinnerProps, type SpinnerSize, Stack, type StackAlign, type StackDirection, type StackGap, type StackJustify, type StackProps, Switch, type SwitchProps, Tabs, TabsList, type TabsListProps, TabsPanel, type TabsPanelProps, type TabsProps, TabsTrigger, type TabsTriggerProps, Textarea, type TextareaProps, type ToastContextValue, type ToastOptions, ToastProvider, type ToastVariant, Tooltip, type TooltipProps, type TreeNode, TreeView, type TreeViewProps, type TreeViewSelectable, useToast };
|
|
525
|
+
export { Accordion, AccordionContent, type AccordionContentProps, AccordionItem, type AccordionItemProps, type AccordionProps, AccordionTrigger, type AccordionTriggerProps, Alert, type AlertProps, type AlertVariant, Avatar, type AvatarProps, type AvatarSize, type AvatarStatus, Badge, type BadgeProps, type BadgeVariant, Breadcrumbs, BreadcrumbsItem, type BreadcrumbsItemProps, type BreadcrumbsProps, Button, type ButtonProps, type ButtonVariant, Calendar, type CalendarProps, Card, type CardElevation, type CardProps, Checkbox, type CheckboxProps, Combobox, type ComboboxOption, type ComboboxProps, DataGrid, type DataGridColumn, type DataGridExportOptions, type DataGridHandle, type DataGridProps, DatePicker, type DatePickerProps, type DateRange, DateRangePicker, type DateRangePickerProps, Divider, type DividerOrientation, type DividerProps, DropdownMenu, DropdownMenuItem, type DropdownMenuItemProps, type DropdownMenuProps, Input, type InputProps, Label, type LabelProps, Modal, type ModalProps, NumberInput, type NumberInputProps, Pagination, type PaginationProps, Popover, type PopoverProps, Progress, type ProgressProps, Radio, type RadioProps, Select, type SelectProps, Slider, type SliderProps, type SliderValue, type SortDirection, type SortState, Spinner, type SpinnerProps, type SpinnerSize, Stack, type StackAlign, type StackDirection, type StackGap, type StackJustify, type StackProps, Switch, type SwitchProps, Tabs, TabsList, type TabsListProps, TabsPanel, type TabsPanelProps, type TabsProps, TabsTrigger, type TabsTriggerProps, Textarea, type TextareaProps, type ToastContextValue, type ToastOptions, ToastProvider, type ToastVariant, Tooltip, type TooltipProps, type TreeNode, TreeView, type TreeViewProps, type TreeViewSelectable, useToast };
|
package/dist/index.js
CHANGED
|
@@ -1100,7 +1100,15 @@ function Alert({
|
|
|
1100
1100
|
}
|
|
1101
1101
|
|
|
1102
1102
|
// src/components/DataGrid/DataGrid.tsx
|
|
1103
|
-
import {
|
|
1103
|
+
import {
|
|
1104
|
+
forwardRef as forwardRef14,
|
|
1105
|
+
useCallback as useCallback2,
|
|
1106
|
+
useEffect as useEffect2,
|
|
1107
|
+
useImperativeHandle,
|
|
1108
|
+
useMemo as useMemo2,
|
|
1109
|
+
useRef as useRef4,
|
|
1110
|
+
useState as useState8
|
|
1111
|
+
} from "react";
|
|
1104
1112
|
|
|
1105
1113
|
// src/components/DataGrid/DataGrid.css.ts
|
|
1106
1114
|
var actionsCell = "DataGrid_actionsCell__7xivx7g";
|
|
@@ -1108,18 +1116,18 @@ var body3 = "DataGrid_body__7xivx77";
|
|
|
1108
1116
|
var cell = "DataGrid_cell__7xivx79";
|
|
1109
1117
|
var checkboxCell = "DataGrid_checkboxCell__7xivx7a";
|
|
1110
1118
|
var container = "DataGrid_container__7xivx71";
|
|
1111
|
-
var editInput = "
|
|
1119
|
+
var editInput = "DataGrid_editInput__7xivx7p";
|
|
1112
1120
|
var emptyState = "DataGrid_emptyState__7xivx7b";
|
|
1113
1121
|
var filterCell = "DataGrid_filterCell__7xivx7j";
|
|
1114
1122
|
var filterInput = "DataGrid_filterInput__7xivx7k";
|
|
1115
1123
|
var filterRow = "DataGrid_filterRow__7xivx7i";
|
|
1116
|
-
var gridWrapper = "
|
|
1124
|
+
var gridWrapper = "DataGrid_gridWrapper__7xivx7m";
|
|
1117
1125
|
var headerButton = "DataGrid_headerButton__7xivx74";
|
|
1118
1126
|
var headerCell = "DataGrid_headerCell__7xivx73";
|
|
1119
1127
|
var headerRow = "DataGrid_headerRow__7xivx72";
|
|
1120
1128
|
var iconButton = "DataGrid_iconButton__7xivx7h";
|
|
1121
|
-
var loadingOverlay = "
|
|
1122
|
-
var paginationFooter = "
|
|
1129
|
+
var loadingOverlay = "DataGrid_loadingOverlay__7xivx7n";
|
|
1130
|
+
var paginationFooter = "DataGrid_paginationFooter__7xivx7o";
|
|
1123
1131
|
var pinnedCell = "DataGrid_pinnedCell__7xivx7c";
|
|
1124
1132
|
var pinnedHeaderCell = "DataGrid_pinnedHeaderCell__7xivx7d";
|
|
1125
1133
|
var pinnedLeftEdge = "DataGrid_pinnedLeftEdge__7xivx7e";
|
|
@@ -1128,6 +1136,7 @@ var resizeHandle = "DataGrid_resizeHandle__7xivx76";
|
|
|
1128
1136
|
var row = "DataGrid_row__7xivx78";
|
|
1129
1137
|
var sortIcon = "DataGrid_sortIcon__7xivx75";
|
|
1130
1138
|
var srOnly2 = "DataGrid_srOnly__7xivx70";
|
|
1139
|
+
var toolbar = "DataGrid_toolbar__7xivx7l";
|
|
1131
1140
|
|
|
1132
1141
|
// src/components/DataGrid/DataGrid.tsx
|
|
1133
1142
|
import { Fragment as Fragment5, jsx as jsx34, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
@@ -1173,6 +1182,18 @@ function FilterTextInput({
|
|
|
1173
1182
|
}
|
|
1174
1183
|
);
|
|
1175
1184
|
}
|
|
1185
|
+
function getExportValue(column, row3) {
|
|
1186
|
+
if (column.exportValue) {
|
|
1187
|
+
return column.exportValue(row3);
|
|
1188
|
+
}
|
|
1189
|
+
if (column.accessor) {
|
|
1190
|
+
return column.accessor(row3);
|
|
1191
|
+
}
|
|
1192
|
+
return row3[column.key];
|
|
1193
|
+
}
|
|
1194
|
+
function getExportHeader(column) {
|
|
1195
|
+
return typeof column.header === "string" ? column.header : column.key;
|
|
1196
|
+
}
|
|
1176
1197
|
function compareValues(a, b) {
|
|
1177
1198
|
if (typeof a === "number" && typeof b === "number") {
|
|
1178
1199
|
return a - b;
|
|
@@ -1185,7 +1206,7 @@ function getCellValue(column, row3) {
|
|
|
1185
1206
|
}
|
|
1186
1207
|
return row3[column.key];
|
|
1187
1208
|
}
|
|
1188
|
-
function
|
|
1209
|
+
function DataGridInner({
|
|
1189
1210
|
columns,
|
|
1190
1211
|
data,
|
|
1191
1212
|
getRowId,
|
|
@@ -1206,8 +1227,12 @@ function DataGrid({
|
|
|
1206
1227
|
totalRowCount,
|
|
1207
1228
|
page,
|
|
1208
1229
|
pageSize,
|
|
1209
|
-
onPageChange
|
|
1210
|
-
|
|
1230
|
+
onPageChange,
|
|
1231
|
+
enableExport = false,
|
|
1232
|
+
onRowClick,
|
|
1233
|
+
onRowDoubleClick,
|
|
1234
|
+
onCellClick
|
|
1235
|
+
}, ref) {
|
|
1211
1236
|
const [uncontrolledSort, setUncontrolledSort] = useState8(
|
|
1212
1237
|
null
|
|
1213
1238
|
);
|
|
@@ -1290,6 +1315,25 @@ function DataGrid({
|
|
|
1290
1315
|
);
|
|
1291
1316
|
return sort.direction === "desc" ? sorted.reverse() : sorted;
|
|
1292
1317
|
}, [filteredData, sort, columns, serverSide, data]);
|
|
1318
|
+
const exportToExcel = useCallback2(
|
|
1319
|
+
async (options) => {
|
|
1320
|
+
const XLSX = await import("xlsx");
|
|
1321
|
+
const headerRowValues = columns.map((column) => getExportHeader(column));
|
|
1322
|
+
const rows = sortedData.map(
|
|
1323
|
+
(row3) => columns.map((column) => getExportValue(column, row3))
|
|
1324
|
+
);
|
|
1325
|
+
const worksheet = XLSX.utils.aoa_to_sheet([headerRowValues, ...rows]);
|
|
1326
|
+
const workbook = XLSX.utils.book_new();
|
|
1327
|
+
XLSX.utils.book_append_sheet(
|
|
1328
|
+
workbook,
|
|
1329
|
+
worksheet,
|
|
1330
|
+
options?.sheetName ?? "Sheet1"
|
|
1331
|
+
);
|
|
1332
|
+
XLSX.writeFile(workbook, options?.filename ?? "export.xlsx");
|
|
1333
|
+
},
|
|
1334
|
+
[columns, sortedData]
|
|
1335
|
+
);
|
|
1336
|
+
useImperativeHandle(ref, () => ({ exportToExcel }), [exportToExcel]);
|
|
1293
1337
|
const selectFilterOptions = useMemo2(() => {
|
|
1294
1338
|
const map = {};
|
|
1295
1339
|
for (const column of columns) {
|
|
@@ -1443,6 +1487,17 @@ function DataGrid({
|
|
|
1443
1487
|
const totalWidth = (selectable ? CHECKBOX_COLUMN_WIDTH : 0) + (editingEnabled ? ACTIONS_COLUMN_WIDTH : 0) + columns.reduce((sum, c) => sum + widthOf(c), 0);
|
|
1444
1488
|
return /* @__PURE__ */ jsxs17(Fragment5, { children: [
|
|
1445
1489
|
/* @__PURE__ */ jsxs17("div", { className: gridWrapper, children: [
|
|
1490
|
+
enableExport ? /* @__PURE__ */ jsx34("div", { className: toolbar, children: /* @__PURE__ */ jsx34(
|
|
1491
|
+
Button,
|
|
1492
|
+
{
|
|
1493
|
+
type: "button",
|
|
1494
|
+
variant: "secondary",
|
|
1495
|
+
onClick: () => {
|
|
1496
|
+
void exportToExcel();
|
|
1497
|
+
},
|
|
1498
|
+
children: "Export"
|
|
1499
|
+
}
|
|
1500
|
+
) }) : null,
|
|
1446
1501
|
/* @__PURE__ */ jsxs17(
|
|
1447
1502
|
"div",
|
|
1448
1503
|
{
|
|
@@ -1620,6 +1675,8 @@ function DataGrid({
|
|
|
1620
1675
|
role: "row",
|
|
1621
1676
|
"data-selected": isSelected || void 0,
|
|
1622
1677
|
"data-editing": isEditing || void 0,
|
|
1678
|
+
onClick: onRowClick ? (e) => onRowClick(rowData, e) : void 0,
|
|
1679
|
+
onDoubleClick: onRowDoubleClick ? (e) => onRowDoubleClick(rowData, e) : void 0,
|
|
1623
1680
|
children: [
|
|
1624
1681
|
selectable ? /* @__PURE__ */ jsx34(
|
|
1625
1682
|
"div",
|
|
@@ -1627,6 +1684,7 @@ function DataGrid({
|
|
|
1627
1684
|
className: [checkboxCell, pinnedCell].join(" "),
|
|
1628
1685
|
style: { left: 0 },
|
|
1629
1686
|
role: "cell",
|
|
1687
|
+
onClick: (e) => e.stopPropagation(),
|
|
1630
1688
|
children: /* @__PURE__ */ jsx34(
|
|
1631
1689
|
"input",
|
|
1632
1690
|
{
|
|
@@ -1647,6 +1705,7 @@ function DataGrid({
|
|
|
1647
1705
|
...pinnedStyle(column)
|
|
1648
1706
|
},
|
|
1649
1707
|
role: "cell",
|
|
1708
|
+
onClick: onCellClick ? (e) => onCellClick(rowData, column, e) : void 0,
|
|
1650
1709
|
children: isEditing && column.editable ? /* @__PURE__ */ jsx34(
|
|
1651
1710
|
"input",
|
|
1652
1711
|
{
|
|
@@ -1674,6 +1733,7 @@ function DataGrid({
|
|
|
1674
1733
|
className: [actionsCell, pinnedCell].join(" "),
|
|
1675
1734
|
style: { right: 0 },
|
|
1676
1735
|
role: "cell",
|
|
1736
|
+
onClick: (e) => e.stopPropagation(),
|
|
1677
1737
|
children: isEditing ? /* @__PURE__ */ jsxs17(Fragment5, { children: [
|
|
1678
1738
|
/* @__PURE__ */ jsx34(
|
|
1679
1739
|
"button",
|
|
@@ -1732,6 +1792,7 @@ function DataGrid({
|
|
|
1732
1792
|
) }) : null
|
|
1733
1793
|
] });
|
|
1734
1794
|
}
|
|
1795
|
+
var DataGrid = forwardRef14(DataGridInner);
|
|
1735
1796
|
|
|
1736
1797
|
// src/components/Calendar/Calendar.tsx
|
|
1737
1798
|
import { useEffect as useEffect3, useMemo as useMemo3, useRef as useRef5, useState as useState9 } from "react";
|
|
@@ -2642,7 +2703,7 @@ function DateRangePicker({
|
|
|
2642
2703
|
}
|
|
2643
2704
|
|
|
2644
2705
|
// src/components/NumberInput/NumberInput.tsx
|
|
2645
|
-
import { forwardRef as
|
|
2706
|
+
import { forwardRef as forwardRef15, useEffect as useEffect6, useRef as useRef7, useState as useState12 } from "react";
|
|
2646
2707
|
import { useMergeRefs as useMergeRefs5 } from "@floating-ui/react";
|
|
2647
2708
|
|
|
2648
2709
|
// src/components/NumberInput/NumberInput.css.ts
|
|
@@ -2662,7 +2723,7 @@ function clamp(value, min, max) {
|
|
|
2662
2723
|
function formatValue(value) {
|
|
2663
2724
|
return value === null ? "" : String(value);
|
|
2664
2725
|
}
|
|
2665
|
-
var NumberInput =
|
|
2726
|
+
var NumberInput = forwardRef15(function NumberInput2({
|
|
2666
2727
|
value: controlledValue,
|
|
2667
2728
|
defaultValue = null,
|
|
2668
2729
|
onChange,
|