Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add border controls to global styles sidebar
  • Loading branch information
aaronrobertshaw committed Jan 20, 2021
commit 4eca9cb927e7d54ce3085b9d2a6fdc9c0dae939f
56 changes: 56 additions & 0 deletions packages/edit-site/src/components/sidebar/border-panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* WordPress dependencies
*/
import { PanelBody, RangeControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { useEditorFeature } from '../editor/utils';

const MIN_BORDER_RADIUS_VALUE = 0;
const MAX_BORDER_RADIUS_VALUE = 50;

export function useHasBorderPanel( { supports, name } ) {
// This function will allow for easy addition of future border properties
// e.g. Border width.
// return (
// useHasBorderRadiusControl( { supports, name } ) ||
// useHasBorderWidthControl( { supports, name } )
// )
return useHasBorderRadiusControl( { supports, name } );
}

function useHasBorderRadiusControl( { supports, name } ) {
return (
useEditorFeature( 'border.customRadius', name ) &&
supports.includes( 'borderRadius' )
);
}

export default function BorderPanel( {
context: { supports, name },
getStyle,
setStyle,
} ) {
const hasBorderRadius = useHasBorderRadiusControl( { supports, name } );

return (
<PanelBody title={ __( 'Border' ) } initialOpen={ true }>
{ hasBorderRadius && (
<RangeControl
value={ getStyle( name, 'borderRadius' ) }
label={ __( 'Border radius' ) }
min={ MIN_BORDER_RADIUS_VALUE }
max={ MAX_BORDER_RADIUS_VALUE }
initialPosition={ getStyle( name, 'borderRadius' ) || 0 }
allowReset
onChange={ ( value ) =>
setStyle( name, 'borderRadius', value )
}
/>
) }
</PanelBody>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
default as TypographyPanel,
useHasTypographyPanel,
} from './typography-panel';
import { default as BorderPanel, useHasBorderPanel } from './border-panel';
import { default as ColorPanel, useHasColorPanel } from './color-panel';
import { default as SpacingPanel, useHasSpacingPanel } from './spacing-panel';

Expand All @@ -38,6 +39,7 @@ function GlobalStylesPanel( {
const hasColorPanel = useHasColorPanel( context );
const hasTypographyPanel = useHasTypographyPanel( context );
const hasSpacingPanel = useHasSpacingPanel( context );
const hasBorderPanel = useHasBorderPanel( context );

if ( ! hasColorPanel && ! hasTypographyPanel && ! hasSpacingPanel ) {
return null;
Expand Down Expand Up @@ -68,6 +70,13 @@ function GlobalStylesPanel( {
setStyle={ setStyle }
/>
) }
{ hasBorderPanel && (
<BorderPanel
context={ context }
getStyle={ getStyle }
setStyle={ setStyle }
/>
) }
</>
);
if ( ! wrapperPanelTitle ) {
Expand Down