diff --git a/src/components/Table/Table.classname.ts b/src/components/Table/Table.classname.ts new file mode 100644 index 0000000..fff9ecb --- /dev/null +++ b/src/components/Table/Table.classname.ts @@ -0,0 +1,3 @@ +import {block} from '../../utils'; + +export const b = block('styled-table'); diff --git a/src/components/Table/Table.scss b/src/components/Table/Table.scss new file mode 100644 index 0000000..27de484 --- /dev/null +++ b/src/components/Table/Table.scss @@ -0,0 +1,25 @@ +@use '@gravity-ui/uikit/styles/mixins'; +@use '../variables'; + +$block: '.#{variables.$ns}styled-table'; + +#{$block} { + &__header { + background: var(--g-color-base-background); + } + + &__cell { + @include mixins.text-body-1(); + } + + &__header-cell { + @include mixins.text-subheader-1(); + } + + &__cell, + &__header-cell, + &__footer-cell { + padding: 11px var(--g-spacing-2) 10px; + border-block-end: 1px solid var(--g-color-line-generic); + } +} diff --git a/src/components/Table/Table.tsx b/src/components/Table/Table.tsx new file mode 100644 index 0000000..d28c08c --- /dev/null +++ b/src/components/Table/Table.tsx @@ -0,0 +1,55 @@ +import React from 'react'; + +import {BaseTable} from '../BaseTable'; +import type {BaseTableProps} from '../BaseTable'; + +import {b} from './Table.classname'; + +import './Table.scss'; + +export interface TableProps + extends BaseTableProps {} + +export const Table = React.forwardRef( + ( + { + className, + cellClassName: cellClassNameProp, + footerCellClassName, + headerCellClassName: headerCellClassNameProp, + headerClassName, + ...props + }: TableProps, + ref: React.Ref, + ) => { + const cellClassName: TableProps['cellClassName'] = React.useMemo(() => { + if (typeof cellClassNameProp === 'function') { + return (...params) => b('cell', cellClassNameProp(...params)); + } + return b('cell', cellClassNameProp); + }, [cellClassNameProp]); + + const headerCellClassName: TableProps['headerCellClassName'] = React.useMemo(() => { + if (typeof headerCellClassNameProp === 'function') { + return (...params) => b('header-cell', headerCellClassNameProp(...params)); + } + return b('header-cell', headerCellClassNameProp); + }, [headerCellClassNameProp]); + + return ( + + ); + }, +) as (( + props: TableProps & {ref?: React.Ref}, +) => React.ReactElement) & {displayName: string}; + +Table.displayName = 'Table'; diff --git a/src/components/Table/index.ts b/src/components/Table/index.ts new file mode 100644 index 0000000..75193ad --- /dev/null +++ b/src/components/Table/index.ts @@ -0,0 +1 @@ +export * from './Table'; diff --git a/src/components/__stories__/BaseTable.stories.tsx b/src/components/__stories__/BaseTable.stories.tsx index 1efa74b..179bc03 100644 --- a/src/components/__stories__/BaseTable.stories.tsx +++ b/src/components/__stories__/BaseTable.stories.tsx @@ -4,27 +4,27 @@ import type {Meta, StoryFn} from '@storybook/react'; import {BaseTable} from '../BaseTable'; -import {ColumnPinningDemo} from './ColumnPinningDemo'; -import {ColumnPinningWithReorderingDemo} from './ColumnPinningWithReorderingDemo'; -import {ColumnPinningWithSelectionDemo} from './ColumnPinningWithSelectionDemo'; -import {DefaultDemo} from './DefaultDemo'; -import {EmptyContentDemo} from './EmptyContent'; -import {GroupingDemo} from './GroupingDemo'; -import {GroupingDemo2} from './GroupingDemo2'; -import {GroupingWithSelectionDemo} from './GroupingWithSelectionDemo'; -import {HeaderGroupsDemo} from './HeaderGroupsDemo'; -import {ReorderingDemo} from './ReorderingDemo'; -import {ReorderingTreeDemo} from './ReorderingTreeDemo'; -import {ReorderingWithVirtualizationDemo} from './ReorderingWithVirtualizationDemo'; -import {ResizingDemo} from './ResizingDemo'; -import {SortingDemo} from './SortingDemo'; -import {StickyHeaderDemo} from './StickyHeaderDemo'; -import {TreeDemo} from './TreeDemo'; -import {TreeWithGroupsDemo} from './TreeWithGroupsDemo'; -import {VirtualizationDemo} from './VirtualizationDemo'; -import {WindowVirtualizationDemo} from './WindowVirtualizationDemo'; -import {WithSelectionDemo} from './WithSelectionDemo'; -import {WithoutHeaderDemo} from './WithoutHeaderDemo'; +import {ColumnPinningDemo} from './components/BaseTable/ColumnPinningDemo'; +import {ColumnPinningWithReorderingDemo} from './components/BaseTable/ColumnPinningWithReorderingDemo'; +import {ColumnPinningWithSelectionDemo} from './components/BaseTable/ColumnPinningWithSelectionDemo'; +import {DefaultDemo} from './components/BaseTable/DefaultDemo'; +import {EmptyContentDemo} from './components/BaseTable/EmptyContent'; +import {GroupingDemo} from './components/BaseTable/GroupingDemo'; +import {GroupingDemo2} from './components/BaseTable/GroupingDemo2'; +import {GroupingWithSelectionDemo} from './components/BaseTable/GroupingWithSelectionDemo'; +import {HeaderGroupsDemo} from './components/BaseTable/HeaderGroupsDemo'; +import {ReorderingDemo} from './components/BaseTable/ReorderingDemo'; +import {ReorderingTreeDemo} from './components/BaseTable/ReorderingTreeDemo'; +import {ReorderingWithVirtualizationDemo} from './components/BaseTable/ReorderingWithVirtualizationDemo'; +import {ResizingDemo} from './components/BaseTable/ResizingDemo'; +import {SortingDemo} from './components/BaseTable/SortingDemo'; +import {StickyHeaderDemo} from './components/BaseTable/StickyHeaderDemo'; +import {TreeDemo} from './components/BaseTable/TreeDemo'; +import {TreeWithGroupsDemo} from './components/BaseTable/TreeWithGroupsDemo'; +import {VirtualizationDemo} from './components/BaseTable/VirtualizationDemo'; +import {WindowVirtualizationDemo} from './components/BaseTable/WindowVirtualizationDemo'; +import {WithSelectionDemo} from './components/BaseTable/WithSelectionDemo'; +import {WithoutHeaderDemo} from './components/BaseTable/WithoutHeaderDemo'; export default { title: 'BaseTable', diff --git a/src/components/__stories__/DefaultDemo.tsx b/src/components/__stories__/DefaultDemo.tsx deleted file mode 100644 index a12557f..0000000 --- a/src/components/__stories__/DefaultDemo.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react'; - -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; - -import {columns} from './constants/columns'; -import {data} from './constants/data'; - -export const DefaultDemo = () => { - const table = useTable({ - columns, - data, - }); - - return ; -}; diff --git a/src/components/__stories__/Table.stories.tsx b/src/components/__stories__/Table.stories.tsx new file mode 100644 index 0000000..57d44a5 --- /dev/null +++ b/src/components/__stories__/Table.stories.tsx @@ -0,0 +1,27 @@ +import React from 'react'; + +import type {Meta, StoryFn} from '@storybook/react'; + +import {Table} from '../Table'; + +import {DefaultDemo} from './components/Table/DefaultDemo'; +import {StickyHeaderDemo} from './components/Table/StickyHeaderDemo'; +import {VirtualizationDemo} from './components/Table/VirtualizationDemo'; +import {WindowVirtualizationDemo} from './components/Table/WindowVirtualizationDemo'; + +export default { + title: 'Table', + component: Table, +} as Meta; + +const DefaultTemplate: StoryFn = () => ; +export const Default: StoryFn = DefaultTemplate.bind({}); + +const VirtualizationTemplate: StoryFn = () => ; +export const Virtualization: StoryFn = VirtualizationTemplate.bind({}); + +const WindowVirtualizationTemplate: StoryFn = () => ; +export const WindowVirtualization: StoryFn = WindowVirtualizationTemplate.bind({}); + +const StickyHeaderTamplate: StoryFn = () => ; +export const StickyHeader: StoryFn = StickyHeaderTamplate.bind({}); diff --git a/src/components/__stories__/cells/ColumnPinningHeaderCell.tsx b/src/components/__stories__/cells/ColumnPinningHeaderCell.tsx index 42670f8..d5aeba7 100644 --- a/src/components/__stories__/cells/ColumnPinningHeaderCell.tsx +++ b/src/components/__stories__/cells/ColumnPinningHeaderCell.tsx @@ -2,7 +2,7 @@ import React from 'react'; import type {HeaderContext} from '@tanstack/react-table'; -import {cnColumnPinningDemo} from '../ColumnPinningDemo.classname'; +import {cnColumnPinningDemo} from '../components/BaseTable/ColumnPinningDemo.classname'; interface ColumnPinningHeaderCellProps { info: HeaderContext; diff --git a/src/components/__stories__/ColumnPinningDemo.classname.ts b/src/components/__stories__/components/BaseTable/ColumnPinningDemo.classname.ts similarity index 62% rename from src/components/__stories__/ColumnPinningDemo.classname.ts rename to src/components/__stories__/components/BaseTable/ColumnPinningDemo.classname.ts index 11c60f1..b50323b 100644 --- a/src/components/__stories__/ColumnPinningDemo.classname.ts +++ b/src/components/__stories__/components/BaseTable/ColumnPinningDemo.classname.ts @@ -1,3 +1,3 @@ -import {cn} from '../../utils'; +import {cn} from '../../../../utils'; export const cnColumnPinningDemo = cn('column-pinning-demo'); diff --git a/src/components/__stories__/ColumnPinningDemo.scss b/src/components/__stories__/components/BaseTable/ColumnPinningDemo.scss similarity index 100% rename from src/components/__stories__/ColumnPinningDemo.scss rename to src/components/__stories__/components/BaseTable/ColumnPinningDemo.scss diff --git a/src/components/__stories__/ColumnPinningDemo.tsx b/src/components/__stories__/components/BaseTable/ColumnPinningDemo.tsx similarity index 79% rename from src/components/__stories__/ColumnPinningDemo.tsx rename to src/components/__stories__/components/BaseTable/ColumnPinningDemo.tsx index 511c0dc..6f93428 100644 --- a/src/components/__stories__/ColumnPinningDemo.tsx +++ b/src/components/__stories__/components/BaseTable/ColumnPinningDemo.tsx @@ -2,12 +2,12 @@ import React from 'react'; import type {ColumnPinningState} from '@tanstack/react-table'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columnPinning'; +import {data} from '../../constants/data'; import {cnColumnPinningDemo} from './ColumnPinningDemo.classname'; -import {columns} from './constants/columnPinning'; -import {data} from './constants/data'; import './ColumnPinningDemo.scss'; diff --git a/src/components/__stories__/ColumnPinningWithReorderingDemo.tsx b/src/components/__stories__/components/BaseTable/ColumnPinningWithReorderingDemo.tsx similarity index 82% rename from src/components/__stories__/ColumnPinningWithReorderingDemo.tsx rename to src/components/__stories__/components/BaseTable/ColumnPinningWithReorderingDemo.tsx index e450fe7..1a7460e 100644 --- a/src/components/__stories__/ColumnPinningWithReorderingDemo.tsx +++ b/src/components/__stories__/components/BaseTable/ColumnPinningWithReorderingDemo.tsx @@ -2,16 +2,16 @@ import React from 'react'; import type {ColumnDef, ColumnPinningState} from '@tanstack/react-table'; -import {defaultDragHandleColumn} from '../../constants'; -import {withTableReorder} from '../../hocs'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; -import type {SortableListDragResult} from '../SortableList'; +import {defaultDragHandleColumn} from '../../../../constants'; +import {withTableReorder} from '../../../../hocs'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import type {SortableListDragResult} from '../../../SortableList'; +import {columns} from '../../constants/columnPinning'; +import {data as originalData} from '../../constants/data'; +import type {Item} from '../../types'; import {cnColumnPinningDemo} from './ColumnPinningDemo.classname'; -import {columns} from './constants/columnPinning'; -import {data as originalData} from './constants/data'; -import type {Item} from './types'; import './ColumnPinningDemo.scss'; diff --git a/src/components/__stories__/ColumnPinningWithSelectionDemo.tsx b/src/components/__stories__/components/BaseTable/ColumnPinningWithSelectionDemo.tsx similarity index 81% rename from src/components/__stories__/ColumnPinningWithSelectionDemo.tsx rename to src/components/__stories__/components/BaseTable/ColumnPinningWithSelectionDemo.tsx index 599ab62..e75a00c 100644 --- a/src/components/__stories__/ColumnPinningWithSelectionDemo.tsx +++ b/src/components/__stories__/components/BaseTable/ColumnPinningWithSelectionDemo.tsx @@ -2,14 +2,14 @@ import React from 'react'; import type {ColumnDef, ColumnPinningState, RowSelectionState} from '@tanstack/react-table'; -import {defaultSelectionColumn} from '../../constants'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {defaultSelectionColumn} from '../../../../constants'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columnPinning'; +import {data} from '../../constants/data'; +import type {Item} from '../../types'; import {cnColumnPinningDemo} from './ColumnPinningDemo.classname'; -import {columns} from './constants/columnPinning'; -import {data} from './constants/data'; -import type {Item} from './types'; import './ColumnPinningDemo.scss'; diff --git a/src/components/__stories__/components/BaseTable/DefaultDemo.tsx b/src/components/__stories__/components/BaseTable/DefaultDemo.tsx new file mode 100644 index 0000000..f801007 --- /dev/null +++ b/src/components/__stories__/components/BaseTable/DefaultDemo.tsx @@ -0,0 +1,15 @@ +import React from 'react'; + +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columns'; +import {data} from '../../constants/data'; + +export const DefaultDemo = () => { + const table = useTable({ + columns, + data, + }); + + return ; +}; diff --git a/src/components/__stories__/EmptyContent.classname.ts b/src/components/__stories__/components/BaseTable/EmptyContent.classname.ts similarity index 61% rename from src/components/__stories__/EmptyContent.classname.ts rename to src/components/__stories__/components/BaseTable/EmptyContent.classname.ts index 42afa4e..0ee8c21 100644 --- a/src/components/__stories__/EmptyContent.classname.ts +++ b/src/components/__stories__/components/BaseTable/EmptyContent.classname.ts @@ -1,3 +1,3 @@ -import {cn} from '../../utils'; +import {cn} from '../../../../utils'; export const cnEmptyContentDemo = cn('empty-content-demo'); diff --git a/src/components/__stories__/EmptyContent.scss b/src/components/__stories__/components/BaseTable/EmptyContent.scss similarity index 100% rename from src/components/__stories__/EmptyContent.scss rename to src/components/__stories__/components/BaseTable/EmptyContent.scss diff --git a/src/components/__stories__/EmptyContent.tsx b/src/components/__stories__/components/BaseTable/EmptyContent.tsx similarity index 74% rename from src/components/__stories__/EmptyContent.tsx rename to src/components/__stories__/components/BaseTable/EmptyContent.tsx index 310d602..bb104f0 100644 --- a/src/components/__stories__/EmptyContent.tsx +++ b/src/components/__stories__/components/BaseTable/EmptyContent.tsx @@ -1,10 +1,10 @@ import React from 'react'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columns'; import {cnEmptyContentDemo} from './EmptyContent.classname'; -import {columns} from './constants/columns'; import './EmptyContent.scss'; diff --git a/src/components/__stories__/GroupingDemo.classname.ts b/src/components/__stories__/components/BaseTable/GroupingDemo.classname.ts similarity index 57% rename from src/components/__stories__/GroupingDemo.classname.ts rename to src/components/__stories__/components/BaseTable/GroupingDemo.classname.ts index 4299ad6..df93e94 100644 --- a/src/components/__stories__/GroupingDemo.classname.ts +++ b/src/components/__stories__/components/BaseTable/GroupingDemo.classname.ts @@ -1,3 +1,3 @@ -import {cn} from '../../utils'; +import {cn} from '../../../../utils'; export const cnGroupingDemo = cn('grouping-demo'); diff --git a/src/components/__stories__/GroupingDemo.scss b/src/components/__stories__/components/BaseTable/GroupingDemo.scss similarity index 100% rename from src/components/__stories__/GroupingDemo.scss rename to src/components/__stories__/components/BaseTable/GroupingDemo.scss diff --git a/src/components/__stories__/GroupingDemo.tsx b/src/components/__stories__/components/BaseTable/GroupingDemo.tsx similarity index 81% rename from src/components/__stories__/GroupingDemo.tsx rename to src/components/__stories__/components/BaseTable/GroupingDemo.tsx index 0f054c9..a329570 100644 --- a/src/components/__stories__/GroupingDemo.tsx +++ b/src/components/__stories__/components/BaseTable/GroupingDemo.tsx @@ -2,12 +2,12 @@ import React from 'react'; import type {ExpandedState, Row} from '@tanstack/react-table'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import type {GroupOrItem} from '../../constants/grouping'; +import {columns, data} from '../../constants/grouping'; import {cnGroupingDemo} from './GroupingDemo.classname'; -import type {GroupOrItem} from './constants/grouping'; -import {columns, data} from './constants/grouping'; import './GroupingDemo.scss'; diff --git a/src/components/__stories__/GroupingDemo2.tsx b/src/components/__stories__/components/BaseTable/GroupingDemo2.tsx similarity index 81% rename from src/components/__stories__/GroupingDemo2.tsx rename to src/components/__stories__/components/BaseTable/GroupingDemo2.tsx index f9d64d0..a044831 100644 --- a/src/components/__stories__/GroupingDemo2.tsx +++ b/src/components/__stories__/components/BaseTable/GroupingDemo2.tsx @@ -2,13 +2,13 @@ import React from 'react'; import type {ExpandedState, Row} from '@tanstack/react-table'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columns'; +import type {Item} from '../../types'; +import {generateData} from '../../utils'; import {cnGroupingDemo} from './GroupingDemo.classname'; -import {columns} from './constants/columns'; -import type {Item} from './types'; -import {generateData} from './utils'; import './GroupingDemo.scss'; diff --git a/src/components/__stories__/GroupingWithSelectionDemo.tsx b/src/components/__stories__/components/BaseTable/GroupingWithSelectionDemo.tsx similarity index 82% rename from src/components/__stories__/GroupingWithSelectionDemo.tsx rename to src/components/__stories__/components/BaseTable/GroupingWithSelectionDemo.tsx index 3408f47..4f7264b 100644 --- a/src/components/__stories__/GroupingWithSelectionDemo.tsx +++ b/src/components/__stories__/components/BaseTable/GroupingWithSelectionDemo.tsx @@ -2,13 +2,13 @@ import React from 'react'; import type {ColumnDef, ExpandedState, Row, RowSelectionState} from '@tanstack/react-table'; -import {defaultSelectionColumn} from '../../constants'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {defaultSelectionColumn} from '../../../../constants'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import type {GroupOrItem} from '../../constants/grouping'; +import {data, columns as originalColumns} from '../../constants/grouping'; import {cnGroupingDemo} from './GroupingDemo.classname'; -import type {GroupOrItem} from './constants/grouping'; -import {data, columns as originalColumns} from './constants/grouping'; import './GroupingDemo.scss'; const columns: ColumnDef[] = [ diff --git a/src/components/__stories__/HeaderGroupsDemo.classname.ts b/src/components/__stories__/components/BaseTable/HeaderGroupsDemo.classname.ts similarity index 61% rename from src/components/__stories__/HeaderGroupsDemo.classname.ts rename to src/components/__stories__/components/BaseTable/HeaderGroupsDemo.classname.ts index f169213..397ffeb 100644 --- a/src/components/__stories__/HeaderGroupsDemo.classname.ts +++ b/src/components/__stories__/components/BaseTable/HeaderGroupsDemo.classname.ts @@ -1,3 +1,3 @@ -import {cn} from '../../utils'; +import {cn} from '../../../../utils'; export const cnHeaderGroupsDemo = cn('header-groups-demo'); diff --git a/src/components/__stories__/HeaderGroupsDemo.scss b/src/components/__stories__/components/BaseTable/HeaderGroupsDemo.scss similarity index 100% rename from src/components/__stories__/HeaderGroupsDemo.scss rename to src/components/__stories__/components/BaseTable/HeaderGroupsDemo.scss diff --git a/src/components/__stories__/HeaderGroupsDemo.tsx b/src/components/__stories__/components/BaseTable/HeaderGroupsDemo.tsx similarity index 82% rename from src/components/__stories__/HeaderGroupsDemo.tsx rename to src/components/__stories__/components/BaseTable/HeaderGroupsDemo.tsx index 1dad382..34777dc 100644 --- a/src/components/__stories__/HeaderGroupsDemo.tsx +++ b/src/components/__stories__/components/BaseTable/HeaderGroupsDemo.tsx @@ -2,13 +2,13 @@ import React from 'react'; import type {ColumnDef} from '@tanstack/react-table'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns as nestedColumns} from '../../constants/columns'; +import {data} from '../../constants/data'; +import type {Item} from '../../types'; import {cnHeaderGroupsDemo} from './HeaderGroupsDemo.classname'; -import {columns as nestedColumns} from './constants/columns'; -import {data} from './constants/data'; -import type {Item} from './types'; import './HeaderGroupsDemo.scss'; diff --git a/src/components/__stories__/ReorderingDemo.tsx b/src/components/__stories__/components/BaseTable/ReorderingDemo.tsx similarity index 75% rename from src/components/__stories__/ReorderingDemo.tsx rename to src/components/__stories__/components/BaseTable/ReorderingDemo.tsx index 9c02840..32e70a2 100644 --- a/src/components/__stories__/ReorderingDemo.tsx +++ b/src/components/__stories__/components/BaseTable/ReorderingDemo.tsx @@ -2,15 +2,14 @@ import React from 'react'; import type {ColumnDef} from '@tanstack/react-table'; -import {defaultDragHandleColumn} from '../../constants'; -import {withTableReorder} from '../../hocs'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; -import type {SortableListDragResult} from '../SortableList'; - -import {columns as originalColumns} from './constants/columns'; -import {data as originalData} from './constants/data'; -import type {Item} from './types'; +import {defaultDragHandleColumn} from '../../../../constants'; +import {withTableReorder} from '../../../../hocs'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import type {SortableListDragResult} from '../../../SortableList'; +import {columns as originalColumns} from '../../constants/columns'; +import {data as originalData} from '../../constants/data'; +import type {Item} from '../../types'; const TableWithReordering = withTableReorder(BaseTable); diff --git a/src/components/__stories__/ReorderingTreeDemo.tsx b/src/components/__stories__/components/BaseTable/ReorderingTreeDemo.tsx similarity index 68% rename from src/components/__stories__/ReorderingTreeDemo.tsx rename to src/components/__stories__/components/BaseTable/ReorderingTreeDemo.tsx index 335662b..8168471 100644 --- a/src/components/__stories__/ReorderingTreeDemo.tsx +++ b/src/components/__stories__/components/BaseTable/ReorderingTreeDemo.tsx @@ -2,14 +2,13 @@ import React from 'react'; import type {ColumnDef, ExpandedState} from '@tanstack/react-table'; -import {defaultDragHandleColumn} from '../../constants'; -import {withTableReorder} from '../../hocs'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; - -import type {TreeItem} from './constants/tree'; -import {draggableTreeColumns, data as originalData} from './constants/tree'; -import {useTreeDataReordering} from './hooks/useTreeDataReordering'; +import {defaultDragHandleColumn} from '../../../../constants'; +import {withTableReorder} from '../../../../hocs'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import type {TreeItem} from '../../constants/tree'; +import {draggableTreeColumns, data as originalData} from '../../constants/tree'; +import {useTreeDataReordering} from '../../hooks/useTreeDataReordering'; const TableWithReordering = withTableReorder(BaseTable); diff --git a/src/components/__stories__/ReorderingWithVirtualizationDemo.tsx b/src/components/__stories__/components/BaseTable/ReorderingWithVirtualizationDemo.tsx similarity index 79% rename from src/components/__stories__/ReorderingWithVirtualizationDemo.tsx rename to src/components/__stories__/components/BaseTable/ReorderingWithVirtualizationDemo.tsx index 8a36a76..f57a361 100644 --- a/src/components/__stories__/ReorderingWithVirtualizationDemo.tsx +++ b/src/components/__stories__/components/BaseTable/ReorderingWithVirtualizationDemo.tsx @@ -2,17 +2,17 @@ import React from 'react'; import type {ColumnDef} from '@tanstack/react-table'; -import {defaultDragHandleColumn} from '../../constants'; -import {withTableReorder} from '../../hocs'; -import {useTable, useWindowRowVirtualizer} from '../../hooks'; -import {getVirtualRowRangeExtractor} from '../../utils'; -import {BaseTable} from '../BaseTable'; -import type {SortableListDragResult} from '../SortableList'; +import {defaultDragHandleColumn} from '../../../../constants'; +import {withTableReorder} from '../../../../hocs'; +import {useTable, useWindowRowVirtualizer} from '../../../../hooks'; +import {getVirtualRowRangeExtractor} from '../../../../utils'; +import {BaseTable} from '../../../BaseTable'; +import type {SortableListDragResult} from '../../../SortableList'; +import {columns as originalColumns} from '../../constants/columns'; +import type {Item} from '../../types'; +import {generateData} from '../../utils'; import {cnVirtualizationDemo} from './VirtualizationDemo.classname'; -import {columns as originalColumns} from './constants/columns'; -import type {Item} from './types'; -import {generateData} from './utils'; import './VirtualizationDemo.scss'; diff --git a/src/components/__stories__/ResizingDemo.tsx b/src/components/__stories__/components/BaseTable/ResizingDemo.tsx similarity index 57% rename from src/components/__stories__/ResizingDemo.tsx rename to src/components/__stories__/components/BaseTable/ResizingDemo.tsx index fe75709..ec78d83 100644 --- a/src/components/__stories__/ResizingDemo.tsx +++ b/src/components/__stories__/components/BaseTable/ResizingDemo.tsx @@ -1,10 +1,9 @@ import React from 'react'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; - -import {columns} from './constants/columns'; -import {data} from './constants/data'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columns'; +import {data} from '../../constants/data'; export const ResizingDemo = () => { const table = useTable({ diff --git a/src/components/__stories__/SortingDemo.tsx b/src/components/__stories__/components/BaseTable/SortingDemo.tsx similarity index 71% rename from src/components/__stories__/SortingDemo.tsx rename to src/components/__stories__/components/BaseTable/SortingDemo.tsx index c56dc31..32279a1 100644 --- a/src/components/__stories__/SortingDemo.tsx +++ b/src/components/__stories__/components/BaseTable/SortingDemo.tsx @@ -2,11 +2,10 @@ import React from 'react'; import type {SortingState} from '@tanstack/react-table'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; - -import {columns} from './constants/columns'; -import {data} from './constants/data'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columns'; +import {data} from '../../constants/data'; export const SortingDemo = () => { const [sorting, setSorting] = React.useState([]); diff --git a/src/components/__stories__/StickyHeaderDemo.classname.ts b/src/components/__stories__/components/BaseTable/StickyHeaderDemo.classname.ts similarity index 61% rename from src/components/__stories__/StickyHeaderDemo.classname.ts rename to src/components/__stories__/components/BaseTable/StickyHeaderDemo.classname.ts index f3afce4..22e6316 100644 --- a/src/components/__stories__/StickyHeaderDemo.classname.ts +++ b/src/components/__stories__/components/BaseTable/StickyHeaderDemo.classname.ts @@ -1,3 +1,3 @@ -import {cn} from '../../utils'; +import {cn} from '../../../../utils'; export const cnStickyHeaderDemo = cn('sticky-header-demo'); diff --git a/src/components/__stories__/StickyHeaderDemo.scss b/src/components/__stories__/components/BaseTable/StickyHeaderDemo.scss similarity index 100% rename from src/components/__stories__/StickyHeaderDemo.scss rename to src/components/__stories__/components/BaseTable/StickyHeaderDemo.scss diff --git a/src/components/__stories__/StickyHeaderDemo.tsx b/src/components/__stories__/components/BaseTable/StickyHeaderDemo.tsx similarity index 71% rename from src/components/__stories__/StickyHeaderDemo.tsx rename to src/components/__stories__/components/BaseTable/StickyHeaderDemo.tsx index c9da76e..b014dbd 100644 --- a/src/components/__stories__/StickyHeaderDemo.tsx +++ b/src/components/__stories__/components/BaseTable/StickyHeaderDemo.tsx @@ -1,11 +1,11 @@ import React from 'react'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columns'; +import {generateData} from '../../utils'; import {cnStickyHeaderDemo} from './StickyHeaderDemo.classname'; -import {columns} from './constants/columns'; -import {generateData} from './utils'; import './StickyHeaderDemo.scss'; diff --git a/src/components/__stories__/TreeDemo.tsx b/src/components/__stories__/components/BaseTable/TreeDemo.tsx similarity index 76% rename from src/components/__stories__/TreeDemo.tsx rename to src/components/__stories__/components/BaseTable/TreeDemo.tsx index 8abca23..4a950f3 100644 --- a/src/components/__stories__/TreeDemo.tsx +++ b/src/components/__stories__/components/BaseTable/TreeDemo.tsx @@ -2,10 +2,9 @@ import React from 'react'; import type {ExpandedState} from '@tanstack/react-table'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; - -import {columns, data} from './constants/tree'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns, data} from '../../constants/tree'; export const TreeDemo = () => { const [expanded, setExpanded] = React.useState({}); diff --git a/src/components/__stories__/TreeWithGroupsDemo.tsx b/src/components/__stories__/components/BaseTable/TreeWithGroupsDemo.tsx similarity index 82% rename from src/components/__stories__/TreeWithGroupsDemo.tsx rename to src/components/__stories__/components/BaseTable/TreeWithGroupsDemo.tsx index f09cdd2..65f2e08 100644 --- a/src/components/__stories__/TreeWithGroupsDemo.tsx +++ b/src/components/__stories__/components/BaseTable/TreeWithGroupsDemo.tsx @@ -2,12 +2,12 @@ import React from 'react'; import type {ExpandedState, Row} from '@tanstack/react-table'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import type {TreeGroupItem} from '../../constants/tree'; +import {groupsColumns, groupsData} from '../../constants/tree'; import {cnGroupingDemo} from './GroupingDemo.classname'; -import type {TreeGroupItem} from './constants/tree'; -import {groupsColumns, groupsData} from './constants/tree'; import './GroupingDemo.scss'; diff --git a/src/components/__stories__/VirtualizationDemo.classname.ts b/src/components/__stories__/components/BaseTable/VirtualizationDemo.classname.ts similarity index 62% rename from src/components/__stories__/VirtualizationDemo.classname.ts rename to src/components/__stories__/components/BaseTable/VirtualizationDemo.classname.ts index aaba477..b4f45c6 100644 --- a/src/components/__stories__/VirtualizationDemo.classname.ts +++ b/src/components/__stories__/components/BaseTable/VirtualizationDemo.classname.ts @@ -1,3 +1,3 @@ -import {cn} from '../../utils'; +import {cn} from '../../../../utils'; export const cnVirtualizationDemo = cn('virtualization-demo'); diff --git a/src/components/__stories__/VirtualizationDemo.scss b/src/components/__stories__/components/BaseTable/VirtualizationDemo.scss similarity index 100% rename from src/components/__stories__/VirtualizationDemo.scss rename to src/components/__stories__/components/BaseTable/VirtualizationDemo.scss diff --git a/src/components/__stories__/VirtualizationDemo.tsx b/src/components/__stories__/components/BaseTable/VirtualizationDemo.tsx similarity index 82% rename from src/components/__stories__/VirtualizationDemo.tsx rename to src/components/__stories__/components/BaseTable/VirtualizationDemo.tsx index d143b0e..61b8d54 100644 --- a/src/components/__stories__/VirtualizationDemo.tsx +++ b/src/components/__stories__/components/BaseTable/VirtualizationDemo.tsx @@ -1,11 +1,11 @@ import React from 'react'; -import {useRowVirtualizer, useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {useRowVirtualizer, useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columns'; +import {generateData} from '../../utils'; import {cnVirtualizationDemo} from './VirtualizationDemo.classname'; -import {columns} from './constants/columns'; -import {generateData} from './utils'; import './VirtualizationDemo.scss'; diff --git a/src/components/__stories__/WindowVirtualizationDemo.tsx b/src/components/__stories__/components/BaseTable/WindowVirtualizationDemo.tsx similarity index 78% rename from src/components/__stories__/WindowVirtualizationDemo.tsx rename to src/components/__stories__/components/BaseTable/WindowVirtualizationDemo.tsx index b2d887e..43f2b08 100644 --- a/src/components/__stories__/WindowVirtualizationDemo.tsx +++ b/src/components/__stories__/components/BaseTable/WindowVirtualizationDemo.tsx @@ -1,11 +1,11 @@ import React from 'react'; -import {useTable, useWindowRowVirtualizer} from '../../hooks'; -import {BaseTable} from '../BaseTable'; +import {useTable, useWindowRowVirtualizer} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columns'; +import {generateData} from '../../utils'; import {cnVirtualizationDemo} from './VirtualizationDemo.classname'; -import {columns} from './constants/columns'; -import {generateData} from './utils'; import './VirtualizationDemo.scss'; diff --git a/src/components/__stories__/WithSelectionDemo.tsx b/src/components/__stories__/components/BaseTable/WithSelectionDemo.tsx similarity index 67% rename from src/components/__stories__/WithSelectionDemo.tsx rename to src/components/__stories__/components/BaseTable/WithSelectionDemo.tsx index 96e95a2..4724eb7 100644 --- a/src/components/__stories__/WithSelectionDemo.tsx +++ b/src/components/__stories__/components/BaseTable/WithSelectionDemo.tsx @@ -2,13 +2,12 @@ import React from 'react'; import type {ColumnDef, RowSelectionState} from '@tanstack/react-table'; -import {defaultSelectionColumn} from '../../constants'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; - -import {columns as originalColumns} from './constants/columns'; -import {data} from './constants/data'; -import type {Item} from './types'; +import {defaultSelectionColumn} from '../../../../constants'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns as originalColumns} from '../../constants/columns'; +import {data} from '../../constants/data'; +import type {Item} from '../../types'; const columns: ColumnDef[] = [defaultSelectionColumn as ColumnDef, ...originalColumns]; diff --git a/src/components/__stories__/WithoutHeaderDemo.tsx b/src/components/__stories__/components/BaseTable/WithoutHeaderDemo.tsx similarity index 52% rename from src/components/__stories__/WithoutHeaderDemo.tsx rename to src/components/__stories__/components/BaseTable/WithoutHeaderDemo.tsx index 2d6fe4c..c9c7f0b 100644 --- a/src/components/__stories__/WithoutHeaderDemo.tsx +++ b/src/components/__stories__/components/BaseTable/WithoutHeaderDemo.tsx @@ -1,10 +1,9 @@ import React from 'react'; -import {useTable} from '../../hooks'; -import {BaseTable} from '../BaseTable'; - -import {columns} from './constants/columns'; -import {data} from './constants/data'; +import {useTable} from '../../../../hooks'; +import {BaseTable} from '../../../BaseTable'; +import {columns} from '../../constants/columns'; +import {data} from '../../constants/data'; export const WithoutHeaderDemo = () => { const table = useTable({ diff --git a/src/components/__stories__/components/Table/DefaultDemo.tsx b/src/components/__stories__/components/Table/DefaultDemo.tsx new file mode 100644 index 0000000..9501bd8 --- /dev/null +++ b/src/components/__stories__/components/Table/DefaultDemo.tsx @@ -0,0 +1,15 @@ +import React from 'react'; + +import {useTable} from '../../../../hooks'; +import {Table} from '../../../Table'; +import {columns} from '../../constants/columns'; +import {data} from '../../constants/data'; + +export const DefaultDemo = () => { + const table = useTable({ + columns, + data, + }); + + return ; +}; diff --git a/src/components/__stories__/components/Table/StickyHeaderDemo.classname.ts b/src/components/__stories__/components/Table/StickyHeaderDemo.classname.ts new file mode 100644 index 0000000..5fa6eae --- /dev/null +++ b/src/components/__stories__/components/Table/StickyHeaderDemo.classname.ts @@ -0,0 +1,3 @@ +import {cn} from '../../../../utils'; + +export const cnStickyHeaderDemo = cn('styled-sticky-header-demo'); diff --git a/src/components/__stories__/components/Table/StickyHeaderDemo.scss b/src/components/__stories__/components/Table/StickyHeaderDemo.scss new file mode 100644 index 0000000..d76bf65 --- /dev/null +++ b/src/components/__stories__/components/Table/StickyHeaderDemo.scss @@ -0,0 +1,6 @@ +.styled-sticky-header-demo { + width: fit-content; + max-height: 400px; + + overflow: auto; +} diff --git a/src/components/__stories__/components/Table/StickyHeaderDemo.tsx b/src/components/__stories__/components/Table/StickyHeaderDemo.tsx new file mode 100644 index 0000000..482163f --- /dev/null +++ b/src/components/__stories__/components/Table/StickyHeaderDemo.tsx @@ -0,0 +1,25 @@ +import React from 'react'; + +import {useTable} from '../../../../hooks'; +import {Table} from '../../../Table'; +import {columns} from '../../constants/columns'; +import {generateData} from '../../utils'; + +import {cnStickyHeaderDemo} from './StickyHeaderDemo.classname'; + +import './StickyHeaderDemo.scss'; + +const data = generateData(30); + +export const StickyHeaderDemo = () => { + const table = useTable({ + columns, + data, + }); + + return ( +
+
+ + ); +}; diff --git a/src/components/__stories__/components/Table/VirtualizationDemo.tsx b/src/components/__stories__/components/Table/VirtualizationDemo.tsx new file mode 100644 index 0000000..c700734 --- /dev/null +++ b/src/components/__stories__/components/Table/VirtualizationDemo.tsx @@ -0,0 +1,31 @@ +import React from 'react'; + +import {useRowVirtualizer, useTable} from '../../../../hooks'; +import {Table} from '../../../Table'; +import {columns} from '../../constants/columns'; +import {generateData} from '../../utils'; + +const data = generateData(300); + +export const VirtualizationDemo = () => { + const table = useTable({ + columns, + data, + getRowId: (item) => item.id, + }); + + const containerRef = React.useRef(null); + + const rowVirtualizer = useRowVirtualizer({ + count: table.getRowModel().rows.length, + estimateSize: () => 40, + overscan: 5, + getScrollElement: () => containerRef.current, + }); + + return ( +
+
+ + ); +}; diff --git a/src/components/__stories__/components/Table/WindowVirtualizationDemo.tsx b/src/components/__stories__/components/Table/WindowVirtualizationDemo.tsx new file mode 100644 index 0000000..0cb5f41 --- /dev/null +++ b/src/components/__stories__/components/Table/WindowVirtualizationDemo.tsx @@ -0,0 +1,24 @@ +import React from 'react'; + +import {useTable, useWindowRowVirtualizer} from '../../../../hooks'; +import {Table} from '../../../Table'; +import {columns} from '../../constants/columns'; +import {generateData} from '../../utils'; + +const data = generateData(300); + +export const WindowVirtualizationDemo = () => { + const table = useTable({ + columns, + data, + getRowId: (item) => item.id, + }); + + const rowVirtualizer = useWindowRowVirtualizer({ + count: table.getRowModel().rows.length, + estimateSize: () => 40, + overscan: 5, + }); + + return
; +}; diff --git a/src/components/index.ts b/src/components/index.ts index 595a3e8..f83f083 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -14,5 +14,6 @@ export * from './SortableList'; export * from './SortableListContext'; export * from './SortableListDndContext'; export * from './BaseTable'; +export * from './Table'; export * from './TableContext'; export * from './TableContextProvider'; diff --git a/src/index.ts b/src/index.ts index 16f05ae..d8ccda6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,10 @@ -export {ReorderingProvider, BaseTable} from './components'; -export type {ReorderingProviderProps, SortableListDragResult, BaseTableProps} from './components'; +export {ReorderingProvider, BaseTable, Table} from './components'; +export type { + ReorderingProviderProps, + SortableListDragResult, + BaseTableProps, + TableProps, +} from './components'; export {defaultDragHandleColumn, defaultSelectionColumn} from './constants';