forked from uber/baseweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.js
145 lines (129 loc) · 4.12 KB
/
types.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow
import * as React from 'react';
import {TETHER_PLACEMENT} from './constants.js';
import type {OverrideT} from '../helpers/overrides.js';
/** LayersManager */
export type LayersManagerPropsT = {
children: React.Node,
overrides?: {
AppContainer?: OverrideT,
LayersContainer?: OverrideT,
},
// z-index to be set for all the layers.
zIndex?: number,
};
export type LayersManagerStateT = {|
escapeKeyHandlers: Array<() => mixed>,
docClickHandlers: Array<(event: MouseEvent) => mixed>,
|};
export type LayersContextT = {
host: ?HTMLElement,
zIndex?: number,
addEscapeHandler: (() => mixed) => void,
removeEscapeHandler: (() => mixed) => void,
addDocClickHandler: (() => mixed) => void,
removeDocClickHandler: (() => mixed) => void,
};
/** Layer */
export type LayerPropsT = {
/** Content to be rendered in the Layer. */
children: React.Node,
/** A DOM element where the Layer will be inserted into as a child.
The host value comes from the layers context provider.
If there is no `LayersManager` added and therefore no host element
in the context, `document.body` will be used as a container element. */
host?: ?HTMLElement,
/** Defines the location (child order) at which the layer will be inserted in
the `host` element. */
index?: number,
/** A custom DOM element where the layer is inserted to as a child.
Note that the `index` prop does not work with a custom `mountNode`. */
mountNode?: HTMLElement,
/** Handler called when escape key is pressed.
Only the top most layer's handler is called. */
onEscape?: () => mixed,
/** Handler called when mousedown event happens on the document.
Only the top most layer's handler is called. */
onDocumentClick?: (event: MouseEvent) => mixed,
/** A handler that is called when the Layer is mounted. */
onMount?: () => mixed,
/** A handler that is called when the Layer is unmounted. */
onUnmount?: () => mixed,
/** A value of z-index to be set on the layer.
The zIndex value comes from the layers context provider. */
zIndex?: number,
};
export type LayerComponentPropsT = {
children: React.Node,
host: ?HTMLElement,
index?: number,
mountNode?: HTMLElement,
onEscape?: () => mixed,
onDocumentClick?: (event: MouseEvent) => mixed,
onMount?: () => mixed,
onUnmount?: () => mixed,
zIndex?: number,
};
export type LayerStateT = {
container: ?HTMLElement,
};
/** TetherBehavior */
export type TetherPlacementT = $Keys<typeof TETHER_PLACEMENT>;
export type NormalizedOffsetT = {
top: number,
left: number,
};
export type NormalizedOffsetsT = {
arrow?: NormalizedOffsetT,
popper: NormalizedOffsetT,
};
export type PopperOffsetT = {
top?: number | null,
left?: number | null,
};
export type PopperDataObjectT = {
offsets: {
arrow?: PopperOffsetT,
popper: PopperOffsetT,
},
placement: string,
};
export type PopperOptionsT = {
placement: string,
modifiers: {
arrow: {},
computeStyle: {},
applyStyle: {},
applyReactStyle: {
fn: (data: PopperDataObjectT) => void,
},
},
};
export type TetherPropsT = {
/** The reference element used to position the popper. */
anchorRef: ?HTMLElement,
/** The arrow element that is passed as an arrow modifier to alter
the popper positioning. */
arrowRef?: ?HTMLElement,
/** The element used as a popper. */
popperRef: ?HTMLElement,
/** Content to be rendered in the Popper. */
children: React.Node,
/** A handler that is called when popper positioning changes. */
onPopperUpdate: (NormalizedOffsetsT, PopperDataObjectT) => mixed,
/** Recommended placement of the popper. */
placement: TetherPlacementT,
/** Options to be passes to the Popper on its initialization.
Refer to the [Popper documentation](https://github.com/popperjs/popper.js/blob/v1.x/docs/_includes/popper-documentation.md)
for the full list of available options. */
// eslint-disable-next-line flowtype/no-weak-types
popperOptions: any,
};
export type TetherStateT = {
isMounted: boolean,
};