Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Lkubok
Created June 17, 2020 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lkubok/b038f9b94c3a809aa775fe2b4d82feaa to your computer and use it in GitHub Desktop.
Save Lkubok/b038f9b94c3a809aa775fe2b4d82feaa to your computer and use it in GitHub Desktop.
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