1 | import clsx from 'clsx';
|
2 | export default function mergeSlotProps(externalSlotProps, defaultSlotProps) {
|
3 | if (!externalSlotProps) {
|
4 | return defaultSlotProps;
|
5 | }
|
6 | if (typeof externalSlotProps === 'function' || typeof defaultSlotProps === 'function') {
|
7 | return ownerState => {
|
8 | const defaultSlotPropsValue = typeof defaultSlotProps === 'function' ? defaultSlotProps(ownerState) : defaultSlotProps;
|
9 | const externalSlotPropsValue = typeof externalSlotProps === 'function' ? externalSlotProps({
|
10 | ...ownerState,
|
11 | ...defaultSlotPropsValue
|
12 | }) : externalSlotProps;
|
13 | const className = clsx(ownerState?.className, defaultSlotPropsValue?.className, externalSlotPropsValue?.className);
|
14 | return {
|
15 | ...defaultSlotPropsValue,
|
16 | ...externalSlotPropsValue,
|
17 | ...(!!className && {
|
18 | className
|
19 | }),
|
20 | ...(defaultSlotPropsValue?.style && externalSlotPropsValue?.style && {
|
21 | style: {
|
22 | ...defaultSlotPropsValue.style,
|
23 | ...externalSlotPropsValue.style
|
24 | }
|
25 | })
|
26 | };
|
27 | };
|
28 | }
|
29 | const className = clsx(defaultSlotProps?.className, externalSlotProps?.className);
|
30 | return {
|
31 | ...defaultSlotProps,
|
32 | ...externalSlotProps,
|
33 | ...(!!className && {
|
34 | className
|
35 | }),
|
36 | ...(defaultSlotProps?.style && externalSlotProps?.style && {
|
37 | style: {
|
38 | ...defaultSlotProps.style,
|
39 | ...externalSlotProps.style
|
40 | }
|
41 | })
|
42 | };
|
43 | } |
\ | No newline at end of file |