@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
51 lines (48 loc) • 1.73 kB
JavaScript
import { getBreakpointValue, getSize } from '@mantine/styles';
function getSortedKeys(value, theme) {
const sorted = Object.keys(value).filter((breakpoint) => breakpoint !== "base").sort((a, b) => getBreakpointValue(getSize({ size: a, sizes: theme.breakpoints })) - getBreakpointValue(getSize({ size: b, sizes: theme.breakpoints })));
return "base" in value ? ["base", ...sorted] : sorted;
}
function getResponsiveValue({ value, theme, getValue, property }) {
if (value == null) {
return void 0;
}
if (typeof value === "object") {
const result = getSortedKeys(value, theme).reduce((acc, breakpointKey) => {
if (breakpointKey === "base" && value.base !== void 0) {
const baseValue = getValue(value.base, theme);
if (Array.isArray(property)) {
property.forEach((prop) => {
acc[prop] = baseValue;
});
return acc;
}
acc[property] = baseValue;
return acc;
}
const breakpointValue = getValue(value[breakpointKey], theme);
if (Array.isArray(property)) {
acc[theme.fn.largerThan(breakpointKey)] = {};
property.forEach((prop) => {
acc[theme.fn.largerThan(breakpointKey)][prop] = breakpointValue;
});
return acc;
}
acc[theme.fn.largerThan(breakpointKey)] = {
[property]: breakpointValue
};
return acc;
}, {});
return result;
}
const cssValue = getValue(value, theme);
if (Array.isArray(property)) {
return property.reduce((acc, prop) => {
acc[prop] = cssValue;
return acc;
}, {});
}
return { [property]: cssValue };
}
export { getResponsiveValue };
//# sourceMappingURL=get-responsive-value.js.map