Skip to content

Commit 88d24da

Browse files
authored
feat(Label): penta updates (#10037)
* feat(Label): penta updates * move overflow and add labels to variant * use css for spacing
1 parent 1794095 commit 88d24da

12 files changed

Lines changed: 250 additions & 124 deletions

File tree

packages/react-core/src/components/Label/Label.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export interface LabelProps extends React.HTMLProps<HTMLSpanElement> {
1515
/** Additional classes added to the label. */
1616
className?: string;
1717
/** Color of the label. */
18-
color?: 'blue' | 'cyan' | 'green' | 'orange' | 'purple' | 'red' | 'grey' | 'gold';
18+
color?: 'blue' | 'cyan' | 'green' | 'orange' | 'purple' | 'red' | 'orangered' | 'grey' | 'gold';
1919
/** Variant of the label. */
20-
variant?: 'outline' | 'filled';
20+
variant?: 'outline' | 'filled' | 'overflow' | 'add';
2121
/** Flag indicating the label is compact. */
2222
isCompact?: boolean;
2323
/** @beta Flag indicating the label is editable. */
@@ -58,8 +58,6 @@ export interface LabelProps extends React.HTMLProps<HTMLSpanElement> {
5858
closeBtnProps?: any;
5959
/** Href for a label that is a link. If present, the label will change to an anchor element. This should not be passed in if the onClick prop is also passed in. */
6060
href?: string;
61-
/** Flag indicating if the label is an overflow label. */
62-
isOverflowLabel?: boolean;
6361
/** Callback for when the label is clicked. This should not be passed in if the href or isEditable props are also passed in. */
6462
onClick?: (event: React.MouseEvent) => void;
6563
/** Forwards the label content and className to rendered function. Use this prop for react router support.*/
@@ -81,6 +79,7 @@ const colorStyles = {
8179
orange: styles.modifiers.orange,
8280
purple: styles.modifiers.purple,
8381
red: styles.modifiers.red,
82+
orangered: styles.modifiers.orangered,
8483
gold: styles.modifiers.gold,
8584
grey: ''
8685
};
@@ -104,7 +103,6 @@ export const Label: React.FunctionComponent<LabelProps> = ({
104103
closeBtnAriaLabel,
105104
closeBtnProps,
106105
href,
107-
isOverflowLabel,
108106
render,
109107
...props
110108
}: LabelProps) => {
@@ -113,6 +111,10 @@ export const Label: React.FunctionComponent<LabelProps> = ({
113111
const editableButtonRef = React.useRef<HTMLButtonElement>();
114112
const editableInputRef = React.useRef<HTMLInputElement>();
115113

114+
const isOverflowLabel = variant === 'overflow';
115+
const isAddLabel = variant === 'add';
116+
const isClickable = (onLabelClick && !isOverflowLabel && !isAddLabel) || href;
117+
116118
React.useEffect(() => {
117119
document.addEventListener('mousedown', onDocMouseDown);
118120
document.addEventListener('keydown', onKeyDown);
@@ -198,12 +200,13 @@ export const Label: React.FunctionComponent<LabelProps> = ({
198200
}
199201
};
200202

201-
const LabelComponent = (isOverflowLabel ? 'button' : 'span') as any;
203+
const LabelComponent = (isOverflowLabel || isAddLabel ? 'button' : 'span') as any;
202204

203205
const defaultButton = (
204206
<Button
205207
type="button"
206208
variant="plain"
209+
hasNoPadding
207210
onClick={onClose}
208211
aria-label={closeBtnAriaLabel || `Close ${children}`}
209212
{...closeBtnProps}
@@ -253,7 +256,7 @@ export const Label: React.FunctionComponent<LabelProps> = ({
253256
let LabelComponentChildElement = 'span';
254257
if (href) {
255258
LabelComponentChildElement = 'a';
256-
} else if (isEditable || (onLabelClick && !isOverflowLabel)) {
259+
} else if (isEditable || (onLabelClick && !isOverflowLabel && !isAddLabel)) {
257260
LabelComponentChildElement = 'button';
258261
}
259262

@@ -265,7 +268,7 @@ export const Label: React.FunctionComponent<LabelProps> = ({
265268
const isButton = LabelComponentChildElement === 'button';
266269

267270
const labelComponentChildProps = {
268-
className: css(styles.labelContent),
271+
className: css(styles.labelContent, isClickable && styles.modifiers.clickable),
269272
...(isTooltipVisible && { tabIndex: 0 }),
270273
...(href && { href }),
271274
...(isButton && clickableLabelProps),
@@ -313,9 +316,11 @@ export const Label: React.FunctionComponent<LabelProps> = ({
313316
isCompact && styles.modifiers.compact,
314317
isEditable && labelGrpStyles.modifiers.editable,
315318
isEditableActive && styles.modifiers.editableActive,
319+
isClickable && styles.modifiers.clickable,
320+
isAddLabel && styles.modifiers.add,
316321
className
317322
)}
318-
onClick={isOverflowLabel ? onLabelClick : undefined}
323+
onClick={isOverflowLabel || isAddLabel ? onLabelClick : undefined}
319324
>
320325
{!isEditableActive && labelComponentChild}
321326
{!isEditableActive && onClose && button}

packages/react-core/src/components/Label/LabelGroup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class LabelGroup extends React.Component<LabelGroupProps, LabelGroupState> {
183183
{numChildren > numLabels && (
184184
<li className={css(styles.labelGroupListItem)}>
185185
<Label
186-
isOverflowLabel
186+
variant="overflow"
187187
onClick={this.toggleCollapse}
188188
className={css(isCompact && labelStyles.modifiers.compact)}
189189
>
@@ -205,6 +205,7 @@ class LabelGroup extends React.Component<LabelGroupProps, LabelGroupState> {
205205
<div className={css(styles.labelGroupClose)}>
206206
<Button
207207
variant="plain"
208+
hasNoPadding
208209
aria-label={closeBtnAriaLabel}
209210
onClick={onClick}
210211
id={`remove_group_${id}`}

packages/react-core/src/components/Label/__tests__/__snapshots__/Label.test.tsx.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exports[`Label editable label 1`] = `
2121
<button
2222
aria-disabled="false"
2323
aria-label="Close Something"
24-
class="pf-v5-c-button pf-m-plain"
24+
class="pf-v5-c-button pf-m-plain pf-m-no-padding"
2525
data-ouia-component-id="OUIA-Generated-Button-plain-3"
2626
data-ouia-component-type="PF5/Button"
2727
data-ouia-safe="true"
@@ -155,7 +155,7 @@ exports[`Label label with close button 1`] = `
155155
<button
156156
aria-disabled="false"
157157
aria-label="Close Something"
158-
class="pf-v5-c-button pf-m-plain"
158+
class="pf-v5-c-button pf-m-plain pf-m-no-padding"
159159
data-ouia-component-id="OUIA-Generated-Button-plain-1"
160160
data-ouia-component-type="PF5/Button"
161161
data-ouia-safe="true"
@@ -200,7 +200,7 @@ exports[`Label label with close button and outline variant 1`] = `
200200
<button
201201
aria-disabled="false"
202202
aria-label="Close Something"
203-
class="pf-v5-c-button pf-m-plain"
203+
class="pf-v5-c-button pf-m-plain pf-m-no-padding"
204204
data-ouia-component-id="OUIA-Generated-Button-plain-2"
205205
data-ouia-component-type="PF5/Button"
206206
data-ouia-safe="true"
@@ -336,10 +336,10 @@ exports[`Label label with grey color with outline variant 1`] = `
336336
exports[`Label label with href 1`] = `
337337
<DocumentFragment>
338338
<span
339-
class="pf-v5-c-label"
339+
class="pf-v5-c-label pf-m-clickable"
340340
>
341341
<a
342-
class="pf-v5-c-label__content"
342+
class="pf-v5-c-label__content pf-m-clickable"
343343
href="#"
344344
>
345345
<span
@@ -355,10 +355,10 @@ exports[`Label label with href 1`] = `
355355
exports[`Label label with href with outline variant 1`] = `
356356
<DocumentFragment>
357357
<span
358-
class="pf-v5-c-label pf-m-outline"
358+
class="pf-v5-c-label pf-m-outline pf-m-clickable"
359359
>
360360
<a
361-
class="pf-v5-c-label__content"
361+
class="pf-v5-c-label__content pf-m-clickable"
362362
href="#"
363363
>
364364
<span

packages/react-core/src/components/Label/__tests__/__snapshots__/LabelGroup.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ exports[`LabelGroup label group with closable category 1`] = `
255255
aria-disabled="false"
256256
aria-label="Close label group"
257257
aria-labelledby="remove_group_pf-random-id-2 pf-random-id-2"
258-
class="pf-v5-c-button pf-m-plain"
258+
class="pf-v5-c-button pf-m-plain pf-m-no-padding"
259259
data-ouia-component-id="OUIA-Generated-Button-plain-1"
260260
data-ouia-component-type="PF5/Button"
261261
data-ouia-safe="true"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ws-react-c-label-filled-labels .pf-v5-c-label,
2+
#ws-react-c-label-outlined-labels .pf-v5-c-label,
3+
#ws-react-c-label-compact-labels .pf-v5-c-label {
4+
margin-inline-end: var(--pf-t--global--spacer--sm);
5+
margin-block-end: var(--pf-t--global--spacer--sm);
6+
}

packages/react-core/src/components/Label/examples/Label.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,76 +7,92 @@ propComponents: ['Label', 'LabelGroup']
77

88
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';
99
import { Link } from '@reach/router';
10+
import './Label.css';
1011

1112
## Examples
1213

1314
### Filled labels
1415

1516
```ts file="LabelFilled.tsx"
17+
1618
```
1719

1820
### Outlined labels
1921

2022
```ts file="LabelOutline.tsx"
23+
2124
```
2225

2326
### Compact labels
2427

2528
```ts file="LabelCompact.tsx"
29+
2630
```
2731

2832
### Label with router link
2933

3034
```ts file="LabelRouterLink.tsx"
35+
3136
```
3237

3338
### Editable labels
3439

35-
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.
40+
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.
3641

3742
You can also customize any Label's close button aria-label as this example shows with `closeBtnAriaLabel`.
3843

3944
```ts file="LabelEditable.tsx" isBeta
40-
```
4145

46+
```
4247

4348
### Basic label group
44-
Use a label group when you have multiple labels to display at once.
49+
50+
Use a label group when you have multiple labels to display at once.
4551

4652
```ts file="LabelGroupBasic.tsx"
53+
4754
```
4855

4956
### Label group with overflow
57+
5058
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.
5159

5260
```ts file="LabelGroupOverflow.tsx"
61+
5362
```
5463

5564
### Label group with categories
65+
5666
Use a category name to organize a set of labels
5767

5868
```ts file="LabelGroupCategory.tsx"
69+
5970
```
6071

6172
### Label group with removable categories
6273

6374
```ts file="LabelGroupCategoryRemovable.tsx"
75+
6476
```
6577

6678
### Vertical label group
79+
6780
Labels in a group can also be stacked vertically. This example shows a verical label group with a category name and overflow.
6881

6982
```ts file="LabelGroupVerticalCategoryOverflowRemovable.tsx"
83+
7084
```
7185

7286
### Editable label group
7387

7488
```ts isBeta file="LabelGroupEditableLabels.tsx"
89+
7590
```
7691

7792
### Editable label group with add button
7893

7994
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).
8095

8196
```ts isBeta file="LabelGroupEditableAdd.tsx"
97+
8298
```

packages/react-core/src/components/Label/examples/LabelCompact.tsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,54 @@ import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-i
44

55
export const LabelCompact: React.FunctionComponent = () => (
66
<React.Fragment>
7-
<Label isCompact>Grey</Label>{' '}
7+
<Label isCompact>Compact</Label>
88
<Label isCompact icon={<InfoCircleIcon />}>
99
Compact icon
10-
</Label>{' '}
10+
</Label>
1111
<Label isCompact onClose={() => Function.prototype}>
1212
Compact removable
13-
</Label>{' '}
13+
</Label>
1414
<Label isCompact icon={<InfoCircleIcon />} onClose={() => Function.prototype}>
1515
Compact icon removable
16-
</Label>{' '}
16+
</Label>
1717
<Label isCompact href="#compact">
1818
Compact link
19-
</Label>{' '}
19+
</Label>
2020
<Label isCompact href="#compact" onClose={() => Function.prototype}>
2121
Compact link removable
2222
</Label>
2323
<Label isCompact icon={<InfoCircleIcon />} onClose={() => Function.prototype} textMaxWidth="16ch">
2424
Compact label with icon that overflows
2525
</Label>
26+
<br />
27+
<br />
28+
<Label variant="outline" color="blue" isCompact>
29+
Compact
30+
</Label>
31+
<Label variant="outline" color="blue" isCompact icon={<InfoCircleIcon />}>
32+
Compact icon
33+
</Label>
34+
<Label variant="outline" color="blue" isCompact onClose={() => Function.prototype}>
35+
Compact removable
36+
</Label>
37+
<Label variant="outline" color="blue" isCompact icon={<InfoCircleIcon />} onClose={() => Function.prototype}>
38+
Compact icon removable
39+
</Label>
40+
<Label variant="outline" color="blue" isCompact href="#compact">
41+
Compact link
42+
</Label>
43+
<Label variant="outline" color="blue" isCompact href="#compact" onClose={() => Function.prototype}>
44+
Compact link removable
45+
</Label>
46+
<Label
47+
variant="outline"
48+
color="blue"
49+
isCompact
50+
icon={<InfoCircleIcon />}
51+
onClose={() => Function.prototype}
52+
textMaxWidth="16ch"
53+
>
54+
Compact label with icon that overflows
55+
</Label>
2656
</React.Fragment>
2757
);

0 commit comments

Comments
 (0)