Skip to content

Commit afeab9d

Browse files
committed
feat: Table stories
1 parent 59c54de commit afeab9d

File tree

7 files changed

+147
-7
lines changed

7 files changed

+147
-7
lines changed

example/src/stories/Table/Cell.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default {
1313
padding: {
1414
control: {
1515
type: 'select',
16-
options: ['none', 'normal', 'wide'],
16+
options: ['none', 'dense', 'normal', 'wide'],
1717
},
1818
description: 'The padding of the cell',
1919
},
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Cell, Row } from '@solved-ac/ui-react'
2+
import { ComponentMeta, ComponentStory } from '@storybook/react'
3+
import React from 'react'
4+
5+
export default {
6+
title: 'Components/Table/Row',
7+
component: Row,
8+
argTypes: {
9+
children: {
10+
control: 'none',
11+
description: 'The cells to display inside the row',
12+
},
13+
padding: {
14+
control: {
15+
type: 'select',
16+
options: ['none', 'dense', 'normal', 'wide'],
17+
},
18+
description: 'The padding of the cell',
19+
},
20+
header: {
21+
control: {
22+
type: 'boolean',
23+
},
24+
description: 'Whether the row is a header',
25+
},
26+
},
27+
} as ComponentMeta<typeof Row>
28+
29+
const Template: ComponentStory<typeof Row> = (args) => <Row {...args} />
30+
31+
export const Default = Template.bind({})
32+
Default.args = {
33+
children: (
34+
<>
35+
<Cell>Cell 1</Cell>
36+
<Cell>Cell 2</Cell>
37+
<Cell>Cell 3</Cell>
38+
<Cell>Cell 4</Cell>
39+
<Cell>Cell 5</Cell>
40+
</>
41+
),
42+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { Cell, Row, Table, TableBody, TableHead } from '@solved-ac/ui-react'
2+
import { ComponentMeta, ComponentStory } from '@storybook/react'
3+
import React from 'react'
4+
5+
export default {
6+
title: 'Components/Table/Table',
7+
component: Table,
8+
argTypes: {
9+
children: {
10+
control: 'none',
11+
description: 'The content to display inside the table',
12+
},
13+
padding: {
14+
control: {
15+
type: 'select',
16+
options: ['none', 'dense', 'normal', 'wide'],
17+
},
18+
description: 'The padding of the cell',
19+
},
20+
fullWidth: {
21+
control: {
22+
type: 'boolean',
23+
},
24+
description:
25+
'Whether the table should take up the full width of the container',
26+
},
27+
},
28+
} as ComponentMeta<typeof Table>
29+
30+
const Template: ComponentStory<typeof Table> = (args) => <Table {...args} />
31+
32+
export const Default = Template.bind({})
33+
Default.args = {
34+
children: (
35+
<>
36+
<TableHead>
37+
<Row>
38+
<Cell>#</Cell>
39+
<Cell>Title</Cell>
40+
<Cell>Solved</Cell>
41+
<Cell>Tries</Cell>
42+
</Row>
43+
</TableHead>
44+
<TableBody>
45+
<Row>
46+
<Cell>1000</Cell>
47+
<Cell>A+B</Cell>
48+
<Cell numeric>179,871</Cell>
49+
<Cell numeric>2.37</Cell>
50+
</Row>
51+
<Row>
52+
<Cell>1001</Cell>
53+
<Cell>A-B</Cell>
54+
<Cell numeric>150,867</Cell>
55+
<Cell numeric>1.40</Cell>
56+
</Row>
57+
<Row>
58+
<Cell>1002</Cell>
59+
<Cell>Turrets</Cell>
60+
<Cell numeric>26,390</Cell>
61+
<Cell numeric>4.59</Cell>
62+
</Row>
63+
<Row>
64+
<Cell>1003</Cell>
65+
<Cell>Fibonacci Function</Cell>
66+
<Cell numeric>35,585</Cell>
67+
<Cell numeric>3.18</Cell>
68+
</Row>
69+
<Row>
70+
<Cell>1004</Cell>
71+
<Cell>Le Petit Prince</Cell>
72+
<Cell numeric>8,769</Cell>
73+
<Cell numeric>2.34</Cell>
74+
</Row>
75+
<Row>
76+
<Cell>1005</Cell>
77+
<Cell>ACM Craft</Cell>
78+
<Cell numeric>8,364</Cell>
79+
<Cell numeric>3.92</Cell>
80+
</Row>
81+
</TableBody>
82+
</>
83+
),
84+
}

src/components/Table/Cell.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@ import { TableRowGroupContext } from './TableRowGroupContext'
66

77
const paddingMap = {
88
none: 'padding: 0;',
9+
dense: 'padding: 8px;',
910
normal: 'padding: 16px;',
1011
wide: 'padding: 32px;',
1112
}
1213

1314
interface CellContainerProps {
14-
padding: 'none' | 'normal' | 'wide'
15+
padding: 'none' | 'dense' | 'normal' | 'wide'
16+
numeric: boolean
1517
}
1618

1719
const CellContainer = styled.td<CellContainerProps>`
1820
display: table-cell;
1921
border-bottom: ${({ theme }) => theme.styles.border()};
2022
${({ padding }) => paddingMap[padding]}
23+
${({ numeric }) =>
24+
numeric && "text-align: right; font-feature-settings: 'tnum';"}
2125
`
2226

2327
export interface CellProps {
24-
padding?: 'none' | 'normal' | 'wide'
28+
padding?: 'none' | 'dense' | 'normal' | 'wide'
29+
numeric?: boolean
2530
}
2631

2732
export const Cell: PC<'td', CellProps> = React.forwardRef(
@@ -31,9 +36,18 @@ export const Cell: PC<'td', CellProps> = React.forwardRef(
3136
const {
3237
padding = tableContext.padding,
3338
as = tableRowGroupContext.header ? 'th' : 'td',
39+
numeric = false,
3440
...rest
3541
} = props
3642

37-
return <CellContainer padding={padding} ref={ref} as={as} {...rest} />
43+
return (
44+
<CellContainer
45+
padding={padding}
46+
numeric={numeric}
47+
ref={ref}
48+
as={as}
49+
{...rest}
50+
/>
51+
)
3852
}
3953
)

src/components/Table/Row.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const RowContainer = styled.tr<RowContainerProps>`
1414

1515
export interface RowProps {
1616
header?: boolean
17-
padding?: 'none' | 'normal' | 'wide'
17+
padding?: 'none' | 'dense' | 'normal' | 'wide'
1818
}
1919

2020
export const Row: PC<'tr', RowProps> = React.forwardRef(

src/components/Table/Table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const TableContainer = styled.table<TableContainerProps>`
1515

1616
export interface TableProps {
1717
fullWidth?: boolean
18-
padding?: 'none' | 'normal' | 'wide'
18+
padding?: 'none' | 'dense' | 'normal' | 'wide'
1919
}
2020

2121
export const Table: PC<'table', TableProps> = React.forwardRef(

src/components/Table/TableContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22

33
export interface TableContextProps {
4-
padding: 'none' | 'normal' | 'wide'
4+
padding: 'none' | 'dense' | 'normal' | 'wide'
55
}
66

77
export const TableContext = React.createContext<TableContextProps>({

0 commit comments

Comments
 (0)