@chakra-ui/react
Version:
Responsive and accessible React UI components built with React and Emotion
45 lines (41 loc) • 1.21 kB
JavaScript
;
;
var entries = require('../utils/entries.cjs');
var memo = require('../utils/memo.cjs');
const SPECIAL_KEY_REGEX = /^@|&|&$/;
const createConditions = (options) => {
const { breakpoints, conditions: conds = {} } = options;
const conditions = entries.mapEntries(conds, (key, value) => [`_${key}`, value]);
const values = Object.assign({}, conditions, breakpoints.conditions);
function keys() {
return Object.keys(values);
}
function has(key) {
return keys().includes(key) || SPECIAL_KEY_REGEX.test(key) || key.startsWith("_");
}
const sort = memo.memo((paths) => {
return paths.filter((v) => v !== "base").sort((a, b) => {
const aa = has(a);
const bb = has(b);
if (aa && !bb) return 1;
if (!aa && bb) return -1;
return 0;
});
});
function expandAtRule(key) {
if (!key.startsWith("@breakpoint")) return key;
return breakpoints.getCondition(key.replace("@breakpoint ", ""));
}
function resolve(key) {
return Reflect.get(values, key) || key;
}
return {
keys,
sort,
has,
resolve,
breakpoints: breakpoints.keys(),
expandAtRule
};
};
exports.createConditions = createConditions;