Skip to content

Commit

Permalink
Simplify by removing RangeControl.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Aug 27, 2024
1 parent cf4f2b2 commit 31ba0ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import {
__experimentalItemGroup as ItemGroup,
__experimentalInputControl as InputControl,
__experimentalUnitControl as UnitControl,
__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
__experimentalGrid as Grid,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
__experimentalUseNavigator as useNavigator,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalConfirmDialog as ConfirmDialog,
Dropdown,
RangeControl,
Button,
Flex,
FlexItem,
Expand All @@ -34,7 +33,6 @@ import {
plus,
shadow as shadowIcon,
reset,
settings,
moreVertical,
} from '@wordpress/icons';
import { useState, useMemo } from '@wordpress/element';
Expand All @@ -50,7 +48,6 @@ import {
getShadowParts,
shadowStringToObject,
shadowObjectToString,
CUSTOM_VALUE_SETTINGS,
} from './shadow-utils';

const { useGlobalSetting } = unlock( blockEditorPrivateApis );
Expand Down Expand Up @@ -449,8 +446,7 @@ function ShadowPopover( { shadowObj, onChange } ) {
label={ __( 'Inset' ) }
/>
</ToggleGroupControl>
<VStack gap={ 4 }>
>
<Grid columns={ 2 } gap={ 4 }>
<ShadowInputControl
label={ __( 'X Position' ) }
value={ shadowObj.x }
Expand All @@ -474,21 +470,12 @@ function ShadowPopover( { shadowObj, onChange } ) {
hasNegativeRange
onChange={ ( value ) => onShadowChange( 'spread', value ) }
/>
</VStack>
</Grid>
</VStack>
);
}

function ShadowInputControl( { label, value, onChange, hasNegativeRange } ) {
const [ isCustomInput, setIsCustomInput ] = useState( false );
const [ parsedQuantity, parsedUnit ] =
parseQuantityAndUnitFromRawValue( value );

const sliderOnChange = ( next ) => {
onChange(
next !== undefined ? [ next, parsedUnit || 'px' ].join( '' ) : '0px'
);
};
function ShadowInputControl( { label, value, onChange } ) {
const onValueChange = ( next ) => {
const isNumeric = next !== undefined && ! isNaN( parseFloat( next ) );
const nextValue = isNumeric ? next : '0px';
Expand All @@ -497,54 +484,13 @@ function ShadowInputControl( { label, value, onChange, hasNegativeRange } ) {

return (
<HStack align="flex-end">
{ isCustomInput ? (
<UnitControl
label={ label }
__next40pxDefaultSize
value={ value }
onChange={ onValueChange }
className="edit-site-global-styles__shadow-editor-control"
/>
) : (
<RangeControl
label={ label }
value={ parsedQuantity ?? 0 }
onChange={ sliderOnChange }
withInputField={ false }
__next40pxDefaultSize
__nextHasNoMarginBottom
min={
hasNegativeRange
? -(
CUSTOM_VALUE_SETTINGS[ parsedUnit ?? 'px' ]
?.max ?? 10
)
: 0
}
max={
CUSTOM_VALUE_SETTINGS[ parsedUnit ?? 'px' ]?.max ?? 10
}
step={
CUSTOM_VALUE_SETTINGS[ parsedUnit ?? 'px' ]?.step ?? 0.1
}
className="edit-site-global-styles__shadow-editor-control"
/>
) }
<Flex
expanded={ false }
align="center"
className="edit-site-global-styles__shadow-editor-control-toggle-wrapper"
>
<Button
label={ __( 'Use custom size' ) }
icon={ settings }
onClick={ () => {
setIsCustomInput( ! isCustomInput );
} }
isPressed={ isCustomInput }
size="small"
/>
</Flex>
<UnitControl
label={ label }
__next40pxDefaultSize
value={ value }
onChange={ onValueChange }
className="edit-site-global-styles__shadow-editor-control"
/>
</HStack>
);
}
9 changes: 0 additions & 9 deletions packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,6 @@
.edit-site-global-styles__shadow-editor-panel {
// because tooltip of the range control is too close to the edge and creates overflow
margin-bottom: $grid-unit-05;

.edit-site-global-styles__shadow-editor-control {
flex-grow: 1;
}

.edit-site-global-styles__shadow-editor-control-toggle-wrapper {
// Make the button wrapper height the same as the adjacent input height.
height: $button-size-next-default-40px;
}
}

.edit-site-global-styles__shadow-editor__dropdown {
Expand Down

0 comments on commit 31ba0ff

Please sign in to comment.