Skip to content

Commit

Permalink
Merge pull request #117 from bigbite/feature/border-radius-setting
Browse files Browse the repository at this point in the history
[#113] - Radius not an option
  • Loading branch information
g-elwell authored Feb 24, 2025
2 parents f47b1a5 + 56a9c5f commit 00fda62
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
70 changes: 63 additions & 7 deletions src/editor/components/StylesBorder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { set } from 'lodash';
import { __ } from '@wordpress/i18n';
import { useContext } from '@wordpress/element';
import { __experimentalBorderBoxControl as BorderBoxControl } from '@wordpress/components';
import {
Flex,
__experimentalBorderBoxControl as BorderBoxControl,
} from '@wordpress/components';
import { __experimentalBorderRadiusControl as BorderRadiusControl } from '@wordpress/block-editor';

import getThemeOption from '../../utils/get-theme-option';
import EditorContext from '../context/EditorContext';
Expand All @@ -22,9 +26,48 @@ const Border = ( { selector } ) => {
themeConfig
);

/**
* General handler for border changes
*
* @param {Object} newValue - Updated border values
*/
const onChange = ( newValue ) => {
// If the value has a radius, we need to merge it with the new value
const valueRadius = value?.radius;
let updatedValue = newValue;
if ( valueRadius ) {
updatedValue = {
...newValue,
radius: valueRadius,
};
}

// Set the new value in the user config
let config = structuredClone( userConfig );
config = set( config, selector, updatedValue );
setUserConfig( config );
};

/**
* Specific handler for radius changes
*
* @param {Object} newValue - Updated radius values
*/
const onRadiusChange = ( newValue ) => {
/**
* If the updated value is an object, ensure a value is present for each radius point.
* If no value is present, set it to 0.
* This avoids display issues when a radius value is missing.
*/
if ( typeof newValue === 'object' ) {
newValue.topLeft = newValue.topLeft ?? 0;
newValue.topRight = newValue.topRight ?? 0;
newValue.bottomRight = newValue.bottomRight ?? 0;
newValue.bottomLeft = newValue.bottomLeft ?? 0;
}

let config = structuredClone( userConfig );
config = set( config, selector, newValue );
config = set( config, `${ selector }.radius`, newValue );
setUserConfig( config );
};

Expand All @@ -33,11 +76,24 @@ const Border = ( { selector } ) => {
<span className="themer--styles__item__title">
{ __( 'Border', 'themer' ) }
</span>
<BorderBoxControl
colors={ themePalette }
onChange={ onChange }
value={ value }
/>
<div className="themer--styles__item__columns themer--styles__item__columns--2">
<Flex direction="column" justify="flex-start">
<span className="themer--styles__item__label">
{ __( 'Border', 'themer' ) }
</span>
<BorderBoxControl
colors={ themePalette }
onChange={ onChange }
value={ value }
/>
</Flex>
<div>
<BorderRadiusControl
values={ value?.radius }
onChange={ ( newValue ) => onRadiusChange( newValue ) }
/>
</div>
</div>
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/editor/styles/components/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}

.themer--styles__item__label {
font-weight: 600;
font-weight: 500;
font-size: 11px;
line-height: 25.4px;
text-transform: uppercase;
Expand Down

0 comments on commit 00fda62

Please sign in to comment.