Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated documentation for Typography #2324

Open
wants to merge 64 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
4018aeb
added doc for flex
smmr-dn Sep 23, 2024
908570a
Merge branch 'main' into uyen/flex-doc
smmr-dn Sep 24, 2024
8835ddd
Merge branch 'main' into uyen/flex-doc
smmr-dn Sep 24, 2024
85fed56
added copyright
smmr-dn Sep 24, 2024
e443046
Merge branch 'uyen/flex-doc' of https://github.com/iTwin/iTwinUI into…
smmr-dn Sep 24, 2024
d9560be
Merge branch 'main' into uyen/flex-doc
smmr-dn Sep 24, 2024
cd6ecbb
more examples
smmr-dn Sep 25, 2024
716ef3e
updated documentation for trees
smmr-dn Sep 30, 2024
3d1ec77
WIP selection
smmr-dn Sep 30, 2024
3156ec2
examples
smmr-dn Oct 9, 2024
dc9a30b
conflicts and merged main
smmr-dn Oct 9, 2024
b0046e9
expansion
smmr-dn Oct 10, 2024
7d806b8
Merge branch 'main' into uyen/tree-doc
smmr-dn Oct 10, 2024
1f259c5
Merge branch 'main' of https://github.com/iTwin/iTwinUI into uyen/tre…
smmr-dn Oct 10, 2024
793fb14
Merge branch 'uyen/tree-doc' of https://github.com/iTwin/iTwinUI into…
smmr-dn Oct 10, 2024
d07d19d
conflicts
smmr-dn Oct 10, 2024
012a0fd
conflicts
smmr-dn Oct 10, 2024
032c720
Update react-table.types-test.tsx
smmr-dn Oct 10, 2024
4b88788
conflicts
smmr-dn Oct 10, 2024
ff184cf
checkbox label error
smmr-dn Oct 10, 2024
631e2fc
added virtualization
smmr-dn Oct 10, 2024
2d7b18b
rewording
smmr-dn Oct 10, 2024
47b3cdb
Merge branch 'main' into uyen/tree-doc
smmr-dn Oct 15, 2024
62d5575
Merge branch 'main' into uyen/tree-doc
smmr-dn Oct 17, 2024
885dd56
Merge branch 'main' into uyen/tree-doc
smmr-dn Oct 31, 2024
d856beb
updated selection section
smmr-dn Nov 1, 2024
57a607d
Merge branch 'uyen/tree-doc' of https://github.com/iTwin/iTwinUI into…
smmr-dn Nov 1, 2024
d193fa0
moved prop table to the end
smmr-dn Nov 1, 2024
866d10f
attempted label a11y error
smmr-dn Nov 1, 2024
25d1793
attempted label a11y error
smmr-dn Nov 1, 2024
024c0c2
wip for text section
smmr-dn Nov 4, 2024
39bef73
Merge branch 'main' into uyen/typography-doc
smmr-dn Nov 4, 2024
eb7d44f
Merge branch 'main' of https://github.com/iTwin/iTwinUI into uyen/typ…
smmr-dn Nov 4, 2024
84fbba5
merged main
smmr-dn Nov 4, 2024
de5f053
Merge branch 'uyen/typography-doc' of https://github.com/iTwin/iTwinU…
smmr-dn Nov 4, 2024
784b40c
Merge branch 'main' into uyen/typography-doc
smmr-dn Nov 5, 2024
769b375
added docs for Label
smmr-dn Nov 8, 2024
d8d520a
Merge branch 'uyen/typography-doc' of https://github.com/iTwin/iTwinU…
smmr-dn Nov 8, 2024
e4e0e11
added more examples for Label
smmr-dn Nov 8, 2024
6f92d2e
Merge branch 'main' into uyen/typography-doc
smmr-dn Nov 11, 2024
db1ba3d
Merge branch 'main' into uyen/typography-doc
smmr-dn Nov 19, 2024
7b7fecd
Merge branch 'main' into uyen/typography-doc
smmr-dn Dec 4, 2024
b76a182
Merge branch 'main' of https://github.com/iTwin/iTwinUI into uyen/typ…
smmr-dn Dec 5, 2024
220ca6e
moved things around Label
smmr-dn Dec 10, 2024
fd9b81e
Merge branch 'uyen/typography-doc' of https://github.com/iTwin/iTwinU…
smmr-dn Dec 10, 2024
a42acbe
Merge branch 'main' into uyen/typography-doc
smmr-dn Dec 10, 2024
e92001b
added polymorphic label
smmr-dn Dec 13, 2024
a55eb92
Merge branch 'main' into uyen/typography-doc
smmr-dn Dec 13, 2024
843280e
wording in usage
smmr-dn Dec 13, 2024
f9cedb7
Merge branch 'uyen/typography-doc' of https://github.com/iTwin/iTwinU…
smmr-dn Dec 13, 2024
fddcd59
Merge branch 'main' into uyen/typography-doc
smmr-dn Dec 18, 2024
0935c91
Merge branch 'main' into uyen/typography-doc
smmr-dn Dec 19, 2024
39004b7
wording
smmr-dn Dec 19, 2024
10d66be
Merge branch 'uyen/typography-doc' of https://github.com/iTwin/iTwinU…
smmr-dn Dec 19, 2024
25583c4
flex import in live demo
smmr-dn Dec 19, 2024
ee24604
Merge branch 'main' into uyen/typography-doc
smmr-dn Dec 23, 2024
fdbc025
comments
smmr-dn Dec 23, 2024
ab1b96a
changed link to section
smmr-dn Dec 23, 2024
a8c8afe
small fixes
smmr-dn Dec 23, 2024
26210d5
added block example to display styles
smmr-dn Dec 23, 2024
8dc34af
combined block and inline label in one example
smmr-dn Dec 23, 2024
cba1113
wording
smmr-dn Dec 24, 2024
ed6bc63
wording
smmr-dn Dec 24, 2024
426a888
wording
smmr-dn Jan 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 72 additions & 7 deletions apps/website/src/content/docs/typography.mdx
Original file line number Diff line number Diff line change
@@ -1,17 +1,63 @@
---
title: Typography
description:
description: Typography components provide consistency in text styling across the application.
thumbnail: Typography
---

