Skip to content
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

Use ToolsPanel in Global Styles → Typography #44180

Merged
merged 9 commits into from
Sep 29, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalSpacer as Spacer,
} from '@wordpress/components';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import TypographyPanel from './typography-panel';
import ScreenHeader from './header';
import TypographyPreview from './typography-preview';

const elements = {
text: {
Expand All @@ -29,13 +36,70 @@ const elements = {
};

function ScreenTypographyElement( { name, element } ) {
const [ headingLevel, setHeadingLevel ] = useState( 'heading' );

return (
<>
<ScreenHeader
title={ elements[ element ].title }
description={ elements[ element ].description }
/>
<TypographyPanel name={ name } element={ element } />
<Spacer marginX={ 4 }>
<TypographyPreview
name={ name }
element={ element }
headingLevel={ headingLevel }
/>
</Spacer>
{ element === 'heading' && (
<Spacer marginX={ 4 } marginBottom="1em">
<ToggleGroupControl
label={ __( 'Select heading level' ) }
hideLabelFromVision
value={ headingLevel }
onChange={ setHeadingLevel }
isBlock
size="__unstable-large"
__nextHasNoMarginBottom
>
<ToggleGroupControlOption
value="heading"
/* translators: 'All' refers to selecting all heading levels
and applying the same style to h1-h6. */
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>
</Spacer>
) }
<TypographyPanel
name={ name }
element={ element }
headingLevel={ headingLevel }
/>
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
display: block;
}

.edit-site-typography-panel__preview {
.edit-site-typography-preview {
display: flex;
align-items: center;
justify-content: center;
Expand Down
Loading