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

Border Support: Add support for custom border units #33315

Merged
merged 3 commits into from
Jul 14, 2021
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
1 change: 1 addition & 0 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class WP_Theme_JSON_Gutenberg {
'customRadius' => null,
'customStyle' => null,
'customWidth' => null,
'units' => null,
),
'color' => array(
'custom' => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { __ } from '@wordpress/i18n';
import AllInputControl from './all-input-control';
import InputControls from './input-controls';
import LinkedButton from './linked-button';
import useSetting from '../use-setting';
import {
getAllValue,
getAllUnit,
Expand Down Expand Up @@ -49,7 +50,9 @@ export default function BorderRadiusControl( { onChange, values } ) {
! hasDefinedValues( values ) || ! hasMixedValues( values )
);

const units = useCustomUnits( { availableUnits: [ 'px', 'em', 'rem' ] } );
const units = useCustomUnits( {
availableUnits: useSetting( 'border.units' ) || [ 'px', 'em', 'rem' ],
Copy link
Member

Choose a reason for hiding this comment

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

In #33280 (comment) we consolidated all units into spacing.units so there's no longer a layout.units. I wonder if we can do the same here.

See this specific thread for more context #33280 (comment) The concerns were that the relation between both wasn't well understood and the implementation of UnitControl made layout values dependant on spacing values (layout couldn't have values that spacing also had).

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 can change this to spacing.units if desired. I'm not sure I follow why we wouldn't potentially want a different set of units for borders.

For example, do vh and vw make sense for borders? Would a theme author wish to have a different set of available units for borders as opposed to spacing?

(layout couldn't have values that spacing also had).

Unless I'm missing something, is it not that the supplied units had to be a subset of spacing units? That makes sense to me for borders. If you didn't want em or rem for spacing, I can see them also not being desired for border units.

From the linked thread, you mention there that units can only be a subset of spacing.units.

This means that what you pass as units can only be a subset of spacing.units

I'm also fine with a desire to simplify the handling and config of units. If the extra flexibility of different border units isn't worth the cost, I'll change this PR accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After some further testing, the borders behave ok with all units. I also found I'd missed the global styles' border panel units.

Given that, I've taken the opportunity to switch everything to use spacing.units while updating the global styles panel.

} );
const unit = getAllUnit( values );
const unitConfig = units.find( ( item ) => item.value === unit );
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
const step = unitConfig?.step || 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.components-border-style-control {
legend {
line-height: 1.2;
padding-bottom: $grid-unit-05;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/border-width.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const BorderWidthEdit = ( props ) => {
};

const units = useCustomUnits( {
availableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],
availableUnits: useSetting( 'border.units' ) || [ 'px', 'em', 'rem' ],
} );

return (
Expand Down