@bsol-oss/react-datatable5 6.0.2 → 6.0.3

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
@@ -69,6 +69,8 @@ declare const ResetSortingButton: ({ text, }: ResetSortingButtonProps) => react_
69
69
 
70
70
  declare const RowCountText: () => react_jsx_runtime.JSX.Element;
71
71
 
72
+ declare const TablePagination: () => react_jsx_runtime.JSX.Element;
73
+
72
74
  interface CardHeaderProps<TData> {
73
75
  row: Row<TData>;
74
76
  imageColumnId?: keyof TData;
@@ -360,8 +362,6 @@ declare const TableLoadingComponent: ({ render, }: TableLoadingComponentProps) =
360
362
 
361
363
  declare const TableOrderer: () => react_jsx_runtime.JSX.Element;
362
364
 
363
- declare const TablePagination: () => react_jsx_runtime.JSX.Element;
364
-
365
365
  declare const TableSelector: () => react_jsx_runtime.JSX.Element;
366
366
 
367
367
  declare const TableSorter: () => react_jsx_runtime.JSX.Element;
@@ -385,13 +385,6 @@ declare const useDataTableContext: () => {
385
385
  hasError: boolean;
386
386
  };
387
387
 
388
- interface FilterOptionsProps {
389
- column: string;
390
- }
391
- declare const FilterOptions: ({ column }: FilterOptionsProps) => react_jsx_runtime.JSX.Element;
392
-
393
- declare const GlobalFilter: () => react_jsx_runtime.JSX.Element;
394
-
395
388
  interface GetColumnsConfigs<K extends RowData> {
396
389
  schema: JSONSchema7;
397
390
  ignore?: K[];
@@ -404,6 +397,13 @@ interface GetColumnsConfigs<K extends RowData> {
404
397
  declare const widthSanityCheck: <K extends unknown>(widthList: number[], ignoreList: K[], properties: { [key in K as string]?: object | undefined; }) => void;
405
398
  declare const getColumns: <TData extends unknown>({ schema, ignore, width, meta, defaultWidth, }: GetColumnsConfigs<TData>) => ColumnDef<TData>[];
406
399
 
400
+ interface FilterOptionsProps {
401
+ column: string;
402
+ }
403
+ declare const FilterOptions: ({ column }: FilterOptionsProps) => react_jsx_runtime.JSX.Element;
404
+
405
+ declare const GlobalFilter: () => react_jsx_runtime.JSX.Element;
406
+
407
407
  interface DisplayTextProps {
408
408
  title?: string;
409
409
  addNew?: string;
package/dist/index.js CHANGED
@@ -10,13 +10,13 @@ var fa6 = require('react-icons/fa6');
10
10
  var bi = require('react-icons/bi');
11
11
  var cg = require('react-icons/cg');
12
12
  var io = require('react-icons/io');
13
+ var hi2 = require('react-icons/hi2');
13
14
  var reactTable = require('@tanstack/react-table');
14
15
  var matchSorterUtils = require('@tanstack/match-sorter-utils');
15
16
  var bs = require('react-icons/bs');
16
17
  var gr = require('react-icons/gr');
17
18
  var io5 = require('react-icons/io5');
18
19
  var hi = require('react-icons/hi');
19
- var hi2 = require('react-icons/hi2');
20
20
  var adapter = require('@atlaskit/pragmatic-drag-and-drop/element/adapter');
21
21
  var invariant = require('tiny-invariant');
22
22
  var axios = require('axios');
@@ -197,6 +197,77 @@ const RowCountText = () => {
197
197
  return jsxRuntime.jsx(react.Text, { children: table.getRowCount() });
198
198
  };
199
199
 
200
+ const { withContext } = react.createRecipeContext({ key: "button" });
201
+ // Replace "a" with your framework's link component
202
+ const LinkButton = withContext("a");
203
+
204
+ const [RootPropsProvider, useRootProps] = react.createContext({
205
+ name: "RootPropsProvider",
206
+ });
207
+ const variantMap = {
208
+ outline: { default: "ghost", ellipsis: "plain", current: "outline" },
209
+ solid: { default: "outline", ellipsis: "outline", current: "solid" },
210
+ subtle: { default: "ghost", ellipsis: "plain", current: "subtle" },
211
+ };
212
+ const PaginationRoot = React__namespace.forwardRef(function PaginationRoot(props, ref) {
213
+ const { size = "sm", variant = "outline", getHref, ...rest } = props;
214
+ return (jsxRuntime.jsx(RootPropsProvider, { value: { size, variantMap: variantMap[variant], getHref }, children: jsxRuntime.jsx(react.Pagination.Root, { ref: ref, type: getHref ? "link" : "button", ...rest }) }));
215
+ });
216
+ const PaginationEllipsis = React__namespace.forwardRef(function PaginationEllipsis(props, ref) {
217
+ const { size, variantMap } = useRootProps();
218
+ return (jsxRuntime.jsx(react.Pagination.Ellipsis, { ref: ref, ...props, asChild: true, children: jsxRuntime.jsx(react.Button, { as: "span", variant: variantMap.ellipsis, size: size, children: jsxRuntime.jsx(hi2.HiMiniEllipsisHorizontal, {}) }) }));
219
+ });
220
+ const PaginationItem = React__namespace.forwardRef(function PaginationItem(props, ref) {
221
+ const { page } = react.usePaginationContext();
222
+ const { size, variantMap, getHref } = useRootProps();
223
+ const current = page === props.value;
224
+ const variant = current ? variantMap.current : variantMap.default;
225
+ if (getHref) {
226
+ return (jsxRuntime.jsx(LinkButton, { href: getHref(props.value), variant: variant, size: size, children: props.value }));
227
+ }
228
+ return (jsxRuntime.jsx(react.Pagination.Item, { ref: ref, ...props, asChild: true, children: jsxRuntime.jsx(react.Button, { variant: variant, size: size, children: props.value }) }));
229
+ });
230
+ const PaginationPrevTrigger = React__namespace.forwardRef(function PaginationPrevTrigger(props, ref) {
231
+ const { size, variantMap, getHref } = useRootProps();
232
+ const { previousPage } = react.usePaginationContext();
233
+ if (getHref) {
234
+ return (jsxRuntime.jsx(LinkButton, { href: previousPage != null ? getHref(previousPage) : undefined, variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronLeft, {}) }));
235
+ }
236
+ return (jsxRuntime.jsx(react.Pagination.PrevTrigger, { ref: ref, asChild: true, ...props, children: jsxRuntime.jsx(react.IconButton, { variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronLeft, {}) }) }));
237
+ });
238
+ const PaginationNextTrigger = React__namespace.forwardRef(function PaginationNextTrigger(props, ref) {
239
+ const { size, variantMap, getHref } = useRootProps();
240
+ const { nextPage } = react.usePaginationContext();
241
+ if (getHref) {
242
+ return (jsxRuntime.jsx(LinkButton, { href: nextPage != null ? getHref(nextPage) : undefined, variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronRight, {}) }));
243
+ }
244
+ return (jsxRuntime.jsx(react.Pagination.NextTrigger, { ref: ref, asChild: true, ...props, children: jsxRuntime.jsx(react.IconButton, { variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronRight, {}) }) }));
245
+ });
246
+ const PaginationItems = (props) => {
247
+ return (jsxRuntime.jsx(react.Pagination.Context, { children: ({ pages }) => pages.map((page, index) => {
248
+ return page.type === "ellipsis" ? (jsxRuntime.jsx(PaginationEllipsis, { index: index, ...props }, index)) : (jsxRuntime.jsx(PaginationItem, { type: "page", value: page.value, ...props }, index));
249
+ }) }));
250
+ };
251
+ const PaginationPageText = React__namespace.forwardRef(function PaginationPageText(props, ref) {
252
+ const { format = "compact", ...rest } = props;
253
+ const { page, totalPages, pageRange, count } = react.usePaginationContext();
254
+ const content = React__namespace.useMemo(() => {
255
+ if (format === "short")
256
+ return `${page} / ${totalPages}`;
257
+ if (format === "compact")
258
+ return `${page} of ${totalPages}`;
259
+ return `${pageRange.start + 1} - ${Math.min(pageRange.end, count)} of ${count}`;
260
+ }, [format, page, totalPages, pageRange, count]);
261
+ return (jsxRuntime.jsx(react.Text, { fontWeight: "medium", ref: ref, ...rest, children: content }));
262
+ });
263
+
264
+ const TablePagination = () => {
265
+ const { table } = useDataTableContext();
266
+ return (jsxRuntime.jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: table.getRowCount(), pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
267
+ table.setPageIndex(e.page - 1);
268
+ }, children: jsxRuntime.jsxs(react.HStack, { children: [jsxRuntime.jsx(PaginationPageText, { format: "long" }), jsxRuntime.jsx(PaginationPrevTrigger, {}), jsxRuntime.jsx(PaginationItems, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) }));
269
+ };
270
+
200
271
  const Tag = React__namespace.forwardRef(function Tag(props, ref) {
201
272
  const { startElement, endElement, onClose, closable = !!onClose, children, ...rest } = props;
202
273
  return (jsxRuntime.jsxs(react.Tag.Root, { ref: ref, ...rest, children: [startElement && (jsxRuntime.jsx(react.Tag.StartElement, { children: startElement })), jsxRuntime.jsx(react.Tag.Label, { children: children }), endElement && (jsxRuntime.jsx(react.Tag.EndElement, { children: endElement })), closable && (jsxRuntime.jsx(react.Tag.EndElement, { children: jsxRuntime.jsx(react.Tag.CloseTrigger, { onClick: onClose }) }))] }));
@@ -964,77 +1035,6 @@ const TableOrderer = () => {
964
1035
  return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
965
1036
  };
966
1037
 
967
- const { withContext } = react.createRecipeContext({ key: "button" });
968
- // Replace "a" with your framework's link component
969
- const LinkButton = withContext("a");
970
-
971
- const [RootPropsProvider, useRootProps] = react.createContext({
972
- name: "RootPropsProvider",
973
- });
974
- const variantMap = {
975
- outline: { default: "ghost", ellipsis: "plain", current: "outline" },
976
- solid: { default: "outline", ellipsis: "outline", current: "solid" },
977
- subtle: { default: "ghost", ellipsis: "plain", current: "subtle" },
978
- };
979
- const PaginationRoot = React__namespace.forwardRef(function PaginationRoot(props, ref) {
980
- const { size = "sm", variant = "outline", getHref, ...rest } = props;
981
- return (jsxRuntime.jsx(RootPropsProvider, { value: { size, variantMap: variantMap[variant], getHref }, children: jsxRuntime.jsx(react.Pagination.Root, { ref: ref, type: getHref ? "link" : "button", ...rest }) }));
982
- });
983
- const PaginationEllipsis = React__namespace.forwardRef(function PaginationEllipsis(props, ref) {
984
- const { size, variantMap } = useRootProps();
985
- return (jsxRuntime.jsx(react.Pagination.Ellipsis, { ref: ref, ...props, asChild: true, children: jsxRuntime.jsx(react.Button, { as: "span", variant: variantMap.ellipsis, size: size, children: jsxRuntime.jsx(hi2.HiMiniEllipsisHorizontal, {}) }) }));
986
- });
987
- const PaginationItem = React__namespace.forwardRef(function PaginationItem(props, ref) {
988
- const { page } = react.usePaginationContext();
989
- const { size, variantMap, getHref } = useRootProps();
990
- const current = page === props.value;
991
- const variant = current ? variantMap.current : variantMap.default;
992
- if (getHref) {
993
- return (jsxRuntime.jsx(LinkButton, { href: getHref(props.value), variant: variant, size: size, children: props.value }));
994
- }
995
- return (jsxRuntime.jsx(react.Pagination.Item, { ref: ref, ...props, asChild: true, children: jsxRuntime.jsx(react.Button, { variant: variant, size: size, children: props.value }) }));
996
- });
997
- const PaginationPrevTrigger = React__namespace.forwardRef(function PaginationPrevTrigger(props, ref) {
998
- const { size, variantMap, getHref } = useRootProps();
999
- const { previousPage } = react.usePaginationContext();
1000
- if (getHref) {
1001
- return (jsxRuntime.jsx(LinkButton, { href: previousPage != null ? getHref(previousPage) : undefined, variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronLeft, {}) }));
1002
- }
1003
- return (jsxRuntime.jsx(react.Pagination.PrevTrigger, { ref: ref, asChild: true, ...props, children: jsxRuntime.jsx(react.IconButton, { variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronLeft, {}) }) }));
1004
- });
1005
- const PaginationNextTrigger = React__namespace.forwardRef(function PaginationNextTrigger(props, ref) {
1006
- const { size, variantMap, getHref } = useRootProps();
1007
- const { nextPage } = react.usePaginationContext();
1008
- if (getHref) {
1009
- return (jsxRuntime.jsx(LinkButton, { href: nextPage != null ? getHref(nextPage) : undefined, variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronRight, {}) }));
1010
- }
1011
- return (jsxRuntime.jsx(react.Pagination.NextTrigger, { ref: ref, asChild: true, ...props, children: jsxRuntime.jsx(react.IconButton, { variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronRight, {}) }) }));
1012
- });
1013
- const PaginationItems = (props) => {
1014
- return (jsxRuntime.jsx(react.Pagination.Context, { children: ({ pages }) => pages.map((page, index) => {
1015
- return page.type === "ellipsis" ? (jsxRuntime.jsx(PaginationEllipsis, { index: index, ...props }, index)) : (jsxRuntime.jsx(PaginationItem, { type: "page", value: page.value, ...props }, index));
1016
- }) }));
1017
- };
1018
- const PaginationPageText = React__namespace.forwardRef(function PaginationPageText(props, ref) {
1019
- const { format = "compact", ...rest } = props;
1020
- const { page, totalPages, pageRange, count } = react.usePaginationContext();
1021
- const content = React__namespace.useMemo(() => {
1022
- if (format === "short")
1023
- return `${page} / ${totalPages}`;
1024
- if (format === "compact")
1025
- return `${page} of ${totalPages}`;
1026
- return `${pageRange.start + 1} - ${Math.min(pageRange.end, count)} of ${count}`;
1027
- }, [format, page, totalPages, pageRange, count]);
1028
- return (jsxRuntime.jsx(react.Text, { fontWeight: "medium", ref: ref, ...rest, children: content }));
1029
- });
1030
-
1031
- const TablePagination = () => {
1032
- const { table } = useDataTableContext();
1033
- return (jsxRuntime.jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: table.getRowCount(), pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
1034
- table.setPageIndex(e.page - 1);
1035
- }, children: jsxRuntime.jsxs(react.HStack, { children: [jsxRuntime.jsx(PaginationPageText, { format: "long" }), jsxRuntime.jsx(PaginationPrevTrigger, {}), jsxRuntime.jsx(PaginationItems, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) }));
1036
- };
1037
-
1038
1038
  const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineChecklist, {}), clearAllIcon = jsxRuntime.jsx(md.MdClear, {}), selectAllText = "", clearAllText = "", }) => {
1039
1039
  const { table } = useDataTableContext();
1040
1040
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!selectAllText === false && (jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": table.getIsAllRowsSelected() ? clearAllText : selectAllText, onClick: (event) => {
@@ -1326,45 +1326,6 @@ const useDataTableServer = ({ url, onFetchSuccess = () => { }, default: { sortin
1326
1326
  };
1327
1327
  };
1328
1328
 
1329
- const FilterOptions = ({ column }) => {
1330
- const { table } = useDataTableContext();
1331
- const tableColumn = table.getColumn(column);
1332
- const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
1333
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((option) => {
1334
- const selected = table.getColumn(column)?.getFilterValue() === option;
1335
- return (jsxRuntime.jsxs(react.Button, { size: "sm", onClick: () => {
1336
- if (selected) {
1337
- table.setColumnFilters((state) => {
1338
- return state.filter((filter) => {
1339
- return filter.id !== column;
1340
- });
1341
- });
1342
- return;
1343
- }
1344
- table.getColumn(column)?.setFilterValue(option);
1345
- }, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [option, selected && jsxRuntime.jsx(md.MdClose, {})] }, option));
1346
- }) }));
1347
- };
1348
-
1349
- const InputGroup = React__namespace.forwardRef(function InputGroup(props, ref) {
1350
- const { startElement, startElementProps, endElement, endElementProps, children, startOffset = "6px", endOffset = "6px", ...rest } = props;
1351
- return (jsxRuntime.jsxs(react.Group, { ref: ref, ...rest, children: [startElement && (jsxRuntime.jsx(react.InputElement, { pointerEvents: "none", ...startElementProps, children: startElement })), React__namespace.cloneElement(children, {
1352
- ...(startElement && {
1353
- ps: `calc(var(--input-height) - ${startOffset})`,
1354
- }),
1355
- ...(endElement && { pe: `calc(var(--input-height) - ${endOffset})` }),
1356
- // @ts-expect-error chakra generated files
1357
- ...children.props,
1358
- }), endElement && (jsxRuntime.jsx(react.InputElement, { placement: "end", ...endElementProps, children: endElement }))] }));
1359
- });
1360
-
1361
- const GlobalFilter = () => {
1362
- const { table } = useDataTableContext();
1363
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(InputGroup, { flex: "1", startElement: jsxRuntime.jsx(md.MdSearch, {}), children: jsxRuntime.jsx(react.Input, { placeholder: "Outline", variant: "outline", onChange: (e) => {
1364
- table.setGlobalFilter(e.target.value);
1365
- } }) }) }));
1366
- };
1367
-
1368
1329
  const idListSanityCheck = (param, idList, properties) => {
1369
1330
  const allKeyExists = idList.every((key) => Object.keys(properties).some((column) => column == key));
1370
1331
  if (!allKeyExists) {
@@ -1419,6 +1380,45 @@ const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth =
1419
1380
  return columns;
1420
1381
  };
1421
1382
 
1383
+ const FilterOptions = ({ column }) => {
1384
+ const { table } = useDataTableContext();
1385
+ const tableColumn = table.getColumn(column);
1386
+ const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
1387
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((option) => {
1388
+ const selected = table.getColumn(column)?.getFilterValue() === option;
1389
+ return (jsxRuntime.jsxs(react.Button, { size: "sm", onClick: () => {
1390
+ if (selected) {
1391
+ table.setColumnFilters((state) => {
1392
+ return state.filter((filter) => {
1393
+ return filter.id !== column;
1394
+ });
1395
+ });
1396
+ return;
1397
+ }
1398
+ table.getColumn(column)?.setFilterValue(option);
1399
+ }, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [option, selected && jsxRuntime.jsx(md.MdClose, {})] }, option));
1400
+ }) }));
1401
+ };
1402
+
1403
+ const InputGroup = React__namespace.forwardRef(function InputGroup(props, ref) {
1404
+ const { startElement, startElementProps, endElement, endElementProps, children, startOffset = "6px", endOffset = "6px", ...rest } = props;
1405
+ return (jsxRuntime.jsxs(react.Group, { ref: ref, ...rest, children: [startElement && (jsxRuntime.jsx(react.InputElement, { pointerEvents: "none", ...startElementProps, children: startElement })), React__namespace.cloneElement(children, {
1406
+ ...(startElement && {
1407
+ ps: `calc(var(--input-height) - ${startOffset})`,
1408
+ }),
1409
+ ...(endElement && { pe: `calc(var(--input-height) - ${endOffset})` }),
1410
+ // @ts-expect-error chakra generated files
1411
+ ...children.props,
1412
+ }), endElement && (jsxRuntime.jsx(react.InputElement, { placement: "end", ...endElementProps, children: endElement }))] }));
1413
+ });
1414
+
1415
+ const GlobalFilter = () => {
1416
+ const { table } = useDataTableContext();
1417
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(InputGroup, { flex: "1", startElement: jsxRuntime.jsx(md.MdSearch, {}), children: jsxRuntime.jsx(react.Input, { placeholder: "Outline", variant: "outline", onChange: (e) => {
1418
+ table.setGlobalFilter(e.target.value);
1419
+ } }) }) }));
1420
+ };
1421
+
1422
1422
  //@ts-expect-error TODO: find appropriate type
