Debian Codegraph @

node/@patternfly/react-core/src/components/ToggleGroup/examples/ToggleGroup.md

raw
1 ---
2 id: Toggle group
3 section: components
4 cssPrefix: pf-v6-c-toggle-group
5 propComponents: ['ToggleGroup', 'ToggleGroupItem']
6 ---
7
8 import './toggleGroup.css';
9
10 import { useRef, useState } from 'react';
11 import { ToggleGroup, ToggleGroupItem, Button, Stack, StackItem } from '@patternfly/react-core';
12 import UndoIcon from '@patternfly/react-icons/dist/esm/icons/undo-icon';
13 import RhUiCopyFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-copy-fill-icon';
14 import ShareSquareIcon from '@patternfly/react-icons/dist/esm/icons/share-square-icon';
15
16 ## Examples
17
18 ### Single select toggle group
19
20 A single select toggle group allows users to toggle between multiple items.
21
22 To indicate whether a `<ToggleGroupItem>` is selected or not, use the `isSelected` property.
23
24 ```ts file="./ToggleGroupDefaultSingle.tsx"
25
26 ```
27
28 ### Multi select toggle group
29
30 A multi select toggle group allows users to select multiple items at once.
31
32 When a toggle item is disabled it cannot be selected. Click the "Disable all" button in the following example to see this in action.
33
34 ```ts file="./ToggleGroupDefaultMultiple.tsx"
35
36 ```
37
38 ### With icons
39
40 You can use a recognizable icon as a toggle item label.
41
42 To do this, pass an imported icon to the `icon` property of a `<ToggleGroupItem>`.
43
44 ```ts file="./ToggleGroupIcon.tsx"
45
46 ```
47
48 ### With text and icons
49
50 Adding text to a toggle item with an icon helps clarify the button's function.
51
52 To do this, pass a descriptive label to the `text` property of a `<ToggleGroupItem>`.
53
54 When passing both `text` and `icon` properties to a `<ToggleGroupItem>`, you can also pass in `iconPosition` to determine whether the icon is rendered at the start or end of the item.
55
56 ```ts file="./ToggleGroupTextIcon.tsx"
57
58 ```
59
60 ### Compact toggle group
61
62 When space in a UI is limited, you can use a compact toggle group.
63
64 To apply compact styling to a `<ToggleGroup>`, use `isCompact`.
65
66 ```ts file="./ToggleGroupCompact.tsx"
67
68 ```
69
70 ### Full-width toggle group
71
72 To make toggle group items fill the available horizontal space, use `isFill` on a `<ToggleGroup>`. The following example shows full-width toggle groups for a single-select, multi-select, and single-select with disabled item.
73
74 ```ts file="./ToggleGroupFill.tsx"
75
76 ```