@bcgov-sso/common-react-components 2.0.0 → 2.1.1

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,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import React__default from 'react';
3
3
  import * as _button_inc_component_library_Button from '@button-inc/component-library/Button';
4
+ import { ColumnDef } from '@tanstack/react-table';
4
5
  import * as rc_tabs_lib_TabPanelList_TabPane from 'rc-tabs/lib/TabPanelList/TabPane';
5
6
  import * as styled_components_dist_types from 'styled-components/dist/types';
6
7
  import * as styled_components from 'styled-components';
@@ -38,15 +39,12 @@ interface Props$4 {
38
39
  }
39
40
  declare const Alert: (props: Props$4) => React__default.JSX.Element;
40
41
 
41
- interface Column {
42
- header: string;
43
- accessorKey: string;
44
- }
45
- interface TableProps {
42
+ interface TableProps<T extends object> {
46
43
  variant?: string;
47
44
  readOnly?: boolean;
48
- columns: Column[];
49
- data: unknown[];
45
+ columns: ColumnDef<T, any>[];
46
+ hiddenColumns?: string[];
47
+ data: T[];
50
48
  onRowSelect?: Function;
51
49
  defaultPageSize?: number;
52
50
  enableGlobalSearch?: boolean;
@@ -56,7 +54,7 @@ interface TableProps {
56
54
  pageSizeOptions?: number[];
57
55
  noDataFoundText?: string;
58
56
  }
59
- declare const Table: ({ variant, columns, data, readOnly, onRowSelect, defaultPageSize, enableGlobalSearch, globalSearchPlaceholder, globalSearchStyle, enablePagination, pageSizeOptions, noDataFoundText, }: TableProps) => React__default.JSX.Element;
57
+ declare const Table: <T extends object>({ variant, columns, hiddenColumns, data, readOnly, onRowSelect, defaultPageSize, enableGlobalSearch, globalSearchPlaceholder, globalSearchStyle, enablePagination, pageSizeOptions, noDataFoundText, }: TableProps<T>) => React__default.JSX.Element;
60
58
 
61
59
  declare const StyledTabs: styled_components_dist_types.IStyledComponentBase<"web", styled_components.FastOmit<rc_tabs.TabsProps & React.RefAttributes<HTMLDivElement>, never>> & string & Omit<React.ForwardRefExoticComponent<rc_tabs.TabsProps & React.RefAttributes<HTMLDivElement>>, keyof React.Component<any, {}, any>>;
62
60
 
package/dist/index.esm.js CHANGED
@@ -24195,7 +24195,7 @@ const StyledTable = dt$1.table `
24195
24195
  overflow: hidden;
24196
24196
  }
24197
24197
  `;
24198
- const Table = ({ variant = 'default', columns = [], data = [], readOnly = false, onRowSelect = (rowData) => { }, defaultPageSize = 5, enableGlobalSearch = true, globalSearchPlaceholder = 'Search all columns...', globalSearchStyle = {}, enablePagination = true, pageSizeOptions = [5, 10, 20, 30, 40, 50], noDataFoundText = 'No data found', }) => {
24198
+ const Table = ({ variant = 'default', columns = [], hiddenColumns = [], data = [], readOnly = false, onRowSelect = (rowData) => { }, defaultPageSize = 5, enableGlobalSearch = true, globalSearchPlaceholder = 'Search all columns...', globalSearchStyle = {}, enablePagination = true, pageSizeOptions = [5, 10, 20, 30, 40, 50], noDataFoundText = 'No data found', }) => {
24199
24199
  const [selectedRow, setSelectedRow] = useState();
24200
24200
  const [pagination, setPagination] = React__default.useState({
24201
24201
  pageIndex: 0,
@@ -24204,6 +24204,17 @@ const Table = ({ variant = 'default', columns = [], data = [], readOnly = false,
24204
24204
  const [globalFilter, setGlobalFilter] = React__default.useState('');
24205
24205
  const [columnFilters, setColumnFilters] = React__default.useState([]);
24206
24206
  const [filterState, setFilterState] = useState({});
24207
+ const initialVisibility = useMemo$1(() => {
24208
+ const visibility = {};
24209
+ columns.forEach((col) => {
24210
+ const key = col.accessorKey;
24211
+ if (key) {
24212
+ visibility[key] = !hiddenColumns.includes(key);
24213
+ }
24214
+ });
24215
+ return visibility;
24216
+ }, [columns, hiddenColumns]);
24217
+ const [columnVisibility, setColumnVisibility] = React__default.useState(initialVisibility);
24207
24218
  const table = useReactTable({
24208
24219
  data,
24209
24220
  columns,
@@ -24221,7 +24232,9 @@ const Table = ({ variant = 'default', columns = [], data = [], readOnly = false,
24221
24232
  pagination,
24222
24233
  globalFilter,
24223
24234
  columnFilters,
24235
+ columnVisibility,
24224
24236
  },
24237
+ onColumnVisibilityChange: setColumnVisibility,
24225
24238
  });
24226
24239
  const onRowClick = (row) => {
24227
24240
  if (!readOnly) {
@@ -24250,7 +24263,7 @@ const Table = ({ variant = 'default', columns = [], data = [], readOnly = false,
24250
24263
  ? Array.from(selected.values()).map((selection) => selection.value)
24251
24264
  : selected?.value ?? '';
24252
24265
  header.column?.setFilterValue(newFilter.toString());
24253
- }, options: header.column.columnDef?.meta?.filterOptions || [], isMulti: header.column.columnDef?.meta?.multiSelect || false, placeholder: header.column.columnDef?.meta?.filterPlaceholder || 'Select...', isClearable: true })))))),
24266
+ }, options: header.column.columnDef?.meta?.filterOptions || [], isMulti: header.column.columnDef?.meta?.multiSelect || false, placeholder: header.column.columnDef?.meta?.filterPlaceholder || 'Select...', isClearable: true, defaultValue: header.column.columnDef?.meta?.defaultValue || null })))))),
24254
24267
  React__default.createElement(StyledTable, { variant: variant, readOnly: readOnly },
24255
24268
  React__default.createElement("thead", null, table.getHeaderGroups().map((headerGroup) => (React__default.createElement("tr", { key: headerGroup.id }, headerGroup.headers.map((header) => (React__default.createElement("th", { key: header.id },
24256
24269
  React__default.createElement("div", { className: header.column.getCanSort() ? 'sortable' : '',