22 lines
693 B
JavaScript
22 lines
693 B
JavaScript
import fastDeepAssign from '@mui/utils/fastDeepAssign';
|
|
function compose(...styles) {
|
|
const handlers = styles.reduce((acc, style) => {
|
|
style.filterProps.forEach(prop => {
|
|
acc[prop] = style;
|
|
});
|
|
return acc;
|
|
}, {});
|
|
const fn = props => {
|
|
const result = {};
|
|
for (const prop in props) {
|
|
if (handlers[prop]) {
|
|
fastDeepAssign(result, handlers[prop](props));
|
|
}
|
|
}
|
|
return result;
|
|
};
|
|
fn.propTypes = process.env.NODE_ENV !== 'production' ? styles.reduce((acc, style) => Object.assign(acc, style.propTypes), {}) : {};
|
|
fn.filterProps = styles.reduce((acc, style) => acc.concat(style.filterProps), []);
|
|
return fn;
|
|
}
|
|
export default compose; |