UNPKG

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