UNPKG

2.07 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4Object.defineProperty(exports, "__esModule", {
5 value: true
6});
7exports.default = useSlotProps;
8var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10var _utils = require("@mui/utils");
11var _appendOwnerState = _interopRequireDefault(require("./appendOwnerState"));
12var _mergeSlotProps = _interopRequireDefault(require("./mergeSlotProps"));
13var _resolveComponentProps = _interopRequireDefault(require("./resolveComponentProps"));
14const _excluded = ["elementType", "externalSlotProps", "ownerState"];
15/**
16 * @ignore - do not document.
17 * Builds the props to be passed into the slot of an unstyled component.
18 * It merges the internal props of the component with the ones supplied by the user, allowing to customize the behavior.
19 * If the slot component is not a host component, it also merges in the `ownerState`.
20 *
21 * @param parameters.getSlotProps - A function that returns the props to be passed to the slot component.
22 */
23function useSlotProps(parameters) {
24 var _parameters$additiona;
25 const {
26 elementType,
27 externalSlotProps,
28 ownerState
29 } = parameters,
30 rest = (0, _objectWithoutPropertiesLoose2.default)(parameters, _excluded);
31 const resolvedComponentsProps = (0, _resolveComponentProps.default)(externalSlotProps, ownerState);
32 const {
33 props: mergedProps,
34 internalRef
35 } = (0, _mergeSlotProps.default)((0, _extends2.default)({}, rest, {
36 externalSlotProps: resolvedComponentsProps
37 }));
38 const ref = (0, _utils.unstable_useForkRef)(internalRef, resolvedComponentsProps == null ? void 0 : resolvedComponentsProps.ref, (_parameters$additiona = parameters.additionalProps) == null ? void 0 : _parameters$additiona.ref);
39 const props = (0, _appendOwnerState.default)(elementType, (0, _extends2.default)({}, mergedProps, {
40 ref
41 }), ownerState);
42 return props;
43}
\No newline at end of file