Skip to content

Commit

Permalink
Update: Global Styes: Count all color palette origins on the palette …
Browse files Browse the repository at this point in the history
…counter (#36922)
  • Loading branch information
jorgefilipecosta authored and noisysocks committed Nov 29, 2021
1 parent 186403d commit 8d9e4a8
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions packages/edit-site/src/components/global-styles/palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ColorIndicator,
} from '@wordpress/components';
import { __, _n, sprintf } from '@wordpress/i18n';
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -22,12 +23,29 @@ import { useSetting } from './hooks';
const EMPTY_COLORS = [];

function Palette( { name } ) {
const [ colorsSetting ] = useSetting( 'color.palette.custom', name );
const colors = colorsSetting || EMPTY_COLORS;
const [ customColors ] = useSetting( 'color.palette.custom' );
const [ themeColors ] = useSetting( 'color.palette.theme' );
const [ defaultColors ] = useSetting( 'color.palette.default' );

const [ defaultPaletteEnabled ] = useSetting(
'color.defaultPalette',
name
);
const colors = useMemo(
() => [
...( customColors || EMPTY_COLORS ),
...( themeColors || EMPTY_COLORS ),
...( defaultColors && defaultPaletteEnabled
? defaultColors
: EMPTY_COLORS ),
],
[ customColors, themeColors, defaultColors, defaultPaletteEnabled ]
);

const screenPath = ! name
? '/colors/palette'
: '/blocks/' + name + '/colors/palette';
const palleteButtonText =
const paletteButtonText =
colors.length > 0
? sprintf(
// Translators: %d: Number of palette colors.
Expand All @@ -52,7 +70,7 @@ function Palette( { name } ) {
) ) }
</ZStack>
</FlexBlock>
<FlexItem>{ palleteButtonText }</FlexItem>
<FlexItem>{ paletteButtonText }</FlexItem>
</HStack>
</NavigationButton>
</ItemGroup>
Expand Down

0 comments on commit 8d9e4a8

Please sign in to comment.