UNPKG

@chakra-v2/styled-system

Version:

Style function for css-in-js building component libraries

35 lines (32 loc) 1.02 kB
import { runIfFn, isObject } from '@chakra-v2/utils'; const expandResponsive = (styles) => (theme) => { if (!theme.__breakpoints) return styles; const { isResponsive, toArrayValue, media: medias } = theme.__breakpoints; const computedStyles = {}; for (const key in styles) { let value = runIfFn(styles[key], theme); if (value == null) continue; value = isObject(value) && isResponsive(value) ? toArrayValue(value) : value; if (!Array.isArray(value)) { computedStyles[key] = value; continue; } const queries = value.slice(0, medias.length).length; for (let index = 0; index < queries; index += 1) { const media = medias?.[index]; if (!media) { computedStyles[key] = value[index]; continue; } computedStyles[media] = computedStyles[media] || {}; if (value[index] == null) { continue; } computedStyles[media][key] = value[index]; } } return computedStyles; }; export { expandResponsive };