-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add background color control for table block #10611
Conversation
}, | ||
] } | ||
> | ||
<ContrastChecker |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
||
const applyFallbackStyles = withFallbackStyles( ( node, props ) => { | ||
const { textColor, backgroundColor } = props.attributes; | ||
const styles = node ? getComputedStyle( node.querySelector( 'tr' ) ) : undefined; |
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.
Currently only grabs fallback colors for the first row.
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.
Let's scale this back a little to just having the background color and not a text color also. We should only have this for the stripes not for every cell right now. I have some ideas how we can do this and will comment in issue but let's also make sure this gets a 'design feedback' label as this goes in for Wednesday because a UI change.
We need to remove text color options and focus just on background ones that can't become inaccessible, just for stripes. As part of this, we should remove the color picker. Color palette wise let's have it use a fixed palette. We have a few options: Ideally, we would go for 2 but with time stop of Wednesday, let's make sure we get something in. |
What if the stripes were a lighter or darker variant of the selected background color? Would that idea work? |
That could work as well! |
7c024ea
to
b58fdcc
Compare
I've refactored this quite a bit now from yesterday:
I think this makes the implementation a lot cleaner, and hopefully mergeable, but would love @jorgefilipecosta's feedback on the changes to color utils, ColorPalette and withColorContext. |
Hi @karmatosed - My understanding is that the colors can be provided by the theme, so potentially the second option would be preferable so that the colors are still in keeping with the theme. Having said that, I'm not sure how we can lighten the colors dynamically if they're specified through css. I think we'd have to only set the colors using inline styles (instead of classes) and lighten the colors in JavaScript. Potentially that could work, but might need input from a dev with more experience of themes / the color system to validate that approach. At the moment I've used a different approach - I've filtered the color palette down to only accessible colors, which means the red and black colors are no longer available: I know this is not a particularly great set of colors to choose from. Three or four of them are ok. Option 1 - I think I could make that work, but I worry about it being too prescriptive and maybe hard to undo in the future. |
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.
Hi @talldan I think if we manage to merge #10457 before this PR we may be able to simplify the changes here as it looks like the other PR is addressing a need from this PR.
I really like the feature being added here 👍
In the last version when I try to execute this branch I'm getting an error:
TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
at edit.js:47
const settings = select( 'core/editor' ).getEditorSettings(); | ||
const colors = settings.colors; | ||
const disableCustomColors = settings.disableCustomColors; | ||
const disableCustomColors = settings.disableCustomColors || ownProps.disableCustomColors; |
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.
In PR #10457 I'm adding the possibility to overwrite color definitions for a specific component. If we manage the land it before it this PR it may be very useful and simplify the changes here.
82d5ca7
to
c6c4cc9
Compare
Hi @karmatosed - I had a go at lightening and desaturating the theme colors, but it ended up being very hit and miss, and was hard to find a happy medium that works for a decent selection. The current version of this branch goes with your first recommendation - there's a static selection of colors: |
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.
Hi @talldan this PR is testing well for me, nice work 👍
I think it would be perfect if we could avoid the use of inline styles I created a PR and left a comment with a possible path to get us there.
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.
LGTM, minor comments aside 👍
I was confused by the createCustomColorsHOC
API at first but the JSDoc code examples helped me eventually grok it. I think that using render props here might be simpler than a HOC but then again I think that about most of our HOCs, so... 😀
|
||
export default compose( [ | ||
withCustomBackgroundColors( 'backgroundColor' ), | ||
] )( TableEdit ); |
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.
We don't need to use compose()
here since it's just one HOC.
export default withCustomBackgroundColors( 'backgroundColor' )( TableEdit );
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.
Very true, addressed in 38a74ad
const classes = classnames( { | ||
'has-fixed-layout': hasFixedLayout, | ||
'has-background': !! backgroundClass, | ||
[ backgroundClass ]: backgroundClass, | ||
} ); |
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 object given to classnames
should only map strings to booleans. I think for this use case we ought to pass backgroundClass
as an argument.
const classes = classnames( backgroundClass, {
'has-fixed-layout': hasFixedLayout,
'has-background': !! backgroundClass,
} );
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.
Good spot! Addressed in 8fddd40
- Remove text color control - Disable custom colors - Apply class names to table element instead of tr element - Remove JS striping
…ntrast with the default text color
… that contrast with the default text color" This reverts commit 8a39fbc.
… usages with custom colors array. Refactor withColorHOC. Ensure withSelect is not used when not needed, and ensure custom color HOC has the right display name Add tests for new createCustomColorsHOC
…ly class names to set the background color
…table block has custom background colors designed to meet contrast requirements
… of using the object form
d64ba6b
to
8fddd40
Compare
Requested changes have been addressed
673ef10
to
1384c41
Compare
👍 Nice |
* Add background and text color controls for table block * Modify fallback styles to use first table row * Make text color control apply to all rows, not only striped row * Simplify implementation of colors for table block. - Remove text color control - Disable custom colors - Apply class names to table element instead of tr element - Remove JS striping * Filter colors in table background color control to only those that contrast with the default text color * Remove errant tab * Export using a single statement * Revert "Filter colors in table background color control to only those that contrast with the default text color" This reverts commit 8a39fbc. * Fix issue with row element not being present when fallback styles first applied * Use a predefined set of background colors suitable for a table * Add createCustomColorsHOC HOC builder that creates withColors HOC for usages with custom colors array. Refactor withColorHOC. Ensure withSelect is not used when not needed, and ensure custom color HOC has the right display name Add tests for new createCustomColorsHOC * Use createCustomColorHOC for table backgrounds and refactor to use only class names to set the background color * Remove contrast checker from table block background color selector - table block has custom background colors designed to meet contrast requirements * Remove use of compose for single HOC * Modify use of classnames, pass backgroundColor as an argument instead of using the object form * update CHANGELOG
* Add background and text color controls for table block * Modify fallback styles to use first table row * Make text color control apply to all rows, not only striped row * Simplify implementation of colors for table block. - Remove text color control - Disable custom colors - Apply class names to table element instead of tr element - Remove JS striping * Filter colors in table background color control to only those that contrast with the default text color * Remove errant tab * Export using a single statement * Revert "Filter colors in table background color control to only those that contrast with the default text color" This reverts commit 8a39fbc. * Fix issue with row element not being present when fallback styles first applied * Use a predefined set of background colors suitable for a table * Add createCustomColorsHOC HOC builder that creates withColors HOC for usages with custom colors array. Refactor withColorHOC. Ensure withSelect is not used when not needed, and ensure custom color HOC has the right display name Add tests for new createCustomColorsHOC * Use createCustomColorHOC for table backgrounds and refactor to use only class names to set the background color * Remove contrast checker from table block background color selector - table block has custom background colors designed to meet contrast requirements * Remove use of compose for single HOC * Modify use of classnames, pass backgroundColor as an argument instead of using the object form * update CHANGELOG
Description
Adds background and text color controls to the table block.
Works with both Regular and Stripes style variations of the table block.
How has this been tested?
Screenshots
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: