-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Heading element UI controls #42176
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
327c032
Try adding a global styles screen for heading color
carolinan 81ff7fb
Update utils.js
carolinan 7fd70be
Update screen-color-heading.js
carolinan 03d6869
Update the label and headings to be more descriptive
carolinan 84c118e
Add typography > Headings
carolinan 31c71f5
Rename the heading colors screen file, remove font size for elements.…
carolinan a6b3a3f
Add translators comment.
carolinan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
packages/edit-site/src/components/global-styles/screen-heading-color.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { sprintf, __ } from '@wordpress/i18n'; | ||
import { | ||
__experimentalToggleGroupControl as ToggleGroupControl, | ||
__experimentalToggleGroupControlOption as ToggleGroupControlOption, | ||
} from '@wordpress/components'; | ||
import { __experimentalColorGradientControl as ColorGradientControl } from '@wordpress/block-editor'; | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ScreenHeader from './header'; | ||
import { | ||
getSupportedGlobalStylesPanels, | ||
useSetting, | ||
useStyle, | ||
useColorsPerOrigin, | ||
useGradientsPerOrigin, | ||
} from './hooks'; | ||
|
||
function ScreenHeadingColor( { name } ) { | ||
const [ selectedLevel, setCurrentTab ] = useState( 'heading' ); | ||
|
||
const supports = getSupportedGlobalStylesPanels( name ); | ||
const [ solids ] = useSetting( 'color.palette', name ); | ||
const [ gradients ] = useSetting( 'color.gradients', name ); | ||
const [ areCustomSolidsEnabled ] = useSetting( 'color.custom', name ); | ||
const [ areCustomGradientsEnabled ] = useSetting( | ||
'color.customGradient', | ||
name | ||
); | ||
const [ isTextEnabled ] = useSetting( 'color.text', name ); | ||
const [ isBackgroundEnabled ] = useSetting( 'color.background', name ); | ||
|
||
const colorsPerOrigin = useColorsPerOrigin( name ); | ||
const gradientsPerOrigin = useGradientsPerOrigin( name ); | ||
|
||
const hasTextColor = | ||
supports.includes( 'color' ) && | ||
isTextEnabled && | ||
( solids.length > 0 || areCustomSolidsEnabled ); | ||
|
||
const hasBackgroundColor = | ||
supports.includes( 'backgroundColor' ) && | ||
isBackgroundEnabled && | ||
( solids.length > 0 || areCustomSolidsEnabled ); | ||
const hasGradientColor = | ||
supports.includes( 'background' ) && | ||
( gradients.length > 0 || areCustomGradientsEnabled ); | ||
|
||
const [ color, setColor ] = useStyle( | ||
'elements.' + selectedLevel + '.color.text', | ||
name | ||
); | ||
const [ userColor ] = useStyle( | ||
'elements.' + selectedLevel + '.color.text', | ||
name, | ||
'user' | ||
); | ||
|
||
const [ backgroundColor, setBackgroundColor ] = useStyle( | ||
'elements.' + selectedLevel + '.color.background', | ||
name | ||
); | ||
const [ userBackgroundColor ] = useStyle( | ||
'elements.' + selectedLevel + '.color.background', | ||
name, | ||
'user' | ||
); | ||
const [ gradient, setGradient ] = useStyle( | ||
'elements.' + selectedLevel + '.color.gradient', | ||
name | ||
); | ||
const [ userGradient ] = useStyle( | ||
'elements.' + selectedLevel + '.color.gradient', | ||
name, | ||
'user' | ||
); | ||
|
||
if ( ! hasTextColor && ! hasBackgroundColor && ! hasGradientColor ) { | ||
return null; | ||
} | ||
|
||
let backgroundSettings = {}; | ||
if ( hasBackgroundColor ) { | ||
backgroundSettings = { | ||
colorValue: backgroundColor, | ||
onColorChange: setBackgroundColor, | ||
}; | ||
if ( backgroundColor ) { | ||
backgroundSettings.clearable = | ||
backgroundColor === userBackgroundColor; | ||
} | ||
} | ||
|
||
let gradientSettings = {}; | ||
if ( hasGradientColor ) { | ||
gradientSettings = { | ||
gradientValue: gradient, | ||
onGradientChange: setGradient, | ||
}; | ||
if ( gradient ) { | ||
gradientSettings.clearable = gradient === userGradient; | ||
} | ||
} | ||
|
||
const controlProps = { | ||
...backgroundSettings, | ||
...gradientSettings, | ||
}; | ||
|
||
return ( | ||
<> | ||
<ScreenHeader | ||
title={ __( 'Headings' ) } | ||
description={ __( | ||
'Set the default color used for headings across the site.' | ||
) } | ||
/> | ||
<div className="edit-site-global-styles-screen-heading-color"> | ||
<h4>{ __( 'Select heading level' ) }</h4> | ||
|
||
<ToggleGroupControl | ||
label={ __( 'Select heading level' ) } | ||
hideLabelFromVision={ true } | ||
value={ selectedLevel } | ||
onChange={ setCurrentTab } | ||
isBlock | ||
> | ||
<ToggleGroupControlOption | ||
value="heading" | ||
/* translators: 'All' refers to selecting all heading levels | ||
and applying the same style to h1-h6. */ | ||
label={ __( 'All' ) } | ||
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. Does this need a translators comment? 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. Added. |
||
/> | ||
<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> | ||
{ hasTextColor && ( | ||
<div className="edit-site-global-styles-screen-heading-color"> | ||
<h4> | ||
{ selectedLevel === 'heading' | ||
? __( 'Text color for all heading levels' ) | ||
: sprintf( | ||
/* translators: %s: heading level (h1-h6) */ | ||
__( 'Text color for %s' ), | ||
selectedLevel.toUpperCase() | ||
) } | ||
</h4> | ||
<ColorGradientControl | ||
className="edit-site-screen-heading-text-color__control" | ||
colors={ colorsPerOrigin } | ||
disableCustomColors={ ! areCustomSolidsEnabled } | ||
__experimentalHasMultipleOrigins | ||
showTitle={ false } | ||
enableAlpha | ||
__experimentalIsRenderedInSidebar | ||
colorValue={ color } | ||
onColorChange={ setColor } | ||
clearable={ color === userColor } | ||
/> | ||
</div> | ||
) } | ||
{ hasBackgroundColor && ( | ||
<div className="edit-site-global-styles-screen-heading-color"> | ||
<h4> | ||
{ selectedLevel === 'heading' | ||
? __( 'Background color for all heading levels' ) | ||
: sprintf( | ||
/* translators: %s: heading level (h1-h6) */ | ||
__( 'Background color for %s' ), | ||
selectedLevel.toUpperCase() | ||
) } | ||
</h4> | ||
<ColorGradientControl | ||
className="edit-site-screen-heading-background-color__control" | ||
colors={ colorsPerOrigin } | ||
gradients={ gradientsPerOrigin } | ||
disableCustomColors={ ! areCustomSolidsEnabled } | ||
disableCustomGradients={ ! areCustomGradientsEnabled } | ||
__experimentalHasMultipleOrigins | ||
showTitle={ false } | ||
enableAlpha | ||
__experimentalIsRenderedInSidebar | ||
{ ...controlProps } | ||
/> | ||
</div> | ||
) } | ||
</> | ||
); | ||
} | ||
|
||
export default ScreenHeadingColor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these supports (
hasTextColor
,hasBackgroundColor
,hasGradientColor
) are quite verbose, and we probably have this same logic elsewhere. Can we extract this to some kind of hook or shared function? That could be a follow-up PR....There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I fully agree.