Skip to content

Commit

Permalink
Introduce local ColorIndicatorWithSpacer component, refactor `Color…
Browse files Browse the repository at this point in the history
…Indicator` usages
  • Loading branch information
ciampo committed Apr 5, 2022
1 parent 3ad77e4 commit 27887aa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* WordPress dependencies
*/
import {
ColorIndicator,
__experimentalSpacer as Spacer,
} from '@wordpress/components';

// Compensate for the fact that `ColorIndicator` has a height of 20px,
// while all other icons have a height of 24px.
function ColorIndicatorWithSpacer( colorIndicatorProps ) {
return (
<Spacer
paddingY={ 0.5 }
marginBottom={ 0 }
// Necessary to avoid extra vertical white space, since `ColorIndicator`
// is a `display: inline-block` component.
style={ { fontSize: 0 } }
>
<ColorIndicator { ...colorIndicatorProps } />
</Spacer>
);
}

export default ColorIndicatorWithSpacer;
5 changes: 2 additions & 3 deletions packages/edit-site/src/components/global-styles/palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
__experimentalHStack as HStack,
__experimentalZStack as ZStack,
__experimentalVStack as VStack,
ColorIndicator,
} from '@wordpress/components';
import { __, _n, sprintf } from '@wordpress/i18n';
import { useMemo } from '@wordpress/element';
Expand All @@ -18,6 +17,7 @@ import { useMemo } from '@wordpress/element';
import Subtitle from './subtitle';
import { NavigationButton } from './navigation-button';
import { useSetting } from './hooks';
import ColorIndicatorWithSpacer from './color-indicator-spacer';

const EMPTY_COLORS = [];

Expand Down Expand Up @@ -65,10 +65,9 @@ function Palette( { name } ) {
>
<ZStack isLayered={ false } offset={ -8 }>
{ colors.slice( 0, 5 ).map( ( { color } ) => (
<ColorIndicator
<ColorIndicatorWithSpacer
key={ color }
colorValue={ color }
className="edit-site-global-styles__color-indicator-with-margin"
/>
) ) }
</ZStack>
Expand Down
15 changes: 4 additions & 11 deletions packages/edit-site/src/components/global-styles/screen-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
__experimentalHStack as HStack,
__experimentalVStack as VStack,
FlexItem,
ColorIndicator,
} from '@wordpress/components';

/**
Expand All @@ -18,6 +17,7 @@ import Palette from './palette';
import { NavigationButton } from './navigation-button';
import { getSupportedGlobalStylesPanels, useStyle } from './hooks';
import Subtitle from './subtitle';
import ColorIndicatorWithSpacer from './color-indicator-spacer';

function BackgroundColorItem( { name, parentMenu } ) {
const supports = getSupportedGlobalStylesPanels( name );
Expand All @@ -34,9 +34,8 @@ function BackgroundColorItem( { name, parentMenu } ) {
return (
<NavigationButton path={ parentMenu + '/colors/background' }>
<HStack justify="flex-start">
<ColorIndicator
<ColorIndicatorWithSpacer
colorValue={ gradientValue ?? backgroundColor }
className="edit-site-global-styles__color-indicator-with-margin"
/>
<FlexItem>{ __( 'Background' ) }</FlexItem>
</HStack>
Expand All @@ -56,10 +55,7 @@ function TextColorItem( { name, parentMenu } ) {
return (
<NavigationButton path={ parentMenu + '/colors/text' }>
<HStack justify="flex-start">
<ColorIndicator
colorValue={ color }
className="edit-site-global-styles__color-indicator-with-margin"
/>
<ColorIndicatorWithSpacer colorValue={ color } />
<FlexItem>{ __( 'Text' ) }</FlexItem>
</HStack>
</NavigationButton>
Expand All @@ -78,10 +74,7 @@ function LinkColorItem( { name, parentMenu } ) {
return (
<NavigationButton path={ parentMenu + '/colors/link' }>
<HStack justify="flex-start">
<ColorIndicator
colorValue={ color }
className="edit-site-global-styles__color-indicator-with-margin"
/>
<ColorIndicatorWithSpacer colorValue={ color } />
<FlexItem>{ __( 'Links' ) }</FlexItem>
</HStack>
</NavigationButton>
Expand Down
7 changes: 0 additions & 7 deletions packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,3 @@
border: var(--wp-admin-theme-color) $border-width solid;
}
}

.edit-site-global-styles__color-indicator-with-margin {
// Add 4px to compensate for the fact that `ColorIndicator` has a height
// of 20px, while all other icons have a height of 24px.
margin-top: $grid-unit * 0.25;
margin-bottom: $grid-unit * 0.25;
}

0 comments on commit 27887aa

Please sign in to comment.