-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add elements support to the typography panel in global styles #36718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
37f05d2
892a93b
c06bd79
03bd30f
de4c4e6
7b2259d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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.' ), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess these descriptions should be more consistent and change only the part
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to use any proposed descriptions here :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I guess we should remove the export here? |
||
| title: __( 'Link' ), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be plural
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }, | ||
| }; | ||
|
|
||
| function ScreenTypographyElement( { name, element } ) { | ||
| const parentMenu = | ||
| name === undefined ? '/typography' : '/blocks/' + name + '/typography'; | ||
|
|
||
| return ( | ||
| <> | ||
| <ScreenHeader | ||
| back={ parentMenu } | ||
| title={ elements[ element ].title } | ||
| description={ elements[ element ].description } | ||
| /> | ||
| <TypographyPanel name={ name } element={ element } /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default ScreenTypographyElement; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,8 +54,10 @@ function useHasLetterSpacingControl( name ) { | |
| ); | ||
| } | ||
|
|
||
| export default function TypographyPanel( { name } ) { | ||
| export default function TypographyPanel( { name, element } ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, I'd like us to revisit this conversation #35264 (comment) What are your thoughts about passing the underlying functions Not a blocker for this PR, although I'm now more convinced we should do it for 5.9 than I was a few months ago when we first discussed it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, I'm fine with that change but this is an internal API for the moment, so there's no real urgency yet. |
||
| 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 ( | ||
| <PanelBody className="edit-site-typography-panel" initialOpen={ true }> | ||
| <div | ||
| className="edit-site-typography-panel__preview" | ||
| style={ { | ||
| fontFamily: fontFamily ?? 'serif', | ||
| background: gradientValue ?? backgroundColor, | ||
| color, | ||
| fontSize, | ||
| fontStyle, | ||
| fontWeight, | ||
| letterSpacing, | ||
| ...extraStyles, | ||
| } } | ||
| > | ||
| Aa | ||
| </div> | ||
|
|
||
| { supports.includes( 'fontFamily' ) && ( | ||
| <FontFamilyControl | ||
| fontFamilies={ fontFamilies } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.