How to change the text color based on the background?
Answered
B33fb0n3 posted this in #help-forum
B33fb0n3OP
Hey, React colorful has a demo page. You can change the background with their offered npm package and the color of the text changes automatically based on the background.
How does that work?
I looked at their CSS code, but couldn't find anything related. Maybe I missed something.
Useful links:
https://omgovich.github.io/react-colorful/
https://github.com/omgovich/react-colorful
How does that work?
I looked at their CSS code, but couldn't find anything related. Maybe I missed something.
Useful links:
https://omgovich.github.io/react-colorful/
https://github.com/omgovich/react-colorful
Answered by joulev
it works by simply analysing the active colour and deciding whether it is a dark or a bright colour https://github.com/omgovich/react-colorful/blob/c7e87161d71be9156b0c149d0e110fa24fd7037d/demo/src/index.tsx#L39
2 Replies
@B33fb0n3 Hey, React colorful has a demo page. You can change the background with their offered npm package and the color of the text changes automatically based on the background.
**How does that work?**
I looked at their CSS code, but couldn't find anything related. Maybe I missed something.
Useful links:
https://omgovich.github.io/react-colorful/
https://github.com/omgovich/react-colorful
it works by simply analysing the active colour and deciding whether it is a dark or a bright colour https://github.com/omgovich/react-colorful/blob/c7e87161d71be9156b0c149d0e110fa24fd7037d/demo/src/index.tsx#L39
Answer