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

feat(Label): penta updates #10037

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
19 changes: 14 additions & 5 deletions packages/react-core/src/components/Label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface LabelProps extends React.HTMLProps<HTMLSpanElement> {
/** Additional classes added to the label. */
className?: string;
/** Color of the label. */
color?: 'blue' | 'cyan' | 'green' | 'orange' | 'purple' | 'red' | 'grey' | 'gold';
color?: 'blue' | 'cyan' | 'green' | 'orange' | 'purple' | 'red' | 'orangered' | 'grey' | 'gold';
/** Variant of the label. */
variant?: 'outline' | 'filled';
/** Flag indicating the label is compact. */
Expand Down Expand Up @@ -60,6 +60,8 @@ export interface LabelProps extends React.HTMLProps<HTMLSpanElement> {
href?: string;
/** Flag indicating if the label is an overflow label. */
isOverflowLabel?: boolean;
Copy link
Contributor

@tlabaj tlabaj Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please open codemod issue for this removed prop.

/** Flag indicating if the label is an add label. */
isAddLabel?: boolean;
/** Callback for when the label is clicked. This should not be passed in if the href or isEditable props are also passed in. */
onClick?: (event: React.MouseEvent) => void;
/** Forwards the label content and className to rendered function. Use this prop for react router support.*/
Expand All @@ -81,6 +83,7 @@ const colorStyles = {
orange: styles.modifiers.orange,
purple: styles.modifiers.purple,
red: styles.modifiers.red,
orangered: styles.modifiers.orangered,
gold: styles.modifiers.gold,
grey: ''
};
Expand All @@ -105,6 +108,7 @@ export const Label: React.FunctionComponent<LabelProps> = ({
closeBtnProps,
href,
isOverflowLabel,
isAddLabel,
render,
...props
}: LabelProps) => {
Expand All @@ -113,6 +117,8 @@ export const Label: React.FunctionComponent<LabelProps> = ({
const editableButtonRef = React.useRef<HTMLButtonElement>();
const editableInputRef = React.useRef<HTMLInputElement>();

const isClickable = (onLabelClick && !isOverflowLabel && !isAddLabel) || href;

React.useEffect(() => {
document.addEventListener('mousedown', onDocMouseDown);
document.addEventListener('keydown', onKeyDown);
Expand Down Expand Up @@ -198,12 +204,13 @@ export const Label: React.FunctionComponent<LabelProps> = ({
}
};

const LabelComponent = (isOverflowLabel ? 'button' : 'span') as any;
const LabelComponent = (isOverflowLabel || isAddLabel ? 'button' : 'span') as any;

const defaultButton = (
<Button
type="button"
variant="plain"
hasNoPadding
onClick={onClose}
aria-label={closeBtnAriaLabel || `Close ${children}`}
{...closeBtnProps}
Expand Down Expand Up @@ -253,7 +260,7 @@ export const Label: React.FunctionComponent<LabelProps> = ({
let LabelComponentChildElement = 'span';
if (href) {
LabelComponentChildElement = 'a';
} else if (isEditable || (onLabelClick && !isOverflowLabel)) {
} else if (isEditable || (onLabelClick && !isOverflowLabel && !isAddLabel)) {
LabelComponentChildElement = 'button';
}

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

const labelComponentChildProps = {
className: css(styles.labelContent),
className: css(styles.labelContent, isClickable && styles.modifiers.clickable),
...(isTooltipVisible && { tabIndex: 0 }),
...(href && { href }),
...(isButton && clickableLabelProps),
Expand Down Expand Up @@ -313,9 +320,11 @@ export const Label: React.FunctionComponent<LabelProps> = ({
isCompact && styles.modifiers.compact,
isEditable && labelGrpStyles.modifiers.editable,
isEditableActive && styles.modifiers.editableActive,
isClickable && styles.modifiers.clickable,
isAddLabel && styles.modifiers.add,
className
)}
onClick={isOverflowLabel ? onLabelClick : undefined}
onClick={isOverflowLabel || isAddLabel ? onLabelClick : undefined}
>
{!isEditableActive && labelComponentChild}
{!isEditableActive && onClose && button}
Expand Down
1 change: 1 addition & 0 deletions packages/react-core/src/components/Label/LabelGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class LabelGroup extends React.Component<LabelGroupProps, LabelGroupState> {
<div className={css(styles.labelGroupClose)}>
<Button
variant="plain"
hasNoPadding
aria-label={closeBtnAriaLabel}
onClick={onClick}
id={`remove_group_${id}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports[`Label editable label 1`] = `
<button
aria-disabled="false"
aria-label="Close Something"
class="pf-v5-c-button pf-m-plain"
class="pf-v5-c-button pf-m-plain pf-m-no-padding"
data-ouia-component-id="OUIA-Generated-Button-plain-3"
data-ouia-component-type="PF5/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -155,7 +155,7 @@ exports[`Label label with close button 1`] = `
<button
aria-disabled="false"
aria-label="Close Something"
class="pf-v5-c-button pf-m-plain"
class="pf-v5-c-button pf-m-plain pf-m-no-padding"
data-ouia-component-id="OUIA-Generated-Button-plain-1"
data-ouia-component-type="PF5/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -200,7 +200,7 @@ exports[`Label label with close button and outline variant 1`] = `
<button
aria-disabled="false"
aria-label="Close Something"
class="pf-v5-c-button pf-m-plain"
class="pf-v5-c-button pf-m-plain pf-m-no-padding"
data-ouia-component-id="OUIA-Generated-Button-plain-2"
data-ouia-component-type="PF5/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -336,10 +336,10 @@ exports[`Label label with grey color with outline variant 1`] = `
exports[`Label label with href 1`] = `
<DocumentFragment>
<span
class="pf-v5-c-label"
class="pf-v5-c-label pf-m-clickable"
>
<a
class="pf-v5-c-label__content"
class="pf-v5-c-label__content pf-m-clickable"
href="#"
>
<span
Expand All @@ -355,10 +355,10 @@ exports[`Label label with href 1`] = `
exports[`Label label with href with outline variant 1`] = `
<DocumentFragment>
<span
class="pf-v5-c-label pf-m-outline"
class="pf-v5-c-label pf-m-outline pf-m-clickable"
>
<a
class="pf-v5-c-label__content"
class="pf-v5-c-label__content pf-m-clickable"
href="#"
>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ exports[`LabelGroup label group with closable category 1`] = `
aria-disabled="false"
aria-label="Close label group"
aria-labelledby="remove_group_pf-random-id-2 pf-random-id-2"
class="pf-v5-c-button pf-m-plain"
class="pf-v5-c-button pf-m-plain pf-m-no-padding"
data-ouia-component-id="OUIA-Generated-Button-plain-1"
data-ouia-component-type="PF5/Button"
data-ouia-safe="true"
Expand Down
73 changes: 53 additions & 20 deletions packages/react-core/src/components/Label/examples/LabelCompact.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,60 @@
import React from 'react';
import { Label } from '@patternfly/react-core';
import { Label, Flex } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

export const LabelCompact: React.FunctionComponent = () => (
<React.Fragment>
<Label isCompact>Grey</Label>{' '}
<Label isCompact icon={<InfoCircleIcon />}>
Compact icon
</Label>{' '}
<Label isCompact onClose={() => Function.prototype}>
Compact removable
</Label>{' '}
<Label isCompact icon={<InfoCircleIcon />} onClose={() => Function.prototype}>
Compact icon removable
</Label>{' '}
<Label isCompact href="#compact">
Compact link
</Label>{' '}
<Label isCompact href="#compact" onClose={() => Function.prototype}>
Compact link removable
</Label>
<Label isCompact icon={<InfoCircleIcon />} onClose={() => Function.prototype} textMaxWidth="16ch">
Compact label with icon that overflows
</Label>
<Flex gap={{ default: 'gapSm' }}>
<Label isCompact>Compact</Label>
<Label isCompact icon={<InfoCircleIcon />}>
Compact icon
</Label>
<Label isCompact onClose={() => Function.prototype}>
Compact removable
</Label>
<Label isCompact icon={<InfoCircleIcon />} onClose={() => Function.prototype}>
Compact icon removable
</Label>
<Label isCompact href="#compact">
Compact link
</Label>
<Label isCompact href="#compact" onClose={() => Function.prototype}>
Compact link removable
</Label>
<Label isCompact icon={<InfoCircleIcon />} onClose={() => Function.prototype} textMaxWidth="16ch">
Compact label with icon that overflows
</Label>
</Flex>
<br />
<Flex gap={{ default: 'gapSm' }}>
<Label variant="outline" color="blue" isCompact>
Compact
</Label>
<Label variant="outline" color="blue" isCompact icon={<InfoCircleIcon />}>
Compact icon
</Label>
<Label variant="outline" color="blue" isCompact onClose={() => Function.prototype}>
Compact removable
</Label>
<Label variant="outline" color="blue" isCompact icon={<InfoCircleIcon />} onClose={() => Function.prototype}>
Compact icon removable
</Label>
<Label variant="outline" color="blue" isCompact href="#compact">
Compact link
</Label>
<Label variant="outline" color="blue" isCompact href="#compact" onClose={() => Function.prototype}>
Compact link removable
</Label>
<Label
variant="outline"
color="blue"
isCompact
icon={<InfoCircleIcon />}
onClose={() => Function.prototype}
textMaxWidth="16ch"
>
Compact label with icon that overflows
</Label>
</Flex>
</React.Fragment>
);
Loading
Loading