Skip to content

Commit a3f5565

Browse files
authored
Merge pull request #631 from buildo/typography-docs
2 parents 207a8d4 + fe08965 commit a3f5565

File tree

17 files changed

+214
-1
lines changed

17 files changed

+214
-1
lines changed

packages/bento-design-system/src/Typography/Title/Title.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ export function Title({
2828
...boxProps
2929
}: Props) {
3030
return (
31-
<Box {...boxProps} className={titleRecipe({ size, color, ellipsis })} textAlign={align}>
31+
<Box
32+
as="span"
33+
{...boxProps}
34+
className={titleRecipe({ size, color, ellipsis })}
35+
textAlign={align}
36+
>
3237
{children}
3338
</Box>
3439
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ComponentDoc from "./_ComponentDoc.mdx";
2+
3+
<ComponentDoc
4+
name="Body"
5+
examplePath="Typography/Body"
6+
storybookStoryId="foundations-typography-body"
7+
alternativeNames={["Text"]}
8+
relatedComponents={["Display", "Headline", "Title", "Label"]}
9+
/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ComponentDoc from "./_ComponentDoc.mdx";
2+
3+
<ComponentDoc
4+
name="Display"
5+
examplePath="Typography/Display"
6+
storybookStoryId="foundations-typography-display"
7+
alternativeNames={[]}
8+
relatedComponents={["Headline", "Title", "Label", "Body"]}
9+
/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ComponentDoc from "./_ComponentDoc.mdx";
2+
3+
<ComponentDoc
4+
name="Headline"
5+
examplePath="Typography/Headline"
6+
storybookStoryId="foundations-typography-headline"
7+
alternativeNames={[]}
8+
relatedComponents={["Display", "Title", "Label", "Body"]}
9+
/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ComponentDoc from "./_ComponentDoc.mdx";
2+
3+
<ComponentDoc
4+
name="Label"
5+
examplePath="Typography/Label"
6+
storybookStoryId="foundations-typography-label"
7+
alternativeNames={[]}
8+
relatedComponents={["Display", "Headline", "Title", "Body"]}
9+
/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ComponentDoc from "./_ComponentDoc.mdx";
2+
3+
<ComponentDoc
4+
name="Title"
5+
examplePath="Typography/Title"
6+
storybookStoryId="foundations-typography-title"
7+
alternativeNames={[]}
8+
relatedComponents={["Display", "Headline", "Label", "Body"]}
9+
/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Canvas } from "@site/src/components/Canvas";
2+
3+
# Typography
4+
5+
Bento type scale organizes styles into five roles, semantically named to describe their purposes:
6+
7+
- [Display](../components/Display): reserved for short, important text or numerals. Usually, they work best on large screens.
8+
- [Headline](../components/Headline): best suited for short, high-emphasis text. These styles can be suitable for marking primary text passages or important content regions.
9+
- [Title](../components/Title): used to divide secondary text passages or content regions.
10+
- [Body](../components/Body): used for longer passages of text and paragraphs.
11+
- [Label](../components/Label): utilitarian styles used for text inside of components or very small supporting text in the content body, like captions.
12+
13+
## Usage
14+
15+
You can use any of the typography components like this:
16+
17+
<Canvas path="Typography/All" />
18+
19+
## Font weight
20+
21+
All typography components support a single (configurable) font weight, with the exception of `Body`, which has two weights: `"default"` and `"strong"`.
22+
23+
`"default"` is the default weight, and `"strong"` is a heavier weight that can be used to emphasize certain parts of the text.
24+
25+
<Canvas path="Typography/BodyWeights" />
26+
27+
## Truncation
28+
29+
All typography components support an optional `ellipsis` prop (defaulted to `false`), which causes the text to be truncated with an ellipsis when it overflows its container.
30+
31+
<Canvas path="Typography/Ellipsis" />
32+
33+
This feature uses standard CSS, so the truncation will be accessible (the entire text is still visible in the DOM node) and standard browser feature work as expected (e.g. try copy-pasting the truncated text and you'll see you'll get the full text).
34+
35+
## Semantic HTML
36+
37+
All typography components render as `<span>` by default. This behavior can be customized using the optional `as` prop.
38+
39+
For example, you may want to render `Body` as a `<p>`:
40+
41+
<Canvas path="Typography/BodyP" />
42+
43+
Another example is using `Title` as a `<h2>`:
44+
45+
<Canvas path="Typography/TitleH2" />
46+
47+
## Localization and rich formatting
48+
49+
Typography components accept either a `LocalizedString` (see [Type-safe localization](../Advanced/strict-localization)) or a complex React Node as children.
50+
51+
If you need rich formatting, you can typically rely on the localization library you are using to create a React children node.
52+
53+
For example, if you are using [react-i18next](https://react.i18next.com/), you can use the `Trans` component to create a React node:
54+
55+
```tsx
56+
<Body size="medium">
57+
<Trans i18nKey="My.Localization.Key" />
58+
</Body>
59+
```
60+
61+
where the string matching `My.Localization.Key` can be along the lines of `Hello <b>World</b>!`
62+
63+
You can read more about `Trans` component in the official [react-i18next documentation](https://react.i18next.com/latest/trans-component)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from "react";
2+
import { Body, Display, Headline, Label, Stack, Title } from "..";
3+
4+
export default function AllExample() {
5+
return (
6+
<Stack space={16}>
7+
<Display size="large">Hello, world! (Display)</Display>
8+
<Headline size="large">Hello, world! (Headline)</Headline>
9+
<Title size="large">Hello, world! (Title)</Title>
10+
<Label size="large" color="primary">
11+
Hello, world! (Label)
12+
</Label>
13+
<Body size="large">Hello, world! (Body)</Body>
14+
</Stack>
15+
);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from "react";
2+
import { Body } from "..";
3+
4+
export default function BodyExample() {
5+
return <Body size="large">The quick brown fox jumped over the lazy dog</Body>;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from "react";
2+
import { Body } from "..";
3+
4+
export default function BodyExample() {
5+
return (
6+
<Body as="p" size="large" align="center">
7+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
8+
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
9+
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
10+
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
11+
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
12+
</Body>
13+
);
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from "react";
2+
import { Body, Stack } from "..";
3+
4+
export default function BodyWeightsExample() {
5+
return (
6+
<Stack space={16}>
7+
<Body size="large">Hello, world! (Body default)</Body>
8+
<Body size="large" weight="strong">
9+
Hello, world! (Body strong)
10+
</Body>
11+
</Stack>
12+
);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from "react";
2+
import { Display } from "..";
3+
4+
export default function DisplayExample() {
5+
return <Display size="large">The quick brown fox jumped over the lazy dog</Display>;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from "react";
2+
import { Body, Box, Stack } from "..";
3+
4+
export default function EllipsisExample() {
5+
return (
6+
<Stack space={16}>
7+
<Box style={{ width: 200 }} background="softIndigo" padding={8}>
8+
<Body size="large">Very long string which will NOT be truncated.</Body>
9+
</Box>
10+
<Box style={{ width: 200 }} background="softIndigo" padding={8}>
11+
<Body size="large" ellipsis>
12+
Very long string which WILL be truncated.
13+
</Body>
14+
</Box>
15+
</Stack>
16+
);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from "react";
2+
import { Headline } from "..";
3+
4+
export default function HeadlineExample() {
5+
return <Headline size="large">The quick brown fox jumped over the lazy dog</Headline>;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from "react";
2+
import { Label } from "..";
3+
4+
export default function LabelExample() {
5+
return (
6+
<Label size="large" color="primary">
7+
The quick brown fox jumped over the lazy dog
8+
</Label>
9+
);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from "react";
2+
import { Title } from "..";
3+
4+
export default function TitleExample() {
5+
return <Title size="large">The quick brown fox jumped over the lazy dog</Title>;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from "react";
2+
import { Title } from "..";
3+
4+
export default function TitleExample() {
5+
return <Title as="h2" size="large">{`A title which is rendered as <h2>`}</Title>;
6+
}

0 commit comments

Comments
 (0)