Skip to content

Instantly share code, notes, and snippets.

@jepser
Created May 28, 2019 21:32
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 jepser/fbca1b314fd1b479e69e8b04c127d410 to your computer and use it in GitHub Desktop.
Save jepser/fbca1b314fd1b479e69e8b04c127d410 to your computer and use it in GitHub Desktop.
/**
* Call the styles factory for with the correct props for each media query
* @param {function} stylesGenerator function that generates the styles
*
* @returns {array} array of styles to be applied for the registered media queries
*/
export const generateResponsiveStyles = stylesGenerator => props =>
Object.keys(mediaqueries).reduce((rules, mq) => {
if (!props[mq]) return rules;
const styles = mediaqueries[mq]`
${stylesGenerator(props[mq])}
`;
return [...rules, styles];
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment