Skip to content

Commit

Permalink
Try: Polish link/unlink buttons (#43802)
Browse files Browse the repository at this point in the history
* Border link button.

* Padding & text case.

* Radius.

* Update packages/components/src/border-box-control/styles.ts

Co-authored-by: Aaron Robertshaw <[email protected]>

* Restore is-small padding, and fix spacing between unlink and custom buttons.

* Remove span again.

* Keep spans in place but add a comment.

* Update changelog.

Co-authored-by: Aaron Robertshaw <[email protected]>
  • Loading branch information
jasmussen and aaronrobertshaw authored Sep 16, 2022
1 parent bc41987 commit 68e7f56
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import { link, linkOff } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';

export default function LinkedButton( { isLinked, ...props } ) {
const label = isLinked ? __( 'Unlink Radii' ) : __( 'Link Radii' );
const label = isLinked ? __( 'Unlink radii' ) : __( 'Link radii' );

// TODO: Remove span after merging https://github.com/WordPress/gutenberg/pull/44198
return (
<Tooltip text={ label }>
<Button
{ ...props }
className="component-border-radius-control__linked-button"
isPrimary={ isLinked }
isSecondary={ ! isLinked }
isSmall
icon={ isLinked ? link : linkOff }
iconSize={ 16 }
aria-label={ label }
/>
<span>
<Button
{ ...props }
className="component-border-radius-control__linked-button"
isSmall
icon={ isLinked ? link : linkOff }
iconSize={ 24 }
aria-label={ label }
/>
</span>
</Tooltip>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import { __ } from '@wordpress/i18n';
import { Button, Tooltip } from '@wordpress/components';

export default function LinkedButton( { isLinked, onClick } ) {
const label = isLinked ? __( 'Unlink Sides' ) : __( 'Link Sides' );
const label = isLinked ? __( 'Unlink sides' ) : __( 'Link sides' );

return (
<Tooltip text={ label }>
<span className="component-spacing-sizes-control__linked-button">
<Button
variant={ isLinked ? 'primary' : 'secondary' }
isSmall
icon={ isLinked ? link : linkOff }
iconSize={ 16 }
iconSize={ 24 }
aria-label={ label }
onClick={ onClick }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@
grid-column: 2 / 2;
grid-row: 1 / 1;
justify-self: end;
margin-right: $grid-unit-05;
padding: 0;
}

.component-spacing-sizes-control__linked-button ~ .components-spacing-sizes-control__custom-toggle-all {
margin-right: $grid-unit-05;
}

.components-spacing-sizes-control__custom-toggle-single {
grid-column: 3 / 3;
justify-self: end;
Expand Down
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fix

- The `LinkedButton` to unlink sides in `BoxControl`, `BorderBoxControl` and `BorderRadiusControl` have changed from a rectangular primary button to an icon-only button, with a sentence case tooltip, and default-size icon for better legibility. The `Button` component has been fixed so when `isSmall` and `icon` props are set, and no text is present, the button shape is square rather than rectangular.

### New Features

- `Popover`: added new `anchor` prop, supposed to supersede all previous anchor-related props (`anchorRef`, `anchorRect`, `getAnchorRect`). These older anchor-related props are now marked as deprecated and are scheduled to be removed in WordPress 6.3 ([#43691](https://github.com/WordPress/gutenberg/pull/43691)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ const BorderBoxControlLinkedButton = (
<View className={ className }>
<Button
{ ...buttonProps }
variant={ isLinked ? 'primary' : 'secondary' }
isSmall
icon={ isLinked ? link : linkOff }
iconSize={ 16 }
iconSize={ 24 }
aria-label={ label }
ref={ forwardedRef }
/>
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/border-box-control/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const BorderBoxControlLinkedButton = (
) => {
return css`
flex: 0;
flex-basis: 36px;
flex-basis: 24px;
line-height: 0;
margin-top: ${ __next36pxDefaultSize ? '6px' : '3px' };
`;
};
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/box-control/linked-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import Button from '../button';
import Tooltip from '../tooltip';

export default function LinkedButton( { isLinked, ...props } ) {
const label = isLinked ? __( 'Unlink Sides' ) : __( 'Link Sides' );
const label = isLinked ? __( 'Unlink sides' ) : __( 'Link sides' );

// TODO: Remove span after merging https://github.com/WordPress/gutenberg/pull/44198
return (
<Tooltip text={ label }>
<span>
<Button
{ ...props }
className="component-box-control__linked-button"
variant={ isLinked ? 'primary' : 'secondary' }
isSmall
icon={ isLinked ? link : linkOff }
iconSize={ 16 }
iconSize={ 24 }
aria-label={ label }
/>
</span>
Expand Down
10 changes: 5 additions & 5 deletions packages/components/src/box-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe( 'BoxControl', () => {
} );
} );

describe( 'Unlinked Sides', () => {
describe( 'Unlinked sides', () => {
it( 'should update a single side value when unlinked', async () => {
let state = {};
const setState = ( newState ) => ( state = newState );
Expand All @@ -174,7 +174,7 @@ describe( 'BoxControl', () => {
/>
);
const user = setupUser();
const unlink = screen.getByLabelText( /Unlink Sides/ );
const unlink = screen.getByLabelText( /Unlink sides/ );

await user.click( unlink );

Expand Down Expand Up @@ -207,7 +207,7 @@ describe( 'BoxControl', () => {
/>
);
const user = setupUser();
const unlink = screen.getByLabelText( /Unlink Sides/ );
const unlink = screen.getByLabelText( /Unlink sides/ );

await user.click( unlink );

Expand Down Expand Up @@ -240,7 +240,7 @@ describe( 'BoxControl', () => {
await user.selectOptions( allUnitSelect, [ 'em' ] );

// Unlink the controls.
await user.click( screen.getByLabelText( /Unlink Sides/ ) );
await user.click( screen.getByLabelText( /Unlink sides/ ) );

// Confirm that each individual control has the selected unit
const unlinkedSelects = screen.getAllByDisplayValue( 'em' );
Expand All @@ -257,7 +257,7 @@ describe( 'BoxControl', () => {
await user.selectOptions( allUnitSelect, [ 'vw' ] );

// Unlink the controls.
await user.click( screen.getByLabelText( /Unlink Sides/ ) );
await user.click( screen.getByLabelText( /Unlink sides/ ) );

// Confirm that each individual control has the selected unit
const unlinkedSelects = screen.getAllByDisplayValue( 'vw' );
Expand Down
7 changes: 4 additions & 3 deletions packages/components/src/button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,15 @@
}

&.is-small {
height: 24px;
height: $icon-size;
line-height: 22px;
padding: 0 8px;
font-size: 11px;

&.has-icon:not(.has-text) {
padding: 0 8px;
width: 24px;
padding: 0;
width: $icon-size;
min-width: $icon-size;
}
}

Expand Down

0 comments on commit 68e7f56

Please sign in to comment.