Skip to content

Commit

Permalink
ToggleGroupControl: Only show enclosing border when isBlock (#45492)
Browse files Browse the repository at this point in the history
* ToggleGroupControl: Only show enclosing border when `isBlock`

* Default stories to `isBlock`

* Refactor

* Update snapshot

* Add changelog

* Fix changelog
  • Loading branch information
mirka authored Nov 4, 2022
1 parent 519f0e7 commit 984e9d8
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

- `PaletteEditListView`: Update to ignore `exhaustive-deps` eslint rule ([#45467](https://github.com/WordPress/gutenberg/pull/45467)).

### Experimental

- `ToggleGroupControl`: Only show enclosing border when `isBlock` and not `isDeselectable` ([#45492](https://github.com/WordPress/gutenberg/pull/45492)).

## 22.0.0 (2022-11-02)

### Breaking Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Default.args = {
{ value: 'right', label: 'Right' },
{ value: 'justify', label: 'Justify' },
].map( mapPropsToOptionComponent ),
isBlock: true,
label: 'Label',
};

Expand Down Expand Up @@ -121,6 +122,7 @@ WithIcons.args = {
{ value: 'uppercase', label: 'Uppercase', icon: formatUppercase },
{ value: 'lowercase', label: 'Lowercase', icon: formatLowercase },
].map( mapPropsToOptionIconComponent ),
isBlock: false,
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
.emotion-8 {
background: #fff;
border: 1px solid transparent;
border-radius: 2px;
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
Expand All @@ -51,8 +52,6 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
-webkit-transition: -webkit-transform 100ms linear;
transition: transform 100ms linear;
min-height: 36px;
border-color: #757575;
border-radius: 2px;
}
@media ( prefers-reduced-motion: reduce ) {
Expand Down Expand Up @@ -377,6 +376,7 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
.emotion-8 {
background: #fff;
border: 1px solid transparent;
border-radius: 2px;
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
Expand All @@ -387,8 +387,6 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
-webkit-transition: -webkit-transform 100ms linear;
transition: transform 100ms linear;
min-height: 36px;
border-color: #757575;
border-radius: 2px;
}
@media ( prefers-reduced-motion: reduce ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ Determines if segments should be rendered with equal widths.
- Required: No
- Default: `false`

### `isDeselectable`: `boolean`

Whether an option can be deselected by clicking it again.

- Required: No
- Default: `false`

### `isBlock`: `boolean`

Renders `ToggleGroupControl` as a (CSS) block element.
Renders `ToggleGroupControl` as a (CSS) block element, spanning the entire width of the available space. This is the recommended style when the options are text-based and not icons.

- Required: No
- Default: `false`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function UnconnectedToggleGroupControl(
const classes = useMemo(
() =>
cx(
styles.ToggleGroupControl( { isDeselectable, size } ),
styles.ToggleGroupControl( { isBlock, isDeselectable, size } ),
isBlock && styles.block,
className
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { CONFIG, COLORS, reduceMotion } from '../../utils';
import type { ToggleGroupControlProps } from '../types';

export const ToggleGroupControl = ( {
isBlock,
isDeselectable,
size,
}: {
isDeselectable?: boolean;
}: Pick< ToggleGroupControlProps, 'isBlock' | 'isDeselectable' > & {
size: NonNullable< ToggleGroupControlProps[ 'size' ] >;
} ) => css`
background: ${ COLORS.ui.background };
border: 1px solid transparent;
border-radius: ${ CONFIG.controlBorderRadius };
display: inline-flex;
min-width: 0;
padding: 2px;
Expand All @@ -27,24 +28,29 @@ export const ToggleGroupControl = ( {
${ reduceMotion( 'transition' ) }
${ toggleGroupControlSize( size ) }
${ ! isDeselectable && enclosingBorder }
${ ! isDeselectable && enclosingBorders( isBlock ) }
`;

const enclosingBorder = css`
border-color: ${ COLORS.ui.border };
border-radius: ${ CONFIG.controlBorderRadius };
const enclosingBorders = ( isBlock: ToggleGroupControlProps[ 'isBlock' ] ) => {
const enclosingBorder = css`
border-color: ${ COLORS.ui.border };
`;

return css`
${ isBlock && enclosingBorder }
&:hover {
border-color: ${ COLORS.ui.borderHover };
}
&:hover {
border-color: ${ COLORS.ui.borderHover };
}
&:focus-within {
border-color: ${ COLORS.ui.borderFocus };
box-shadow: ${ CONFIG.controlBoxShadowFocus };
outline: none;
z-index: 1;
}
`;
&:focus-within {
border-color: ${ COLORS.ui.borderFocus };
box-shadow: ${ CONFIG.controlBoxShadowFocus };
outline: none;
z-index: 1;
}
`;
};

export const toggleGroupControlSize = (
size: NonNullable< ToggleGroupControlProps[ 'size' ] >
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/toggle-group-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export type ToggleGroupControlProps = Pick<
*/
isAdaptiveWidth?: boolean;
/**
* Renders `ToggleGroupControl` as a (CSS) block element.
* Renders `ToggleGroupControl` as a (CSS) block element, spanning the entire width of
* the available space. This is the recommended style when the options are text-based and not icons.
*
* @default false
*/
Expand Down

0 comments on commit 984e9d8

Please sign in to comment.