-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
37 lines (33 loc) · 1.13 KB
/
index.ts
File metadata and controls
37 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { CallbacksCreator, MaybeFunc, Merge, PartialProps, ReactComponent, Slots } from './utils';
type SlotsConfigCreator<
TDefaultSlots extends Slots,
TCallbacks extends CallbacksCreator<TDefaultSlots>
> = {
DefaultSlots: TDefaultSlots;
Slots: Partial<Record<keyof TDefaultSlots, ReactComponent>>;
Callbacks: TCallbacks;
};
type SlotPropsCreator<
TSlotsConfig extends SlotsConfigCreator<any, any>,
TSlots extends Slots,
> = {
[SlotKey in keyof TSlots as Lowercase<string & SlotKey>]?:
// Get the props and rename it to Props
PartialProps<TSlots[SlotKey]> extends infer Props ?
// get the slot args for slotProps callback if avaliable, name it Args
TSlotsConfig["Callbacks"][SlotKey] extends infer Args extends Array<any>
? MaybeFunc<Props, Args> : Props
: never
};
type SlotsProps<
TSlotsConfig extends SlotsConfigCreator<any, any>,
TSlots extends TSlotsConfig['Slots'],
> = {
slots?: TSlots;
slotProps?:
SlotPropsCreator<
TSlotsConfig,
Merge<TSlotsConfig['DefaultSlots'], TSlots>
>
};
export type { SlotsProps, SlotsConfigCreator, Slots, CallbacksCreator };