<p>{frontmatter.description}</p>

<Placeholder componentPageName='text--basic' />

## Text

<LiveExample src='Text.main.jsx' truncate={false}>
<AllExamples.TextMainExample client:load />
`Text` is a [polymorphic](#polymorphic-only-semantics-and-not-size) typography component that can be used to render any kind of text as any kind of element.

```jsx
<Text>This is a text.</Text>
```

mayank99 marked this conversation as resolved.
Show resolved Hide resolved
By default, the `Text` component renders a `<div>` element with the regular `"body"` size. The visuals of this component are completely separate from its semantics, which helps ensure proper [heading structure](https://www.w3.org/WAI/tutorials/page-structure/headings/).

- **Visuals**: The `variant` prop can be used to customize the the size (e.g. `variant="subheading"`).
- **Semantics**: The polymorphic `as` prop can be used to render a different element (e.g. `as="h2"`).

### Variant (Only size and not semantics)

The `variant` prop can be used to determine the size of the text. The available variants are (from largest to smallest):

1. `"headline"`.
2. `"title"`.
3. `"subheading"`.
4. `"leading"`.
5. `"body"` (default).
6. `"smaller"`.

<LiveExample src='Text.variant.jsx'>
<AllExamples.TextVariantExample client:load />
</LiveExample>

mayank99 marked this conversation as resolved.
Show resolved Hide resolved
Please note that the `variant` prop only affects the visual size and is completely decoupled from the semantics, which can be controlled using the `as` prop (see below).

### Polymorphic (Only semantics and not size)

The `Text` component supports the polymorphic `as` prop, which can be used to change the underlying HTML element. This is useful when you want to render the text as a specific heading level while maintaining a desired size.

<LiveExample src='Text.polymorphic.jsx' truncate={false}>
<AllExamples.TextPolymorphicExample client:load />
</LiveExample>

### Muted

To achieve a muted or desaturated text effect, the `isMuted` prop can be passed into the component. Muted text helps differentiating less important information as well as enhancing the overall readability.

<LiveExample src='Text.muted.jsx' truncate={false}>
<AllExamples.TextMutedExample client:load />
</LiveExample>

### Skeleton

To indicate that content is loading and will be available soon, you can use the `isSkeleton` prop along with the `variant` prop. This will display a placeholder for any text that is still loading. If no `variant` is specified, the skeleton will default to the size of `"body"` text.

<LiveExample src='Text.skeleton.jsx'>
<AllExamples.TextSkeletonExample client:load />
</LiveExample>

### Props
Expand All @@ -20,12 +66,31 @@ thumbnail: Typography

## Label
mayank99 marked this conversation as resolved.
Show resolved Hide resolved

<Placeholder componentPageName='label--basic' />
`Label` corresponds to an HTML `<label>` and can be linked to an `Input` by matching `Label`'s `htmlFor` with `Input`'s `id` for better accessibility, ensuring assistive technologies correctly identify their relationship.

<LiveExample src='Label.main.jsx' truncate={false}>
<LiveExample src='Label.main.jsx'>
<AllExamples.LabelMainExample client:load />
</LiveExample>

### Required

To make the form field required, you can pass the `required` prop. This also adds the `*` next to the label.

<LiveExample src='Label.required.jsx'>
<AllExamples.LabelRequiredExample client:load />
</LiveExample>

### Display style

There are two available display styles:

- `"block"` (default): places the label and the other fields on separate lines without adding any extra spacing.
- `"inline"`: displays the label inline with other elements by adding a right margin to it.

<LiveExample src='Label.displayStyles.jsx'>
<AllExamples.LabelDisplayStylesExample client:load />
</LiveExample>

### Props

<PropsTable path='@itwin/itwinui-react/esm/core/Label/Label.d.ts' />
6 changes: 6 additions & 0 deletions examples/Label.displayStyles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.demo-container {
display: flex;
flex-direction: column;
gap: var(--iui-size-xs);
width: 300px;
}
21 changes: 21 additions & 0 deletions examples/Label.displayStyles.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { InputGrid, Input, Label, LabeledSelect } from '@itwin/itwinui-react';

export default () => {
return (
<div className='demo-container'>
<InputGrid>
<Label displayStyle='block'>Block label</Label>
<Input />
</InputGrid>
<InputGrid labelPlacement='inline'>
<Label displayStyle='inline'>Inline label</Label>
<Input />
</InputGrid>
</div>
);
};
3 changes: 3 additions & 0 deletions examples/Label.main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.demo-container {
width: 300px;
}
9 changes: 7 additions & 2 deletions examples/Label.main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { Label } from '@itwin/itwinui-react';
import { Flex, Input, Label } from '@itwin/itwinui-react';

export default () => {
return <Label>This is label.</Label>;
return (
<>
<Label htmlFor='text-input'>Name:</Label>
<Input id='text-input' placeholder='Enter name' />
</>
);
};
17 changes: 17 additions & 0 deletions examples/Label.required.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { Input, Label } from '@itwin/itwinui-react';

export default () => {
return (
<div className='demo-container'>
<Label htmlFor='text-input' required>
Name:
</Label>
<Input id='text-input' placeholder='Enter name' />
</div>
);
};
15 changes: 15 additions & 0 deletions examples/Text.muted.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { Flex, Text } from '@itwin/itwinui-react';

export default () => {
return (
<Flex flexDirection='column'>
<Text>This is a regular text</Text>
<Text isMuted>This is a muted text</Text>
</Flex>
);
};
6 changes: 5 additions & 1 deletion examples/Text.main.jsx → examples/Text.polymorphic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ import * as React from 'react';
import { Text } from '@itwin/itwinui-react';

export default () => {
return <Text variant='body'>This is text</Text>;
return (
<Text variant='subheading' as='h1'>
This is a subheading rendered as an h1.
</Text>
);
};
29 changes: 29 additions & 0 deletions examples/Text.skeleton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { Flex, Text } from '@itwin/itwinui-react';

export default () => {
return (
<Flex flexDirection='column'>
<Text isSkeleton variant='headline'>
This is a skeleton text
</Text>
<Text isSkeleton variant='title'>
This is a skeleton text
</Text>
<Text isSkeleton variant='subheading'>
This is a skeleton text
</Text>
<Text isSkeleton variant='leading'>
This is a skeleton text
</Text>
<Text isSkeleton>This is a skeleton text</Text>
<Text isSkeleton variant='small'>
This is a skeleton text
</Text>
</Flex>
);
};
19 changes: 19 additions & 0 deletions examples/Text.variant.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { Flex, Text } from '@itwin/itwinui-react';

export default () => {
return (
<Flex flexDirection='column'>
<Text variant='headline'>This is a headline</Text>
<Text variant='title'>This is a title</Text>
<Text variant='subheading'>This is a subheading</Text>
<Text variant='leading'>This is a leading</Text>
<Text>This is a body</Text>
<Text variant='small'>This is a small text</Text>
</Flex>
);
};
28 changes: 25 additions & 3 deletions examples/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,16 @@ import { default as LabelMainExampleRaw } from './Label.main';
const LabelMainExample = withThemeProvider(LabelMainExampleRaw);
export { LabelMainExample };

import { default as LabelRequiredExampleRaw } from './Label.required';
const LabelRequiredExample = withThemeProvider(LabelRequiredExampleRaw);
export { LabelRequiredExample };

import { default as LabelDisplayStylesExampleRaw } from './Label.displayStyles';
const LabelDisplayStylesExample = withThemeProvider(
LabelDisplayStylesExampleRaw,
);
export { LabelDisplayStylesExample };

// ----------------------------------------------------------------------------

import { default as LinkActionMainExampleRaw } from './LinkAction.main';
Expand Down Expand Up @@ -1306,9 +1316,21 @@ export { TextareaInlineExample };

// ----------------------------------------------------------------------------

import { default as TextMainExampleRaw } from './Text.main';
const TextMainExample = withThemeProvider(TextMainExampleRaw);
export { TextMainExample };
import { default as TextVariantExampleRaw } from './Text.variant';
const TextVariantExample = withThemeProvider(TextVariantExampleRaw);
export { TextVariantExample };

import { default as TextMutedExampleRaw } from './Text.muted';
const TextMutedExample = withThemeProvider(TextMutedExampleRaw);
export { TextMutedExample };

import { default as TextSkeletonExampleRaw } from './Text.skeleton';
const TextSkeletonExample = withThemeProvider(TextSkeletonExampleRaw);
export { TextSkeletonExample };

import { default as TextPolymorphicExampleRaw } from './Text.polymorphic';
const TextPolymorphicExample = withThemeProvider(TextPolymorphicExampleRaw);
export { TextPolymorphicExample };

// ----------------------------------------------------------------------------

Expand Down
Loading