-
Notifications
You must be signed in to change notification settings - Fork 920
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
Invert foreground color when background is light #15230
Conversation
746f984
to
4759542
Compare
A Storybook has been deployed to preview UI for the latest push |
4759542
to
0fe6982
Compare
A Storybook has been deployed to preview UI for the latest push |
For readability, the foreground color is inverted when the background is light. This is based on WCGA2.0 spec.
0fe6982
to
fa9393c
Compare
A Storybook has been deployed to preview UI for the latest push |
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.
Okay, so this looks pretty good to me but I had an idea as I was reading the last bit of the PR: What if instead of adding all of these JS props we optionally added a
--override-readability-color-rgb: 0, 0, 0;
--override-readability-color: rgb(var(--override-readability-color-rgb));
css variable. Then each component that might be overridden could do this:
styled.whatever`
// Fall back to white
color: var(--override-readability-color, #ffffff);
`
styled.other`
// Fall back to --interactive9
color: var(--override-readability-color, var(--interactive9));
`
styled.withAlpha`
// Fallback to white, either with 0.8 opacity
color: rgba(var(--override-readability-color-rgb, 255, 255, 255), 0.8);
`
Then we wouldn't have to pass these JS variables around all over the place!
You could set the variables in components/brave_new_tab_ui/containers/newTab/index.tsx
useEffect(() => {
if (currentColorsAreReadable) return;
const style = document.documentElement.style;
style.setProperty('--override-readability-color-rgb', '0, 0, 0');
style.setProperty('--override-readability-color', 'rgb(var(--override-readability-color))');
return () => {
style.removeProperty('--override-readability-color-rgb')
style.removeProperty('--override-readability-color')
}
}, [background, otherThingsThatChangeTheBackground]);
(you don't have to change anything, it's just an idea I came up with)
margin-right: ${p => p.textDirection === 'ltr' && '8px'}; | ||
margin-left: ${p => p.textDirection === 'rtl' && '8px'}; | ||
border-right: ${p => p.textDirection === 'ltr' && '1px solid rgba(255, 255, 255, 0.6)'}; | ||
border-left: ${p => p.textDirection === 'rtl' && '1px solid rgba(255, 255, 255, 0.6)'}; | ||
border-right: ${p => p.textDirection === 'ltr' && `1px solid ${p.color + '99' /* == 0.6 */}`}; |
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.
It's annoying that you can destructure a color, right? There's actually a proposal for it but I don't think any browsers implement it yet.
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.
Oh, yeah. It looks awesome. I guess it's still in WD status, so not started implementing it yet?
components/brave_new_tab_ui/components/default/widget/assets/ellipsis.ts
Outdated
Show resolved
Hide resolved
When we use setProperty(), a color value defined in reset.css wins over our css variables. In order to avoid this, use createGlobalStyle and override color value in resets.css when we need more readable color
9cc10ce
to
341c5ff
Compare
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.
Thanks @fallaciousreasoning ! I love the "variable idea" so much. But there was a weird thing I couldn't understand. I made an alternative way to stick to the idea. Could you please take a look again?
components/brave_new_tab_ui/components/default/widget/assets/ellipsis.ts
Outdated
Show resolved
Hide resolved
margin-right: ${p => p.textDirection === 'ltr' && '8px'}; | ||
margin-left: ${p => p.textDirection === 'rtl' && '8px'}; | ||
border-right: ${p => p.textDirection === 'ltr' && '1px solid rgba(255, 255, 255, 0.6)'}; | ||
border-left: ${p => p.textDirection === 'rtl' && '1px solid rgba(255, 255, 255, 0.6)'}; | ||
border-right: ${p => p.textDirection === 'ltr' && `1px solid ${p.color + '99' /* == 0.6 */}`}; |
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.
Oh, yeah. It looks awesome. I guess it's still in WD status, so not started implementing it yet?
|
||
// override color property in resets.css. Not sure why this happens but, | ||
// the value in the stylesheet wins over variables above. | ||
color: inherit |
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.
I couldn't figure out why this happens. This happens when we declare variables with setProperty(). I tried setting property for body
, but it didn't work. As a workaround, I override color
here.
The previous trial can be found at 27a0d34
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.
I think I like yours better anyway 😄 It's weird we need to set the color: inherit
though - I just tested removing it and it seems to work without
css`
--override-readability-color-rgb: 0, 0, 0;
--override-readability-color: rgb(0, 0, 0);
`
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.
Ah yeah, I found the culprit. I used wrong variable for some UI.
- color: var(--override-readability-color-rgb, #FFFFFF); <--! oops, rgb is 0, 0, 0 -->
+ color: var(--override-readability-color, #FFFFFF);
341c5ff
to
46371b6
Compare
A Storybook has been deployed to preview UI for the latest push |
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.
Still LGTM @sangwoo108 - I like your solution with createGlobalStyle
more than my useEffect
anyway - it's much more elegant.
components/brave_new_tab_ui/components/default/widget/widgetMenu.tsx
Outdated
Show resolved
Hide resolved
|
||
// override color property in resets.css. Not sure why this happens but, | ||
// the value in the stylesheet wins over variables above. | ||
color: inherit |
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.
I think I like yours better anyway 😄 It's weird we need to set the color: inherit
though - I just tested removing it and it seems to work without
css`
--override-readability-color-rgb: 0, 0, 0;
--override-readability-color: rgb(0, 0, 0);
`
A Storybook has been deployed to preview UI for the latest push |
Thank you so much @fallaciousreasoning ! I learned a lot from you as always! |
Resolves brave/brave-browser#25392
Resolves brave/brave-browser#25393
For readability, the foreground color is inverted when the background is light. This is based on WCGA2.0 spec.
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
,npm run lint
,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
Automated
test-unit ColorUtil.test.ts
Manual
Even when using light solid color background, we should be read stats UI easily.
Storybook