-
Notifications
You must be signed in to change notification settings - Fork 4.7k
BoxControl: update design
#56665
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
Merged
Merged
BoxControl: update design
#56665
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
910badb
Change to vertical formatting without width constraints
brookewp bdf1157
Add RangeControl to input controls
brookewp 5eb20cc
Only show Icon for AllInputControl
brookewp e3c63de
Add RangeControl to AllInputControl
brookewp 5dcef43
Clean up styles and match SpacingInputControl
brookewp 695bba7
Add changes to InputControls to AxialInputControls
brookewp c0a8d7f
Update styles based on design input
brookewp 6b78cf1
Fix issue where changing input didn’t affect rangecontrol
brookewp 94db809
Add labels to sliders
brookewp ac87f8e
Add unit tests for slider
brookewp c9ac4b5
Update changelog
brookewp 6076058
Update function name and add limitations to slider based on units
brookewp 11b46d6
Add right margin to prevent slider thumb from being cut off
brookewp 8fa41ab
Update slider’s initial position to check for a value
brookewp f1c9be2
Replace Tooltip with component
brookewp ec4985c
Use Grid for better semantics and a11y
brookewp a9ae993
Add id for slider aria labels
brookewp 2494cdb
Implement changes from PR feedback
brookewp 0a041fc
Adjust grid
brookewp 8dc9b1c
Update column sizing
brookewp a57f3e2
Fix value by using `allValue` again
brookewp b28c652
Refactor to remove duplicate onChange based on feedback
brookewp 7fbbe43
Fix mapped ids
brookewp 73b65eb
Update naming based on feedback
brookewp f2bdae4
Fix id and key
brookewp 7cdab78
Remove unused border radius logic
brookewp 187ae8a
Update margin to include RTL
brookewp 9121904
Remove unused hover functions for previously replaced visualizer
brookewp b5f546e
Replace custom UnitControl with standard
brookewp 6287be9
Fix all input label
brookewp 25cf3f6
Update naming in tests
brookewp 3f9ec19
Add mixed label and test
brookewp 178ff28
Restore Mixed placeholder
brookewp a780070
Remove unnecessary function
brookewp ced9711
Update naming
brookewp 6dc8d44
Add labels to slider
brookewp 505ac98
Fix label in test
brookewp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 54 additions & 34 deletions
88
packages/components/src/box-control/all-input-control.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,86 +1,106 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useInstanceId } from '@wordpress/compose'; | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import type { UnitControlProps } from '../unit-control/types'; | ||
| import { | ||
| FlexedRangeControl, | ||
| StyledUnitControl, | ||
| } from './styles/box-control-styles'; | ||
| import { HStack } from '../h-stack'; | ||
| import type { BoxControlInputControlProps } from './types'; | ||
| import UnitControl from './unit-control'; | ||
| import { parseQuantityAndUnitFromRawValue } from '../unit-control'; | ||
| import { | ||
| LABELS, | ||
| applyValueToSides, | ||
| getAllValue, | ||
| isValuesMixed, | ||
| isValuesDefined, | ||
| CUSTOM_VALUE_SETTINGS, | ||
| } from './utils'; | ||
|
|
||
| const noop = () => {}; | ||
|
|
||
| export default function AllInputControl( { | ||
| onChange = noop, | ||
| onFocus = noop, | ||
| onHoverOn = noop, | ||
| onHoverOff = noop, | ||
| values, | ||
| sides, | ||
| selectedUnits, | ||
| setSelectedUnits, | ||
| ...props | ||
| }: BoxControlInputControlProps ) { | ||
| const inputId = useInstanceId( AllInputControl, 'box-control-input-all' ); | ||
|
|
||
| const allValue = getAllValue( values, selectedUnits, sides ); | ||
| const hasValues = isValuesDefined( values ); | ||
| const isMixed = hasValues && isValuesMixed( values, selectedUnits, sides ); | ||
| const allPlaceholder = isMixed ? LABELS.mixed : undefined; | ||
|
|
||
| const [ parsedQuantity, parsedUnit ] = | ||
| parseQuantityAndUnitFromRawValue( allValue ); | ||
|
|
||
| const handleOnFocus: React.FocusEventHandler< HTMLInputElement > = ( | ||
| event | ||
| ) => { | ||
| onFocus( event, { side: 'all' } ); | ||
| }; | ||
|
|
||
| const handleOnChange: UnitControlProps[ 'onChange' ] = ( next ) => { | ||
| const onValueChange = ( next?: string ) => { | ||
| const isNumeric = next !== undefined && ! isNaN( parseFloat( next ) ); | ||
| const nextValue = isNumeric ? next : undefined; | ||
| const nextValues = applyValueToSides( values, nextValue, sides ); | ||
|
|
||
| onChange( nextValues ); | ||
| }; | ||
|
|
||
| const sliderOnChange = ( next?: number ) => { | ||
| onValueChange( | ||
| next !== undefined ? [ next, parsedUnit ].join( '' ) : undefined | ||
| ); | ||
| }; | ||
|
|
||
| // Set selected unit so it can be used as fallback by unlinked controls | ||
| // when individual sides do not have a value containing a unit. | ||
| const handleOnUnitChange: UnitControlProps[ 'onUnitChange' ] = ( unit ) => { | ||
| const newUnits = applyValueToSides( selectedUnits, unit, sides ); | ||
| setSelectedUnits( newUnits ); | ||
| }; | ||
|
|
||
| const handleOnHoverOn = () => { | ||
| onHoverOn( { | ||
| top: true, | ||
| bottom: true, | ||
| left: true, | ||
| right: true, | ||
| } ); | ||
| }; | ||
|
|
||
| const handleOnHoverOff = () => { | ||
| onHoverOff( { | ||
| top: false, | ||
| bottom: false, | ||
| left: false, | ||
| right: false, | ||
| } ); | ||
| }; | ||
|
|
||
| return ( | ||
| <UnitControl | ||
| { ...props } | ||
| disableUnits={ isMixed } | ||
| isOnly | ||
| value={ allValue } | ||
| onChange={ handleOnChange } | ||
| onUnitChange={ handleOnUnitChange } | ||
| onFocus={ handleOnFocus } | ||
| onHoverOn={ handleOnHoverOn } | ||
| onHoverOff={ handleOnHoverOff } | ||
| placeholder={ allPlaceholder } | ||
| /> | ||
| <HStack> | ||
| <StyledUnitControl | ||
| { ...props } | ||
| className="component-box-control__unit-control" | ||
| disableUnits={ isMixed } | ||
| id={ inputId } | ||
| isPressEnterToChange | ||
| value={ allValue } | ||
| onChange={ onValueChange } | ||
| onUnitChange={ handleOnUnitChange } | ||
| onFocus={ handleOnFocus } | ||
| placeholder={ allPlaceholder } | ||
| label={ LABELS.all } | ||
| hideLabelFromVision | ||
| /> | ||
|
|
||
| <FlexedRangeControl | ||
| __nextHasNoMarginBottom | ||
| aria-controls={ inputId } | ||
mirka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| label={ LABELS.all } | ||
| hideLabelFromVision | ||
| onChange={ sliderOnChange } | ||
| min={ 0 } | ||
| max={ CUSTOM_VALUE_SETTINGS[ parsedUnit ?? 'px' ]?.max ?? 10 } | ||
| step={ | ||
| CUSTOM_VALUE_SETTINGS[ parsedUnit ?? 'px' ]?.step ?? 0.1 | ||
| } | ||
| value={ parsedQuantity ?? 0 } | ||
| withInputField={ false } | ||
| /> | ||
| </HStack> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.