@rjsf/mui
Version:
Material UI 7 theme, fields and widgets for react-jsonschema-form
33 lines • 1.32 kB
JavaScript
/**
* Extract props meant for MUI components from the `options` field of the `uiSchema`.
* @param {UIOptionsType} options - The options from the uiSchema
* @param {string[]} [propsToFilter] - An optional allowlist of props to return (used by button/icon components)
* @param {boolean} [rjsfSlotPropsOnly] - If true, returns only `rjsfSlotProps`, preventing root-level prop bleeding
* @returns {P}
*/
export function getMuiProps(options, propsToFilter, rjsfSlotPropsOnly) {
const muiProps = (options === null || options === void 0 ? void 0 : options.mui) || {};
if (rjsfSlotPropsOnly) {
const { rjsfSlotProps } = muiProps;
return { rjsfSlotProps };
}
if (propsToFilter) {
return Object.keys(muiProps)
.filter((key) => propsToFilter.includes(key))
.reduce((obj, key) => {
obj[key] = muiProps[key];
return obj;
}, {});
}
return muiProps;
}
export function computeSxProps(sxProps, muiProps) {
if (!muiProps) {
return sxProps;
}
if (Array.isArray(muiProps === null || muiProps === void 0 ? void 0 : muiProps.sx)) {
return [sxProps, ...muiProps.sx];
}
return { ...sxProps, ...muiProps === null || muiProps === void 0 ? void 0 : muiProps.sx };
}
//# sourceMappingURL=util.js.map