Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom color palette: add default color name #36940

Merged
merged 1 commit into from Dec 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/components/src/palette-edit/index.js
Expand Up @@ -7,7 +7,7 @@ import { kebabCase } from 'lodash';
* WordPress dependencies
*/
import { useState, useRef, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { lineSolid, moreVertical, plus } from '@wordpress/icons';
import { __experimentalUseFocusOutside as useFocusOutside } from '@wordpress/compose';

Expand Down Expand Up @@ -64,6 +64,7 @@ function Option( {
} ) {
const focusOutsideProps = useFocusOutside( onStopEditing );
const value = isGradient ? element.gradient : element.color;

return (
<PaletteItem
as="div"
Expand Down Expand Up @@ -240,8 +241,8 @@ export default function PaletteEdit( {
editingElement &&
elements[ editingElement ] &&
! elements[ editingElement ].slug;

const hasElements = elements.length > 0;
const elementsLength = elements.length;
const hasElements = elementsLength > 0;

return (
<PaletteEditStyles>
Expand Down Expand Up @@ -270,13 +271,18 @@ export default function PaletteEdit( {
: __( 'Add color' )
}
onClick={ () => {
const tempOptionName = sprintf(
/* translators: %s: is a temporary id for a custom color */
ramonjd marked this conversation as resolved.
Show resolved Hide resolved
__( 'Color %s ' ),
ramonjd marked this conversation as resolved.
Show resolved Hide resolved
elementsLength + 1
);
onChange( [
...elements,
{
...( isGradient
? { gradient: DEFAULT_GRADIENT }
: { color: '#000' } ),
name: '',
name: tempOptionName,
slug: '',
},
] );
Expand Down