@chakra-v2/styled-system
Version:
Style function for css-in-js building component libraries
37 lines (33 loc) • 1.05 kB
JavaScript
;
var utils = require('@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 = utils.runIfFn(styles[key], theme);
if (value == null)
continue;
value = utils.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;
};
exports.expandResponsive = expandResponsive;