diff --git a/packages/block-editor/src/components/color-palette/test/__snapshots__/control.js.snap b/packages/block-editor/src/components/color-palette/test/__snapshots__/control.js.snap index edfd553100317..6052c2ad71567 100644 --- a/packages/block-editor/src/components/color-palette/test/__snapshots__/control.js.snap +++ b/packages/block-editor/src/components/color-palette/test/__snapshots__/control.js.snap @@ -32,13 +32,38 @@ exports[`ColorPaletteControl matches the snapshot 1`] = ` } .emotion-4>*+*:not( marquee ) { - margin-top: calc(4px * 2); + margin-top: calc(4px * 1); } .emotion-4>* { min-height: 0; } +.emotion-6 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: normal; + -webkit-box-align: normal; + -ms-flex-align: normal; + align-items: normal; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + justify-content: space-between; +} + +.emotion-6>*+*:not( marquee ) { + margin-top: calc(4px * 3); +} + +.emotion-6>* { + min-height: 0; +} +
@@ -59,89 +84,89 @@ exports[`ColorPaletteControl matches the snapshot 1`] = ` className="components-base-control__label" > Test Color -
+ +
+
-
-
-
-
diff --git a/packages/block-editor/src/components/colors-gradients/control.js b/packages/block-editor/src/components/colors-gradients/control.js index 8ec461342d093..534c9e3113f3f 100644 --- a/packages/block-editor/src/components/colors-gradients/control.js +++ b/packages/block-editor/src/components/colors-gradients/control.js @@ -13,25 +13,16 @@ import { __experimentalVStack as VStack, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, - ColorIndicator, ColorPalette, GradientPicker, } from '@wordpress/components'; -import { sprintf, __ } from '@wordpress/i18n'; +import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import { getColorObjectByColorValue } from '../colors'; -import { __experimentalGetGradientObjectByGradientValue } from '../gradients'; import useSetting from '../use-setting'; -// translators: first %s: the color name or value (e.g. red or #ff0000) -const colorIndicatorAriaLabel = __( '(Color: %s)' ); - -// translators: first %s: the gradient name or value (e.g. red to green or linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%) -const gradientIndicatorAriaLabel = __( '(Gradient: %s)' ); - const colorsAndGradientKeys = [ 'colors', 'disableCustomColors', @@ -39,45 +30,6 @@ const colorsAndGradientKeys = [ 'disableCustomGradients', ]; -function VisualLabel( { - colors, - gradients, - label, - currentTab, - colorValue, - gradientValue, -} ) { - let value, ariaLabel; - if ( currentTab === 'color' ) { - if ( colorValue ) { - value = colorValue; - const colorObject = getColorObjectByColorValue( colors, value ); - const colorName = colorObject && colorObject.name; - ariaLabel = sprintf( colorIndicatorAriaLabel, colorName || value ); - } - } else if ( currentTab === 'gradient' && gradientValue ) { - value = gradientValue; - const gradientObject = __experimentalGetGradientObjectByGradientValue( - gradients, - value - ); - const gradientName = gradientObject && gradientObject.name; - ariaLabel = sprintf( - gradientIndicatorAriaLabel, - gradientName || value - ); - } - - return ( - <> - { label } - { !! value && ( - - ) } - - ); -} - function ColorGradientControlInner( { colors, gradients, @@ -90,6 +42,7 @@ function ColorGradientControlInner( { colorValue, gradientValue, clearable, + showTitle = true, } ) { const canChooseAColor = onColorChange && ( ! isEmpty( colors ) || ! disableCustomColors ); @@ -111,19 +64,16 @@ function ColorGradientControlInner( { ) } >
- - -
- - - -
-
+ + { showTitle && ( + +
+ + { label } + +
+
+ ) } { canChooseAColor && canChooseAGradient && ( { settings.map( ( setting, index ) => ( ( element ) => { - return ( - element.type === 'button' && - element.children[ 0 ] === text && - element.children.length === 1 - ); -}; - const getButtonWithAriaLabelStartPredicate = ( ariaLabelStart ) => ( element ) => { @@ -76,9 +68,6 @@ describe( 'ColorPaletteControl', () => { // Is showing the two predefined Colors. expect( screen.getAllByLabelText( /^Color:/ ) ).toHaveLength( 2 ); - - // Is showing the custom color picker. - expect( screen.queryByText( 'Custom color' ) ).toBeInTheDocument(); } ); it( 'renders the color picker and does not render tabs if it is only possible to select a color', async () => { @@ -116,11 +105,6 @@ describe( 'ColorPaletteControl', () => { getButtonWithAriaLabelStartPredicate( 'Color:' ) ) ).toHaveLength( 2 ); - - // Is showing the custom color picker. - expect( - wrapper.root.findAll( getButtonWithTestPredicate( 'Custom color' ) ) - ).toHaveLength( 1 ); } ); it( 'renders the gradient picker and does not render tabs if it is only possible to select a gradient', async () => { diff --git a/packages/components/src/color-palette/index.js b/packages/components/src/color-palette/index.js index c3e503edd58dd..098d8c979171e 100644 --- a/packages/components/src/color-palette/index.js +++ b/packages/components/src/color-palette/index.js @@ -15,8 +15,10 @@ import { useCallback, useMemo } from '@wordpress/element'; /** * Internal dependencies */ +import Dropdown from '../dropdown'; import { ColorPicker } from '../color-picker'; import CircularOptionPicker from '../circular-option-picker'; +import { VStack } from '../v-stack'; extend( [ namesPlugin, a11yPlugin ] ); @@ -76,33 +78,37 @@ export default function ColorPalette( { ); return ( - - { ! disableCustomColors && ( - + + { ! disableCustomColors && ( + ( + ) } - { !! clearable && ( + /> + ) } + { __( 'Clear' ) } - ) } - - } - /> + ) + } + /> + ); } diff --git a/packages/components/src/color-palette/style.scss b/packages/components/src/color-palette/style.scss new file mode 100644 index 0000000000000..e245457754132 --- /dev/null +++ b/packages/components/src/color-palette/style.scss @@ -0,0 +1,18 @@ +.components-color-palette__custom-color { + border: none; + background: none; + outline: 0; + display: block; + border-radius: $radius-block-ui; + height: $grid-unit-60; + text-align: right; + width: 100%; + background-image: + repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200), + repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200); + background-position: 0 0, 25px 25px; + background-size: calc(2 * 25px) calc(2 * 25px); + box-sizing: border-box; + color: $white; + cursor: pointer; +} diff --git a/packages/components/src/color-palette/test/__snapshots__/index.js.snap b/packages/components/src/color-palette/test/__snapshots__/index.js.snap index fa0b4d2f0f7cd..e131b8cf5802a 100644 --- a/packages/components/src/color-palette/test/__snapshots__/index.js.snap +++ b/packages/components/src/color-palette/test/__snapshots__/index.js.snap @@ -16,160 +16,61 @@ exports[`ColorPalette Dropdown .renderContent should render dropdown content 1`] `; exports[`ColorPalette Dropdown .renderToggle should render dropdown content 1`] = ` - - - + `; exports[`ColorPalette Dropdown should render it correctly 1`] = `
- - - + #f00 +
`; exports[`ColorPalette should allow disabling custom color picker 1`] = ` - + + Clear - - } - options={ - Array [ - +`; + +exports[`ColorPalette should render a dynamic toolbar of colors 1`] = ` +.emotion-0 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; +} + +.emotion-1 { + -webkit-align-items: normal; + -webkit-box-align: normal; + -ms-flex-align: normal; + align-items: normal; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + justify-content: space-between; +} + +.emotion-2>*+*:not( marquee ) { + margin-top: calc(4px * 3); +} + +.emotion-3>* { + min-height: 0; +} + +.emotion-4 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: normal; + -webkit-box-align: normal; + -ms-flex-align: normal; + align-items: normal; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + justify-content: space-between; +} + +.emotion-4>*+*:not( marquee ) { + margin-top: calc(4px * 3); +} + +.emotion-4>* { + min-height: 0; +} + + + -
-
- - - +
- - -
- - +
+ + +
+ +
- - - + + +
- - - - - - - + +
- -
+ +
`; diff --git a/packages/components/src/style.scss b/packages/components/src/style.scss index 01231952a2cc0..e5bf92c27e845 100644 --- a/packages/components/src/style.scss +++ b/packages/components/src/style.scss @@ -8,6 +8,7 @@ @import "./color-indicator/style.scss"; @import "./combobox-control/style.scss"; @import "./color-list-picker/style.scss"; +@import "./color-palette/style.scss"; @import "./custom-gradient-picker/style.scss"; @import "./custom-select-control/style.scss"; @import "./date-time/style.scss"; diff --git a/packages/e2e-tests/specs/editor/blocks/heading.test.js b/packages/e2e-tests/specs/editor/blocks/heading.test.js index 02781002dcd5c..bdb2b625380ed 100644 --- a/packages/e2e-tests/specs/editor/blocks/heading.test.js +++ b/packages/e2e-tests/specs/editor/blocks/heading.test.js @@ -9,8 +9,7 @@ import { } from '@wordpress/e2e-test-utils'; describe( 'Heading', () => { - const CUSTOM_COLOR_TEXT = 'Custom color'; - const CUSTOM_COLOR_BUTTON_X_SELECTOR = `//button[contains(text(),'${ CUSTOM_COLOR_TEXT }')]`; + const CUSTOM_COLOR_BUTTON_X_SELECTOR = `.components-color-palette__custom-color`; const CUSTOM_COLOR_DETAILS_BUTTON_SELECTOR = '.components-color-picker button[aria-label="Show detailed inputs"]'; const COLOR_INPUT_FIELD_SELECTOR = @@ -77,7 +76,7 @@ describe( 'Heading', () => { ); await colorPanelToggle.click(); - const customTextColorButton = await page.waitForXPath( + const customTextColorButton = await page.waitForSelector( CUSTOM_COLOR_BUTTON_X_SELECTOR ); @@ -88,9 +87,7 @@ describe( 'Heading', () => { await pressKeyWithModifier( 'primary', 'A' ); await page.keyboard.type( '7700ff' ); await page.click( 'h3[data-type="core/heading"]' ); - await page.waitForSelector( - '.component-color-indicator[aria-label="(Color: #7700ff)"]' - ); + await page.waitForXPath( '//button[text()="#7700ff"]' ); expect( await getEditedPostContent() ).toMatchSnapshot(); } ); diff --git a/packages/e2e-tests/specs/editor/various/rich-text.test.js b/packages/e2e-tests/specs/editor/various/rich-text.test.js index 3e76fe5376f06..e56a5d3b34e00 100644 --- a/packages/e2e-tests/specs/editor/various/rich-text.test.js +++ b/packages/e2e-tests/specs/editor/various/rich-text.test.js @@ -397,6 +397,7 @@ describe( 'RichText', () => { await page.keyboard.press( 'Tab' ); // Select color other than black. await page.keyboard.press( 'Tab' ); + await page.keyboard.press( 'Tab' ); await page.keyboard.press( 'Enter' ); expect( await getEditedPostContent() ).toMatchSnapshot(); diff --git a/packages/edit-site/src/components/global-styles/style.scss b/packages/edit-site/src/components/global-styles/style.scss index ebaae4a24a990..e92d9a832f6ff 100644 --- a/packages/edit-site/src/components/global-styles/style.scss +++ b/packages/edit-site/src/components/global-styles/style.scss @@ -19,13 +19,18 @@ margin: $grid-unit-20; .component-color-indicator { + margin-left: 0; display: block; border-radius: 50%; border: 0; height: 24px; width: 24px; - margin-left: 0; padding: 0; + background-image: + repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200), + repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200); + background-position: 0 0, 25px 25px; + background-size: calc(2 * 5px) calc(2 * 5px); } }