Skip to content

Commit 93919cd

Browse files
committed
fix(ToolbarItem): apply responsive width and flexGrow props
1 parent 869eb6b commit 93919cd

2 files changed

Lines changed: 8 additions & 27 deletions

File tree

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

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as React from 'react';
1+
import { FunctionComponent, ReactNode } from 'react';
22
import styles from '@patternfly/react-styles/css/components/Toolbar/toolbar';
33
import { css } from '@patternfly/react-styles';
44
import { formatBreakpointMods, setBreakpointCssVars, toCamel } from '../../helpers/util';
5-
import c_toolbar__item_Width from '@patternfly/react-tokens/dist/esm/c_toolbar__item_Width';
5+
import toolbarItemWidth from '@patternfly/react-tokens/dist/esm/c_toolbar__item_Width';
66
import { Divider } from '../Divider';
77
import { PageContext } from '../Page/PageContext';
88

@@ -15,15 +15,9 @@ export enum ToolbarItemVariant {
1515
}
1616

1717
export interface ToolbarItemProps extends React.HTMLProps<HTMLDivElement> {
18-
/** Classes applied to root element of the data toolbar item */
1918
className?: string;
20-
/** A type modifier which modifies spacing specifically depending on the type of item */
2119
variant?: ToolbarItemVariant | 'pagination' | 'label' | 'label-group' | 'separator' | 'expand-all';
2220

23-
/**
24-
* Width modifier at various breakpoints.
25-
* Accepts valid CSS width values (e.g. '200px', '3rem', '50%').
26-
*/
2721
widths?: {
2822
default?: string;
2923
sm?: string;
@@ -33,7 +27,6 @@ export interface ToolbarItemProps extends React.HTMLProps<HTMLDivElement> {
3327
'2xl'?: string;
3428
};
3529

36-
/** Indicates whether a flex grow modifier of 1 is applied at various breakpoints */
3730
flexGrow?: {
3831
default?: 'flexGrow';
3932
sm?: 'flexGrow';
@@ -43,7 +36,6 @@ export interface ToolbarItemProps extends React.HTMLProps<HTMLDivElement> {
4336
'2xl'?: 'flexGrow';
4437
};
4538

46-
/** Visibility at various breakpoints. */
4739
visibility?: {
4840
default?: 'hidden' | 'visible';
4941
md?: 'hidden' | 'visible';
@@ -52,7 +44,6 @@ export interface ToolbarItemProps extends React.HTMLProps<HTMLDivElement> {
5244
'2xl'?: 'hidden' | 'visible';
5345
};
5446

55-
/** Applies to a child of a flex layout, and aligns that child to one side of the main axis */
5647
align?: {
5748
default?: 'alignEnd' | 'alignStart' | 'alignCenter';
5849
md?: 'alignEnd' | 'alignStart' | 'alignCenter';
@@ -61,12 +52,9 @@ export interface ToolbarItemProps extends React.HTMLProps<HTMLDivElement> {
6152
'2xl'?: 'alignEnd' | 'alignStart' | 'alignCenter';
6253
};
6354

64-
/** Vertical alignment of children */
6555
alignItems?: 'start' | 'center' | 'baseline' | 'default' | 'end' | 'stretch';
66-
/** Vertical alignment */
6756
alignSelf?: 'start' | 'center' | 'baseline' | 'default' | 'end' | 'stretch';
6857

69-
/** Sets both the column and row gap at various breakpoints. */
7058
gap?: {
7159
default?: 'gapNone' | 'gapXs' | 'gapSm' | 'gapMd' | 'gapLg' | 'gapXl' | 'gap_2xl' | 'gap_3xl' | 'gap_4xl';
7260
md?: 'gapNone' | 'gapXs' | 'gapSm' | 'gapMd' | 'gapLg' | 'gapXl' | 'gap_2xl' | 'gap_3xl' | 'gap_4xl';
@@ -75,7 +63,6 @@ export interface ToolbarItemProps extends React.HTMLProps<HTMLDivElement> {
7563
'2xl'?: 'gapNone' | 'gapXs' | 'gapSm' | 'gapMd' | 'gapLg' | 'gapXl' | 'gap_2xl' | 'gap_3xl' | 'gap_4xl';
7664
};
7765

78-
/** Sets only the column gap at various breakpoints. */
7966
columnGap?: {
8067
default?:
8168
| 'columnGapNone'
@@ -129,7 +116,6 @@ export interface ToolbarItemProps extends React.HTMLProps<HTMLDivElement> {
129116
| 'columnGap_4xl';
130117
};
131118

132-
/** Sets only the row gap at various breakpoints. */
133119
rowGap?: {
134120
default?:
135121
| 'rowGapNone'
@@ -183,7 +169,6 @@ export interface ToolbarItemProps extends React.HTMLProps<HTMLDivElement> {
183169
| 'rowGap_4xl';
184170
};
185171

186-
/** Value to set for row wrapping at various breakpoints */
187172
rowWrap?: {
188173
default?: 'wrap' | 'nowrap';
189174
sm?: 'wrap' | 'nowrap';
@@ -193,17 +178,13 @@ export interface ToolbarItemProps extends React.HTMLProps<HTMLDivElement> {
193178
'2xl'?: 'wrap' | 'nowrap';
194179
};
195180

196-
/** id for this data toolbar item */
197181
id?: string;
198-
/** Flag indicating if the expand-all variant is expanded or not */
199182
isAllExpanded?: boolean;
200-
/** Flag that modifies the toolbar item to hide overflow and respond to available space */
201183
isOverflowContainer?: boolean;
202-
/** Content to be rendered inside the data toolbar item */
203-
children?: React.ReactNode;
184+
children?: ReactNode;
204185
}
205186

206-
export const ToolbarItem: React.FunctionComponent<ToolbarItemProps> = ({
187+
export const ToolbarItem: FunctionComponent<ToolbarItemProps> = ({
207188
className,
208189
variant,
209190
visibility,
@@ -240,6 +221,7 @@ export const ToolbarItem: React.FunctionComponent<ToolbarItemProps> = ({
240221
<PageContext.Consumer>
241222
{({ width, getBreakpoint }) => (
242223
<div
224+
data-testid="toolbaritem"
243225
className={css(
244226
styles.toolbarItem,
245227
variant && styles.modifiers[toCamel(variant) as 'pagination' | 'label'],
@@ -263,8 +245,7 @@ export const ToolbarItem: React.FunctionComponent<ToolbarItemProps> = ({
263245
)}
264246
style={{
265247
...style,
266-
// Apply responsive widths using PatternFly helper
267-
...(widths ? setBreakpointCssVars(widths, c_toolbar__item_Width.name) : undefined)
248+
...(widths ? setBreakpointCssVars(widths, toolbarItemWidth.name) : undefined)
268249
}}
269250
{...(variant === 'label' && { 'aria-hidden': true })}
270251
id={id}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render, screen } from '@testing-library/react';
22
import { ToolbarItem } from '../ToolbarItem';
3-
import c_toolbar__item_Width from '@patternfly/react-tokens/dist/esm/c_toolbar__item_Width';
3+
import toolbarItemWidth from '@patternfly/react-tokens/dist/esm/c_toolbar__item_Width';
44

55
describe('ToolbarItem', () => {
66
it('should render with pf-m-overflow-container when isOverflowContainer is set', () => {
@@ -51,7 +51,7 @@ describe('ToolbarItem', () => {
5151
</ToolbarItem>
5252
);
5353
const styleAttr = screen.getByTestId('toolbaritem').getAttribute('style') || '';
54-
const cssVarName = `${(c_toolbar__item_Width as any).name}${bp === 'default' ? '' : `-on-${bp}`}`;
54+
const cssVarName = `${(toolbarItemWidth as any).name}${bp === 'default' ? '' : `-on-${bp}`}`;
5555
expect(styleAttr).toContain(cssVarName);
5656
});
5757
});

0 commit comments

Comments
 (0)