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

[Alert] Use getContrastText for filled variant font color #29813

Merged
merged 6 commits into from Jun 22, 2022
Merged

[Alert] Use getContrastText for filled variant font color #29813

merged 6 commits into from Jun 22, 2022

Conversation

SamoraMabuya
Copy link
Contributor

@SamoraMabuya SamoraMabuya commented Nov 21, 2021

I have made a small update in Alert.js

Changes:

  1. Implementation of getContrastText method

image

Deploy preview: https://deploy-preview-29813--material-ui.netlify.app/components/alert/

Closes #29731

@mui-pr-bot
Copy link

mui-pr-bot commented Nov 21, 2021

Details of bundle changes

Generated by 🚫 dangerJS against c54e076

@@ -43,6 +43,7 @@ const AlertRoot = styled(Paper, {
})(({ theme, ownerState }) => {
const getColor = theme.palette.mode === 'light' ? darken : lighten;
const getBackgroundColor = theme.palette.mode === 'light' ? lighten : darken;
const getContrastText = theme.palette.mode === 'light' ? lighten : darken;
Copy link
Member

@mbrookes mbrookes Nov 21, 2021

Choose a reason for hiding this comment

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

This returns the same as getBackgroundColor, so is redundant. It also doesn't do what its name suggests.

We have getContrastText in the theme. @mnajdova is it also in System? I couldn't find it documented for either theme or system, but I believe it's what @reramjiawan was referring to in the related issue.

Copy link
Member

Choose a reason for hiding this comment

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

We only have it in the theme.palette as part of the @mui/material's theme.

@@ -71,7 +72,10 @@ const AlertRoot = styled(Paper, {
}),
...(color &&
ownerState.variant === 'filled' && {
color: '#fff',
color:
theme.palette.mode === 'dark'
Copy link
Member

Choose a reason for hiding this comment

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

This (and line 46) relate to palette mode, but the value of contrast text should presumably depend on the background color being contrasted against, regardless of mode.

The standard variant already has a light background with dark text, so I'm beginning to wonder if the premise of #29731 is faulty, although I suppose it might be the case that user provided colors used in the standard variant are light enough to justify dark text.

@mbrookes mbrookes added component: alert This is the name of the generic UI component, not the React module! new feature New feature or request labels Nov 21, 2021
@mbrookes mbrookes changed the title getContrastText method added [Alert] Use getContrastText for filled variant font color Nov 21, 2021
@mnajdova mnajdova mentioned this pull request May 18, 2022
1 task
@siriwatknp
Copy link
Member

siriwatknp commented May 20, 2022

@SamoraMabuya Thanks for your first contribution. Can you explain the issue you are trying to fix?

@SamoraMabuya
Copy link
Contributor Author

@siriwatknp

I was trying to get variant font color to show correct contrast color with getContrastTest method. From what I understand the test contrast is supposed to be dependent on the background color.

@mbrookes
Copy link
Member

mbrookes commented May 25, 2022

@siriwatknp

Can you explain the issue you are trying to fix?

#29731, but see #29813 (comment) (second sentence).

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

Please see my comment. I don't think the darken and lighten is needed because the color just need to have enough contrast with the background and we have the util in theme.palette.getContrastText for that.

Co-authored-by: Siriwat K <siriwatkunaporn@gmail.com>
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Looks good to me now 👍

@mui-bot
Copy link

mui-bot commented Jun 22, 2022

Details of bundle changes

Generated by 🚫 dangerJS against a04cdbe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: alert This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Alert] Filled variant should make use getContrastText instead of hard coding the color white
6 participants