37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
'use client';
|
|
|
|
import { unstable_useForkRef as useForkRef } from '@mui/utils';
|
|
import { appendOwnerState } from './appendOwnerState';
|
|
import { mergeSlotProps } from './mergeSlotProps';
|
|
import { resolveComponentProps } from './resolveComponentProps';
|
|
/**
|
|
* @ignore - do not document.
|
|
* Builds the props to be passed into the slot of an unstyled component.
|
|
* It merges the internal props of the component with the ones supplied by the user, allowing to customize the behavior.
|
|
* If the slot component is not a host component, it also merges in the `ownerState`.
|
|
*
|
|
* @param parameters.getSlotProps - A function that returns the props to be passed to the slot component.
|
|
*/
|
|
export function useSlotProps(parameters) {
|
|
const {
|
|
elementType,
|
|
externalSlotProps,
|
|
ownerState,
|
|
skipResolvingSlotProps = false,
|
|
...rest
|
|
} = parameters;
|
|
const resolvedComponentsProps = skipResolvingSlotProps ? {} : resolveComponentProps(externalSlotProps, ownerState);
|
|
const {
|
|
props: mergedProps,
|
|
internalRef
|
|
} = mergeSlotProps({
|
|
...rest,
|
|
externalSlotProps: resolvedComponentsProps
|
|
});
|
|
const ref = useForkRef(internalRef, resolvedComponentsProps?.ref, parameters.additionalProps?.ref);
|
|
const props = appendOwnerState(elementType, {
|
|
...mergedProps,
|
|
ref
|
|
}, ownerState);
|
|
return props;
|
|
} |