Skip to content

Commit 5fc8cb7

Browse files
author
Eric Olkowski
committed
chore(Toolbar): replaced chip instances with label
1 parent 6aa9964 commit 5fc8cb7

File tree

26 files changed

+193
-193
lines changed

26 files changed

+193
-193
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styles from '@patternfly/react-styles/css/components/Toolbar/toolbar';
33
import { GenerateId } from '../../helpers/GenerateId/GenerateId';
44
import { css } from '@patternfly/react-styles';
55
import { ToolbarContext } from './ToolbarUtils';
6-
import { ToolbarChipGroupContent } from './ToolbarChipGroupContent';
6+
import { ToolbarLabelGroupContent } from './ToolbarLabelGroupContent';
77
import { formatBreakpointMods, canUseDOM } from '../../helpers/util';
88
import { getDefaultOUIAId, getOUIAProps, OUIAProps } from '../../helpers';
99
import { PageContext } from '../Page/PageContext';
@@ -20,9 +20,9 @@ export interface ToolbarProps extends React.HTMLProps<HTMLDivElement>, OUIAProps
2020
clearAllFilters?: () => void;
2121
/** Text to display in the clear all filters button */
2222
clearFiltersButtonText?: string;
23-
/** Custom content appended to the filter generated chip group. To maintain spacing and styling, each node should be wrapped in a ToolbarItem or ToolbarGroup. This property will remove the default "Clear all filters" button. */
24-
customChipGroupContent?: React.ReactNode;
25-
/** The breakpoint at which the listed filters in chip groups are collapsed down to a summary */
23+
/** Custom content appended to the filter generated label group. To maintain spacing and styling, each node should be wrapped in a ToolbarItem or ToolbarGroup. This property will remove the default "Clear all filters" button. */
24+
customLabelGroupContent?: React.ReactNode;
25+
/** The breakpoint at which the listed filters in label groups are collapsed down to a summary */
2626
collapseListedFiltersBreakpoint?: 'all' | 'md' | 'lg' | 'xl' | '2xl';
2727
/** Flag indicating if a data toolbar toggle group's expandable content is expanded */
2828
isExpanded?: boolean;
@@ -65,7 +65,7 @@ export interface ToolbarState {
6565
/** Flag used if the user has opted NOT to manage the 'isExpanded' state of the toggle group.
6666
* Indicates whether or not the toggle group is expanded. */
6767
isManagedToggleExpanded: boolean;
68-
/** Object managing information about how many chips are in each chip group */
68+
/** Object managing information about how many labels are in each label group */
6969
filterInfo: FilterInfo;
7070
/** Used to keep track of window width so we can collapse expanded content when window is resizing */
7171
windowWidth: number;
@@ -78,7 +78,7 @@ interface FilterInfo {
7878

7979
class Toolbar extends React.Component<ToolbarProps, ToolbarState> {
8080
static displayName = 'Toolbar';
81-
chipGroupContentRef = React.createRef<HTMLDivElement>();
81+
labelGroupContentRef = React.createRef<HTMLDivElement>();
8282
staticFilterInfo = {};
8383
state = {
8484
isManagedToggleExpanded: false,
@@ -144,7 +144,7 @@ class Toolbar extends React.Component<ToolbarProps, ToolbarState> {
144144
isSticky,
145145
ouiaId,
146146
numberOfFiltersText,
147-
customChipGroupContent,
147+
customLabelGroupContent,
148148
colorVariant = ToolbarColorVariant.default,
149149
...props
150150
} = this.props;
@@ -180,27 +180,27 @@ class Toolbar extends React.Component<ToolbarProps, ToolbarState> {
180180
value={{
181181
isExpanded,
182182
toggleIsExpanded: isToggleManaged ? this.toggleIsExpanded : toggleIsExpanded,
183-
chipGroupContentRef: this.chipGroupContentRef,
183+
labelGroupContentRef: this.labelGroupContentRef,
184184
updateNumberFilters: this.updateNumberFilters,
185185
numberOfFilters,
186186
clearAllFilters,
187187
clearFiltersButtonText,
188188
showClearFiltersButton,
189189
toolbarId: randomId,
190-
customChipGroupContent
190+
customLabelGroupContent
191191
}}
192192
>
193193
{children}
194-
<ToolbarChipGroupContent
194+
<ToolbarLabelGroupContent
195195
isExpanded={isExpanded}
196-
chipGroupContentRef={this.chipGroupContentRef}
196+
labelGroupContentRef={this.labelGroupContentRef}
197197
clearAllFilters={clearAllFilters}
198198
showClearFiltersButton={showClearFiltersButton}
199199
clearFiltersButtonText={clearFiltersButtonText}
200200
numberOfFilters={numberOfFilters}
201201
numberOfFiltersText={numberOfFiltersText}
202202
collapseListedFiltersBreakpoint={collapseListedFiltersBreakpoint}
203-
customChipGroupContent={customChipGroupContent}
203+
customLabelGroupContent={customLabelGroupContent}
204204
/>
205205
</ToolbarContext.Provider>
206206
</div>

packages/react-core/src/components/Toolbar/ToolbarContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface ToolbarContentProps extends React.HTMLProps<HTMLDivElement> {
3737
class ToolbarContent extends React.Component<ToolbarContentProps> {
3838
static displayName = 'ToolbarContent';
3939
private expandableContentRef = React.createRef<HTMLDivElement>();
40-
private chipContainerRef = React.createRef<HTMLDivElement>();
40+
private labelContainerRef = React.createRef<HTMLDivElement>();
4141
private static currentId = 0;
4242

4343
static defaultProps: ToolbarContentProps = {
@@ -88,7 +88,7 @@ class ToolbarContent extends React.Component<ToolbarContentProps> {
8888
value={{
8989
expandableContentRef: this.expandableContentRef,
9090
expandableContentId,
91-
chipContainerRef: this.chipContainerRef,
91+
labelContainerRef: this.labelContainerRef,
9292
isExpanded: isExpanded || isExpandedContext,
9393
clearAllFilters: clearAllFilters || clearAllFiltersContext,
9494
clearFiltersButtonText: clearFiltersButtonText || clearFiltersButtonContext,

packages/react-core/src/components/Toolbar/ToolbarExpandableContent.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface ToolbarExpandableContentProps extends React.HTMLProps<HTMLDivEl
1616
isExpanded?: boolean;
1717
/** Expandable content reference for passing to data toolbar children */
1818
expandableContentRef?: RefObject<HTMLDivElement>;
19-
/** Chip container reference for passing to data toolbar children */
20-
chipContainerRef?: RefObject<any>;
19+
/** Label container reference for passing to data toolbar children */
20+
labelContainerRef?: RefObject<any>;
2121
/** optional callback for clearing all filters in the toolbar */
2222
clearAllFilters?: () => void;
2323
/** Text to display in the clear all filters button */
@@ -40,16 +40,16 @@ class ToolbarExpandableContent extends React.Component<ToolbarExpandableContentP
4040
children,
4141
className,
4242
expandableContentRef,
43-
chipContainerRef,
43+
labelContainerRef,
4444
isExpanded,
4545
clearAllFilters,
4646
clearFiltersButtonText,
4747
showClearFiltersButton,
4848
...props
4949
} = this.props;
50-
const { numberOfFilters, customChipGroupContent } = this.context;
50+
const { numberOfFilters, customLabelGroupContent } = this.context;
5151

52-
const clearChipGroups = () => {
52+
const clearLabelGroups = () => {
5353
clearAllFilters();
5454
};
5555

@@ -62,15 +62,15 @@ class ToolbarExpandableContent extends React.Component<ToolbarExpandableContentP
6262
<ToolbarGroup>{children}</ToolbarGroup>
6363
{numberOfFilters > 0 && (
6464
<ToolbarGroup>
65-
<ToolbarGroup ref={chipContainerRef} />
66-
{showClearFiltersButton && !customChipGroupContent && (
65+
<ToolbarGroup ref={labelContainerRef} />
66+
{showClearFiltersButton && !customLabelGroupContent && (
6767
<ToolbarItem>
68-
<Button variant="link" onClick={clearChipGroups} isInline>
68+
<Button variant="link" onClick={clearLabelGroups} isInline>
6969
{clearFiltersButtonText}
7070
</Button>
7171
</ToolbarItem>
7272
)}
73-
{customChipGroupContent && customChipGroupContent}
73+
{customLabelGroupContent && customLabelGroupContent}
7474
</ToolbarGroup>
7575
)}
7676
</div>

packages/react-core/src/components/Toolbar/ToolbarFilter.tsx

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,41 @@ import { ToolbarContentContext, ToolbarContext } from './ToolbarUtils';
55
import { PickOptional } from '../../helpers/typeUtils';
66
import { Label, LabelGroup } from '../Label';
77

8-
export interface ToolbarChipGroup {
9-
/** A unique key to identify this chip group category */
8+
export interface ToolbarLabelGroup {
9+
/** A unique key to identify this label group category */
1010
key: string;
11-
/** The category name to display for the chip group */
11+
/** The category name to display for the label group */
1212
name: string;
1313
}
1414

15-
export interface ToolbarChip {
16-
/** A unique key to identify this chip */
15+
export interface ToolbarLabel {
16+
/** A unique key to identify this label */
1717
key: string;
18-
/** The ReactNode to display in the chip */
18+
/** The ReactNode to display in the label */
1919
node: React.ReactNode;
2020
}
2121

2222
export interface ToolbarFilterProps extends ToolbarItemProps {
2323
/** Flag indicating when toolbar toggle group is expanded for non-managed toolbar toggle groups. */
2424
isExpanded?: boolean;
25-
/** An array of strings to be displayed as chips in the expandable content */
26-
chips?: (string | ToolbarChip)[];
27-
/** Callback passed by consumer used to close the entire chip group */
28-
deleteChipGroup?: (category: string | ToolbarChipGroup) => void;
29-
/** Callback passed by consumer used to delete a chip from the chips[] */
30-
deleteChip?: (category: string | ToolbarChipGroup, chip: ToolbarChip | string) => void;
31-
/** Customizable "Show Less" text string for the chip group */
32-
chipGroupExpandedText?: string;
33-
/** Customizeable template string for the chip group. Use variable "${remaining}" for the overflow chip count. */
34-
chipGroupCollapsedText?: string;
35-
/** Content to be rendered inside the data toolbar item associated with the chip group */
25+
/** An array of strings to be displayed as labels in the expandable content */
26+
labels?: (string | ToolbarLabel)[];
27+
/** Callback passed by consumer used to close the entire label group */
28+
deleteLabelGroup?: (category: string | ToolbarLabelGroup) => void;
29+
/** Callback passed by consumer used to delete a label from the labels[] */
30+
deleteLabel?: (category: string | ToolbarLabelGroup, label: ToolbarLabel | string) => void;
31+
/** Customizable "Show Less" text string for the label group */
32+
labelGroupExpandedText?: string;
33+
/** Customizeable template string for the label group. Use variable "${remaining}" for the overflow label count. */
34+
labelGroupCollapsedText?: string;
35+
/** Content to be rendered inside the data toolbar item associated with the label group */
3636
children: React.ReactNode;
37-
/** Unique category name to be used as a label for the chip group */
38-
categoryName: string | ToolbarChipGroup;
37+
/** Unique category name to be used as a label for the label group */
38+
categoryName: string | ToolbarLabelGroup;
3939
/** Flag to show the toolbar item */
4040
showToolbarItem?: boolean;
41-
/** Reference to a chip container created with a custom expandable content group, for non-managed multiple toolbar toggle groups. */
42-
expandableChipContainerRef?: React.RefObject<HTMLDivElement>;
41+
/** Reference to a label container created with a custom expandable content group, for non-managed multiple toolbar toggle groups. */
42+
expandableLabelContainerRef?: React.RefObject<HTMLDivElement>;
4343
}
4444

4545
interface ToolbarFilterState {
@@ -51,7 +51,7 @@ class ToolbarFilter extends React.Component<ToolbarFilterProps, ToolbarFilterSta
5151
static contextType = ToolbarContext;
5252
context!: React.ContextType<typeof ToolbarContext>;
5353
static defaultProps: PickOptional<ToolbarFilterProps> = {
54-
chips: [] as (string | ToolbarChip)[],
54+
labels: [] as (string | ToolbarLabel)[],
5555
showToolbarItem: true
5656
};
5757

@@ -63,65 +63,65 @@ class ToolbarFilter extends React.Component<ToolbarFilterProps, ToolbarFilterSta
6363
}
6464

6565
componentDidMount() {
66-
const { categoryName, chips } = this.props;
66+
const { categoryName, labels } = this.props;
6767
this.context.updateNumberFilters(
6868
typeof categoryName !== 'string' && categoryName.hasOwnProperty('key')
6969
? categoryName.key
7070
: categoryName.toString(),
71-
chips.length
71+
labels.length
7272
);
7373
this.setState({ isMounted: true });
7474
}
7575

7676
componentDidUpdate() {
77-
const { categoryName, chips } = this.props;
77+
const { categoryName, labels } = this.props;
7878
this.context.updateNumberFilters(
7979
typeof categoryName !== 'string' && categoryName.hasOwnProperty('key')
8080
? categoryName.key
8181
: categoryName.toString(),
82-
chips.length
82+
labels.length
8383
);
8484
}
8585

8686
render() {
8787
const {
8888
children,
89-
chips,
90-
deleteChipGroup,
91-
deleteChip,
92-
chipGroupExpandedText,
93-
chipGroupCollapsedText,
89+
labels,
90+
deleteLabelGroup,
91+
deleteLabel,
92+
labelGroupExpandedText,
93+
labelGroupCollapsedText,
9494
categoryName,
9595
showToolbarItem,
9696
isExpanded,
97-
expandableChipContainerRef,
97+
expandableLabelContainerRef,
9898
...props
9999
} = this.props;
100-
const { isExpanded: managedIsExpanded, chipGroupContentRef } = this.context;
100+
const { isExpanded: managedIsExpanded, labelGroupContentRef } = this.context;
101101
const _isExpanded = isExpanded !== undefined ? isExpanded : managedIsExpanded;
102102
const categoryKey =
103103
typeof categoryName !== 'string' && categoryName.hasOwnProperty('key')
104104
? categoryName.key
105105
: categoryName.toString();
106106

107-
const chipGroup = chips.length ? (
108-
<ToolbarItem variant="chip-group">
107+
const labelGroup = labels.length ? (
108+
<ToolbarItem variant="label-group">
109109
<LabelGroup
110110
key={categoryKey}
111111
categoryName={typeof categoryName === 'string' ? categoryName : categoryName.name}
112-
isClosable={deleteChipGroup !== undefined}
113-
onClick={() => deleteChipGroup(categoryName)}
114-
collapsedText={chipGroupCollapsedText}
115-
expandedText={chipGroupExpandedText}
112+
isClosable={deleteLabelGroup !== undefined}
113+
onClick={() => deleteLabelGroup(categoryName)}
114+
collapsedText={labelGroupCollapsedText}
115+
expandedText={labelGroupExpandedText}
116116
>
117-
{chips.map((chip) =>
118-
typeof chip === 'string' ? (
119-
<Label variant="outline" key={chip} onClose={() => deleteChip(categoryKey, chip)}>
120-
{chip}
117+
{labels.map((label) =>
118+
typeof label === 'string' ? (
119+
<Label variant="outline" key={label} onClose={() => deleteLabel(categoryKey, label)}>
120+
{label}
121121
</Label>
122122
) : (
123-
<Label key={chip.key} onClose={() => deleteChip(categoryKey, chip)}>
124-
{chip.node}
123+
<Label key={label.key} onClose={() => deleteLabel(categoryKey, label)}>
124+
{label.node}
125125
</Label>
126126
)
127127
)}
@@ -133,20 +133,20 @@ class ToolbarFilter extends React.Component<ToolbarFilterProps, ToolbarFilterSta
133133
return (
134134
<React.Fragment>
135135
{showToolbarItem && <ToolbarItem {...props}>{children}</ToolbarItem>}
136-
{ReactDOM.createPortal(chipGroup, chipGroupContentRef.current.firstElementChild)}
136+
{ReactDOM.createPortal(labelGroup, labelGroupContentRef.current.firstElementChild)}
137137
</React.Fragment>
138138
);
139139
}
140140

141141
return (
142142
<ToolbarContentContext.Consumer>
143-
{({ chipContainerRef }) => (
143+
{({ labelContainerRef }) => (
144144
<React.Fragment>
145145
{showToolbarItem && <ToolbarItem {...props}>{children}</ToolbarItem>}
146-
{chipContainerRef.current && ReactDOM.createPortal(chipGroup, chipContainerRef.current)}
147-
{expandableChipContainerRef &&
148-
expandableChipContainerRef.current &&
149-
ReactDOM.createPortal(chipGroup, expandableChipContainerRef.current)}
146+
{labelContainerRef.current && ReactDOM.createPortal(labelGroup, labelContainerRef.current)}
147+
{expandableLabelContainerRef &&
148+
expandableLabelContainerRef.current &&
149+
ReactDOM.createPortal(labelGroup, expandableLabelContainerRef.current)}
150150
</React.Fragment>
151151
)}
152152
</ToolbarContentContext.Consumer>

packages/react-core/src/components/Toolbar/ToolbarGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export interface ToolbarGroupProps extends Omit<React.HTMLProps<HTMLDivElement>,
152152
children?: React.ReactNode;
153153
/** Flag that modifies the toolbar group to hide overflow and respond to available space. Used for horizontal navigation. */
154154
isOverflowContainer?: boolean;
155-
/** @hide Reference to pass to this group if it has .pf-m-chip-container modifier */
155+
/** @hide Reference to pass to this group if it has .pf-m-label-container modifier */
156156
innerRef?: React.RefObject<any>;
157157
}
158158

packages/react-core/src/components/Toolbar/ToolbarItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ export enum ToolbarItemVariant {
99
separator = 'separator',
1010
pagination = 'pagination',
1111
label = 'label',
12-
'chip-group' = 'chip-group',
12+
'label-group' = 'label-group',
1313
'expand-all' = 'expand-all'
1414
}
1515

1616
export interface ToolbarItemProps extends React.HTMLProps<HTMLDivElement> {
1717
/** Classes applied to root element of the data toolbar item */
1818
className?: string;
1919
/** A type modifier which modifies spacing specifically depending on the type of item */
20-
variant?: ToolbarItemVariant | 'pagination' | 'label' | 'chip-group' | 'separator' | 'expand-all';
20+
variant?: ToolbarItemVariant | 'pagination' | 'label' | 'label-group' | 'separator' | 'expand-all';
2121
/** Visibility at various breakpoints. */
2222
visibility?: {
2323
default?: 'hidden' | 'visible';
@@ -189,7 +189,7 @@ export const ToolbarItem: React.FunctionComponent<ToolbarItemProps> = ({
189189
className={css(
190190
styles.toolbarItem,
191191
variant && styles.modifiers[toCamel(variant) as 'pagination' | 'label'],
192-
variant === ToolbarItemVariant['chip-group'] && styles.modifiers.labelGroup,
192+
variant === ToolbarItemVariant['label-group'] && styles.modifiers.labelGroup,
193193
isAllExpanded && styles.modifiers.expanded,
194194
isOverflowContainer && styles.modifiers.overflowContainer,
195195
formatBreakpointMods(visibility, styles, '', getBreakpoint(width)),

0 commit comments

Comments
 (0)