@nex-ui/react
Version:
🎉 A beautiful, modern, and reliable React component library.
38 lines (35 loc) • 1.02 kB
JavaScript
import { mergeProps, mergeRefs, isArray, isPlainObject } from '@nex-ui/utils';
import { useMemo } from 'react';
const useSlotProps = ({ style, externalSlotProps, externalForwardedProps, additionalProps, a11y })=>{
const props = mergeProps(additionalProps, externalForwardedProps, externalSlotProps, a11y);
const ref = mergeRefs(additionalProps?.ref, externalForwardedProps?.ref, externalSlotProps?.ref);
const resolvedSx = useMemo(()=>{
if (!style) {
return props.sx;
}
if (isArray(props.sx)) {
return props.sx.reduce((acc, v)=>[
...acc,
v
], [
style
]).flat(1);
}
if (isPlainObject(props.sx)) {
return [
style,
props.sx
];
}
return style;
}, [
props.sx,
style
]);
return {
...props,
ref,
sx: resolvedSx
};
};
export { useSlotProps };