Skip to content

Commit

Permalink
Leverage useColorsPerOrigin hook
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Mar 16, 2022
1 parent 50d00a2 commit c8da70d
Showing 1 changed file with 8 additions and 50 deletions.
58 changes: 8 additions & 50 deletions packages/edit-site/src/components/global-styles/border-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import {
__experimentalUnitControl as UnitControl,
__experimentalUseCustomUnits as useCustomUnits,
} from '@wordpress/components';
import { useMemo } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { getSupportedGlobalStylesPanels, useSetting, useStyle } from './hooks';
import {
getSupportedGlobalStylesPanels,
useColorsPerOrigin,
useSetting,
useStyle,
} from './hooks';

const MIN_BORDER_WIDTH = 0;

Expand Down Expand Up @@ -65,52 +69,6 @@ function useHasBorderWidthControl( name ) {
);
}

function useMultiOriginColors( name ) {
const [ customColors ] = useSetting( 'color.palette.custom', name );
const [ themeColors ] = useSetting( 'color.palette.theme', name );
const [ defaultColors ] = useSetting( 'color.palette.default', name );
const [ defaultPaletteEnabled ] = useSetting(
'color.defaultPalette',
name
);

return useMemo( () => {
const result = [];

if ( themeColors && themeColors.length ) {
result.push( {
name: _x(
'Theme',
'Indicates this palette comes from the theme.'
),
colors: themeColors,
} );
}

if ( defaultPaletteEnabled && defaultColors && defaultColors.length ) {
result.push( {
name: _x(
'Default',
'Indicates this palette comes from WordPress.'
),
colors: defaultColors,
} );
}

if ( customColors && customColors.length ) {
result.push( {
name: _x(
'Custom',
'Indicates this palette comes from the theme.'
),
colors: customColors,
} );
}

return result;
}, [ customColors, defaultColors, defaultPaletteEnabled, themeColors ] );
}

export default function BorderPanel( { name } ) {
// To better reflect if the user has customized a value we need to
// ensure the style value being checked is from the `user` origin.
Expand Down Expand Up @@ -162,7 +120,7 @@ export default function BorderPanel( { name } ) {
const borderColorSettings = [
{
label: __( 'Color' ),
colors: useMultiOriginColors(),
colors: useColorsPerOrigin( name ),
colorValue: borderColor,
onColorChange: handleOnChangeWithStyle( setBorderColor ),
clearable: false,
Expand Down

0 comments on commit c8da70d

Please sign in to comment.