-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
58 lines (45 loc) · 1.56 KB
/
types.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// This module is browser compatible.
import { AllHTMLAttributes, Dispatch, DOMAttributes } from "react";
export type AllHandlerMap = Omit<
DOMAttributes<Element>,
"children" | "dangerouslySetInnerHTML"
>;
export type AllHandler = keyof AllHandlerMap;
export type AllHandlerMapWithoutKeyBoard = Omit<
AllHandlerMap,
"onKeyDown" | "onKeyUp" | "onKeyPress"
>;
export type AllHandlerWithoutKeyBoard = keyof AllHandlerMapWithoutKeyBoard;
export type KeyboardHandlerMap = Pick<
AllHandlerMap,
"onKeyDown" | "onKeyUp" | "onKeyPress"
>;
export type KeyboardHandler = keyof KeyboardHandlerMap;
export type Tag = keyof JSX.IntrinsicElements;
export type WithIntrinsicElements<Props, As extends Tag> =
& Props
& Omit<JSX.IntrinsicElements[As], keyof Props>;
export type KeyboardEventHandler<Ev = KeyboardEvent> = (ev: Ev) => void;
export type ElementProps<
As extends Tag,
Contexts extends Record<PropertyKey, unknown>,
E = Element,
> = {
renderAttributes?: (contexts: Contexts) => AllHTMLAttributes<E>;
} & AsProps<As>;
export type AsProps<As extends Tag> = {
/** Render tag as */
as?: As;
};
export type HasFocusElement = HTMLElement | SVGElement | MathMLElement;
export type HandlerWithContext<
Context,
K extends keyof HandlersWithContext<Context>,
> = Required<HandlersWithContext<Context>>[K];
export type HandlersWithContext<Context> = {
[k in keyof AllHandlerMap]?: (
event: Parameters<Required<AllHandlerMap>[k]>[0],
context: Context,
) => ReturnType<Required<AllHandlerMap>[k]>;
};
export type StateSet<T> = [state: T, dispatch: Dispatch<T>];