Skip to content

Commit

Permalink
feat(Table): table size supported (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanisAvko authored Sep 23, 2024
1 parent ffd60ca commit 50e7778
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/components/Table/Table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ $block: '.#{variables.$ns}styled-table';
@include mixins.text-subheader-1();
}

&_size {
&_s {
--_--cell-padding: 7px var(--g-spacing-2) 6px;
}

&_m {
--_--cell-padding: 11px var(--g-spacing-2) 10px;
}
}

&__cell,
&__header-cell,
&__footer-cell {
padding: 11px var(--g-spacing-2) 10px;
padding: var(--_--cell-padding);
border-block-end: 1px solid var(--g-color-line-generic);
}
}
9 changes: 7 additions & 2 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import {BaseTable} from '../BaseTable';
import type {BaseTableProps} from '../BaseTable';

import {b} from './Table.classname';
import type {TableSize} from './types';

import './Table.scss';

export interface TableProps<TData, TScrollElement extends Element | Window = HTMLDivElement>
extends BaseTableProps<TData, TScrollElement> {}
extends BaseTableProps<TData, TScrollElement> {
/** Table size */
size?: TableSize;
}

export const Table = React.forwardRef(
<TData, TScrollElement extends Element | Window = HTMLDivElement>(
Expand All @@ -18,6 +22,7 @@ export const Table = React.forwardRef(
footerCellClassName: footerCellClassNameProp,
headerCellClassName: headerCellClassNameProp,
headerClassName,
size = 'm',
...props
}: TableProps<TData, TScrollElement>,
ref: React.Ref<HTMLTableElement>,
Expand Down Expand Up @@ -49,7 +54,7 @@ export const Table = React.forwardRef(
return (
<BaseTable
ref={ref}
className={b(null, className)}
className={b({size}, className)}
cellClassName={cellClassName}
footerCellClassName={footerCellClassName}
headerCellClassName={headerCellClassName}
Expand Down
5 changes: 5 additions & 0 deletions src/components/Table/__stories__/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Table} from '../index';
import {DefaultStory} from './stories/DefaultStory';
import {ReorderingStory} from './stories/ReorderingStory';
import {ReorderingWithVirtualizationStory} from './stories/ReorderingWithVirtualizationStory';
import {SizeSStory} from './stories/SizeSStory';
import {StickyHeaderStory} from './stories/StickyHeaderStory';
import {VirtualizationStory} from './stories/VirtualizationStory';
import {WindowVirtualizationStory} from './stories/WindowVirtualizationStory';
Expand All @@ -21,6 +22,10 @@ export const Default: StoryObj<typeof DefaultStory> = {
render: DefaultStory,
};

export const SizeS: StoryObj<typeof SizeSStory> = {
render: SizeSStory,
};

export const WithSelection: StoryObj<typeof WithSelectionStory> = {
render: WithSelectionStory,
};
Expand Down
15 changes: 15 additions & 0 deletions src/components/Table/__stories__/stories/SizeSStory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

import {useTable} from '../../../../hooks';
import {columns} from '../../../BaseTable/__stories__/constants/columns';
import {data} from '../../../BaseTable/__stories__/constants/data';
import {Table} from '../../index';

export const SizeSStory = () => {
const table = useTable({
columns,
data,
});

return <Table table={table} size="s" />;
};
1 change: 1 addition & 0 deletions src/components/Table/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Table';
export * from './types';
1 change: 1 addition & 0 deletions src/components/Table/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type TableSize = 's' | 'm';

0 comments on commit 50e7778

Please sign in to comment.