Skip to content

Commit 918a3f8

Browse files
committed
feat(DDIDS-1152): Table component number column styling
1 parent f673e0c commit 918a3f8

File tree

8 files changed

+43
-16
lines changed

8 files changed

+43
-16
lines changed

apps/angular-demo/src/app/table/table.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<tr *ngFor="let user of users; index as i">
1717
<td>{{ user.firstName }}</td>
1818
<td>{{ user.lastName }}</td>
19-
<td>{{ user.age }}</td>
19+
<td class="goa-table-number-column">{{ user.age }}</td>
2020
</tr>
2121
</tbody>
2222
</goa-table>

apps/react-demo/src/routes/table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default function Table() {
5252
<tr key={user.id}>
5353
<td>{user.firstName}</td>
5454
<td>{user.lastName}</td>
55-
<td>{user.age}</td>
55+
<td className="goa-table-number-column">{user.age}</td>
5656
</tr>
5757
))}
5858
</tbody>

libs/docs/src/components/common/Table.stories.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SupportInfo,
99
Markdown,
1010
} from "@abgov/shared/storybook-common";
11-
import { GoATable } from "@abgov/react-components";
11+
import { GoATable, GoACallout } from "@abgov/react-components";
1212
import { useState, useEffect } from "react";
1313
import { faker } from "@faker-js/faker";
1414

@@ -153,7 +153,7 @@ export const SortableTableTemplate = (args) => {
153153
<tr key={user.id}>
154154
<td>{user.firstName}</td>
155155
<td>{user.lastName}</td>
156-
<td>{user.age}</td>
156+
<td className="goa-table-number-column">{user.age}</td>
157157
</tr>
158158
))}
159159
</tbody>
@@ -356,6 +356,12 @@ export const SortableTableTemplate = (args) => {
356356

357357
#### Sortable columns
358358

359+
<GoACallout>
360+
Columns with numerical data can be styled by adding a css class{" "}
361+
<i>goa-table-column-number</i>. This sets the appropriate font and alignment
362+
on these table cells
363+
</GoACallout>
364+
359365
<Story name="Sortable">{SortableTableTemplate.bind()}</Story>
360366

361367
<Tabs>
@@ -388,7 +394,7 @@ export const SortableTableTemplate = (args) => {
388394
return (a[sortBy] > b[sortBy] ? -1 : 1) * sortDir;
389395
})
390396
}
391-
}
397+
}
392398
`}
393399
/>
394400
<CodeSnippet
@@ -406,7 +412,7 @@ export const SortableTableTemplate = (args) => {
406412
<tr *ngFor="let user of users; index as i">
407413
<td>{{ user.firstName }}</td>
408414
<td>{{ user.lastName }}</td>
409-
<td>{{ user.age }}</td>
415+
<td class="goa-table-number-column">{{ user.age }}</td>
410416
</tr>
411417
</tbody>
412418
</goa-table>
@@ -449,11 +455,11 @@ export const SortableTableTemplate = (args) => {
449455
</tr>
450456
</thead>
451457
<tbody>
452-
{users.map(user =>
458+
{users.map(user =>
453459
<tr key={user.id}>
454460
<td>{user.firstName}</td>
455461
<td>{user.lastName}</td>
456-
<td>{user.age}</td>
462+
<td className="goa-table-number-column">{user.age}</td>
457463
</tr>
458464
)}
459465
</tbody>

libs/react-components/src/lib/notification/notification.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ describe("Notification Banner", () => {
2525
it("Event triggered on notification banner dismiss", async () => {
2626
const onDismiss = jest.fn();
2727
const { container } = render(
28-
<GoANotification type="information" onDismiss={onDismiss}>Information to the user goes in the content</GoANotification>
28+
<GoANotification type="information" onDismiss={onDismiss}>
29+
Information to the user goes in the content
30+
</GoANotification>
2931
);
3032
const notificationBanner = container.querySelector("goa-notification");
3133
fireEvent(notificationBanner, new CustomEvent("_dismiss"));
3234
expect(onDismiss).toBeCalled();
3335
});
34-
3536
});

libs/web-components/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/web-components/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"svelte-check": "^2.0.0",
4444
"svelte-preprocess": "^4.0.0",
4545
"tslib": "^2.0.0",
46-
"typescript": "^4.0.0"
46+
"typescript": "^4.0.0",
47+
"vite-plugin-replace": "^0.1.1"
4748
}
4849
}

libs/web-components/rollup.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import preprocess from "svelte-preprocess";
66
import commonjs from "@rollup/plugin-commonjs";
77
import typescript from "@rollup/plugin-typescript";
88
import css from 'rollup-plugin-css-only';
9+
import {replaceCodePlugin} from 'vite-plugin-replace';
910

1011
export default {
1112
input: "src/index.ts",
@@ -34,6 +35,14 @@ export default {
3435
resolve(),
3536
terser(),
3637
summary(),
38+
replaceCodePlugin({
39+
replacements: [
40+
{
41+
from: /:global\(([\[\]\(\)\-\.\:\*\w]+)\)/g,
42+
to: "$1",
43+
}
44+
]
45+
}),
3746
],
3847
watch: {
3948
clearScreen: true,

libs/web-components/src/components/table/Table.svelte

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
const slot = _rootEl.querySelector("slot") as HTMLSlotElement;
3636
if (!slot || slot.assignedElements().length === 0) {
3737
return;
38-
}
38+
}
3939
// React needs to nest data in a <template><table>...</table></template>
4040
const content = slot.assignedElements()[0].querySelectorAll("template table > *");
4141
_rootEl.append(...(content.length > 0 ? content : slot.assignedElements()));
@@ -57,7 +57,7 @@
5757
const newDirection = direction === "desc" ? "asc" : "desc";
5858
5959
sortDir = newDirection === "asc" ? 1 : -1
60-
child.setAttribute("direction", newDirection)
60+
child.setAttribute("direction", newDirection)
6161
} else {
6262
child.setAttribute("direction", "none")
6363
}
@@ -87,8 +87,8 @@
8787
>
8888
<slot />
8989

90-
<!--
91-
prevents console errors being seen in react
90+
<!--
91+
prevents console errors being seen in react
9292
and prevents the internal styles from being removed
9393
-->
9494
<template>
@@ -118,6 +118,11 @@
118118
line-height: 1rem;
119119
}
120120
121+
table :global(.goa-table-number-column) {
122+
font: var(--goa-typography-number-m);
123+
text-align: right;
124+
}
125+
121126
table.relaxed td {
122127
padding: 1rem;
123128
}
@@ -146,5 +151,5 @@
146151
tfoot tr:last-child td {
147152
border-bottom: none;
148153
}
149-
154+
150155
</style>

0 commit comments

Comments
 (0)