Skip to content

Commit 8a180e6

Browse files
committed
Creating a temporary name when we add a new color to the custom palette
1 parent a295829 commit 8a180e6

File tree

1 file changed

+10
-4
lines changed
  • packages/components/src/palette-edit

1 file changed

+10
-4
lines changed

packages/components/src/palette-edit/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { kebabCase } from 'lodash';
77
* WordPress dependencies
88
*/
99
import { useState, useRef, useEffect } from '@wordpress/element';
10-
import { __ } from '@wordpress/i18n';
10+
import { __, sprintf } from '@wordpress/i18n';
1111
import { lineSolid, moreVertical, plus } from '@wordpress/icons';
1212
import { __experimentalUseFocusOutside as useFocusOutside } from '@wordpress/compose';
1313

@@ -64,6 +64,7 @@ function Option( {
6464
} ) {
6565
const focusOutsideProps = useFocusOutside( onStopEditing );
6666
const value = isGradient ? element.gradient : element.color;
67+
6768
return (
6869
<PaletteItem
6970
as="div"
@@ -240,8 +241,8 @@ export default function PaletteEdit( {
240241
editingElement &&
241242
elements[ editingElement ] &&
242243
! elements[ editingElement ].slug;
243-
244-
const hasElements = elements.length > 0;
244+
const elementsLength = elements.length;
245+
const hasElements = elementsLength > 0;
245246

246247
return (
247248
<PaletteEditStyles>
@@ -270,13 +271,18 @@ export default function PaletteEdit( {
270271
: __( 'Add color' )
271272
}
272273
onClick={ () => {
274+
const tempOptionName = sprintf(
275+
/* translators: %s: is a temporary id for a custom color */
276+
__( 'Color %s ' ),
277+
elementsLength + 1
278+
);
273279
onChange( [
274280
...elements,
275281
{
276282
...( isGradient
277283
? { gradient: DEFAULT_GRADIENT }
278284
: { color: '#000' } ),
279-
name: '',
285+
name: tempOptionName,
280286
slug: '',
281287
},
282288
] );

0 commit comments

Comments
 (0)