1 | import * as React from 'react';
|
2 | import { ClassValue } from 'clsx';
|
3 | export type WithCommonProps<T> = T & {
|
4 | className?: string;
|
5 | style?: React.CSSProperties;
|
6 | ref?: React.Ref<any>;
|
7 | };
|
8 | type EventHandlers = Record<string, React.EventHandler<any>>;
|
9 | type ExtractComponentProps<P> = P extends infer T | ((ownerState: any) => infer T) ? T : never;
|
10 | /**
|
11 | * An internal function to create a Material UI slot.
|
12 | *
|
13 | * This is an advanced version of Base UI `useSlotProps` because Material UI allows leaf component to be customized via `component` prop
|
14 | * while Base UI does not need to support leaf component customization.
|
15 | *
|
16 | * @param {string} name: name of the slot
|
17 | * @param {object} parameters
|
18 | * @returns {[Slot, slotProps]} The slot's React component and the slot's props
|
19 | *
|
20 | * Note: the returned slot's props
|
21 | * - will never contain `component` prop.
|
22 | * - might contain `as` prop.
|
23 | */
|
24 | export default function useSlot<T extends string, ElementType extends React.ElementType, SlotProps, OwnerState extends {}, ExternalSlotProps extends {
|
25 | component?: React.ElementType;
|
26 | ref?: React.Ref<any>;
|
27 | }, ExternalForwardedProps extends {
|
28 | component?: React.ElementType;
|
29 | slots?: {
|
30 | [k in T]?: React.ElementType;
|
31 | };
|
32 | slotProps?: {
|
33 | [k in T]?: ExternalSlotProps | ((ownerState: OwnerState) => ExternalSlotProps);
|
34 | };
|
35 | }, AdditionalProps, SlotOwnerState extends {}>(
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | name: T, parameters: (T extends 'root' ? {
|
43 | ref: React.ForwardedRef<any>;
|
44 | } : {
|
45 | ref?: React.ForwardedRef<any>;
|
46 | }) & {
|
47 | |
48 |
|
49 |
|
50 | className: ClassValue | ClassValue[];
|
51 | |
52 |
|
53 |
|
54 | elementType: ElementType;
|
55 | |
56 |
|
57 |
|
58 | ownerState: OwnerState;
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | externalForwardedProps: ExternalForwardedProps;
|
66 | getSlotProps?: (other: EventHandlers) => WithCommonProps<SlotProps>;
|
67 | additionalProps?: WithCommonProps<AdditionalProps>;
|
68 | |
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | getSlotOwnerState?: (mergedProps: AdditionalProps & SlotProps & ExternalSlotProps & ExtractComponentProps<Exclude<Exclude<ExternalForwardedProps['slotProps'], undefined>[T], undefined>>) => SlotOwnerState;
|
75 | |
76 |
|
77 |
|
78 |
|
79 | internalForwardedProps?: any;
|
80 | }): [ElementType, {
|
81 | className: string;
|
82 | ownerState: OwnerState & SlotOwnerState;
|
83 | } & AdditionalProps & SlotProps & ExternalSlotProps & ExtractComponentProps<Exclude<Exclude<ExternalForwardedProps["slotProps"], undefined>[T], undefined>>];
|
84 | export {};
|
85 |
|
\ | No newline at end of file |