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

[Styles] expose getContrastText method #18577

Closed
numToStr opened this issue Nov 26, 2019 · 5 comments
Closed

[Styles] expose getContrastText method #18577

numToStr opened this issue Nov 26, 2019 · 5 comments

Comments

@numToStr
Copy link
Contributor

Motivation 🔦

Suppose, the app has 3 different types of background-color like twitter, by exposing getContrastText method it can really help to make custom themes. Currently, there is no way of calculating contrasting text.primary color when creating a theme with createMuiTheme

We can get getContrastText by calling useTheme hook. But I suppose It can be used standalone without calling the hook just like lighten, darken, getContrastRatio methods.

@oliviertassinari
Copy link
Member

The method depends on the theme to behave correctly (have a look at the implementation to see the dependencies). I would suggest two possible alternatives. 1. You can start from a lower level helper: getContrastRatio that is standalone. 2. You can make your theme global and import is directly where needed.

@numToStr
Copy link
Contributor Author

I can't find about getContrastRatio in the docs.

@oliviertassinari
Copy link
Member

Yeah, we have an open issue about adding documention for our color helpers.

@oliviertassinari
Copy link
Member

#13039

@dantman
Copy link
Contributor

dantman commented Feb 8, 2020

I just ran into/discovered this issue because I need to use getContrastText in an override style, which means the theme object does not exist yet. But I suppose this suggests that overrides may need an overhaul.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants