Skip to content

Commit 2254fc9

Browse files
committed
feat(#76): Document text component
1 parent 6524134 commit 2254fc9

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

public/images/text.png

105 KB
Loading

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import SpacerPage from "@routes/components/Spacer";
5656
import TablePage from "@routes/components/Table";
5757
import TabsPage from "@routes/components/Tabs.tsx";
5858
import TooltipPage from "@routes/components/Tooltip";
59+
import TextPage from "@routes/components/Text";
5960
import TextFieldPage from "@routes/components/TextField";
6061
import TextAreaPage from "@routes/components/TextArea";
6162
import MicrositeHeaderPage from "@routes/components/MicrositeHeader";
@@ -175,6 +176,7 @@ const router = createBrowserRouter(
175176
<Route path="spacer" element={<SpacerPage />} />
176177
<Route path="table" element={<TablePage />} />
177178
<Route path="tabs" element={<TabsPage />} />
179+
<Route path="text" element={<TextPage />} />
178180
<Route path="text-area" element={<TextAreaPage />} />
179181
<Route path="tooltip" element={<TooltipPage />} />
180182
<Route path="text-field" element={<TextFieldPage />} />

src/routes/components/AllComponents.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ export default function AllComponentsPage() {
314314
tags: ["gap", "margin", "padding", "space", "utilities"],
315315
description: "Negative area between the components and the interface.",
316316
},
317+
{
318+
name: "text",
319+
groups: ["utilities"],
320+
tags: ["heading", "font", "typography", "utilities"],
321+
description: "Provides consistent sizing, spacing, and colour to written content."
322+
}
317323
];
318324

319325
function getComponentsByGroup(group: string): ReactNode[] {

src/routes/components/Components.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export function Components() {
6767
<Link to="spacer">Spacer</Link>
6868
<Link to="table">Table</Link>
6969
<Link to="tabs">Tabs</Link>
70+
<Link to="text">Text</Link>
7071
<Link to="text-area">Text area</Link>
7172
<Link to="tooltip">Tooltip</Link>
7273
</GoASideMenu>

src/routes/components/Text.tsx

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import { useState } from "react";
2+
import { ComponentBinding, Sandbox } from "@components/sandbox";
3+
import {
4+
ComponentProperties,
5+
ComponentProperty,
6+
} from "@components/component-properties/ComponentProperties.tsx";
7+
import { Category, ComponentHeader } from "@components/component-header/ComponentHeader.tsx";
8+
import { GoAText, GoATab, GoATabs, GoABadge } from "@abgov/react-components";
9+
10+
export default function TextPage() {
11+
const [textProps, setTextProps] = useState({});
12+
13+
const [textBindings, setTextBindings] = useState<ComponentBinding[]>([
14+
{
15+
label: "Size",
16+
type: "list",
17+
name: "size",
18+
options: ["", "heading-xl", "heading-l", "heading-m", "heading-s", "heading-xs", "body-l", "body-m", "body-s", "body-xs"],
19+
value: "",
20+
},
21+
{
22+
label: "As",
23+
type: "list",
24+
name: "as",
25+
options: ["", "h1", "h2", "h3", "h4", "h5", "span", "div", "p" ],
26+
value: "",
27+
},
28+
{
29+
label: "Max width",
30+
type: "string",
31+
name: "maxWidth",
32+
value: ""
33+
},
34+
{
35+
label: "Color",
36+
type: "list",
37+
name: "color",
38+
options: ["", "primary", "secondary"],
39+
value: ""
40+
},
41+
{
42+
label: "Top Margin",
43+
type: "list",
44+
name: "mt",
45+
options: ["none", "3xs", "2xs", "xs", "s", "m", "l", "xl", "2xl", "3xl", "4xl"],
46+
value: "none",
47+
},
48+
{
49+
label: "Bottom Margin",
50+
type: "list",
51+
name: "mb",
52+
options: ["none", "3xs", "2xs", "xs", "s", "m", "l", "xl", "2xl", "3xl", "4xl"],
53+
value: "none",
54+
},
55+
]);
56+
57+
const componentProperties: ComponentProperty[] = [
58+
{
59+
name: "as",
60+
type: "h1 | h2 | h3 | h4 | h5 | span | div | p",
61+
description: "Sets the tag and text size.",
62+
defaultValue: "div"
63+
},
64+
{
65+
name: "size",
66+
type: "heading-xl | heading-l | heading-m | heading-s | heading-xs | body-l | body-m | body-s | body-xs",
67+
description: "Overrides the text size from the 'as' property."
68+
},
69+
{
70+
name: "maxWidth",
71+
type: "string",
72+
description: "Sets the max width.",
73+
defaultValue: "65ch"
74+
},
75+
{
76+
name: "color",
77+
type: "primary | secondary",
78+
description: "Sets the text colour.",
79+
defaultValue: "primary"
80+
},
81+
{
82+
name: "mt,mr,mb,ml",
83+
type: "none | 3xs | 2xs | xs | s | m | l | xl | 2xl | 3xl | 4xl",
84+
description: "Apply margin to the top, right, bottom, and/or left of the component.",
85+
},
86+
];
87+
88+
function onSandboxChange(bindings: ComponentBinding[], props: Record<string, unknown>) {
89+
setTextBindings(bindings);
90+
setTextProps(props);
91+
}
92+
93+
return (
94+
<>
95+
<ComponentHeader
96+
name="Text"
97+
category={Category.CONTENT_AND_LAYOUT}
98+
description="Provides consistent sizing, spacing, and colour to written content."
99+
/>
100+
101+
<GoATabs>
102+
<GoATab heading="Code examples">
103+
<Sandbox properties={textBindings} onChange={onSandboxChange}>
104+
105+
<GoAText {...textProps}>
106+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
107+
</GoAText>
108+
109+
</Sandbox>
110+
<ComponentProperties properties={componentProperties} />
111+
</GoATab>
112+
113+
<GoATab
114+
heading={
115+
<>
116+
Design guidelines
117+
<GoABadge type="information" content="In progress" />
118+
</>
119+
}
120+
></GoATab>
121+
</GoATabs>
122+
</>
123+
);
124+
}

0 commit comments

Comments
 (0)