From 5c1d41054176e4f5930ecebd5d277c26353e9dd5 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 24 Nov 2021 14:11:05 +0100 Subject: [PATCH] Add elements support to the typography panel in global styles (#36718) --- packages/block-editor/src/hooks/typography.js | 2 +- .../screen-typography-element.js | 39 +++++++++ .../global-styles/screen-typography.js | 87 ++++++++++++++++++- .../src/components/global-styles/style.scss | 24 +++++ .../global-styles/typography-panel.js | 44 ++++++++-- .../src/components/global-styles/ui.js | 9 ++ 6 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 packages/edit-site/src/components/global-styles/screen-typography-element.js diff --git a/packages/block-editor/src/hooks/typography.js b/packages/block-editor/src/hooks/typography.js index 847c6b9c8d52..edddb713cf69 100644 --- a/packages/block-editor/src/hooks/typography.js +++ b/packages/block-editor/src/hooks/typography.js @@ -231,7 +231,7 @@ export function TypographyPanel( props ) { ); } -const hasTypographySupport = ( blockName ) => { +export const hasTypographySupport = ( blockName ) => { return TYPOGRAPHY_SUPPORT_KEYS.some( ( key ) => hasBlockSupport( blockName, key ) ); 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 new file mode 100644 index 000000000000..706d361448ed --- /dev/null +++ b/packages/edit-site/src/components/global-styles/screen-typography-element.js @@ -0,0 +1,39 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import TypographyPanel from './typography-panel'; +import ScreenHeader from './header'; + +const elements = { + text: { + description: __( 'Manage the fonts used on the site.' ), + title: __( 'Text' ), + }, + link: { + description: __( 'Manage the fonts and typography used on the links.' ), + title: __( 'Link' ), + }, +}; + +function ScreenTypographyElement( { name, element } ) { + const parentMenu = + name === undefined ? '/typography' : '/blocks/' + name + '/typography'; + + return ( + <> + + + + ); +} + +export default ScreenTypographyElement; 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 5a9b19154a43..e1d7520b4c20 100644 --- a/packages/edit-site/src/components/global-styles/screen-typography.js +++ b/packages/edit-site/src/components/global-styles/screen-typography.js @@ -2,12 +2,69 @@ * WordPress dependencies */ import { __ } from '@wordpress/i18n'; +import { + __experimentalItemGroup as ItemGroup, + __experimentalVStack as VStack, + __experimentalHStack as HStack, + FlexItem, +} from '@wordpress/components'; /** * Internal dependencies */ -import TypographyPanel from './typography-panel'; import ScreenHeader from './header'; +import NavigationButton from './navigation-button'; +import { useStyle } from './hooks'; +import Subtitle from './subtitle'; +import TypographyPanel from './typography-panel'; + +function Item( { name, parentMenu, element, label } ) { + const hasSupport = ! name; + const prefix = + element === 'text' || ! element ? '' : `elements.${ element }.`; + const extraStyles = + element === 'link' + ? { + textDecoration: 'underline', + } + : {}; + const [ fontFamily ] = useStyle( prefix + 'typography.fontFamily', name ); + const [ fontStyle ] = useStyle( prefix + 'typography.fontStyle', name ); + const [ fontWeight ] = useStyle( prefix + 'typography.fontWeight', name ); + const [ letterSpacing ] = useStyle( + prefix + 'typography.letterSpacing', + name + ); + const [ backgroundColor ] = useStyle( prefix + 'color.background', name ); + const [ gradientValue ] = useStyle( prefix + 'color.gradient', name ); + const [ color ] = useStyle( prefix + 'color.text', name ); + + if ( ! hasSupport ) { + return null; + } + + return ( + + + + { __( 'Aa' ) } + + { label } + + + ); +} function ScreenTypography( { name } ) { const parentMenu = name === undefined ? '' : '/blocks/' + name; @@ -18,10 +75,34 @@ function ScreenTypography( { name } ) { back={ parentMenu ? parentMenu : '/' } title={ __( 'Typography' ) } description={ __( - 'Manage the fonts used on the website and the default aspect of different global elements.' + 'Manage the typography settings for different elements.' ) } /> - + + { ! name && ( +
+ + { __( 'Elements' ) } + + + + + +
+ ) } + + { /* no typogrpahy elements support yet for blocks */ } + { !! name && } ); } diff --git a/packages/edit-site/src/components/global-styles/style.scss b/packages/edit-site/src/components/global-styles/style.scss index e92d9a832f6f..0429695eb99b 100644 --- a/packages/edit-site/src/components/global-styles/style.scss +++ b/packages/edit-site/src/components/global-styles/style.scss @@ -15,6 +15,30 @@ } } +.edit-site-typography-panel__preview { + display: flex; + align-items: center; + justify-content: center; + min-height: 100px; + margin-bottom: $grid-unit-20; + background: $gray-100; + border-radius: $radius-block-ui; +} + +.edit-site-global-styles-screen-typography { + margin: $grid-unit-20; +} + +.edit-site-global-styles-screen-typography__indicator { + height: 24px; + width: 24px; + font-size: 14px; + display: flex !important; + align-items: center; + justify-content: center; + border-radius: $radius-block-ui; +} + .edit-site-global-styles-screen-colors { margin: $grid-unit-20; 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 85a990ccca29..03e3634ce77d 100644 --- a/packages/edit-site/src/components/global-styles/typography-panel.js +++ b/packages/edit-site/src/components/global-styles/typography-panel.js @@ -54,8 +54,10 @@ function useHasLetterSpacingControl( name ) { ); } -export default function TypographyPanel( { name } ) { +export default function TypographyPanel( { name, element } ) { const supports = getSupportedGlobalStylesPanels( name ); + const prefix = + element === 'text' || ! element ? '' : `elements.${ element }.`; const [ fontSizes ] = useSetting( 'typography.fontSizes', name ); const disableCustomFontSizes = ! useSetting( 'typography.customFontSize', @@ -73,30 +75,58 @@ export default function TypographyPanel( { name } ) { const hasLetterSpacingControl = useHasLetterSpacingControl( name ); const [ fontFamily, setFontFamily ] = useStyle( - 'typography.fontFamily', + prefix + 'typography.fontFamily', + name + ); + const [ fontSize, setFontSize ] = useStyle( + prefix + 'typography.fontSize', name ); - const [ fontSize, setFontSize ] = useStyle( 'typography.fontSize', name ); const [ fontStyle, setFontStyle ] = useStyle( - 'typography.fontStyle', + prefix + 'typography.fontStyle', name ); const [ fontWeight, setFontWeight ] = useStyle( - 'typography.fontWeight', + prefix + 'typography.fontWeight', name ); const [ lineHeight, setLineHeight ] = useStyle( - 'typography.lineHeight', + prefix + 'typography.lineHeight', name ); const [ letterSpacing, setLetterSpacing ] = useStyle( - 'typography.letterSpacing', + prefix + 'typography.letterSpacing', name ); + const [ backgroundColor ] = useStyle( prefix + 'color.background', name ); + const [ gradientValue ] = useStyle( prefix + 'color.gradient', name ); + const [ color ] = useStyle( prefix + 'color.text', name ); + const extraStyles = + element === 'link' + ? { + textDecoration: 'underline', + } + : {}; return ( +
+ Aa +
+ { supports.includes( 'fontFamily' ) && ( + + + + + + + +