Skip to content

Commit 81a8289

Browse files
committed
Restructure table on mobile
1 parent 96b2cfa commit 81a8289

File tree

7 files changed

+57
-4
lines changed

7 files changed

+57
-4
lines changed

.changeset/breezy-lies-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sumup-oss/circuit-ui": patch
3+
---
4+
5+
Improved ComparisonTable's layout in narrow viewports by moving its features' information inside table cells.

packages/circuit-ui/components/ComparisonTable/components/PlanTable/PlanTable.module.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
table-layout: fixed;
6262
}
6363

64+
.table thead td {
65+
display: none;
66+
}
67+
68+
.table colgroup col:nth-child(1) {
69+
display: none;
70+
}
71+
6472
.table thead .offset {
6573
top: calc(
6674
var(--top-navigation-height, 0px) + 80px

packages/circuit-ui/components/ComparisonTable/components/PlanTable/PlanTable.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ export const PlanTable = forwardRef<HTMLTableElement, PlanTableProps>(
214214
className={classes.section}
215215
scope="rowgroup"
216216
id={`cui-ct-sections-${sectionIndex}`}
217-
colSpan={headers.length + 1}
217+
colSpan={
218+
isMobile
219+
? headersToDisplay.length
220+
: headersToDisplay.length + 1
221+
}
218222
style={{
219223
top: `${sectionOffset}px`,
220224
}}
@@ -248,6 +252,7 @@ export const PlanTable = forwardRef<HTMLTableElement, PlanTableProps>(
248252
key={`cui-comparison-table-${feature.featureDescription.label}-cell-${index}`}
249253
headers={`cui-ct-sections-${sectionIndex} ${featureId} cui-ct-headers-${headersToDisplay[index]?.id}`}
250254
cellValue={value}
255+
feature={feature}
251256
/>
252257
))}
253258
</tr>

packages/circuit-ui/components/ComparisonTable/components/RowHeader/RowHeader.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@
2323
line-height: var(--cui-compact-m-line-height);
2424
}
2525
}
26+
27+
@media (max-width: 767px) {
28+
.base {
29+
display: none;
30+
}
31+
}

packages/circuit-ui/components/ComparisonTable/components/TableCell/TableCell.module.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@
66

77
.content {
88
display: flex;
9-
flex-direction: row;
9+
flex-direction: column;
10+
gap: var(--cui-spacings-byte);
1011
align-items: center;
1112
justify-content: center;
1213
min-height: 64px;
1314
padding: var(--cui-spacings-mega);
14-
text-align: start;
15+
text-align: center;
1516
}
1617

1718
@media (min-width: 768px) {
1819
.text {
1920
font-size: var(--cui-compact-m-font-size);
2021
line-height: var(--cui-compact-m-line-height);
2122
}
23+
24+
.label,
25+
.description {
26+
display: none;
27+
}
2228
}

packages/circuit-ui/components/ComparisonTable/components/TableCell/TableCell.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type { TdHTMLAttributes } from 'react';
2020
import { BooleanValue } from '../BooleanValue/BooleanValue.js';
2121
import { Compact } from '../../../Compact/index.js';
2222
import { clsx } from '../../../../styles/clsx.js';
23+
import type { Feature } from '../PlanTable/PlanTable.js';
2324

2425
import classes from './TableCell.module.css';
2526

@@ -32,10 +33,12 @@ export interface TableCellProps extends TdHTMLAttributes<HTMLTableCellElement> {
3233
* If the value is a boolean, it will be rendered as an icon with a descriptive label.
3334
*/
3435
cellValue: CellValue;
36+
feature: Feature;
3537
}
3638
export const TableCell = ({
3739
cellValue,
3840
className,
41+
feature,
3942
...props
4043
}: TableCellProps) => {
4144
let content = <BooleanValue label={''} value={false} />;
@@ -52,7 +55,18 @@ export const TableCell = ({
5255

5356
return (
5457
<td className={clsx(classes.base, className)} {...props}>
55-
<div className={classes.content}>{content}</div>
58+
<div className={classes.content}>
59+
{content}
60+
61+
<Compact className={classes.label} size="s">
62+
{feature.featureDescription.label}
63+
</Compact>
64+
{feature.featureDescription.description && (
65+
<Compact className={classes.description} size="s" color="subtle">
66+
{feature.featureDescription.description}
67+
</Compact>
68+
)}
69+
</div>
5670
</td>
5771
);
5872
};

packages/circuit-ui/components/ComparisonTable/fixtures.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ export const exclusiveFeature: Feature = {
116116
],
117117
};
118118

119+
export const extraFeature: Feature = {
120+
featureDescription: {
121+
label: 'Extra privileges',
122+
description: 'for life',
123+
},
124+
values: ['0%', '15%'],
125+
};
126+
119127
export const essentialFeaturesSection: FeatureSection = {
120128
title: 'Essential Features',
121129
features: [
@@ -124,6 +132,7 @@ export const essentialFeaturesSection: FeatureSection = {
124132
premiumFeature,
125133
limitedFeature,
126134
exclusiveFeature,
135+
extraFeature,
127136
],
128137
};
129138

0 commit comments

Comments
 (0)