seti-ramesesv1
Version:
Reusable components and context for Next.js apps
56 lines (53 loc) • 1.18 kB
JavaScript
import defaultSxConfig from './defaultSxConfig.js';
import { isPlainObject } from '../../../utils/esm/deepmerge/deepmerge.js';
const splitProps = props => {
const result = {
systemProps: {},
otherProps: {}
};
const config = props?.theme?.unstable_sxConfig ?? defaultSxConfig;
Object.keys(props).forEach(prop => {
if (config[prop]) {
result.systemProps[prop] = props[prop];
} else {
result.otherProps[prop] = props[prop];
}
});
return result;
};
function extendSxProp(props) {
const {
sx: inSx,
...other
} = props;
const {
systemProps,
otherProps
} = splitProps(other);
let finalSx;
if (Array.isArray(inSx)) {
finalSx = [systemProps, ...inSx];
} else if (typeof inSx === 'function') {
finalSx = (...args) => {
const result = inSx(...args);
if (!isPlainObject(result)) {
return systemProps;
}
return {
...systemProps,
...result
};
};
} else {
finalSx = {
...systemProps,
...inSx
};
}
return {
...otherProps,
sx: finalSx
};
}
export { extendSxProp as default };
//# sourceMappingURL=extendSxProp.js.map