UNPKG

@nex-ui/react

Version:

🎉 A beautiful, modern, and reliable React component library.

36 lines (33 loc) • 899 B
import { mergeProps, 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 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, sx: resolvedSx }; }; export { useSlotProps };