1423
1423
  const SchemaFormContext = React.createContext({
1424
1424
  schema: {},
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, useDisclosure, Flex, DialogRoot as DialogRoot$1, DialogBackdrop, DialogTrigger as DialogTrigger$1, DialogContent as DialogContent$1, DialogCloseTrigger as DialogCloseTrigger$1, DialogHeader as DialogHeader$1, DialogTitle as DialogTitle$1, DialogBody as DialogBody$1, DialogFooter as DialogFooter$1, Text, Menu, Tag as Tag$1, Grid, Image, Card, DataList, Checkbox as Checkbox$1, Table as Table$1, Box, Tooltip as Tooltip$1, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$1, VStack, List, Input, Slider as Slider$1, HStack, For, RadioGroup as RadioGroup$1, createRecipeContext, createContext as createContext$1, Pagination, usePaginationContext, Switch as Switch$1, Group, InputElement, Popover, RadioCard, Field as Field$1, NumberInput, Accordion, CheckboxCard as CheckboxCard$1, Show, Heading, Alert, Center } from '@chakra-ui/react';
2
+ import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, useDisclosure, Flex, DialogRoot as DialogRoot$1, DialogBackdrop, DialogTrigger as DialogTrigger$1, DialogContent as DialogContent$1, DialogCloseTrigger as DialogCloseTrigger$1, DialogHeader as DialogHeader$1, DialogTitle as DialogTitle$1, DialogBody as DialogBody$1, DialogFooter as DialogFooter$1, Text, Menu, createRecipeContext, createContext as createContext$1, Pagination, usePaginationContext, HStack, Tag as Tag$1, Grid, Image, Card, DataList, Checkbox as Checkbox$1, Table as Table$1, Box, Tooltip as Tooltip$1, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$1, VStack, List, Input, Slider as Slider$1, For, RadioGroup as RadioGroup$1, Switch as Switch$1, Group, InputElement, Popover, RadioCard, Field as Field$1, NumberInput, Accordion, CheckboxCard as CheckboxCard$1, Show, Heading, Alert, Center } from '@chakra-ui/react';
3
3
  import { AiOutlineColumnWidth } from 'react-icons/ai';
