Skip to content

Commit

Permalink
Fix custom units for margin support (#31776)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw authored May 13, 2021
1 parent 60432f0 commit 8195c17
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion packages/block-editor/src/hooks/margin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,35 @@ import { SPACING_SUPPORT_KEY, useCustomSides } from './spacing';
import { cleanEmptyObject } from './utils';
import { useCustomUnits } from '../components/unit-control';

const isWeb = Platform.OS === 'web';
const CSS_UNITS = [
{
value: '%',
label: isWeb ? '%' : __( 'Percentage (%)' ),
default: '',
},
{
value: 'px',
label: isWeb ? 'px' : __( 'Pixels (px)' ),
default: '',
},
{
value: 'em',
label: isWeb ? 'em' : __( 'Relative to parent font size (em)' ),
default: '',
},
{
value: 'rem',
label: isWeb ? 'rem' : __( 'Relative to root font size (rem)' ),
default: '',
},
{
value: 'vw',
label: isWeb ? 'vw' : __( 'Viewport width (vw)' ),
default: '',
},
];

/**
* Determines if there is margin support.
*
Expand Down Expand Up @@ -49,7 +78,7 @@ export function MarginEdit( props ) {
setAttributes,
} = props;

const units = useCustomUnits();
const units = useCustomUnits( CSS_UNITS );
const sides = useCustomSides( blockName, 'margin' );

if ( useIsMarginDisabled( props ) ) {
Expand Down

0 comments on commit 8195c17

Please sign in to comment.