Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101032467
mergeSlotProps.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 5, 00:25
Size
3 KB
Mime Type
text/x-java
Expires
Fri, Feb 7, 00:25 (2 d)
Engine
blob
Format
Raw Data
Handle
24080236
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
mergeSlotProps.js
View Options
import _extends from "@babel/runtime/helpers/esm/extends";
import clsx from 'clsx';
import extractEventHandlers from './extractEventHandlers';
import omitEventHandlers from './omitEventHandlers';
/**
* Merges the slot component internal props (usually coming from a hook)
* with the externally provided ones.
*
* The merge order is (the latter overrides the former):
* 1. The internal props (specified as a getter function to work with get*Props hook result)
* 2. Additional props (specified internally on an unstyled component)
* 3. External props specified on the owner component. These should only be used on a root slot.
* 4. External props specified in the `slotProps.*` prop.
* 5. The `className` prop - combined from all the above.
* @param parameters
* @returns
*/
export default function mergeSlotProps(parameters) {
const {
getSlotProps,
additionalProps,
externalSlotProps,
externalForwardedProps,
className
} = parameters;
if (!getSlotProps) {
// The simpler case - getSlotProps is not defined, so no internal event handlers are defined,
// so we can simply merge all the props without having to worry about extracting event handlers.
const joinedClasses = clsx(externalForwardedProps?.className, externalSlotProps?.className, className, additionalProps?.className);
const mergedStyle = _extends({}, additionalProps?.style, externalForwardedProps?.style, externalSlotProps?.style);
const props = _extends({}, additionalProps, externalForwardedProps, externalSlotProps);
if (joinedClasses.length > 0) {
props.className = joinedClasses;
}
if (Object.keys(mergedStyle).length > 0) {
props.style = mergedStyle;
}
return {
props,
internalRef: undefined
};
}
// In this case, getSlotProps is responsible for calling the external event handlers.
// We don't need to include them in the merged props because of this.
const eventHandlers = extractEventHandlers(_extends({}, externalForwardedProps, externalSlotProps));
const componentsPropsWithoutEventHandlers = omitEventHandlers(externalSlotProps);
const otherPropsWithoutEventHandlers = omitEventHandlers(externalForwardedProps);
const internalSlotProps = getSlotProps(eventHandlers);
// The order of classes is important here.
// Emotion (that we use in libraries consuming MUI Base) depends on this order
// to properly override style. It requires the most important classes to be last
// (see https://github.com/mui/material-ui/pull/33205) for the related discussion.
const joinedClasses = clsx(internalSlotProps?.className, additionalProps?.className, className, externalForwardedProps?.className, externalSlotProps?.className);
const mergedStyle = _extends({}, internalSlotProps?.style, additionalProps?.style, externalForwardedProps?.style, externalSlotProps?.style);
const props = _extends({}, internalSlotProps, additionalProps, otherPropsWithoutEventHandlers, componentsPropsWithoutEventHandlers);
if (joinedClasses.length > 0) {
props.className = joinedClasses;
}
if (Object.keys(mergedStyle).length > 0) {
props.style = mergedStyle;
}
return {
props,
internalRef: internalSlotProps.ref
};
}
Event Timeline
Log In to Comment