|
| 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