From 327c032b54e85fd9066460e16b202d4b99184496 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Wed, 6 Jul 2022 08:21:52 +0200 Subject: [PATCH 1/7] Try adding a global styles screen for heading color --- .../global-styles/screen-color-heading.js | 182 ++++++++++++++++++ .../components/global-styles/screen-colors.js | 34 ++++ .../src/components/global-styles/style.scss | 1 + .../src/components/global-styles/ui.js | 7 + 4 files changed, 224 insertions(+) create mode 100644 packages/edit-site/src/components/global-styles/screen-color-heading.js diff --git a/packages/edit-site/src/components/global-styles/screen-color-heading.js b/packages/edit-site/src/components/global-styles/screen-color-heading.js new file mode 100644 index 00000000000000..eef750fed34745 --- /dev/null +++ b/packages/edit-site/src/components/global-styles/screen-color-heading.js @@ -0,0 +1,182 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { + __experimentalToggleGroupControl as ToggleGroupControl, + __experimentalToggleGroupControlOption as ToggleGroupControlOption, +} from '@wordpress/components'; +import { __experimentalColorGradientControl as ColorGradientControl } from '@wordpress/block-editor'; +import { useState } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import ScreenHeader from './header'; +import { + getSupportedGlobalStylesPanels, + useSetting, + useStyle, + useColorsPerOrigin, + useGradientsPerOrigin, +} from './hooks'; + +function ScreenHeadingColor( { name } ) { + const [ selectedLevel, setCurrentTab ] = useState( 'heading' ); + + const supports = getSupportedGlobalStylesPanels( name ); + const [ solids ] = useSetting( 'color.palette', name ); + const [ gradients ] = useSetting( 'color.gradients', name ); + const [ areCustomSolidsEnabled ] = useSetting( 'color.custom', name ); + const [ areCustomGradientsEnabled ] = useSetting( + 'color.customGradient', + name + ); + const [ isTextEnabled ] = useSetting( 'color.text', name ); + const [ isBackgroundEnabled ] = useSetting( 'color.background', name ); + + const colorsPerOrigin = useColorsPerOrigin( name ); + const gradientsPerOrigin = useGradientsPerOrigin( name ); + + const hasTextColor = + supports.includes( 'color' ) && + isTextEnabled && + ( solids.length > 0 || areCustomSolidsEnabled ); + + const hasBackgroundColor = + supports.includes( 'backgroundColor' ) && + isBackgroundEnabled && + ( solids.length > 0 || areCustomSolidsEnabled ); + const hasGradientColor = + supports.includes( 'background' ) && + ( gradients.length > 0 || areCustomGradientsEnabled ); + + const [ color, setColor ] = useStyle( + 'elements.' + selectedLevel + '.color.text', + name + ); + const [ userColor ] = useStyle( + 'elements.' + selectedLevel + '.color.text', + name, + 'user' + ); + + const [ backgroundColor, setBackgroundColor ] = useStyle( + 'elements.' + selectedLevel + '.color.background', + name + ); + const [ userBackgroundColor ] = useStyle( + 'elements.' + selectedLevel + '.color.background', + name, + 'user' + ); + const [ gradient, setGradient ] = useStyle( + 'elements.' + selectedLevel + '.color.gradient', + name + ); + const [ userGradient ] = useStyle( + 'elements.' + selectedLevel + '.color.gradient', + name, + 'user' + ); + + if ( ! hasTextColor && ! hasBackgroundColor && ! hasGradientColor ) { + return null; + } + + let backgroundSettings = {}; + if ( hasBackgroundColor ) { + backgroundSettings = { + colorValue: backgroundColor, + onColorChange: setBackgroundColor, + }; + if ( backgroundColor ) { + backgroundSettings.clearable = + backgroundColor === userBackgroundColor; + } + } + + let gradientSettings = {}; + if ( hasGradientColor ) { + gradientSettings = { + gradientValue: gradient, + onGradientChange: setGradient, + }; + if ( gradient ) { + gradientSettings.clearable = gradient === userGradient; + } + } + + const controlProps = { + ...backgroundSettings, + ...gradientSettings, + }; + + return ( + <> + +
+ + + + + + + + + +
+ { hasTextColor && ( +
+

{ __( 'Text color' ) }

+ + +
+ ) } + { hasBackgroundColor && ( +
+

{ __( 'Background color' ) }

+ + +
+ ) } + + ); +} + +export default ScreenHeadingColor; 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 d11d863b46f46e..449aba03496daa 100644 --- a/packages/edit-site/src/components/global-styles/screen-colors.js +++ b/packages/edit-site/src/components/global-styles/screen-colors.js @@ -108,6 +108,36 @@ function LinkColorItem( { name, parentMenu } ) { ); } +function HeadingColorItem( { name, parentMenu } ) { + const supports = getSupportedGlobalStylesPanels( name ); + const hasSupport = supports.includes( 'color' ); + const [ color ] = useStyle( 'elements.heading.color.text', name ); + const [ bgColor ] = useStyle( 'elements.heading.color.background', name ); + + if ( ! hasSupport ) { + return null; + } + + return ( + + + + + + + + + + + { __( 'Headings' ) } + + + ); +} + function ButtonColorItem( { name, parentMenu } ) { const supports = getSupportedGlobalStylesPanels( name ); const hasSupport = supports.includes( 'buttonColor' ); @@ -166,6 +196,10 @@ function ScreenColors( { name } ) { name={ name } parentMenu={ parentMenu } /> + + + + + From 81ff7fb30e47b7770a375086f5ec531a23642937 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Wed, 6 Jul 2022 09:19:18 +0200 Subject: [PATCH 2/7] Update utils.js --- packages/edit-site/src/components/global-styles/utils.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/edit-site/src/components/global-styles/utils.js b/packages/edit-site/src/components/global-styles/utils.js index 4c4aef887c6e0d..54d607f09374df 100644 --- a/packages/edit-site/src/components/global-styles/utils.js +++ b/packages/edit-site/src/components/global-styles/utils.js @@ -85,6 +85,9 @@ const STYLE_PATH_TO_CSS_VAR_INFIX = { 'elements.link.color.text': 'color', 'elements.button.color.text': 'color', 'elements.button.backgroundColor': 'background-color', + 'elements.heading.color': 'color', + 'elements.heading.backgroundColor': 'background-color', + 'elements.heading.gradient': 'gradient', 'color.gradient': 'gradient', 'typography.fontSize': 'font-size', 'typography.fontFamily': 'font-family', From 7fd70be40190b89a2c2ed0331fe5850267b46830 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Wed, 6 Jul 2022 09:43:28 +0200 Subject: [PATCH 3/7] Update screen-color-heading.js --- .../src/components/global-styles/screen-color-heading.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/edit-site/src/components/global-styles/screen-color-heading.js b/packages/edit-site/src/components/global-styles/screen-color-heading.js index eef750fed34745..c990dd878028bf 100644 --- a/packages/edit-site/src/components/global-styles/screen-color-heading.js +++ b/packages/edit-site/src/components/global-styles/screen-color-heading.js @@ -121,8 +121,11 @@ function ScreenHeadingColor( { name } ) { ) } />
+

{ __( 'Heading Level' ) }

+ Date: Mon, 1 Aug 2022 09:41:09 +0200 Subject: [PATCH 4/7] Update the label and headings to be more descriptive --- .../global-styles/screen-color-heading.js | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/screen-color-heading.js b/packages/edit-site/src/components/global-styles/screen-color-heading.js index c990dd878028bf..40f9209d67b986 100644 --- a/packages/edit-site/src/components/global-styles/screen-color-heading.js +++ b/packages/edit-site/src/components/global-styles/screen-color-heading.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { __ } from '@wordpress/i18n'; +import { sprintf, __ } from '@wordpress/i18n'; import { __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, @@ -121,10 +121,10 @@ function ScreenHeadingColor( { name } ) { ) } />
-

{ __( 'Heading Level' ) }

+

{ __( 'Select heading level' ) }

{ hasTextColor && (
-

{ __( 'Text color' ) }

- +

+ { selectedLevel === 'heading' + ? __( 'Text color for all heading levels' ) + : sprintf( + /* translators: %s: heading level (h1-h6) */ + __( 'Text color for %s' ), + selectedLevel.toUpperCase() + ) } +

-

{ __( 'Background color' ) }

- +

+ { selectedLevel === 'heading' + ? __( 'Background color for all heading levels' ) + : sprintf( + /* translators: %s: heading level (h1-h6) */ + __( 'Background color for %s' ), + selectedLevel.toUpperCase() + ) } +

Date: Mon, 1 Aug 2022 11:31:47 +0200 Subject: [PATCH 5/7] Add typography > Headings --- .../screen-typography-element.js | 4 ++ .../global-styles/screen-typography.js | 6 ++ .../global-styles/typography-panel.js | 56 +++++++++++++++++-- .../src/components/global-styles/ui.js | 6 ++ 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/screen-typography-element.js b/packages/edit-site/src/components/global-styles/screen-typography-element.js index 4f7abe955803ee..a14801c43a3b0e 100644 --- a/packages/edit-site/src/components/global-styles/screen-typography-element.js +++ b/packages/edit-site/src/components/global-styles/screen-typography-element.js @@ -18,6 +18,10 @@ const elements = { description: __( 'Manage the fonts and typography used on the links.' ), title: __( 'Links' ), }, + heading: { + description: __( 'Manage the fonts and typography used on headings.' ), + title: __( 'Headings' ), + }, button: { description: __( 'Manage the fonts and typography used on buttons.' ), title: __( 'Buttons' ), diff --git a/packages/edit-site/src/components/global-styles/screen-typography.js b/packages/edit-site/src/components/global-styles/screen-typography.js index f2b59ee320f301..3f7a5eb3eb8670 100644 --- a/packages/edit-site/src/components/global-styles/screen-typography.js +++ b/packages/edit-site/src/components/global-styles/screen-typography.js @@ -104,6 +104,12 @@ function ScreenTypography( { name } ) { element="link" label={ __( 'Links' ) } /> + Aa
- + { element === 'heading' && ( +
+

{ __( 'Select heading level' ) }

+ + + + + + + + + +
+ ) } { supports.includes( 'fontFamily' ) && ( + + + + From 31c71f5290d77385ee8e7338b0b57a3af56c7d39 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Tue, 2 Aug 2022 06:35:21 +0200 Subject: [PATCH 6/7] Rename the heading colors screen file, remove font size for elements.heading. --- .../{screen-color-heading.js => screen-heading-color.js} | 0 .../src/components/global-styles/typography-panel.js | 8 +++++++- packages/edit-site/src/components/global-styles/ui.js | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) rename packages/edit-site/src/components/global-styles/{screen-color-heading.js => screen-heading-color.js} (100%) diff --git a/packages/edit-site/src/components/global-styles/screen-color-heading.js b/packages/edit-site/src/components/global-styles/screen-heading-color.js similarity index 100% rename from packages/edit-site/src/components/global-styles/screen-color-heading.js rename to packages/edit-site/src/components/global-styles/screen-heading-color.js diff --git a/packages/edit-site/src/components/global-styles/typography-panel.js b/packages/edit-site/src/components/global-styles/typography-panel.js index 6175060b35465c..a1737fa261997d 100644 --- a/packages/edit-site/src/components/global-styles/typography-panel.js +++ b/packages/edit-site/src/components/global-styles/typography-panel.js @@ -86,6 +86,12 @@ export default function TypographyPanel( { name, element } ) { const hasAppearanceControl = useHasAppearanceControl( name ); const hasLetterSpacingControl = useHasLetterSpacingControl( name ); + /* Disable font size controls when the option to style all headings is selected. */ + let hasFontSizeEnabled = supports.includes( 'fontSize' ); + if ( element === 'heading' && selectedLevel === 'heading' ) { + hasFontSizeEnabled = false; + } + const [ fontFamily, setFontFamily ] = useStyle( prefix + 'typography.fontFamily', name @@ -186,7 +192,7 @@ export default function TypographyPanel( { name, element } ) { onChange={ setFontFamily } /> ) } - { supports.includes( 'fontSize' ) && ( + { hasFontSizeEnabled && ( Date: Tue, 2 Aug 2022 14:11:52 +0200 Subject: [PATCH 7/7] Add translators comment. --- .../src/components/global-styles/screen-heading-color.js | 2 ++ .../edit-site/src/components/global-styles/typography-panel.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/edit-site/src/components/global-styles/screen-heading-color.js b/packages/edit-site/src/components/global-styles/screen-heading-color.js index 40f9209d67b986..4a40ebc4d4d80a 100644 --- a/packages/edit-site/src/components/global-styles/screen-heading-color.js +++ b/packages/edit-site/src/components/global-styles/screen-heading-color.js @@ -132,6 +132,8 @@ function ScreenHeadingColor( { name } ) { > diff --git a/packages/edit-site/src/components/global-styles/typography-panel.js b/packages/edit-site/src/components/global-styles/typography-panel.js index a1737fa261997d..f0b6cc15170dc0 100644 --- a/packages/edit-site/src/components/global-styles/typography-panel.js +++ b/packages/edit-site/src/components/global-styles/typography-panel.js @@ -156,6 +156,8 @@ export default function TypographyPanel( { name, element } ) { >