From cc6fcc45c59f111c04bff820db2e1cae578b760e Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Mon, 12 Sep 2022 17:51:05 +0200 Subject: [PATCH] started interface to edit caption colors in Global Styles --- .../global-styles/screen-caption-color.js | 98 +++++++++++++++++++ .../components/global-styles/screen-colors.js | 34 +++++++ .../src/components/global-styles/style.scss | 1 + .../src/components/global-styles/ui.js | 7 ++ .../src/components/global-styles/utils.js | 3 + 5 files changed, 143 insertions(+) create mode 100644 packages/edit-site/src/components/global-styles/screen-caption-color.js diff --git a/packages/edit-site/src/components/global-styles/screen-caption-color.js b/packages/edit-site/src/components/global-styles/screen-caption-color.js new file mode 100644 index 0000000000000..fe9821842ef11 --- /dev/null +++ b/packages/edit-site/src/components/global-styles/screen-caption-color.js @@ -0,0 +1,98 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { __experimentalColorGradientControl as ColorGradientControl } from '@wordpress/block-editor'; +/** + * Internal dependencies + */ +import ScreenHeader from './header'; +import { + getSupportedGlobalStylesPanels, + useSetting, + useStyle, + useColorsPerOrigin, +} from './hooks'; + +function ScreenCaptionColor( { name } ) { + const supports = getSupportedGlobalStylesPanels( name ); + const colorsPerOrigin = useColorsPerOrigin( name ); + const [ solids ] = useSetting( 'color.palette', name ); + const [ areCustomSolidsEnabled ] = useSetting( 'color.custom', name ); + + const hasCaptionColor = + supports.includes( 'color' ) && + ( solids.length > 0 || areCustomSolidsEnabled ); + + const [ captionTextColor, setCaptionTextColor ] = useStyle( + 'elements.caption.color.text', + name + ); + const [ userCaptionTextColor ] = useStyle( + 'elements.caption.color.text', + name, + 'user' + ); + + const [ captionBgColor, setCaptionBgColor ] = useStyle( + 'elements.caption.color.background', + name + ); + const [ userCaptionBgColor ] = useStyle( + 'elements.caption.color.background', + name, + 'user' + ); + + if ( ! hasCaptionColor ) { + return null; + } + + return ( + <> + +
+

+ { __( 'Text color' ) } +

+ + + +

+ { __( 'Background color' ) } +

+ + +
+ + ); +} + +export default ScreenCaptionColor; diff --git a/packages/edit-site/src/components/global-styles/screen-colors.js b/packages/edit-site/src/components/global-styles/screen-colors.js index 87d74604e63e1..fc96ced0ba096 100644 --- a/packages/edit-site/src/components/global-styles/screen-colors.js +++ b/packages/edit-site/src/components/global-styles/screen-colors.js @@ -114,6 +114,36 @@ function LinkColorItem( { name, parentMenu } ) { ); } +function CaptionColorItem( { name, parentMenu } ) { + const supports = getSupportedGlobalStylesPanels( name ); + const hasSupport = supports.includes( 'color' ); + const [ color ] = useStyle( 'elements.caption.color.text', name ); + const [ bgColor ] = useStyle( 'elements.caption.color.background', name ); + + if ( ! hasSupport ) { + return null; + } + + return ( + + + + + + + + + + + { __( 'Captions' ) } + + + ); +} + function HeadingColorItem( { name, parentMenu } ) { const supports = getSupportedGlobalStylesPanels( name ); const hasSupport = supports.includes( 'color' ); @@ -204,6 +234,10 @@ function ScreenColors( { name } ) { name={ name } parentMenu={ parentMenu } /> + + + + + diff --git a/packages/edit-site/src/components/global-styles/utils.js b/packages/edit-site/src/components/global-styles/utils.js index 4c9d7bae19f7a..9bce803acf7b0 100644 --- a/packages/edit-site/src/components/global-styles/utils.js +++ b/packages/edit-site/src/components/global-styles/utils.js @@ -92,6 +92,9 @@ const STYLE_PATH_TO_CSS_VAR_INFIX = { 'elements.link.color.text': 'color', 'elements.button.color.text': 'color', 'elements.button.backgroundColor': 'background-color', + 'elements.caption.color.text': 'color', + 'elements.caption.backgroundColor': 'background-color', + 'elements.caption.gradient': 'gradient', 'elements.heading.color': 'color', 'elements.heading.backgroundColor': 'background-color', 'elements.heading.gradient': 'gradient',