Skip to content

Commit 5a0e3fa

Browse files
authored
Table responsive wrapper (#23)
1 parent 7a2ad25 commit 5a0e3fa

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

components/layout/table/Table.es6.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,23 @@ type Props = {
1313
padding?: 'compact' | 'comfortable',
1414
verticalAlign: 'top' | 'middle',
1515
background: 'light' | 'transparent',
16+
responsive?: boolean,
1617
children: React.ChildrenArray<TableHeadType | TableBodyType> | TableHeadType | TableBodyType
1718
}
1819

19-
function Table ({ className, cardLike, padding, verticalAlign, children, background, ...otherProps }: Props) {
20+
function Table ({
21+
className,
22+
cardLike,
23+
padding,
24+
verticalAlign,
25+
children,
26+
background,
27+
responsive = false,
28+
...otherProps
29+
}: Props) {
2030
const wrapperClasses = classnames({
21-
'ds-table-wrapper': cardLike
31+
'ds-table-wrapper': cardLike,
32+
'ds-table-responsive': responsive
2233
})
2334
const tableClasses = classnames(
2435
'ds-table',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@b12/metronome",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "",
55
"main": "index.es6.js",
66
"scripts": {

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7-
<title>B12 Design System</title>
7+
<title>Metronome</title>
88
</head>
99
<body>
1010
<section id="index"></section>

src/react-demo/Table.es6.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ const TABLE_PROPS = [
3030
value: 'light | transparent',
3131
defaultValue: 'light',
3232
description: 'Table background color'
33+
},
34+
{
35+
property: 'responsive',
36+
value: 'boolean',
37+
defaultValue: 'false',
38+
description: 'Responsive table (horizontal scroll)'
3339
}
3440
]
3541

@@ -133,6 +139,44 @@ import TablePagination from '@b12/design-system/components/layout/table/TablePag
133139
<DemoSimpleTable />
134140
</CodeExample>
135141
</div>
142+
<div className="ds-block">
143+
<div className="ds-block__title">
144+
<h4>Responsive table</h4>
145+
<p>Adding <code>responsive</code> prop allows table to be scrollable horizontally on smaller devices.</p>
146+
</div>
147+
148+
<CodeExample code={`<Table
149+
responsive
150+
cardLike
151+
>
152+
<TableHead>
153+
<TableRow>
154+
{rows.map(row => (
155+
<TableCell
156+
key={row.id}
157+
align={row.numeric ? 'center' : 'left'}
158+
>{row.label}</TableCell>
159+
))}
160+
</TableRow>
161+
</TableHead>
162+
<TableBody>
163+
{data.map(row => (
164+
<TableRow key={row.id}>
165+
<TableCell>{row.name}</TableCell>
166+
<TableCell>{row.calories}</TableCell>
167+
<TableCell>{row.fat}</TableCell>
168+
<TableCell>{row.carbs}</TableCell>
169+
<TableCell>{row.protein}</TableCell>
170+
</TableRow>
171+
))}
172+
</TableBody>
173+
</Table>`}>
174+
<DemoSimpleTable
175+
responsive
176+
cardLike
177+
/>
178+
</CodeExample>
179+
</div>
136180
<div className="ds-block">
137181
<div className="ds-block__title">
138182
<h4>Table with wrapper (card-like table)</h4>

style/_table.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020
}
2121
}
2222

23+
.ds-table-responsive {
24+
overflow-x: auto;
25+
-webkit-overflow-scrolling: touch;
26+
27+
@media (max-width: 825px) {
28+
.ds-table {
29+
td,
30+
th {
31+
white-space: nowrap;
32+
}
33+
}
34+
}
35+
}
36+
2337
.ds-table {
2438
border-collapse: collapse;
2539
box-sizing: border-box;

0 commit comments

Comments
 (0)