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

Global Styles: Elements: Add a text decoration control to link elements #45643

Merged
merged 2 commits into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
__experimentalFontAppearanceControl as FontAppearanceControl,
__experimentalLetterSpacingControl as LetterSpacingControl,
__experimentalTextTransformControl as TextTransformControl,
__experimentalTextDecorationControl as TextDecorationControl,
} from '@wordpress/block-editor';
import {
FontSizePicker,
Expand Down Expand Up @@ -101,6 +102,13 @@ function useHasTextTransformControl( name, element ) {
return supports.includes( 'textTransform' );
}

function useHasTextDecorationControl( name, element ) {
// This is an exception for link elements.
// We shouldn't allow other blocks or elements to set textDecoration
// because this will be inherited by their children.
return ! name && element === 'link';
}

function useStyleWithReset( path, blockName ) {
const [ style, setStyle ] = useStyle( path, blockName );
const [ userStyle ] = useStyle( path, blockName, 'user' );
Expand Down Expand Up @@ -190,6 +198,10 @@ export default function TypographyPanel( { name, element, headingLevel } ) {
const appearanceControlLabel = useAppearanceControlLabel( name );
const hasLetterSpacingControl = useHasLetterSpacingControl( name, element );
const hasTextTransformControl = useHasTextTransformControl( name, element );
const hasTextDecorationControl = useHasTextDecorationControl(
name,
element
);

/* Disable font size controls when the option to style all headings is selected. */
let hasFontSizeEnabled = supports.includes( 'fontSize' );
Expand Down Expand Up @@ -223,6 +235,12 @@ export default function TypographyPanel( { name, element, headingLevel } ) {
hasTextTransform,
resetTextTransform,
] = useStyleWithReset( prefix + 'typography.textTransform', name );
const [
textDecoration,
setTextDecoration,
hasTextDecoration,
resetTextDecoration,
] = useStyleWithReset( prefix + 'typography.textDecoration', name );

const resetAll = () => {
resetFontFamily();
Expand Down Expand Up @@ -347,6 +365,22 @@ export default function TypographyPanel( { name, element, headingLevel } ) {
/>
</ToolsPanelItem>
) }
{ hasTextDecorationControl && (
<ToolsPanelItem
className="single-column"
label={ __( 'Text decoration' ) }
hasValue={ hasTextDecoration }
onDeselect={ resetTextDecoration }
isShownByDefault
>
<TextDecorationControl
value={ textDecoration }
onChange={ setTextDecoration }
size="__unstable-large"
__unstableInputWidth="auto"
/>
</ToolsPanelItem>
) }
</ToolsPanel>
);
}