Skip to content

Commit

Permalink
feat(TableSettings): extend table settings column story
Browse files Browse the repository at this point in the history
  • Loading branch information
tapo4ek committed Oct 22, 2024
1 parent c534010 commit 466d470
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';

import type {ColumnDef, ColumnPinningState} from '@tanstack/react-table';
import type {ColumnDef, ColumnPinningState, RowSelectionState} from '@tanstack/react-table';

import {SETTINGS_COLUMN_ID, getSettingsColumn} from '../../../../constants';
import {SETTINGS_COLUMN_ID, getSettingsColumn, selectionColumn} from '../../../../constants';
import {useTable} from '../../../../hooks';
import {Table} from '../../../Table/Table';
import type {TableSettingsOptions} from '../../TableSettings';
Expand Down Expand Up @@ -97,17 +97,21 @@ const columns: ColumnDef<Item>[] = [
];

export const TableSettingsColumnStory = (options: TableSettingsOptions) => {
const [rowSelection, setRowSelection] = React.useState<RowSelectionState>({});
const settingsColumn = getSettingsColumn<Item>(SETTINGS_COLUMN_ID, options);
const [columnPinning, setColumnPinning] = React.useState<ColumnPinningState>({
left: [],
left: ['_select'],
right: [SETTINGS_COLUMN_ID],
});
const table = useTable({
columns: [...columns, settingsColumn],
columns: [selectionColumn as ColumnDef<Item>, ...columns, settingsColumn],
data,
enableColumnPinning: true,
state: {columnPinning},
state: {rowSelection, columnPinning},
onColumnPinningChange: setColumnPinning,
enableRowSelection: true,
enableMultiRowSelection: true,
onRowSelectionChange: setRowSelection,
});

return (
Expand Down
3 changes: 3 additions & 0 deletions src/constants/selectionColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const selectionColumn: ColumnDef<unknown> = {
onChange={row.getToggleSelectedHandler()}
/>
),
meta: {
hideInSettings: true,
},
size: 32,
minSize: 32,
};

0 comments on commit 466d470

Please sign in to comment.