Created
June 17, 2020 20:30
-
-
Save Lkubok/b038f9b94c3a809aa775fe2b4d82feaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createContext } from 'react'; | |
import PropTypes from 'prop-types'; | |
import { useSelector } from 'react-redux'; | |
import { split, trimEnd, toNumber } from 'lodash'; | |
import colors from 'res/colors'; | |
import { selectors } from 'store/branding'; | |
import { hexToHSL } from 'utils/helpers'; | |
export const BrandingContext = createContext({}); | |
export const BrandingProvider = ({ children }) => { | |
const brandingColor = useSelector(selectors.getBrandColor); | |
const brandingCardImage = useSelector(selectors.getBrandingCardImage); | |
const haveBrandedCardImage = !!brandingCardImage; | |
const brandingLogo = useSelector(selectors.getBrandingLogo); | |
const brandingLogoImageType = useSelector(selectors.getLogoImageType); | |
const brandingCardImageType = useSelector(selectors.getCardImageType); | |
const brandingLoading = useSelector(selectors.getBrandingLoading); | |
const isBrandedColor = !!brandingColor; | |
const brandingHslColor = brandingColor && hexToHSL(brandingColor); | |
const brandColorLuminosity = toNumber(trimEnd(split(brandingHslColor, ',')[2], '%)')); | |
const brandingHighlightColor = brandColorLuminosity > 65 ? colors.dusk : colors.white; | |
return ( | |
<BrandingContext.Provider | |
value={{ | |
brandingCardImage, | |
brandingCardImageType, | |
brandingColor, | |
brandingHighlightColor, | |
brandingLoading, | |
brandingLogo, | |
brandingLogoImageType, | |
haveBrandedCardImage, | |
isBrandedColor, | |
}} | |
> | |
{children} | |
</BrandingContext.Provider> | |
); | |
}; | |
BrandingProvider.propTypes = { | |
children: PropTypes.node, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment