Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
className={ classes }
/* translators: accessibility text for the block toolbar */
aria-label={ __( 'Block tools' ) }
variant={ isFixed ? 'unstyled' : undefined }
{ ...props }
>
{ ! isCollapsed && <BlockToolbar hideDragHandle={ isFixed } /> }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
overflow-y: hidden;
}

border: none;
border-bottom: $border-width solid $gray-200;
border-radius: 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function ToolSelector( props, ref ) {
label={ __( 'Tools' ) }
/>
) }
popoverProps={ { placement: 'bottom-start', variant: undefined } }
popoverProps={ { placement: 'bottom-start' } }
renderContent={ () => (
<>
<NavigableMenu role="menu" aria-label={ __( 'Tools' ) }>
Expand Down
43 changes: 43 additions & 0 deletions packages/components/src/toolbar/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const meta: Meta< typeof Toolbar > = {
},
argTypes: {
children: { control: { type: null } },
variant: {
options: [ undefined, 'unstyled' ],
control: { type: 'radio' },
},
},
parameters: {
controls: { expanded: true },
Expand Down Expand Up @@ -181,3 +185,42 @@ WithoutGroup.args = {
</>
),
};

/**
* Set the variant to `unstyled` to remove default border styles.
* Otherwise, leave it as `undefined` for default styles.
*/

export const WithoutStyles = Template.bind( {} );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mentioned consistency with Popover...

So if we decide to keep the name 'unstyled', I'll update the story name to match.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll update the story name to match.

Yeah, "Unstyled" sounds like a better name for this story.

Also, I think we could get away with re-using the default story's arguments — ie.

WithoutStyles.args = {
	...Default.args,
	variant: 'unstyled',
};

And even more in general, I wonder if we could avoid adding a new story altogether, since folks could just use the variant controls on existing stories?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could leave the story out. I added it because it's a visual change, so I thought seeing an explicit demo could be helpful. Also, Popover has the same story so I can add another point to my consistency list 😄

But I'm happy to remove it if you don't think it adds enough value.

Copy link
Contributor

@ciampo ciampo Oct 11, 2023

Choose a reason for hiding this comment

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

Let's keep it for now, but maybe rewrite the args to reuse Default.args like suggested above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good!

WithoutStyles.args = {
label: 'Options',
id: 'options-toolbar-without-styles',
variant: 'unstyled',
children: (
<>
<ToolbarGroup>
<ToolbarButton icon={ paragraph } text="Paragraph" />
</ToolbarGroup>
<ToolbarGroup>
<ToolbarButton>Text</ToolbarButton>
<ToolbarButton icon={ formatBold } label="Bold" isPressed />
<ToolbarButton icon={ formatItalic } label="Italic" />
<ToolbarButton icon={ link } label="Link" />
</ToolbarGroup>
<ToolbarGroup
icon={ chevronDown }
title="Align"
isCollapsed
controls={ [
{
icon: alignLeft,
title: 'Align left',
isActive: true,
},
{ icon: alignCenter, title: 'Align center' },
{ icon: alignRight, title: 'Align right' },
] }
/>
</>
),
};
8 changes: 8 additions & 0 deletions packages/components/src/toolbar/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,13 @@ describe( 'Toolbar', () => {
screen.getByLabelText( 'control2', { selector: 'button' } )
).toBeInTheDocument();
} );

it( 'should render a toolbar without styles if variant has been defined', () => {
render( <Toolbar label="blocks" variant="unstyled" /> );

expect( screen.getByRole( 'toolbar' ) ).toHaveClass(
'is-unstyled'
);
} );
} );
} );
27 changes: 18 additions & 9 deletions packages/components/src/toolbar/toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@ import type { ToolbarProps } from './types';
import type { WordPressComponentProps } from '../../context';
import { ContextSystemProvider } from '../../context';

const CONTEXT_SYSTEM_VALUE = {
DropdownMenu: {
variant: 'toolbar',
},
Dropdown: {
variant: 'toolbar',
},
const CONTEXT_SYSTEM_VALUE = ( variant: string | undefined ) => {
if ( variant !== undefined ) {
return {};
}

return {
DropdownMenu: {
variant: 'toolbar',
},
Dropdown: {
variant: 'toolbar',
},
};
};

function UnforwardedToolbar(
{
className,
label,
variant,
...props
}: WordPressComponentProps< ToolbarProps, 'div', false >,
ref: ForwardedRef< any >
Expand All @@ -55,10 +62,12 @@ function UnforwardedToolbar(
// `ToolbarGroup` already uses components-toolbar for compatibility reasons.
const finalClassName = classnames(
'components-accessible-toolbar',
className
className,
variant === undefined ? undefined : `is-${ variant }`
);

return (
<ContextSystemProvider value={ CONTEXT_SYSTEM_VALUE }>
<ContextSystemProvider value={ CONTEXT_SYSTEM_VALUE( variant ) }>
<ToolbarContainer
className={ finalClassName }
label={ label }
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/toolbar/toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
}
}

.components-accessible-toolbar.is-unstyled {
border: none;

& > .components-toolbar-group {
border: none;

}
}

.components-accessible-toolbar,
.components-toolbar {
.components-button {
Expand Down
10 changes: 10 additions & 0 deletions packages/components/src/toolbar/toolbar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ export type ToolbarProps = {
* An accessible label for the toolbar.
*/
label: string;
/**
* Specifies the toolbar's style.
*
* Leave undefined for the default style. Or 'unstyled' which
* removes the border from the toolbar, but keeps the default
* popover style.
*
* @default undefined
*/
variant?: 'unstyled' | undefined;
};
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function HeaderToolbar( { setListViewToggleElement } ) {
className="edit-post-header-toolbar"
aria-label={ toolbarAriaLabel }
shouldUseKeyboardFocusShortcut={ ! blockToolbarCanBeFocused }
variant={ 'unstyled' }
>
<div className="edit-post-header-toolbar__left">
<ToolbarItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.edit-post-header-toolbar {
display: inline-flex;
align-items: center;
border: none;

// Hide all action buttons except the inserter on mobile.
.edit-post-header-toolbar__left > .components-button {
Expand Down