lecom-ui 4.7.8 → 4.8.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.
@@ -1,9 +1,10 @@
1
1
  import * as React from 'react';
2
- import { useReactTable, getSortedRowModel, getCoreRowModel, flexRender } from '@tanstack/react-table';
2
+ import { cn } from '../../lib/utils.js';
3
+ import { useReactTable, getSortedRowModel, getCoreRowModel } from '@tanstack/react-table';
3
4
  import { Pagination } from '../Pagination/Pagination.js';
4
5
  import { ScrollArea, ScrollBar } from '../ScrollArea/ScrollArea.js';
5
- import { Skeleton } from '../Skeleton/Skeleton.js';
6
6
  import { buildColumns } from './DataTable.utils.js';
7
+ import { Table } from './Table.js';
7
8
 
8
9
  function DataTable({
9
10
  isLoading,
@@ -13,6 +14,8 @@ function DataTable({
13
14
  pagination,
14
15
  vwDiff,
15
16
  vhDiff,
17
+ className,
18
+ noScroll,
16
19
  onIsSelected
17
20
  }) {
18
21
  const [sorting, setSorting] = React.useState([]);
@@ -36,22 +39,6 @@ function DataTable({
36
39
  }
37
40
  return /* @__PURE__ */ React.createElement(Pagination, { ...pagination });
38
41
  };
39
- const styleColumn = (meta, elem) => {
40
- if (elem === "td" && meta.truncate) {
41
- return {
42
- width: meta.width,
43
- overflow: "hidden",
44
- maxWidth: "0",
45
- textOverflow: "ellipsis",
46
- whiteSpace: "nowrap"
47
- };
48
- }
49
- return {
50
- width: meta.width
51
- };
52
- };
53
- const getFixed = (meta) => meta.fixed;
54
- const arrSkeleton = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
55
42
  React.useEffect(() => {
56
43
  if (!isLoading) {
57
44
  const listRows = document.querySelectorAll(`table#data-table tr`);
@@ -105,76 +92,32 @@ function DataTable({
105
92
  document.querySelector("[data-radix-scroll-area-viewport]")?.addEventListener("scroll", onScroll);
106
93
  return () => document.querySelector("[data-radix-scroll-area-viewport]")?.removeEventListener("scroll", onScroll);
107
94
  }, []);
95
+ const renderTable = () => /* @__PURE__ */ React.createElement(
96
+ Table,
97
+ {
98
+ table,
99
+ columns,
100
+ noResults,
101
+ onIsSelected,
102
+ isLoading
103
+ }
104
+ );
108
105
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
109
106
  "div",
110
107
  {
111
- className: "bg-white rounded-[8px] p-2 transition-all duration-500",
112
- style: { width: styleDataTableContainer().width }
108
+ className: cn(
109
+ "bg-white rounded-[8px] p-2 transition-all duration-500",
110
+ className
111
+ ),
112
+ style: noScroll ? void 0 : { width: styleDataTableContainer().width }
113
113
  },
114
- /* @__PURE__ */ React.createElement(ScrollArea, { type: "always", className: "p-2" }, /* @__PURE__ */ React.createElement(
114
+ noScroll ? renderTable() : /* @__PURE__ */ React.createElement(ScrollArea, { type: "always", className: "p-2" }, /* @__PURE__ */ React.createElement(
115
115
  "div",
116
116
  {
117
117
  className: "transition-all duration-500",
118
118
  style: { maxHeight: styleDataTableContainer().height }
119
119
  },
120
- isLoading ? /* @__PURE__ */ React.createElement("div", { className: "flex flex-col gap-4" }, arrSkeleton.map((id) => /* @__PURE__ */ React.createElement(
121
- Skeleton,
122
- {
123
- key: id,
124
- className: "w-full h-[25px] rounded-lg bg-grey-200"
125
- }
126
- ))) : /* @__PURE__ */ React.createElement("table", { id: "data-table", className: "w-full" }, /* @__PURE__ */ React.createElement("thead", { className: "sticky top-0 z-10" }, table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ React.createElement("tr", { key: headerGroup.id }, headerGroup.headers.map((header) => /* @__PURE__ */ React.createElement(
127
- "th",
128
- {
129
- key: header.id,
130
- className: "h-12 px-4 [&:has([role=checkbox])]:pr-0 bg-white shadow-[0_-1.5px_0px_0px_#c9c9c9_inset] text-left",
131
- "data-header": header.id,
132
- "data-fixed": getFixed(
133
- header.column.columnDef.meta
134
- ),
135
- style: styleColumn(
136
- header.column.columnDef.meta,
137
- "th"
138
- )
139
- },
140
- header.isPlaceholder ? null : flexRender(
141
- header.column.columnDef.header,
142
- header.getContext()
143
- )
144
- ))))), /* @__PURE__ */ React.createElement("tbody", { className: "[&_tr:last-child]:border-0 [&_tr:last-child_td]:shadow-none" }, table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ React.createElement(
145
- "tr",
146
- {
147
- key: row.id,
148
- "data-state": onIsSelected?.(row) ? "selected" : "",
149
- className: "[&_td]:hover:bg-grey-100 [&_td]:data-[state=selected]:bg-grey-100"
150
- },
151
- row.getVisibleCells().map((cell) => /* @__PURE__ */ React.createElement(
152
- "td",
153
- {
154
- key: cell.id,
155
- className: "p-4 py-0 h-10 [&:has([role=checkbox])]:pr-0 transition-colors bg-white shadow-[0_-0.5px_0px_0px_#c9c9c9_inset] text-left",
156
- "data-column": cell.column.id,
157
- "data-fixed": getFixed(
158
- cell.column.columnDef.meta
159
- ),
160
- style: styleColumn(
161
- cell.column.columnDef.meta,
162
- "td"
163
- )
164
- },
165
- flexRender(
166
- cell.column.columnDef.cell,
167
- cell.getContext()
168
- )
169
- ))
170
- )) : /* @__PURE__ */ React.createElement("tr", { className: "border-b-[0.5px] [&_td]:hover:bg-grey-100 [&_td]:data-[state=selected]:bg-grey-100" }, /* @__PURE__ */ React.createElement(
171
- "td",
172
- {
173
- colSpan: columns.length,
174
- className: "p-4 py-0 h-10 align-middle [&:has([role=checkbox])]:pr-0 transition-colors bg-white"
175
- },
176
- noResults ?? /* @__PURE__ */ React.createElement("div", { className: "text-center" }, "-")
177
- ))))
120
+ renderTable()
178
121
  ), /* @__PURE__ */ React.createElement(ScrollBar, { orientation: "horizontal" }))
179
122
  ), hasPagination());
180
123
  }
@@ -59,7 +59,15 @@ function buildColumns({
59
59
  ),
60
60
  onClick: () => externalColumn.onSort?.({ table, column })
61
61
  },
62
- typeof externalColumn.title === "string" ? /* @__PURE__ */ React.createElement(Typography, { variant: "body-large-500", textColor: "text-grey-950" }, externalColumn.title) : title,
62
+ typeof externalColumn.title === "string" ? /* @__PURE__ */ React.createElement(
63
+ Typography,
64
+ {
65
+ variant: "body-large-500",
66
+ textColor: "text-grey-950",
67
+ className: "truncate"
68
+ },
69
+ externalColumn.title
70
+ ) : title,
63
71
  hasSort && /* @__PURE__ */ React.createElement(
64
72
  ArrowUpDown,
65
73
  {
@@ -0,0 +1,79 @@
1
+ import * as React from 'react';
2
+ import { flexRender } from '@tanstack/react-table';
3
+ import { Skeleton } from '../Skeleton/Skeleton.js';
4
+
5
+ function Table({
6
+ table,
7
+ isLoading,
8
+ columns,
9
+ noResults,
10
+ onIsSelected
11
+ }) {
12
+ const styleColumn = (meta, elem) => {
13
+ if (elem === "td" && meta.truncate) {
14
+ return {
15
+ width: meta.width,
16
+ overflow: "hidden",
17
+ maxWidth: "0",
18
+ textOverflow: "ellipsis",
19
+ whiteSpace: "nowrap"
20
+ };
21
+ }
22
+ return {
23
+ width: meta.width
24
+ };
25
+ };
26
+ const getFixed = (meta) => meta.fixed;
27
+ const arrSkeleton = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
28
+ if (isLoading) {
29
+ return /* @__PURE__ */ React.createElement("div", { className: "flex flex-col gap-4" }, arrSkeleton.map((id) => /* @__PURE__ */ React.createElement(
30
+ Skeleton,
31
+ {
32
+ key: id,
33
+ className: "w-full h-[25px] rounded-lg bg-grey-200"
34
+ }
35
+ )));
36
+ }
37
+ return /* @__PURE__ */ React.createElement("table", { id: "data-table", className: "w-full" }, /* @__PURE__ */ React.createElement("thead", { className: "sticky top-0 z-10" }, table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ React.createElement("tr", { key: headerGroup.id }, headerGroup.headers.map((header) => /* @__PURE__ */ React.createElement(
38
+ "th",
39
+ {
40
+ key: header.id,
41
+ className: "h-12 px-4 [&:has([role=checkbox])]:pr-0 shadow-[0_-1.5px_0px_0px_#c9c9c9_inset] text-left",
42
+ "data-header": header.id,
43
+ "data-fixed": getFixed(header.column.columnDef.meta),
44
+ style: styleColumn(header.column.columnDef.meta, "th")
45
+ },
46
+ header.isPlaceholder ? null : flexRender(
47
+ header.column.columnDef.header,
48
+ header.getContext()
49
+ )
50
+ ))))), /* @__PURE__ */ React.createElement("tbody", { className: "[&_tr:last-child]:border-0 [&_tr:last-child_td]:shadow-none" }, table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ React.createElement(
51
+ "tr",
52
+ {
53
+ key: row.id,
54
+ "data-state": onIsSelected?.(row) ? "selected" : "",
55
+ className: "[&_td]:hover:bg-grey-100 [&_td]:data-[state=selected]:bg-grey-100"
56
+ },
57
+ row.getVisibleCells().map((cell) => /* @__PURE__ */ React.createElement(
58
+ "td",
59
+ {
60
+ key: cell.id,
61
+ className: "p-4 py-0 h-10 [&:has([role=checkbox])]:pr-0 transition-colors shadow-[0_-0.5px_0px_0px_#c9c9c9_inset] text-left",
62
+ "data-column": cell.column.id,
63
+ "data-fixed": getFixed(cell.column.columnDef.meta),
64
+ style: styleColumn(cell.column.columnDef.meta, "td")
65
+ },
66
+ flexRender(cell.column.columnDef.cell, cell.getContext())
67
+ ))
68
+ )) : /* @__PURE__ */ React.createElement("tr", { className: "border-b-[0.5px] [&_td]:hover:bg-grey-100 [&_td]:data-[state=selected]:bg-grey-100" }, /* @__PURE__ */ React.createElement(
69
+ "td",
70
+ {
71
+ colSpan: columns.length,
72
+ className: "p-4 py-0 h-10 align-middle [&:has([role=checkbox])]:pr-0 transition-colors"
73
+ },
74
+ noResults ?? /* @__PURE__ */ React.createElement("div", { className: "text-center" }, "-")
75
+ ))));
76
+ }
77
+ Table.displayName = "Table";
78
+
79
+ export { Table };
package/dist/index.d.ts CHANGED
@@ -369,6 +369,8 @@ interface DataTableProps<TData, TValue> {
369
369
  pagination?: PaginationProps;
370
370
  vwDiff?: number;
371
371
  vhDiff?: number;
372
+ className?: string;
373
+ noScroll?: boolean;
372
374
  onIsSelected?: (row: Row$1<TData>) => boolean;
373
375
  }
374
376
  interface Row<TData> {
@@ -393,8 +395,15 @@ interface BuildCellSelect<TData, TValue> {
393
395
  onCheckedCellChange: Column<TData, TValue>['onCheckedCellChange'];
394
396
  }
395
397
  type Meta = Record<string, string | number>;
398
+ interface TableProps<TData, TValue> {
399
+ table: Table<TData>;
400
+ isLoading?: boolean;
401
+ columns: Column<TData, TValue>[];
402
+ noResults?: React.ReactNode;
403
+ onIsSelected?: (row: Row$1<TData>) => boolean;
404
+ }
396
405
 
397
- declare function DataTable<TData, TValue>({ isLoading, columns, data, noResults, pagination, vwDiff, vhDiff, onIsSelected, }: DataTableProps<TData, TValue>): React$1.JSX.Element;
406
+ declare function DataTable<TData, TValue>({ isLoading, columns, data, noResults, pagination, vwDiff, vhDiff, className, noScroll, onIsSelected, }: DataTableProps<TData, TValue>): React$1.JSX.Element;
398
407
  declare namespace DataTable {
399
408
  var displayName: string;
400
409
  }
@@ -550,9 +559,9 @@ interface HeaderProps extends React$1.HTMLAttributes<HTMLElement>, VariantProps<
550
559
  }
551
560
 
552
561
  declare const inputVariants: (props?: ({
553
- variant?: "filled" | "default" | "borderless" | null | undefined;
554
- size?: "small" | "large" | "default" | null | undefined;
555
- radius?: "small" | "large" | "default" | null | undefined;
562
+ variant?: "default" | "filled" | "borderless" | null | undefined;
563
+ size?: "default" | "small" | "large" | null | undefined;
564
+ radius?: "default" | "small" | "large" | null | undefined;
556
565
  } & class_variance_authority_types.ClassProp) | undefined) => string;
557
566
  interface InputProps extends Omit<React$1.InputHTMLAttributes<HTMLInputElement>, 'size' | 'sufix' | 'prefix'>, VariantProps<typeof inputVariants> {
558
567
  sufix?: React$1.ReactNode;
@@ -713,7 +722,7 @@ declare const TooltipTrigger: React$1.ForwardRefExoticComponent<TooltipPrimitive
713
722
  declare const TooltipArrow: React$1.ForwardRefExoticComponent<TooltipPrimitive.TooltipArrowProps & React$1.RefAttributes<SVGSVGElement>>;
714
723
  declare const TooltipPortal: React$1.FC<TooltipPrimitive.TooltipPortalProps>;
715
724
  declare const tooltipContentVariants: (props?: ({
716
- color?: "white" | "black" | null | undefined;
725
+ color?: "black" | "white" | null | undefined;
717
726
  arrow?: boolean | null | undefined;
718
727
  } & class_variance_authority_types.ClassProp) | undefined) => string;
719
728
  interface TooltipContentProps extends React$1.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>, VariantProps<typeof tooltipContentVariants> {
@@ -809,4 +818,4 @@ declare const fonts: {
809
818
  };
810
819
 
811
820
  export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Button, CadastroFacil, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, DataTable, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogScroll, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, ErrorEmptyDisplay, Input, Layout, LogoLecom, LogoLecomBrand, ModoTeste, Notification, Pagination, PaginationContent, PaginationEllipsis, PaginationFirst, PaginationIndex, PaginationItem, PaginationLast, PaginationNext, PaginationPrevious, Popover, PopoverContent, PopoverTrigger, RadioGroup, RadioGroupItem, Rpa, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Skeleton, Spin, Switch, TOAST_REMOVE_DELAY, Tag, Tooltip, TooltipArrow, TooltipContent, TooltipPortal, TooltipProvider, TooltipTrigger, Translations, TypeMessageNotification, Typography, Upload, accordionVariants, buttonVariants, colors, fonts, getPositionClass, initializeI18n, inputVariants, notificationVariants, reducer, tagVariants, toast, typographyVariants, useIsMobile, useNotificationToast, usePagination, useSidebar };
812
- export type { BgColor, BuildCellSelect, BuildColumns, BuildHeaderSelect, ButtonProps, CadastroFacilProps, CalloutNotificationProps, CheckboxProps, CheckedCell, CheckedCellChange, CheckedHeader, CheckedHeaderChange, Color, ColorToken, Column, ColumnRender, ColumnSort, ColumnTitle, CustomStyles$1 as CustomStyles, DataTableProps, ErrorEmptyDisplayProps, File, FillColor, Fonts, Header, HeaderProps, InlineNotificationProps, InputProps, LayoutProps, LogoLecomBrandProps, LogoLecomProps, Meta, ModoTesteProps, NotificationProps, PaginationProps, Row, RpaProps, SideBarProps, SpinProps, TagProps, TextColor, ToastNotificationProps, ToasterToast, TooltipContentProps, TypographyProps, UploadProps, UsePaginationItem };
821
+ export type { BgColor, BuildCellSelect, BuildColumns, BuildHeaderSelect, ButtonProps, CadastroFacilProps, CalloutNotificationProps, CheckboxProps, CheckedCell, CheckedCellChange, CheckedHeader, CheckedHeaderChange, Color, ColorToken, Column, ColumnRender, ColumnSort, ColumnTitle, CustomStyles$1 as CustomStyles, DataTableProps, ErrorEmptyDisplayProps, File, FillColor, Fonts, Header, HeaderProps, InlineNotificationProps, InputProps, LayoutProps, LogoLecomBrandProps, LogoLecomProps, Meta, ModoTesteProps, NotificationProps, PaginationProps, Row, RpaProps, SideBarProps, SpinProps, TableProps, TagProps, TextColor, ToastNotificationProps, ToasterToast, TooltipContentProps, TypographyProps, UploadProps, UsePaginationItem };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lecom-ui",
3
- "version": "4.7.8",
3
+ "version": "4.8.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",