diff --git a/src/components/Table/Table.scss b/src/components/Table/Table.scss index 1360256..e2c158f 100644 --- a/src/components/Table/Table.scss +++ b/src/components/Table/Table.scss @@ -31,27 +31,25 @@ $block: '.#{variables.$ns}styled-table'; &__footer-cell { padding: var(--_--cell-padding); border-block-end: 1px solid var(--g-color-line-generic); - } - - &__row { - &:last-of-type { - #{$block}__cell { - border-block-end: none; - } - } &_vertical-align { &_top { - vertical-align: top; + align-content: start; } &_center { - vertical-align: middle; + align-content: center; } &_bottom { - vertical-align: bottom; + align-content: end; } } } + + &__row:last-of-type { + #{$block}__cell { + border-block-end: none; + } + } } diff --git a/src/components/Table/Table.tsx b/src/components/Table/Table.tsx index 904a9e5..cc12a41 100644 --- a/src/components/Table/Table.tsx +++ b/src/components/Table/Table.tsx @@ -8,12 +8,16 @@ import type {TableSize} from './types'; import './Table.scss'; +type VerticalAlignment = 'top' | 'center' | 'bottom'; + export interface TableProps extends BaseTableProps { /** Table size */ size?: TableSize; /** Row vertical align */ - verticalAlign?: 'top' | 'center' | 'bottom'; + verticalAlign?: VerticalAlignment; + headerVerticalAlign?: VerticalAlignment; + footerVerticalAlign?: VerticalAlignment; } export const Table = React.forwardRef( @@ -26,45 +30,53 @@ export const Table = React.forwardRef( rowClassName: rowClassNameProp, headerClassName, size = 'm', - verticalAlign = 'center', + verticalAlign = 'top', + headerVerticalAlign = 'top', + footerVerticalAlign = 'top', ...props }: TableProps, ref: React.Ref, ) => { const cellClassName: TableProps['cellClassName'] = React.useMemo(() => { + const mod = { + 'vertical-align': verticalAlign, + }; if (typeof cellClassNameProp === 'function') { - return (...args) => b('cell', cellClassNameProp(...args)); + return (...args) => b('cell', mod, cellClassNameProp(...args)); } - return b('cell', cellClassNameProp); - }, [cellClassNameProp]); + return b('cell', mod, cellClassNameProp); + }, [cellClassNameProp, verticalAlign]); const headerCellClassName: TableProps['headerCellClassName'] = React.useMemo(() => { + const mod = { + 'vertical-align': headerVerticalAlign, + }; if (typeof headerCellClassNameProp === 'function') { - return (...args) => b('header-cell', headerCellClassNameProp(...args)); + return (...args) => b('header-cell', mod, headerCellClassNameProp(...args)); } - return b('header-cell', headerCellClassNameProp); - }, [headerCellClassNameProp]); + return b('header-cell', mod, headerCellClassNameProp); + }, [headerCellClassNameProp, headerVerticalAlign]); const footerCellClassName: TableProps['footerCellClassName'] = React.useMemo(() => { + const mod = { + 'vertical-align': footerVerticalAlign, + }; if (typeof footerCellClassNameProp === 'function') { - return (...args) => b('footer-cell', footerCellClassNameProp(...args)); + return (...args) => b('footer-cell', mod, footerCellClassNameProp(...args)); } - return b('footer-cell', footerCellClassNameProp); - }, [footerCellClassNameProp]); + return b('footer-cell', mod, footerCellClassNameProp); + }, [footerCellClassNameProp, footerVerticalAlign]); const rowClassName: TableProps['rowClassName'] = React.useMemo(() => { - const mod = { - 'vertical-align': verticalAlign, - }; if (typeof rowClassNameProp === 'function') { - return (...args) => b('row', mod, rowClassNameProp(...args)); + return (...args) => b('row', rowClassNameProp(...args)); } - return b('row', mod, rowClassNameProp); - }, [rowClassNameProp, verticalAlign]); + return b('row', rowClassNameProp); + }, [rowClassNameProp]); return ( = { render: DefaultStory, - args: { - verticalAlign: 'center', - }, -}; - -export const Alignment: StoryObj = { - render: AlignmentStory, - args: { - verticalAlign: 'center', - }, }; export const SizeS: StoryObj = { diff --git a/src/components/Table/__stories__/stories/AlignmentStory.tsx b/src/components/Table/__stories__/stories/AlignmentStory.tsx deleted file mode 100644 index 5c338c9..0000000 --- a/src/components/Table/__stories__/stories/AlignmentStory.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import React from 'react'; - -import {Label} from '@gravity-ui/uikit'; -import type {LabelProps} from '@gravity-ui/uikit'; - -import {useTable} from '../../../../hooks'; -import type {ColumnDef} from '../../../../tanstack'; -import {data} from '../../../BaseTable/__stories__/constants/data'; -import type {Item} from '../../../BaseTable/__stories__/types'; -import {Table} from '../../index'; -import type {TableProps} from '../../index'; - -export const columns: ColumnDef[] = [ - { - accessorKey: 'name', - header: 'Name', - size: 100, - }, - { - accessorKey: 'age', - header: 'Age', - size: 100, - }, - { - id: 'name-age', - accessorFn: (item) => `${item.name}: ${item.age}`, - header: () => Name: Age, - cell: (info) => {info.getValue()}, - maxSize: 200, - minSize: 100, - }, - { - accessorKey: 'status', - header: 'Status', - size: 100, - cell: (info) => { - const value = info.getValue(); - let theme: LabelProps['theme'] = 'unknown'; - switch (value) { - case 'free': - theme = 'success'; - break; - case 'busy': - theme = 'warning'; - break; - } - return ; - }, - }, -]; - -export const AlignmentStory = (args: Omit, 'table'>) => { - const table = useTable({ - columns, - data, - }); - - return ; -}; diff --git a/src/components/Table/__stories__/stories/VirtualizationStory.tsx b/src/components/Table/__stories__/stories/VirtualizationStory.tsx index 70a2e97..bf9a744 100644 --- a/src/components/Table/__stories__/stories/VirtualizationStory.tsx +++ b/src/components/Table/__stories__/stories/VirtualizationStory.tsx @@ -2,12 +2,14 @@ import React from 'react'; import {useRowVirtualizer, useTable} from '../../../../hooks'; import {columns} from '../../../BaseTable/__stories__/constants/columns'; +import type {Item} from '../../../BaseTable/__stories__/types'; import {generateData} from '../../../BaseTable/__stories__/utils'; import {Table} from '../../index'; +import type {TableProps} from '../../index'; const data = generateData(300); -export const VirtualizationStory = () => { +export const VirtualizationStory = (args: Omit, 'table' | 'rowVirtualizer'>) => { const table = useTable({ columns, data, @@ -25,7 +27,7 @@ export const VirtualizationStory = () => { return (
-
+
); };