diff --git a/packages/components/src/palette-edit/index.tsx b/packages/components/src/palette-edit/index.tsx index 0732f8015db562..3999b6bb9f7b24 100644 --- a/packages/components/src/palette-edit/index.tsx +++ b/packages/components/src/palette-edit/index.tsx @@ -40,6 +40,7 @@ import { DoneButton, RemoveButton, PaletteEditContents, + PaletteVariation, } from './styles'; import { NavigableMenu } from '../navigable-container'; import { DEFAULT_GRADIENT } from '../custom-gradient-picker/constants'; @@ -52,6 +53,8 @@ import type { OptionProps, PaletteEditListViewProps, PaletteEditProps, + PaletteEditColorVariation, + PaletteEditGradientVariation, PaletteElement, } from './types'; @@ -353,6 +356,10 @@ function PaletteEditListView< T extends PaletteElement >( { } const EMPTY_ARRAY: Color[] = []; +const EMPTY_VARIATIONS: ( + | PaletteEditColorVariation + | PaletteEditGradientVariation +)[] = []; /** * Allows editing a palette of colors or gradients. @@ -379,6 +386,8 @@ export function PaletteEdit( { colors = EMPTY_ARRAY, onChange, paletteLabel, + paletteIcon, + paletteVariations = EMPTY_VARIATIONS, paletteLabelHeadingLevel = 2, emptyMessage, canOnlyChangeValues, @@ -388,6 +397,10 @@ export function PaletteEdit( { }: PaletteEditProps ) { const isGradient = !! gradients; const elements = isGradient ? gradients : colors; + const variations = paletteVariations.map( ( variation ) => ( { + ...variation, + elements: isGradient ? variation.gradients : variation.colors, + } ) ); const [ isEditing, setIsEditing ] = useState( false ); const [ editingElement, setEditingElement ] = useState< number | null | undefined @@ -399,6 +412,12 @@ export function PaletteEdit( { ! elements[ editingElement ].slug; const elementsLength = elements.length; const hasElements = elementsLength > 0; + const hasVariations = variations.some( + ( variation ) => variation.elements.length > 0 + ); + const hasAnyElements = hasElements || hasVariations; + const canResetAny = + canReset || variations.some( ( variation ) => variation.canReset ); const debounceOnChange = useDebounce( onChange, 100 ); const onSelectPaletteItem = useCallback( ( @@ -426,10 +445,11 @@ export function PaletteEdit( { + { paletteIcon } { paletteLabel } - { hasElements && isEditing && ( + { hasAnyElements && isEditing && ( { @@ -483,10 +503,10 @@ export function PaletteEdit( { /> ) } - { hasElements && + { hasAnyElements && ( ! isEditing || ! canOnlyChangeValues || - canReset ) && ( + canResetAny ) && ( ) } - { canReset && ( + { canResetAny && (