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(toolbar): adds color variant #10284

Merged
merged 5 commits into from
Apr 29, 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
6 changes: 6 additions & 0 deletions packages/react-core/src/components/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface ToolbarProps extends React.HTMLProps<HTMLDivElement>, OUIAProps
ouiaId?: number | string;
/** Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. */
ouiaSafe?: boolean;
/** Color variant of the toolbar */
colorVariant?: 'no-background' | 'primary' | 'secondary';
Copy link
Contributor

Choose a reason for hiding this comment

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

Question for react-dev - should we have a default which will unset colorVariant? Without a colorVariant set, the toolbar background can be dynamic depending on how it's used. By default, a toolbar's background is transparent (same as colorVariant="no-background") except when it's sticky, then it's the primary background (same as colorVariant="primary")

Copy link
Contributor

Choose a reason for hiding this comment

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

I would usually lean towards having the "default" case be where a user would leave out the colorVariant prop entirely, and only apply the colors if the prop is present. But we've done both ways in different areas, so either works.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did a quick search to see what we do with other color variant props. It looks like the Drawer has a color variant that has a default option. So I would lean towards adding one here as well for consistency.

}

export interface ToolbarState {
Expand Down Expand Up @@ -136,6 +138,7 @@ class Toolbar extends React.Component<ToolbarProps, ToolbarState> {
ouiaId,
numberOfFiltersText,
customChipGroupContent,
colorVariant,
...props
} = this.props;

Expand All @@ -157,6 +160,9 @@ class Toolbar extends React.Component<ToolbarProps, ToolbarState> {
usePageInsets && styles.modifiers.pageInsets,
isSticky && styles.modifiers.sticky,
formatBreakpointMods(inset, styles, '', getBreakpoint(width)),
colorVariant === 'primary' && styles.modifiers.primary,
colorVariant === 'secondary' && styles.modifiers.secondary,
colorVariant === 'no-background' && styles.modifiers.noBackground,
className
)}
id={randomId}
Expand Down
10 changes: 10 additions & 0 deletions packages/react-core/src/components/Toolbar/examples/Toolbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,13 @@ When all of a toolbar's required elements cannot fit in a single line, you can s
```ts file="./ToolbarStacked.tsx"

```

### Toolbar with secondary color

To change the background color of a toolbar, use the `colorVariant` property on the `<Toolbar>`.

In the following example, toggle the "Secondary" checkbox to see the difference between primary and secondary variants.

```ts file="./ToolbarColorVariant.tsx"

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { Toolbar, ToolbarItem, ToolbarContent, Button, SearchInput, Checkbox } from '@patternfly/react-core';

export const ToolbarColorVariant: React.FunctionComponent = () => {
const [isSecondary, setisSecondary] = React.useState(true);

return (
<React.Fragment>
<Toolbar id="toolbar-" colorVariant={isSecondary ? 'secondary' : 'primary'}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<Toolbar id="toolbar-" colorVariant={isSecondary ? 'secondary' : 'primary'}>
<Toolbar id="toolbar-color-variant" colorVariant={isSecondary ? 'secondary' : 'primary'}>

<ToolbarContent>
<ToolbarItem>
<SearchInput aria-label="Items example search input" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to give this a unique name:

Suggested change
<SearchInput aria-label="Items example search input" />
<SearchInput aria-label="With secondary color example search input" />

</ToolbarItem>
<ToolbarItem>
<Button variant="secondary">Action</Button>
</ToolbarItem>
<ToolbarItem variant="separator" />
<ToolbarItem>
<Button variant="primary">Action</Button>
</ToolbarItem>
</ToolbarContent>
</Toolbar>
<Checkbox
label="Secondary"
isChecked={isSecondary}
onChange={(_event, checked) => setisSecondary(checked)}
id="isSecondaryCheckbox"
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add the ability to see all of the variants? Looks like the way it is now toggles between secondary and primary, which we should at least call out that it's secondary when checked, and primary when unchecked, which is different from the default (no value for colorVariant). Seems like it might be more clear if we showed primary, secondary, and no-background.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought of that but followed the drawer model, which has a no-background modifier but only showed an example for secondary - and also I didn't know how to make a dropdown work lol. Maybe I can pair program with someone to do that?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say it may be nice to see all the color variants. We could lay them out individually instead of with a dropdown since there's only 3 (similar to how we show Alert or Label), but if we want to go the dropdown route feel free to ping me and I can help out. @srambach

Copy link
Contributor

Choose a reason for hiding this comment

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

@sarah, we should probably update the Drawer example as well. I agree that we should show all variants.

</React.Fragment>
);
};
Loading