-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Spacing presets: add editor UI support #42173
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
Changes from 86 commits
f979215
f034f2f
b57577f
4e8381a
42615f5
2b9970e
ecb59b0
496dba1
332c3c2
39c4b0c
6409fda
e3b871b
0548311
281c76f
2ad0f96
5bc1046
6cdc706
e998877
7568aaa
71b7fb7
aca422e
b7b8f8d
7592079
448d56a
bc17c58
94e119d
14b7bb5
d3ab731
ae88165
9b496bd
bd60740
cdda2fc
4d900a6
b178c4b
bfd6598
a5bc925
8b78443
b041551
8ae9147
a7aa0d5
7992536
4c866ea
bebffd4
cbe9c5c
7f1cc8e
a31f3b8
b4f664c
563e4bf
5eee65c
a87050d
2b6cade
8f525ee
98118a8
9fbc3b0
87343dd
a4088ea
82c3c3c
2465154
73f96cd
9d390ed
cae7ee2
6ff2352
ca87605
b54163c
deaed6c
b7c53dc
cecbc7f
f11bc9a
bc07d84
038b1c2
f04dff6
7c55b8d
5c34101
cf9822d
bebd991
a71709d
3c64a0c
bce9da8
868f61e
ce380eb
d05bfbf
1abc3a5
aeedc1d
4397dfb
9b73207
1b1f299
68f60bf
cb11f83
884c77a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __experimentalApplyValueToSides as applyValueToSides } from '@wordpress/components'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import SpacingInputControl from './spacing-input-control'; | ||
| import { getAllRawValue, isValuesMixed, isValuesDefined } from './utils'; | ||
|
|
||
| export default function AllInputControl( { | ||
| onChange, | ||
| values, | ||
| sides, | ||
| spacingSizes, | ||
| type, | ||
| minimumCustomValue, | ||
| } ) { | ||
| const allValue = getAllRawValue( values ); | ||
| const hasValues = isValuesDefined( values ); | ||
| const isMixed = hasValues && isValuesMixed( values ); | ||
|
|
||
| const handleOnChange = ( next ) => { | ||
| const nextValues = applyValueToSides( values, next, sides ); | ||
| onChange( nextValues ); | ||
| }; | ||
|
|
||
| return ( | ||
| <SpacingInputControl | ||
| value={ allValue } | ||
| onChange={ handleOnChange } | ||
| side={ 'all' } | ||
| spacingSizes={ spacingSizes } | ||
| isMixed={ isMixed } | ||
| type={ type } | ||
| minimumCustomValue={ minimumCustomValue } | ||
| /> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import SpacingInputControl from './spacing-input-control'; | ||
| import { LABELS } from './utils'; | ||
|
|
||
| const groupedSides = [ 'vertical', 'horizontal' ]; | ||
|
|
||
| export default function AxialInputControls( { | ||
| onChange, | ||
| values, | ||
| sides, | ||
| spacingSizes, | ||
| type, | ||
| minimumCustomValue, | ||
| } ) { | ||
| const createHandleOnChange = ( side ) => ( next ) => { | ||
| if ( ! onChange ) { | ||
| return; | ||
| } | ||
| const nextValues = { ...values }; | ||
|
|
||
| if ( side === 'vertical' ) { | ||
| nextValues.top = next; | ||
| nextValues.bottom = next; | ||
| } | ||
|
|
||
| if ( side === 'horizontal' ) { | ||
| nextValues.left = next; | ||
| nextValues.right = next; | ||
| } | ||
|
|
||
| onChange( nextValues ); | ||
| }; | ||
|
|
||
| // Filter sides if custom configuration provided, maintaining default order. | ||
| const filteredSides = sides?.length | ||
| ? groupedSides.filter( ( side ) => sides.includes( side ) ) | ||
| : groupedSides; | ||
|
|
||
| return ( | ||
| <> | ||
| { filteredSides.map( ( side ) => { | ||
| const axisValue = | ||
| side === 'vertical' ? values.top : values.left; | ||
| return ( | ||
| <SpacingInputControl | ||
| value={ axisValue } | ||
| onChange={ createHandleOnChange( side ) } | ||
| label={ LABELS[ side ] } | ||
| key={ `spacing-sizes-control-${ side }` } | ||
| withInputField={ false } | ||
| side={ side } | ||
| spacingSizes={ spacingSizes } | ||
| type={ type } | ||
| minimumCustomValue={ minimumCustomValue } | ||
| /> | ||
| ); | ||
| } ) } | ||
| </> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||
| /** | ||||||
| * WordPress dependencies | ||||||
| */ | ||||||
| import { useState } from '@wordpress/element'; | ||||||
| import { __ } from '@wordpress/i18n'; | ||||||
| import { __experimentalText as Text } from '@wordpress/components'; | ||||||
|
|
||||||
| /** | ||||||
| * Internal dependencies | ||||||
| */ | ||||||
| import AllInputControl from './all-input-control'; | ||||||
| import InputControls from './input-controls'; | ||||||
| import AxialInputControls from './axial-input-controls'; | ||||||
| import LinkedButton from './linked-button'; | ||||||
| import { DEFAULT_VALUES, isValuesMixed, isValuesDefined } from './utils'; | ||||||
| import useSetting from '../use-setting'; | ||||||
|
|
||||||
| export default function SpacingSizesControl( { | ||||||
| inputProps, | ||||||
| onChange, | ||||||
| label = __( 'Spacing Control' ), | ||||||
| values, | ||||||
| sides, | ||||||
| splitOnAxis = false, | ||||||
| useSelect, | ||||||
| minimumCustomValue = 0, | ||||||
| } ) { | ||||||
| const spacingSizes = [ | ||||||
| { name: 0, slug: '0', size: 0 }, | ||||||
| ...useSetting( 'spacing.spacingSizes' ), | ||||||
|
||||||
| Block editor | Site editor |
|---|---|
![]() |
![]() |
(I noticed this because I forgot to update my theme.json file after testing out #43105 🙂)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch, let me think about that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason for this role="region"? It appears this conflicts with useNavigateRegions, especially in the Site Editor Will create a new issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't remember the reasoning, so do add a new issue thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Reported in #46509 together with other issues.
glendaviesnz marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import SpacingInputControl from './spacing-input-control'; | ||
| import { ALL_SIDES, LABELS } from './utils'; | ||
|
|
||
| export default function BoxInputControls( { | ||
| values, | ||
| sides, | ||
| onChange, | ||
| spacingSizes, | ||
| type, | ||
| minimumCustomValue, | ||
| } ) { | ||
| // Filter sides if custom configuration provided, maintaining default order. | ||
| const filteredSides = sides?.length | ||
| ? ALL_SIDES.filter( ( side ) => sides.includes( side ) ) | ||
| : ALL_SIDES; | ||
|
|
||
| const createHandleOnChange = ( side ) => ( next ) => { | ||
| const nextValues = { ...values }; | ||
| nextValues[ side ] = next; | ||
|
|
||
| onChange( nextValues ); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| { filteredSides.map( ( side ) => { | ||
| return ( | ||
| <SpacingInputControl | ||
| value={ values[ side ] } | ||
| label={ LABELS[ side ] } | ||
| key={ `spacing-sizes-control-${ side }` } | ||
| withInputField={ false } | ||
| side={ side } | ||
| onChange={ createHandleOnChange( side ) } | ||
| spacingSizes={ spacingSizes } | ||
| type={ type } | ||
| minimumCustomValue={ minimumCustomValue } | ||
| /> | ||
| ); | ||
| } ) } | ||
| </> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { link, linkOff } from '@wordpress/icons'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { Button, Tooltip } from '@wordpress/components'; | ||
|
|
||
| export default function LinkedButton( { isLinked, onClick } ) { | ||
| 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 } | ||
| aria-label={ label } | ||
| onClick={ onClick } | ||
| /> | ||
| </span> | ||
| </Tooltip> | ||
| ); | ||
| } |


Uh oh!
There was an error while loading. Please reload this page.