UNPKG

1.68 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3const _excluded = ["elementType", "externalSlotProps", "ownerState"];
4import { unstable_useForkRef as useForkRef } from '@mui/utils';
5import appendOwnerState from './appendOwnerState';
6import mergeSlotProps from './mergeSlotProps';
7import resolveComponentProps from './resolveComponentProps';
8/**
9 * @ignore - do not document.
10 * Builds the props to be passed into the slot of an unstyled component.
11 * It merges the internal props of the component with the ones supplied by the user, allowing to customize the behavior.
12 * If the slot component is not a host component, it also merges in the `ownerState`.
13 *
14 * @param parameters.getSlotProps - A function that returns the props to be passed to the slot component.
15 */
16export default function useSlotProps(parameters) {
17 var _parameters$additiona;
18 const {
19 elementType,
20 externalSlotProps,
21 ownerState
22 } = parameters,
23 rest = _objectWithoutPropertiesLoose(parameters, _excluded);
24 const resolvedComponentsProps = resolveComponentProps(externalSlotProps, ownerState);
25 const {
26 props: mergedProps,
27 internalRef
28 } = mergeSlotProps(_extends({}, rest, {
29 externalSlotProps: resolvedComponentsProps
30 }));
31 const ref = useForkRef(internalRef, resolvedComponentsProps == null ? void 0 : resolvedComponentsProps.ref, (_parameters$additiona = parameters.additionalProps) == null ? void 0 : _parameters$additiona.ref);
32 const props = appendOwnerState(elementType, _extends({}, mergedProps, {
33 ref
34 }), ownerState);
35 return props;
36}
\No newline at end of file