{ hoveredStyle && ! isMobileViewport && (
diff --git a/packages/block-editor/src/components/block-styles/style.scss b/packages/block-editor/src/components/block-styles/style.scss
index 01ed5a4a3f1f08..b6ef2c8bfe8406 100644
--- a/packages/block-editor/src/components/block-styles/style.scss
+++ b/packages/block-editor/src/components/block-styles/style.scss
@@ -20,6 +20,51 @@
box-shadow: inset 0 0 0 $border-width $gray-300;
width: 100%;
}
+.block-editor-block-styles__variants {
+ display: grid;
+ gap: $grid-unit-10;
+ grid-template-columns: repeat(3, 1fr);
+ // Sidebar width minus sidebar and popover padding.
+ width: $sidebar-width - ($grid-unit-20 * 2) - ($grid-unit-10 * 2);
+
+ .block-editor-block-styles__item {
+ color: $gray-900;
+ box-shadow: inset 0 0 0 $border-width $gray-300;
+ display: inline-block;
+ // width: calc(50% - #{$grid-unit-05});
+
+ &:hover {
+ color: var(--wp-admin-theme-color);
+ box-shadow: inset 0 0 0 $border-width $gray-300;
+ }
+
+ &.is-active,
+ &.is-active:hover {
+ background-color: $gray-900;
+ box-shadow: none;
+ }
+
+ &.is-active .block-editor-block-styles__item-text,
+ &.is-active:hover .block-editor-block-styles__item-text {
+ color: $white;
+ }
+
+ &:focus,
+ &.is-active:focus {
+ @include block-toolbar-button-style__focus();
+ }
+ }
+}
+
+.block-editor-block-styles__item-text {
+ word-break: break-all;
+ // The Button component is white-space: nowrap, and that won't work with line-clamp.
+ white-space: normal;
+
+ // Without this, the ellipsis can sometimes be partially hidden by the Button padding.
+ text-align: start;
+ text-align-last: center;
+}
// To prevent overflow in the preview container,
// ensure that block contents' margin and padding
From 6e84280f2654151b2f694e74b563ff640a73caa2 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Thu, 29 Feb 2024 15:24:14 +1000
Subject: [PATCH 13/15] Revert "Try color cards in a dropdown"
This reverts commit fa360c30a9057eae6a208a4b6646d389baceeeb1.
---
.../block-styles/block-styles-dropdown.js | 139 ++++++------------
.../src/components/block-styles/index.js | 2 +-
.../src/components/block-styles/style.scss | 45 ------
3 files changed, 44 insertions(+), 142 deletions(-)
diff --git a/packages/block-editor/src/components/block-styles/block-styles-dropdown.js b/packages/block-editor/src/components/block-styles/block-styles-dropdown.js
index 83c54b213a211d..90b4038ee8a7d2 100644
--- a/packages/block-editor/src/components/block-styles/block-styles-dropdown.js
+++ b/packages/block-editor/src/components/block-styles/block-styles-dropdown.js
@@ -12,76 +12,37 @@ import {
Dropdown,
Flex,
FlexItem,
+ Icon,
+ MenuGroup,
+ MenuItem,
__experimentalHStack as HStack,
- __experimentalTruncate as Truncate,
__experimentalZStack as ZStack,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
+import { check } from '@wordpress/icons';
+const checkIcon =
;
const noop = () => undefined;
-function BlockStyleColorCard( { blockStyle } ) {
- const textColor = blockStyle?.styles?.color?.text;
- const linkColor = blockStyle?.styles?.elements?.link?.color?.text;
+function BlockStyleColorIndicator( { blockStyle } ) {
+ const { background, gradient, text } = blockStyle?.styles?.color || {};
+ const label = blockStyle?.label || blockStyle?.name;
return (
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+ { label }
);
}
-function BlockStyleButton( {
- handlePreview,
- isSelected,
- onClick,
- blockStyle,
-} ) {
- // If the block style variation does not contain color values,
- // render a textual label to cover styles such as the Button's
- // Outline, or Image's Rounded, block styles.
- const { label, name } = blockStyle;
- const { background, gradient, text } = blockStyle.styles?.color || {};
- const hasColors = background || gradient || text;
- const styles = {
- background: gradient,
- backgroundColor: gradient ? undefined : background,
- };
-
- return (
-
- );
-}
-
function BlockStylesDropdownToggle( { onToggle, isOpen, blockStyle } ) {
const toggleProps = {
onClick: onToggle,
@@ -92,58 +53,44 @@ function BlockStylesDropdownToggle( { onToggle, isOpen, blockStyle } ) {
'aria-label': __( 'Block style options' ),
};
- const { background, gradient, text } = blockStyle?.styles?.color || {};
- const linkColor = blockStyle?.styles?.elements?.link?.color?.text;
- const label = blockStyle?.label || blockStyle?.name;
- const hasColors = gradient || background || text || linkColor;
-
return (
);
}
function BlockStylesDropdownContent( {
activeStyle,
- blockStyles,
handlePreview,
onSelect,
- ...props
+ styles,
} ) {
return (
-
- { blockStyles.map( ( style ) => {
+
+ { styles.map( ( style ) => {
+ const isSelected = activeStyle?.name === style.name;
+
return (
-
+ onBlur={ () => handlePreview( null ) }
+ onClick={ () => onSelect( style ) }
+ onFocus={ () => handlePreview( style ) }
+ onMouseEnter={ () => handlePreview( style ) }
+ onMouseLeave={ () => handlePreview( null ) }
+ role="menuitemradio"
+ suffix={ isSelected ? checkIcon : undefined }
+ >
+
+
);
} ) }
-
+
);
}
@@ -151,11 +98,11 @@ export default function BlockStylesDropdown( {
className,
handlePreview = noop,
onSelect = noop,
- blockStyles,
+ styles,
value,
...props
} ) {
- if ( ! blockStyles?.length ) {
+ if ( ! styles?.length ) {
return null;
}
@@ -179,9 +126,9 @@ export default function BlockStylesDropdown( {
) }
/>
diff --git a/packages/block-editor/src/components/block-styles/index.js b/packages/block-editor/src/components/block-styles/index.js
index ee1064dc43d845..0a986091e742a6 100644
--- a/packages/block-editor/src/components/block-styles/index.js
+++ b/packages/block-editor/src/components/block-styles/index.js
@@ -54,9 +54,9 @@ function BlockStyles( { clientId, onSwitch = noop, onHoverClassName = noop } ) {
return (
{ hoveredStyle && ! isMobileViewport && (
diff --git a/packages/block-editor/src/components/block-styles/style.scss b/packages/block-editor/src/components/block-styles/style.scss
index b6ef2c8bfe8406..01ed5a4a3f1f08 100644
--- a/packages/block-editor/src/components/block-styles/style.scss
+++ b/packages/block-editor/src/components/block-styles/style.scss
@@ -20,51 +20,6 @@
box-shadow: inset 0 0 0 $border-width $gray-300;
width: 100%;
}
-.block-editor-block-styles__variants {
- display: grid;
- gap: $grid-unit-10;
- grid-template-columns: repeat(3, 1fr);
- // Sidebar width minus sidebar and popover padding.
- width: $sidebar-width - ($grid-unit-20 * 2) - ($grid-unit-10 * 2);
-
- .block-editor-block-styles__item {
- color: $gray-900;
- box-shadow: inset 0 0 0 $border-width $gray-300;
- display: inline-block;
- // width: calc(50% - #{$grid-unit-05});
-
- &:hover {
- color: var(--wp-admin-theme-color);
- box-shadow: inset 0 0 0 $border-width $gray-300;
- }
-
- &.is-active,
- &.is-active:hover {
- background-color: $gray-900;
- box-shadow: none;
- }
-
- &.is-active .block-editor-block-styles__item-text,
- &.is-active:hover .block-editor-block-styles__item-text {
- color: $white;
- }
-
- &:focus,
- &.is-active:focus {
- @include block-toolbar-button-style__focus();
- }
- }
-}
-
-.block-editor-block-styles__item-text {
- word-break: break-all;
- // The Button component is white-space: nowrap, and that won't work with line-clamp.
- white-space: normal;
-
- // Without this, the ellipsis can sometimes be partially hidden by the Button padding.
- text-align: start;
- text-align-last: center;
-}
// To prevent overflow in the preview container,
// ensure that block contents' margin and padding
From 26d3afa8482fe5efdaea258322e79286d9e92ba0 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Thu, 29 Feb 2024 16:41:54 +1000
Subject: [PATCH 14/15] Try Dropdown with stack of items including color cards
---
.../block-styles/block-styles-dropdown.js | 45 +++++++++++++------
.../src/components/block-styles/style.scss | 12 +++++
2 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/packages/block-editor/src/components/block-styles/block-styles-dropdown.js b/packages/block-editor/src/components/block-styles/block-styles-dropdown.js
index 90b4038ee8a7d2..044e39f1c8169b 100644
--- a/packages/block-editor/src/components/block-styles/block-styles-dropdown.js
+++ b/packages/block-editor/src/components/block-styles/block-styles-dropdown.js
@@ -16,7 +16,6 @@ import {
MenuGroup,
MenuItem,
__experimentalHStack as HStack,
- __experimentalZStack as ZStack,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { check } from '@wordpress/icons';
@@ -24,20 +23,39 @@ import { check } from '@wordpress/icons';
const checkIcon = ;
const noop = () => undefined;
-function BlockStyleColorIndicator( { blockStyle } ) {
- const { background, gradient, text } = blockStyle?.styles?.color || {};
+function BlockStyleColorCard( { blockStyle } ) {
+ const { background, gradient, text } = blockStyle.styles?.color || {};
+ const linkColor = blockStyle?.styles?.elements?.link?.color?.text;
+ const styles = {
+ background: gradient,
+ backgroundColor: gradient ? undefined : background,
+ };
+
+ return (
+
+
+
+
+
+
+
+
+ );
+}
+
+function BlockStyleItem( { blockStyle } ) {
const label = blockStyle?.label || blockStyle?.name;
return (
-
-
-
-
-
-
-
-
+
{ label }
);
@@ -55,7 +73,7 @@ function BlockStylesDropdownToggle( { onToggle, isOpen, blockStyle } ) {
return (
);
}
@@ -85,8 +103,9 @@ function BlockStylesDropdownContent( {
onMouseLeave={ () => handlePreview( null ) }
role="menuitemradio"
suffix={ isSelected ? checkIcon : undefined }
+ __next40pxDefaultSize
>
-
+
);
} ) }
diff --git a/packages/block-editor/src/components/block-styles/style.scss b/packages/block-editor/src/components/block-styles/style.scss
index 01ed5a4a3f1f08..1d948e0d3c9d03 100644
--- a/packages/block-editor/src/components/block-styles/style.scss
+++ b/packages/block-editor/src/components/block-styles/style.scss
@@ -20,6 +20,18 @@
box-shadow: inset 0 0 0 $border-width $gray-300;
width: 100%;
}
+.block-editor-block-styles__dropdown-group,
+.block-editor-block-styles__dropdown-toggle {
+ .block-editor-block-styles__color-card {
+ width: $grid-unit-80;
+ padding: $grid-unit-05 $grid-unit-10;
+ box-sizing: border-box;
+
+ &.no-background {
+ box-shadow: inset 0 0 0 $border-width $gray-300;
+ }
+ }
+}
// To prevent overflow in the preview container,
// ensure that block contents' margin and padding
From ad093163dfc4513e486e3e70e08c1cc3b99bea62 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Thu, 29 Feb 2024 17:00:31 +1000
Subject: [PATCH 15/15] Tweak styling of color card
---
.../block-styles/block-styles-dropdown.js | 17 ++++++++++-------
.../src/components/block-styles/style.scss | 10 ++++++++--
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/packages/block-editor/src/components/block-styles/block-styles-dropdown.js b/packages/block-editor/src/components/block-styles/block-styles-dropdown.js
index 044e39f1c8169b..39503fbb5b5c02 100644
--- a/packages/block-editor/src/components/block-styles/block-styles-dropdown.js
+++ b/packages/block-editor/src/components/block-styles/block-styles-dropdown.js
@@ -38,13 +38,19 @@ function BlockStyleColorCard( { blockStyle } ) {
} ) }
justify="space-around"
style={ styles }
- spacing={ 2 }
+ spacing={ 1 }
>
-
+
-
+
);
@@ -85,10 +91,7 @@ function BlockStylesDropdownContent( {
styles,
} ) {
return (
-
+
{ styles.map( ( style ) => {
const isSelected = activeStyle?.name === style.name;
diff --git a/packages/block-editor/src/components/block-styles/style.scss b/packages/block-editor/src/components/block-styles/style.scss
index 1d948e0d3c9d03..d4dfc69fa768ff 100644
--- a/packages/block-editor/src/components/block-styles/style.scss
+++ b/packages/block-editor/src/components/block-styles/style.scss
@@ -20,12 +20,18 @@
box-shadow: inset 0 0 0 $border-width $gray-300;
width: 100%;
}
+.block-editor-block-styles__color-indicator {
+ width: $grid-unit-10;
+ height: $grid-unit-10;
+}
.block-editor-block-styles__dropdown-group,
.block-editor-block-styles__dropdown-toggle {
.block-editor-block-styles__color-card {
- width: $grid-unit-80;
- padding: $grid-unit-05 $grid-unit-10;
+ // Width is 2 x 8px indicators, 2 x 8px padding, 4px gap.
+ width: $grid-unit-40 + $grid-unit-05;
+ padding: $grid-unit-10;
box-sizing: border-box;
+ border-radius: $radius-block-ui;
&.no-background {
box-shadow: inset 0 0 0 $border-width $gray-300;