@vesture/react 0.2.5 → 0.2.6

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.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, 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,19 @@ 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;
335
339
  }
336
- declare function DataGrid<T>({ columns, data, getRowId, rowHeight, height, overscan, selectable, selectedIds: controlledSelectedIds, onSelectionChange, sort: controlledSort, onSortChange, filters: controlledFilters, onFilterChange, emptyMessage, onRowEdit, serverSide, loading, totalRowCount, page, pageSize, onPageChange, }: DataGridProps<T>): ReactElement;
340
+ interface DataGridExportOptions {
341
+ filename?: string;
342
+ sheetName?: string;
343
+ }
344
+ interface DataGridHandle<T> {
345
+ exportToExcel: (options?: DataGridExportOptions) => Promise<void>;
346
+ }
347
+ declare const DataGrid: <T>(props: DataGridProps<T> & {
348
+ ref?: ForwardedRef<DataGridHandle<T>>;
349
+ }) => ReactElement;
337
350
 
338
351
  interface CalendarProps {
339
352
  /** Controlled selected date. Pass `null` for "controlled, nothing selected". */
@@ -506,4 +519,4 @@ interface TreeViewProps<T = unknown> {
506
519
 
507
520
  declare function TreeView<T = unknown>({ nodes, expanded: controlledExpanded, defaultExpanded, onExpandedChange, selected: controlledSelected, defaultSelected, onSelectedChange, selectable, onLoadChildren, height, rowHeight, }: TreeViewProps<T>): ReactElement;
508
521
 
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 };
522
+ 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 { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef4, useState as useState8 } from "react";
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 = "DataGrid_editInput__7xivx7o";
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 = "DataGrid_gridWrapper__7xivx7l";
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 = "DataGrid_loadingOverlay__7xivx7m";
1122
- var paginationFooter = "DataGrid_paginationFooter__7xivx7n";
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 DataGrid({
1209
+ function DataGridInner({
1189
1210
  columns,
1190
1211
  data,
1191
1212
  getRowId,
@@ -1206,8 +1227,9 @@ function DataGrid({
1206
1227
  totalRowCount,
1207
1228
  page,
1208
1229
  pageSize,
1209
- onPageChange
1210
- }) {
1230
+ onPageChange,
1231
+ enableExport = false
1232
+ }, ref) {
1211
1233
  const [uncontrolledSort, setUncontrolledSort] = useState8(
1212
1234
  null
1213
1235
  );
@@ -1290,6 +1312,25 @@ function DataGrid({
1290
1312
  );
1291
1313
  return sort.direction === "desc" ? sorted.reverse() : sorted;
1292
1314
  }, [filteredData, sort, columns, serverSide, data]);
1315
+ const exportToExcel = useCallback2(
1316
+ async (options) => {
1317
+ const XLSX = await import("xlsx");
1318
+ const headerRowValues = columns.map((column) => getExportHeader(column));
1319
+ const rows = sortedData.map(
1320
+ (row3) => columns.map((column) => getExportValue(column, row3))
1321
+ );
1322
+ const worksheet = XLSX.utils.aoa_to_sheet([headerRowValues, ...rows]);
1323
+ const workbook = XLSX.utils.book_new();
1324
+ XLSX.utils.book_append_sheet(
1325
+ workbook,
1326
+ worksheet,
1327
+ options?.sheetName ?? "Sheet1"
1328
+ );
1329
+ XLSX.writeFile(workbook, options?.filename ?? "export.xlsx");
1330
+ },
1331
+ [columns, sortedData]
1332
+ );
1333
+ useImperativeHandle(ref, () => ({ exportToExcel }), [exportToExcel]);
1293
1334
  const selectFilterOptions = useMemo2(() => {
1294
1335
  const map = {};
1295
1336
  for (const column of columns) {
@@ -1443,6 +1484,17 @@ function DataGrid({
1443
1484
  const totalWidth = (selectable ? CHECKBOX_COLUMN_WIDTH : 0) + (editingEnabled ? ACTIONS_COLUMN_WIDTH : 0) + columns.reduce((sum, c) => sum + widthOf(c), 0);
1444
1485
  return /* @__PURE__ */ jsxs17(Fragment5, { children: [
1445
1486
  /* @__PURE__ */ jsxs17("div", { className: gridWrapper, children: [
1487
+ enableExport ? /* @__PURE__ */ jsx34("div", { className: toolbar, children: /* @__PURE__ */ jsx34(
1488
+ Button,
1489
+ {
1490
+ type: "button",
1491
+ variant: "secondary",
1492
+ onClick: () => {
1493
+ void exportToExcel();
1494
+ },
1495
+ children: "Export"
1496
+ }
1497
+ ) }) : null,
1446
1498
  /* @__PURE__ */ jsxs17(
1447
1499
  "div",
1448
1500
  {
@@ -1732,6 +1784,7 @@ function DataGrid({
1732
1784
  ) }) : null
1733
1785
  ] });
1734
1786
  }
1787
+ var DataGrid = forwardRef14(DataGridInner);
1735
1788
 
1736
1789
  // src/components/Calendar/Calendar.tsx
1737
1790
  import { useEffect as useEffect3, useMemo as useMemo3, useRef as useRef5, useState as useState9 } from "react";
@@ -2642,7 +2695,7 @@ function DateRangePicker({
2642
2695
  }
2643
2696
 
2644
2697
  // src/components/NumberInput/NumberInput.tsx
2645
- import { forwardRef as forwardRef14, useEffect as useEffect6, useRef as useRef7, useState as useState12 } from "react";
2698
+ import { forwardRef as forwardRef15, useEffect as useEffect6, useRef as useRef7, useState as useState12 } from "react";
2646
2699
  import { useMergeRefs as useMergeRefs5 } from "@floating-ui/react";
2647
2700
 
2648
2701
  // src/components/NumberInput/NumberInput.css.ts
@@ -2662,7 +2715,7 @@ function clamp(value, min, max) {
2662
2715
  function formatValue(value) {
2663
2716
  return value === null ? "" : String(value);
2664
2717
  }
2665
- var NumberInput = forwardRef14(function NumberInput2({
2718
+ var NumberInput = forwardRef15(function NumberInput2({
2666
2719
  value: controlledValue,
2667
2720
  defaultValue = null,
2668
2721
  onChange,