diff --git a/packages/components/src/tools-panel/stories/index.js b/packages/components/src/tools-panel/stories/index.js index 803a01eb341d3..2a550b36cb008 100644 --- a/packages/components/src/tools-panel/stories/index.js +++ b/packages/components/src/tools-panel/stories/index.js @@ -27,6 +27,7 @@ export default { export const _default = () => { const [ height, setHeight ] = useState(); + const [ maxHeight, setMaxHeight ] = useState(); const [ minHeight, setMinHeight ] = useState(); const [ width, setWidth ] = useState(); @@ -71,7 +72,6 @@ export const _default = () => { hasValue={ () => !! minHeight } label="Minimum height" onDeselect={ () => setMinHeight( undefined ) } - isShownByDefault={ true } > { onChange={ ( next ) => setMinHeight( next ) } /> + !! maxHeight } + label="Maximum height" + onDeselect={ () => setMaxHeight( undefined ) } + > + setMaxHeight( next ) } + /> + diff --git a/packages/components/src/tools-panel/styles.ts b/packages/components/src/tools-panel/styles.ts index 7fe2fc0a0a1a2..9c82f740c001b 100644 --- a/packages/components/src/tools-panel/styles.ts +++ b/packages/components/src/tools-panel/styles.ts @@ -12,7 +12,7 @@ import { Wrapper as BaseControlWrapper, } from '../base-control/styles/base-control-styles'; import { LabelWrapper } from '../input-control/styles/input-control-styles'; -import { COLORS, CONFIG } from '../utils'; +import { baseLabelTypography, COLORS, CONFIG } from '../utils'; import { space } from '../ui/utils/space'; const toolsPanelGrid = { @@ -145,3 +145,32 @@ export const ToolsPanelItemPlaceholder = css` export const DropdownMenu = css` min-width: 200px; `; + +// Following provides for rendering "reset" text within a MenuItem. +export const DefaultControlsItem = css` + /** + * This high level of specificity is needed to overcome styles for items + * with no icon or shortcut. + */ + &&&&& > span { + display: flex; + /* item text plus icon min-width to match optional items. */ + min-width: 208px; + justify-content: space-between; + padding-right: 0; + } + + span > span:last-child { + flex: 0; + color: var( --wp-admin-theme-color-darker-10 ); + ${ baseLabelTypography } + } + + &&[aria-disabled='true'] { + opacity: 1; + + span > span:last-child { + opacity: 0.3; + } + } +`; diff --git a/packages/components/src/tools-panel/tools-panel-header/component.tsx b/packages/components/src/tools-panel/tools-panel-header/component.tsx index 62a40a966dcb7..414256f5eda52 100644 --- a/packages/components/src/tools-panel/tools-panel-header/component.tsx +++ b/packages/components/src/tools-panel/tools-panel-header/component.tsx @@ -7,7 +7,7 @@ import type { ForwardedRef } from 'react'; * WordPress dependencies */ import { speak } from '@wordpress/a11y'; -import { check, reset, moreVertical, plus } from '@wordpress/icons'; +import { check, moreVertical, plus } from '@wordpress/icons'; import { __, _x, sprintf } from '@wordpress/i18n'; /** @@ -26,6 +26,7 @@ import type { } from '../types'; const DefaultControlsGroup = ( { + itemClassName, items, toggleItem, }: ToolsPanelControlsGroupProps ) => { @@ -34,14 +35,14 @@ const DefaultControlsGroup = ( { } return ( - + { items.map( ( [ label, hasValue ] ) => { if ( hasValue ) { return ( - { label } + { label } + { __( 'Reset' ) } ); } @@ -67,12 +69,13 @@ const DefaultControlsGroup = ( { return ( - { label } + { label } + { __( 'Reset' ) } ); } ) } @@ -89,7 +92,7 @@ const OptionalControlsGroup = ( { } return ( - + { items.map( ( [ label, isSelected ] ) => { const itemLabel = isSelected ? sprintf( @@ -147,6 +150,7 @@ const ToolsPanelHeader = ( ) => { const { areAllOptionalControlsHidden, + defaultControlsItemClassName, dropdownMenuClassName, hasMenuItems, headingClassName, @@ -197,6 +201,7 @@ const ToolsPanelHeader = ( { + return cx( styles.DefaultControlsItem ); + }, [ cx ] ); + const { menuItems, hasMenuItems, areAllOptionalControlsHidden } = useToolsPanelContext(); return { ...otherProps, areAllOptionalControlsHidden, + defaultControlsItemClassName, dropdownMenuClassName, hasMenuItems, headingClassName, diff --git a/packages/components/src/tools-panel/types.ts b/packages/components/src/tools-panel/types.ts index 3290b9fe497fc..b95a50a4aa9cb 100644 --- a/packages/components/src/tools-panel/types.ts +++ b/packages/components/src/tools-panel/types.ts @@ -147,6 +147,7 @@ export type ToolsPanelContext = { }; export type ToolsPanelControlsGroupProps = { + itemClassName?: string; items: [ string, boolean ][]; toggleItem: ( label: string ) => void; };