Debian Codegraph @

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

raw
1 ---
2 id: Label
3 section: components
4 cssPrefix: ['pf-v6-c-label', 'pf-v6-c-label-group']
5 propComponents: ['Label', 'LabelGroup']
6 ---
7
8 import { Fragment, useEffect, useRef, useState } from 'react';
9 import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
10 import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon';
11 import './Label.css';
12
13 ## Examples
14
15 ### Filled labels
16
17 ```ts file="LabelFilled.tsx"
18
19 ```
20
21 ### Outlined labels
22
23 ```ts file="LabelOutline.tsx"
24
25 ```
26
27 ### Compact labels
28
29 ```ts file="LabelCompact.tsx"
30
31 ```
32
33 ### Label with custom render
34
35 Labels may be passed a custom renderer to display customized content or for use with router components. When using a custom render, `isClickable` may also be passed to remove the underline text decoration of anchors or router links.
36
37 ```ts file="LabelCustomRender.tsx"
38
39 ```
40
41 ### Editable labels
42
43 Click or press either enter or space to begin editing a label. After editing, click outside the label or press enter again to complete the edit. To cancel an edit, press escape.
44
45 You can also customize any Label's close button aria-label as this example shows with `closeBtnAriaLabel`.
46
47 ```ts file="LabelEditable.tsx"
48
49 ```
50
51 ### Basic label group
52
53 Use a label group when you have multiple labels to display at once.
54
55 ```ts file="LabelGroupBasic.tsx"
56
57 ```
58
59 ### Label group with overflow
60
61 An overflow label can be added to the end of a group to save space when the number of labels exceeds some threshold. Click the overflow label to expand and collapse the group.
62
63 ```ts file="LabelGroupOverflow.tsx"
64
65 ```
66
67 ### Label group with categories
68
69 Use a category name to organize a set of labels
70
71 ```ts file="LabelGroupCategory.tsx"
72
73 ```
74
75 ### Label group with removable categories
76
77 ```ts file="LabelGroupCategoryRemovable.tsx"
78
79 ```
80
81 ### Vertical label group
82
83 Labels in a group can also be stacked vertically. This example shows a verical label group with a category name and overflow.
84
85 ```ts file="LabelGroupVerticalCategoryOverflowRemovable.tsx"
86
87 ```
88
89 ### Editable label group
90
91 ```ts file="LabelGroupEditableLabels.tsx"
92
93 ```
94
95 ### Editable label group with add button
96
97 The contents of a label group can be modified by removing labels or adding new ones using the add button. For additional documentation that showcases adding a new label, see [label demos](/components/label/react-demos).
98
99 ```ts file="LabelGroupEditableAdd.tsx"
100
101 ```
102
103 ## Using router links
104
105 Router links can be used for in-app linking in React environments to prevent page reloading. To use a `Link` component from a router package, you can use the `render` property of the `Label`:
106
107 ```nolive
108 <Label
109 render={({ className, content, componentRef }) => (
110 <Link to="/" className={className} innerRef={componentRef}>
111 {content}
112 </Link>
113 )}
114 >
115 Label router link
116 </Label>
117 ```