-
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: Caption element UI controls for color and typography #49141
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3690bf8
abstract the button color screen into a generic element one
MaggieCabrera 56bf7ed
use screen color element with the text element
MaggieCabrera a02f19e
added color and typography controls for caption element
MaggieCabrera 6214e87
hide caption color control on blocks that don't support it
MaggieCabrera 27610f4
copypaste fail
MaggieCabrera 637af78
removed background controls
MaggieCabrera 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
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
104 changes: 0 additions & 104 deletions
104
packages/edit-site/src/components/global-styles/screen-button-color.js
This file was deleted.
Oops, something went wrong.
141 changes: 141 additions & 0 deletions
141
packages/edit-site/src/components/global-styles/screen-color-element.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,141 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
__experimentalColorGradientControl as ColorGradientControl, | ||
privateApis as blockEditorPrivateApis, | ||
} from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ScreenHeader from './header'; | ||
import { useSupportedStyles, useColorsPerOrigin } from './hooks'; | ||
import { unlock } from '../../private-apis'; | ||
|
||
const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorPrivateApis ); | ||
|
||
const elements = { | ||
text: { | ||
description: __( | ||
'Set the default color used for text accross the site.' | ||
), | ||
title: __( 'Text' ), | ||
}, | ||
caption: { | ||
description: __( | ||
'Set the default color used for captions accross the site.' | ||
), | ||
title: __( 'Captions' ), | ||
}, | ||
button: { | ||
description: __( | ||
'Set the default color used for buttons accross the site.' | ||
), | ||
title: __( 'Buttons' ), | ||
}, | ||
}; | ||
|
||
function ScreenColorElement( { name, element, variation = '' } ) { | ||
const prefix = variation ? `variations.${ variation }.` : ''; | ||
const supports = useSupportedStyles( name ); | ||
const colorsPerOrigin = useColorsPerOrigin( name ); | ||
const [ isTextEnabled ] = useGlobalSetting( 'color.text', name ); | ||
const [ areCustomSolidsEnabled ] = useGlobalSetting( 'color.custom', name ); | ||
let [ isBackgroundEnabled ] = useGlobalSetting( 'color.background', name ); | ||
|
||
let textColorElementSelector = 'elements.' + element + '.color.text'; | ||
const backgroundColorElementSelector = | ||
'elements.' + element + '.color.background'; | ||
|
||
let hasElementColor = | ||
supports.includes( 'buttonColor' ) && | ||
( colorsPerOrigin.length > 0 || areCustomSolidsEnabled ); | ||
|
||
if ( element === 'text' ) { | ||
isBackgroundEnabled = false; | ||
textColorElementSelector = 'color.text'; | ||
hasElementColor = | ||
supports.includes( 'color' ) && | ||
isTextEnabled && | ||
( colorsPerOrigin.length > 0 || areCustomSolidsEnabled ); | ||
} else if ( element === 'button' ) { | ||
hasElementColor = | ||
supports.includes( 'buttonColor' ) && | ||
isBackgroundEnabled && | ||
( colorsPerOrigin.length > 0 || areCustomSolidsEnabled ); | ||
} | ||
|
||
const [ elementTextColor, setElementTextColor ] = useGlobalStyle( | ||
prefix + textColorElementSelector, | ||
name | ||
); | ||
const [ userElementTextColor ] = useGlobalStyle( | ||
textColorElementSelector, | ||
name, | ||
'user' | ||
); | ||
|
||
const [ elementBgColor, setElementBgColor ] = useGlobalStyle( | ||
backgroundColorElementSelector, | ||
name | ||
); | ||
const [ userElementBgColor ] = useGlobalStyle( | ||
backgroundColorElementSelector, | ||
name, | ||
'user' | ||
); | ||
|
||
if ( ! hasElementColor ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<ScreenHeader | ||
title={ elements[ element ].title } | ||
description={ elements[ element ].description } | ||
/> | ||
|
||
<h3 className="edit-site-global-styles-section-title"> | ||
{ __( 'Text color' ) } | ||
</h3> | ||
|
||
<ColorGradientControl | ||
className="edit-site-screen-element-color__control" | ||
colors={ colorsPerOrigin } | ||
disableCustomColors={ ! areCustomSolidsEnabled } | ||
showTitle={ false } | ||
enableAlpha | ||
__experimentalIsRenderedInSidebar | ||
colorValue={ elementTextColor } | ||
onColorChange={ setElementTextColor } | ||
clearable={ elementTextColor === userElementTextColor } | ||
headingLevel={ 4 } | ||
/> | ||
{ isBackgroundEnabled && ( | ||
<> | ||
<h3 className="edit-site-global-styles-section-title"> | ||
{ __( 'Background color' ) } | ||
</h3> | ||
|
||
<ColorGradientControl | ||
className="edit-site-screen-element-color__control" | ||
colors={ colorsPerOrigin } | ||
disableCustomColors={ ! areCustomSolidsEnabled } | ||
showTitle={ false } | ||
enableAlpha | ||
__experimentalIsRenderedInSidebar | ||
colorValue={ elementBgColor } | ||
onColorChange={ setElementBgColor } | ||
clearable={ elementBgColor === userElementBgColor } | ||
headingLevel={ 4 } | ||
/> | ||
</> | ||
) } | ||
</> | ||
); | ||
} | ||
|
||
export default ScreenColorElement; |
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.
what happened to this file?
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.
the two files are incredibly similar and can be refactored into one, so that's what I did in
packages/edit-site/src/components/global-styles/screen-color-element.js
. The rest of the elements were a bit more different, but in the future they could probably be abstracted too.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.
Could we do this in another PR? 🙏🏻 Just moving the code around?
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.
that's what I did on the original PR and was encouraged to abstract it like this! :D