Skip to content

Commit

Permalink
Add typography > Headings
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinan authored and aristath committed Aug 1, 2022
1 parent 03d6869 commit 84c118e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ function ScreenTypography( { name } ) {
element="link"
label={ __( 'Links' ) }
/>
<Item
name={ name }
parentMenu={ parentMenu }
element="heading"
label={ __( 'Headings' ) }
/>
<Item
name={ name }
parentMenu={ parentMenu }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import {
PanelBody,
FontSizePicker,
__experimentalSpacer as Spacer,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
} from '@wordpress/components';

import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -59,9 +62,14 @@ function useHasLetterSpacingControl( name ) {
}

export default function TypographyPanel( { name, element } ) {
const [ selectedLevel, setCurrentTab ] = useState( 'heading' );
const supports = getSupportedGlobalStylesPanels( name );
const prefix =
element === 'text' || ! element ? '' : `elements.${ element }.`;
let prefix = '';
if ( element === 'heading' ) {
prefix = `elements.${ selectedLevel }.`;
} else if ( element && element !== 'text' ) {
prefix = `elements.${ element }.`;
}
const [ fontSizes ] = useSetting( 'typography.fontSizes', name );
const disableCustomFontSizes = ! useSetting(
'typography.customFontSize',
Expand Down Expand Up @@ -130,7 +138,47 @@ export default function TypographyPanel( { name, element } ) {
>
Aa
</div>

{ element === 'heading' && (
<div>
<h4>{ __( 'Select heading level' ) }</h4>
<ToggleGroupControl
label={ __( 'Select heading level' ) }
hideLabelFromVision={ true }
value={ selectedLevel }
onChange={ setCurrentTab }
isBlock
>
<ToggleGroupControlOption
value="heading"
label={ __( 'All' ) }
/>
<ToggleGroupControlOption
value="h1"
label={ __( 'H1' ) }
/>
<ToggleGroupControlOption
value="h2"
label={ __( 'H2' ) }
/>
<ToggleGroupControlOption
value="h3"
label={ __( 'H3' ) }
/>
<ToggleGroupControlOption
value="h4"
label={ __( 'H4' ) }
/>
<ToggleGroupControlOption
value="h5"
label={ __( 'H5' ) }
/>
<ToggleGroupControlOption
value="h6"
label={ __( 'H6' ) }
/>
</ToggleGroupControl>
</div>
) }
{ supports.includes( 'fontFamily' ) && (
<FontFamilyControl
fontFamilies={ fontFamilies }
Expand Down
6 changes: 6 additions & 0 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ function ContextScreens( { name } ) {
<ScreenTypographyElement name={ name } element="link" />
</GlobalStylesNavigationScreen>

<GlobalStylesNavigationScreen
path={ parentMenu + '/typography/heading' }
>
<ScreenTypographyElement name={ name } element="heading" />
</GlobalStylesNavigationScreen>

<GlobalStylesNavigationScreen
path={ parentMenu + '/typography/button' }
>
Expand Down

0 comments on commit 84c118e

Please sign in to comment.