4
4
  import * as React from 'react';
5
5
  import React__default, { createContext, useContext, useEffect, useState, useRef } from 'react';
@@ -9,13 +9,13 @@ import { FaUpDown, FaGripLinesVertical } from 'react-icons/fa6';
9
9
  import { BiDownArrow, BiUpArrow } from 'react-icons/bi';
10
10
  import { CgClose } from 'react-icons/cg';
11
11
  import { IoMdEye, IoMdCheckbox } from 'react-icons/io';
12
+ import { HiMiniEllipsisHorizontal, HiChevronLeft, HiChevronRight } from 'react-icons/hi2';
12
13
  import { makeStateUpdater, functionalUpdate, useReactTable, getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, flexRender, createColumnHelper } from '@tanstack/react-table';
13
14
  import { rankItem } from '@tanstack/match-sorter-utils';
14
15
  import { BsExclamationCircleFill } from 'react-icons/bs';
15
16
  import { GrAscend, GrDescend } from 'react-icons/gr';
16
17
  import { IoReload } from 'react-icons/io5';
17
18
  import { HiColorSwatch, HiOutlineInformationCircle } from 'react-icons/hi';
18
- import { HiMiniEllipsisHorizontal, HiChevronLeft, HiChevronRight } from 'react-icons/hi2';
19
19
  import { monitorForElements, draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
20
20
  import invariant from 'tiny-invariant';
21
21
  import axios from 'axios';
@@ -177,6 +177,77 @@ const RowCountText = () => {
177
177
  return jsx(Text, { children: table.getRowCount() });
178
178
  };
179
179
 
180
+ const { withContext } = createRecipeContext({ key: "button" });
181
+ // Replace "a" with your framework's link component
182
+ const LinkButton = withContext("a");
183
+
184
+ const [RootPropsProvider, useRootProps] = createContext$1({
185
+ name: "RootPropsProvider",
186
+ });
187
+ const variantMap = {
188
+ outline: { default: "ghost", ellipsis: "plain", current: "outline" },
189
+ solid: { default: "outline", ellipsis: "outline", current: "solid" },
190
+ subtle: { default: "ghost", ellipsis: "plain", current: "subtle" },
191
+ };
192
+ const PaginationRoot = React.forwardRef(function PaginationRoot(props, ref) {
193
+ const { size = "sm", variant = "outline", getHref, ...rest } = props;
194
+ return (jsx(RootPropsProvider, { value: { size, variantMap: variantMap[variant], getHref }, children: jsx(Pagination.Root, { ref: ref, type: getHref ? "link" : "button", ...rest }) }));
195
+ });
196
+ const PaginationEllipsis = React.forwardRef(function PaginationEllipsis(props, ref) {
197
+ const { size, variantMap } = useRootProps();
198
+ return (jsx(Pagination.Ellipsis, { ref: ref, ...props, asChild: true, children: jsx(Button$1, { as: "span", variant: variantMap.ellipsis, size: size, children: jsx(HiMiniEllipsisHorizontal, {}) }) }));
199
+ });
200
+ const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
201
+ const { page } = usePaginationContext();
202
+ const { size, variantMap, getHref } = useRootProps();
203
+ const current = page === props.value;
204
+ const variant = current ? variantMap.current : variantMap.default;
205
+ if (getHref) {
206
+ return (jsx(LinkButton, { href: getHref(props.value), variant: variant, size: size, children: props.value }));
207
+ }
208
+ return (jsx(Pagination.Item, { ref: ref, ...props, asChild: true, children: jsx(Button$1, { variant: variant, size: size, children: props.value }) }));
209
+ });
210
+ const PaginationPrevTrigger = React.forwardRef(function PaginationPrevTrigger(props, ref) {
211
+ const { size, variantMap, getHref } = useRootProps();
212
+ const { previousPage } = usePaginationContext();
213
+ if (getHref) {
214
+ return (jsx(LinkButton, { href: previousPage != null ? getHref(previousPage) : undefined, variant: variantMap.default, size: size, children: jsx(HiChevronLeft, {}) }));
215
+ }
216
+ return (jsx(Pagination.PrevTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronLeft, {}) }) }));
217
+ });
218
+ const PaginationNextTrigger = React.forwardRef(function PaginationNextTrigger(props, ref) {
219
+ const { size, variantMap, getHref } = useRootProps();
220
+ const { nextPage } = usePaginationContext();
221
+ if (getHref) {
222
+ return (jsx(LinkButton, { href: nextPage != null ? getHref(nextPage) : undefined, variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }));
223
+ }
224
+ return (jsx(Pagination.NextTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }) }));
225
+ });
226
+ const PaginationItems = (props) => {
227
+ return (jsx(Pagination.Context, { children: ({ pages }) => pages.map((page, index) => {
228
+ return page.type === "ellipsis" ? (jsx(PaginationEllipsis, { index: index, ...props }, index)) : (jsx(PaginationItem, { type: "page", value: page.value, ...props }, index));
229
+ }) }));
230
+ };
231
+ const PaginationPageText = React.forwardRef(function PaginationPageText(props, ref) {
232
+ const { format = "compact", ...rest } = props;
233
+ const { page, totalPages, pageRange, count } = usePaginationContext();
234
+ const content = React.useMemo(() => {
235
+ if (format === "short")
236
+ return `${page} / ${totalPages}`;
237
+ if (format === "compact")
238
+ return `${page} of ${totalPages}`;
239
+ return `${pageRange.start + 1} - ${Math.min(pageRange.end, count)} of ${count}`;
240
+ }, [format, page, totalPages, pageRange, count]);
241
+ return (jsx(Text, { fontWeight: "medium", ref: ref, ...rest, children: content }));
242
+ });
243
+
244
+ const TablePagination = () => {
245
+ const { table } = useDataTableContext();
246
+ return (jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: table.getRowCount(), pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
247
+ table.setPageIndex(e.page - 1);
248
+ }, children: jsxs(HStack, { children: [jsx(PaginationPageText, { format: "long" }), jsx(PaginationPrevTrigger, {}), jsx(PaginationItems, {}), jsx(PaginationNextTrigger, {})] }) }));
249
+ };
250
+
180
251
  const Tag = React.forwardRef(function Tag(props, ref) {
181
252
  const { startElement, endElement, onClose, closable = !!onClose, children, ...rest } = props;
182
253
  return (jsxs(Tag$1.Root, { ref: ref, ...rest, children: [startElement && (jsx(Tag$1.StartElement, { children: startElement })), jsx(Tag$1.Label, { children: children }), endElement && (jsx(Tag$1.EndElement, { children: endElement })), closable && (jsx(Tag$1.EndElement, { children: jsx(Tag$1.CloseTrigger, { onClick: onClose }) }))] }));
@@ -944,77 +1015,6 @@ const TableOrderer = () => {
944
1015
  return (jsx(Fragment, { children: jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
945
1016
  };
946
1017
 
947
- const { withContext } = createRecipeContext({ key: "button" });
948
- // Replace "a" with your framework's link component
949
- const LinkButton = withContext("a");
950
-
951
- const [RootPropsProvider, useRootProps] = createContext$1({
952
- name: "RootPropsProvider",
953
- });
954
- const variantMap = {
955
- outline: { default: "ghost", ellipsis: "plain", current: "outline" },
956
- solid: { default: "outline", ellipsis: "outline", current: "solid" },
957
- subtle: { default: "ghost", ellipsis: "plain", current: "subtle" },
958
- };
959
- const PaginationRoot = React.forwardRef(function PaginationRoot(props, ref) {
960
- const { size = "sm", variant = "outline", getHref, ...rest } = props;
961
- return (jsx(RootPropsProvider, { value: { size, variantMap: variantMap[variant], getHref }, children: jsx(Pagination.Root, { ref: ref, type: getHref ? "link" : "button", ...rest }) }));
962
- });
963
- const PaginationEllipsis = React.forwardRef(function PaginationEllipsis(props, ref) {
964
- const { size, variantMap } = useRootProps();
965
- return (jsx(Pagination.Ellipsis, { ref: ref, ...props, asChild: true, children: jsx(Button$1, { as: "span", variant: variantMap.ellipsis, size: size, children: jsx(HiMiniEllipsisHorizontal, {}) }) }));
966
- });
967
- const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
968
- const { page } = usePaginationContext();
969
- const { size, variantMap, getHref } = useRootProps();
970
- const current = page === props.value;
971
- const variant = current ? variantMap.current : variantMap.default;
972
- if (getHref) {
973
- return (jsx(LinkButton, { href: getHref(props.value), variant: variant, size: size, children: props.value }));
974
- }
975
- return (jsx(Pagination.Item, { ref: ref, ...props, asChild: true, children: jsx(Button$1, { variant: variant, size: size, children: props.value }) }));
976
- });
977
- const PaginationPrevTrigger = React.forwardRef(function PaginationPrevTrigger(props, ref) {
978
- const { size, variantMap, getHref } = useRootProps();
979
- const { previousPage } = usePaginationContext();
980
- if (getHref) {
981
- return (jsx(LinkButton, { href: previousPage != null ? getHref(previousPage) : undefined, variant: variantMap.default, size: size, children: jsx(HiChevronLeft, {}) }));
982
- }
983
- return (jsx(Pagination.PrevTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronLeft, {}) }) }));
984
- });
985
- const PaginationNextTrigger = React.forwardRef(function PaginationNextTrigger(props, ref) {
986
- const { size, variantMap, getHref } = useRootProps();
987
- const { nextPage } = usePaginationContext();
988
- if (getHref) {
989
- return (jsx(LinkButton, { href: nextPage != null ? getHref(nextPage) : undefined, variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }));
990
- }
991
- return (jsx(Pagination.NextTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }) }));
992
- });
993
- const PaginationItems = (props) => {
994
- return (jsx(Pagination.Context, { children: ({ pages }) => pages.map((page, index) => {
995
- return page.type === "ellipsis" ? (jsx(PaginationEllipsis, { index: index, ...props }, index)) : (jsx(PaginationItem, { type: "page", value: page.value, ...props }, index));
996
- }) }));
997
- };
998
- const PaginationPageText = React.forwardRef(function PaginationPageText(props, ref) {
999
- const { format = "compact", ...rest } = props;
1000
- const { page, totalPages, pageRange, count } = usePaginationContext();
1001
- const content = React.useMemo(() => {
1002
- if (format === "short")
1003
- return `${page} / ${totalPages}`;
1004
- if (format === "compact")
1005
- return `${page} of ${totalPages}`;
1006
- return `${pageRange.start + 1} - ${Math.min(pageRange.end, count)} of ${count}`;
1007
- }, [format, page, totalPages, pageRange, count]);
1008
- return (jsx(Text, { fontWeight: "medium", ref: ref, ...rest, children: content }));
1009
- });
1010
-
1011
- const TablePagination = () => {
1012
- const { table } = useDataTableContext();
1013
- return (jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: table.getRowCount(), pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
1014
- table.setPageIndex(e.page - 1);
1015
- }, children: jsxs(HStack, { children: [jsx(PaginationPageText, { format: "long" }), jsx(PaginationPrevTrigger, {}), jsx(PaginationItems, {}), jsx(PaginationNextTrigger, {})] }) }));
1016
- };
1017
-
1018
1018
  const SelectAllRowsToggle = ({ selectAllIcon = jsx(MdOutlineChecklist, {}), clearAllIcon = jsx(MdClear, {}), selectAllText = "", clearAllText = "", }) => {
1019
1019
  const { table } = useDataTableContext();
1020
1020
  return (jsxs(Fragment, { children: [!!selectAllText === false && (jsx(IconButton, { variant: "ghost", "aria-label": table.getIsAllRowsSelected() ? clearAllText : selectAllText, onClick: (event) => {
@@ -1306,45 +1306,6 @@ const useDataTableServer = ({ url, onFetchSuccess = () => { }, default: { sortin
1306
1306
  };
1307
1307
  };
1308
1308
 
1309
- const FilterOptions = ({ column }) => {
1310
- const { table } = useDataTableContext();
1311
- const tableColumn = table.getColumn(column);
1312
- const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
1313
- return (jsx(Fragment, { children: options.map((option) => {
1314
- const selected = table.getColumn(column)?.getFilterValue() === option;
1315
- return (jsxs(Button$1, { size: "sm", onClick: () => {
1316
- if (selected) {
1317
- table.setColumnFilters((state) => {
1318
- return state.filter((filter) => {
1319
- return filter.id !== column;
1320
- });
1321
- });
1322
- return;
1323
- }
1324
- table.getColumn(column)?.setFilterValue(option);
1325
- }, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [option, selected && jsx(MdClose, {})] }, option));
1326
- }) }));
1327
- };
1328
-
1329
- const InputGroup = React.forwardRef(function InputGroup(props, ref) {
1330
- const { startElement, startElementProps, endElement, endElementProps, children, startOffset = "6px", endOffset = "6px", ...rest } = props;
1331
- return (jsxs(Group, { ref: ref, ...rest, children: [startElement && (jsx(InputElement, { pointerEvents: "none", ...startElementProps, children: startElement })), React.cloneElement(children, {
1332
- ...(startElement && {
1333
- ps: `calc(var(--input-height) - ${startOffset})`,
1334
- }),
1335
- ...(endElement && { pe: `calc(var(--input-height) - ${endOffset})` }),
1336
- // @ts-expect-error chakra generated files
1337
- ...children.props,
1338
- }), endElement && (jsx(InputElement, { placement: "end", ...endElementProps, children: endElement }))] }));
1339
- });
1340
-
1341
- const GlobalFilter = () => {
1342
- const { table } = useDataTableContext();
1343
- return (jsx(Fragment, { children: jsx(InputGroup, { flex: "1", startElement: jsx(MdSearch, {}), children: jsx(Input, { placeholder: "Outline", variant: "outline", onChange: (e) => {
1344
- table.setGlobalFilter(e.target.value);
1345
- } }) }) }));
1346
- };
1347
-
1348
1309
  const idListSanityCheck = (param, idList, properties) => {
1349
1310
  const allKeyExists = idList.every((key) => Object.keys(properties).some((column) => column == key));
1350
1311
  if (!allKeyExists) {
@@ -1399,6 +1360,45 @@ const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth =
1399
1360
  return columns;
1400
1361
  };
1401
1362
 
1363
+ const FilterOptions = ({ column }) => {
1364
+ const { table } = useDataTableContext();
1365
+ const tableColumn = table.getColumn(column);
1366
+ const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
1367
+ return (jsx(Fragment, { children: options.map((option) => {
1368
+ const selected = table.getColumn(column)?.getFilterValue() === option;
1369
+ return (jsxs(Button$1, { size: "sm", onClick: () => {
1370
+ if (selected) {
1371
+ table.setColumnFilters((state) => {
1372
+ return state.filter((filter) => {
1373
+ return filter.id !== column;
1374
+ });
1375
+ });
1376
+ return;
1377
+ }
1378
+ table.getColumn(column)?.setFilterValue(option);
1379
+ }, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [option, selected && jsx(MdClose, {})] }, option));
1380
+ }) }));
1381
+ };
1382
+
1383
+ const InputGroup = React.forwardRef(function InputGroup(props, ref) {
1384
+ const { startElement, startElementProps, endElement, endElementProps, children, startOffset = "6px", endOffset = "6px", ...rest } = props;
1385
+ return (jsxs(Group, { ref: ref, ...rest, children: [startElement && (jsx(InputElement, { pointerEvents: "none", ...startElementProps, children: startElement })), React.cloneElement(children, {
1386
+ ...(startElement && {
1387
+ ps: `calc(var(--input-height) - ${startOffset})`,
1388
+ }),
1389
+ ...(endElement && { pe: `calc(var(--input-height) - ${endOffset})` }),
1390
+ // @ts-expect-error chakra generated files
1391
+ ...children.props,
1392
+ }), endElement && (jsx(InputElement, { placement: "end", ...endElementProps, children: endElement }))] }));
1393
+ });
1394
+
1395
+ const GlobalFilter = () => {
1396
+ const { table } = useDataTableContext();
1397
+ return (jsx(Fragment, { children: jsx(InputGroup, { flex: "1", startElement: jsx(MdSearch, {}), children: jsx(Input, { placeholder: "Outline", variant: "outline", onChange: (e) => {
1398
+ table.setGlobalFilter(e.target.value);
1399
+ } }) }) }));
1400
+ };
1401
+
1402
1402
  //@ts-expect-error TODO: find appropriate type
1403
1403
  const SchemaFormContext = createContext({
1404
1404
  schema: {},
@@ -61,6 +61,7 @@ export * from "./components/Controls/ResetFilteringButton";
61
61
  export * from "./components/Controls/ResetSelectionButton";
62
62
  export * from "./components/Controls/ResetSortingButton";
63
63
  export * from "./components/Controls/RowCountText";
64
+ export * from "./components/Controls/TablePagination";
64
65
  export * from "./components/DataTable/CardHeader";
65
66
  export * from "./components/DataTable/DataDisplay";
66
67
  export * from "./components/DataTable/DataTable";
@@ -79,7 +80,6 @@ export * from "./components/DataTable/TableFooter";
79
80
  export * from "./components/DataTable/TableHeader";
80
81
  export * from "./components/DataTable/TableLoadingComponent";
81
82
  export * from "./components/DataTable/TableOrderer";
82
- export * from "./components/Controls/TablePagination";
83
83
  export * from "./components/DataTable/TableSelector";
84
84
  export * from "./components/DataTable/TableSorter";
85
85
  export * from "./components/DataTable/TableViewer";
@@ -88,9 +88,9 @@ export * from "./components/DataTable/useDataFromUrl";
88
88
  export * from "./components/DataTable/useDataTable";
89
89
  export * from "./components/DataTable/useDataTableContext";
90
90
  export * from "./components/DataTable/useDataTableServer";
91
+ export * from "./components/DataTable/utils/getColumns";
91
92
  export * from "./components/Filter/FilterOptions";
92
93
  export * from "./components/Filter/GlobalFilter";
93
- export * from "./components/DataTable/utils/getColumns";
94
94
  export * from "./components/Form/Form";
95
95
  export * from "./components/DatePicker/DatePicker";
96
96
  export * from "./components/DatePicker/getMultiDates";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsol-oss/react-datatable5",
3
- "version": "6.0.2",
3
+ "version": "6.0.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",