-
Notifications
You must be signed in to change notification settings - Fork 701
Add bgLighten to Base #446
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,15 @@ const convertFontSizeToPx = function (fontSize) { | |
| return convertedFontSize; | ||
| }; | ||
|
|
||
| const hexToRGB = function (hex) { | ||
| hex = (hex.charAt(0) === '#') ? hex.substring(1, 7) : hex; | ||
| const RGB = []; | ||
| RGB.push(parseInt(hex.substring(0, 2), 16)); // R | ||
| RGB.push(parseInt(hex.substring(2, 4), 16)); // G | ||
| RGB.push(parseInt(hex.substring(4, 6), 16)); // B | ||
| return RGB; | ||
| }; | ||
|
|
||
| export const getStyles = function getStyles() { | ||
| if (process.env.NODE_ENV !== 'production' && typeof this.warnedAboutFontSize === 'undefined') { | ||
| this.warnedAboutFontSize = false; | ||
|
|
@@ -68,7 +77,8 @@ export const getStyles = function getStyles() { | |
| textAlign, | ||
| bgColor, | ||
| bgImage, | ||
| bgDarken, | ||
| bgOverlayColour, | ||
| bgOverlayIntensity, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't call this prop "intensity" as that would refer to the saturation of the colour: https://www.uwgb.edu/heuerc/2D/ColorTerms.html Instead I would just call this "opacity" or "opacify" or "transparentize" depending on what it'll do.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its bgTransparentize now ✨ |
||
| bgSize, | ||
| bgPosition, | ||
| bgRepeat, | ||
|
|
@@ -135,9 +145,11 @@ export const getStyles = function getStyles() { | |
| styles.backgroundColor = color; | ||
| } | ||
| if (bgImage) { | ||
| if (bgDarken) { | ||
| if (bgOverlayColour) { | ||
| const rgbOverlay = hexToRGB(bgOverlayColour); | ||
| const bi = bgOverlayIntensity || 0.5; //default intensity - 0.5 | ||
| styles.backgroundImage = | ||
| `linear-gradient( rgba(0, 0, 0, ${bgDarken}), rgba(0, 0, 0, ${bgDarken}) ), url(${bgImage})`; | ||
| `linear-gradient( rgba(${rgbOverlay.join(',')}, ${bi}), rgba(${rgbOverlay.join(',')}, ${bi}) ), url(${bgImage})`; | ||
| } else { | ||
| styles.backgroundImage = `url(${bgImage})`; | ||
| } | ||
|
|
||
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.
Instead of maintaining this piece of code ourselves it should probably use a helper. Polished has some excellent ones and we won't need to pull in the entire library ✨
https://polished.js.org/docs/#transparentize
or
https://polished.js.org/docs/#parsetorgb