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

Button Block: Added configurable text color. #3034

Merged
merged 1 commit into from
Oct 17, 2017

Conversation

jorgefilipecosta
Copy link
Member

Description

This PR adds the option to set the text color of a button as specified in issue #2766.

Testing instructions

  1. Create a new post/edit an existing one.
  2. Add a button.
  3. Go to the block inspector set the background color and the text color.
  4. Verify the chosen colors appear in the editor, save the post publish and verify the button appears with correct colors.

Screenshots:

screen shot 2017-10-17 at 09 13 19

Some notes:

The background and text color configurators are very similar to the ones in the paragraph, and other components will probably have it too. I think maybe creating a new component to choose the colors for background and text may be a good idea. This component than would be able to have a contrast verification feature as being discussed in #2381. If you prefer this approach let me know, and I will create a new component and use it in paragraph and button.

@jorgefilipecosta jorgefilipecosta added Needs Design Feedback Needs general design feedback. [Feature] Inspector Controls The interface showing block settings and the controls available for each block [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. [Type] Task Issues or PRs that have been broken down into an individual action to take labels Oct 17, 2017
@codecov
Copy link

codecov bot commented Oct 17, 2017

Codecov Report

Merging #3034 into master will not change coverage.
The diff coverage is 25%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3034   +/-   ##
=======================================
  Coverage   32.76%   32.76%           
=======================================
  Files         203      203           
  Lines        5951     5951           
  Branches     1052     1052           
=======================================
  Hits         1950     1950           
  Misses       3375     3375           
  Partials      626      626
Impacted Files Coverage Δ
blocks/library/button/index.js 20% <25%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3feb0d7...f3aca2a. Read the comment docs.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some minor comments, but this is working good

@@ -76,7 +79,7 @@ registerBlockType( 'core/button', {
<BlockAlignmentToolbar value={ align } onChange={ updateAlignment } />
</BlockControls>
),
<span key="button" className={ className } title={ title } style={ { backgroundColor: color } } >
<span key="button" className={ className } title={ title } style={ { backgroundColor: backgroundColor } } >
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: could be written { backgroundColor }

textColor: {
type: 'string',
},
backgroundColor: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the attribute's name make the "old" buttons block for existing posts invalid, Maybe we should just keep the name as is

<ColorPalette
value={ backgroundColor }
onChange={ ( colorValue ) => setAttributes( { backgroundColor: colorValue } ) }
withTransparentOption
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this prop is not used anymore, we should just drop it

<div className={ `align${ align }` } style={ { backgroundColor: color } }>
<a href={ url } title={ title }>
<div className={ `align${ align }` } style={ { backgroundColor: backgroundColor } }>
<a href={ url } title={ title } style={ { color: textColor } }>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what HTML would this produce if textColor is undefined. My thinking is that it should not add any style attribute to the dom node to keep the old blocks "valid"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works as expected

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the HTML produced and if textColor is null no style is added.

@jorgefilipecosta jorgefilipecosta force-pushed the add/configurable-text-color-button branch from 9ab3088 to 225c28c Compare October 17, 2017 09:16
@jorgefilipecosta jorgefilipecosta force-pushed the add/configurable-text-color-button branch from 225c28c to f3aca2a Compare October 17, 2017 09:18
@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Oct 17, 2017

Thank you for the feedback @youknowriad 👍 I think I addressed the concerns raised.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. 🚢 it

@jorgefilipecosta jorgefilipecosta merged commit 5648768 into master Oct 17, 2017
@jorgefilipecosta jorgefilipecosta deleted the add/configurable-text-color-button branch October 17, 2017 10:32
@karmatosed
Copy link
Member

@jorgefilipecosta right now I am seeing this:

2017-11-13 at 20 20

This is after the button contrast check merge, I'm wondering if it's impacted by that?

@jorgefilipecosta
Copy link
Member Author

Hi @karmatosed, the contrast verification was only applied to button it did not affect the paragraph. In the screens, I see that a paragraph is selected with the same color for background and text and no contrast verification is appearing (because it was not yet added to paragraph). As long as the colors were the chosen ones, I'm not being able to see other problem, could you please describe the wrong behavior? So I can try to find the cause.

@karmatosed
Copy link
Member

Update: after chatting to @jorgefilipecosta it seems the paragraph hasn't been added. I was mistaken on seeing the issue closed. Thanks for confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inspector Controls The interface showing block settings and the controls available for each block Needs Design Feedback Needs general design feedback. [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants