-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
166 lines (143 loc) · 3.91 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { ReactNode } from 'react'
import { Properties } from 'csstype'
export enum Direction {
left = 'left',
right = 'right',
top = 'top',
bottom = 'bottom',
}
export const directions: Direction[] = [
Direction.left,
Direction.right,
Direction.top,
Direction.bottom,
]
export const isHorizontal = (direction: Direction) =>
direction === Direction.left || direction === Direction.right
export const isVertical = (direction: Direction) =>
direction === Direction.top || direction === Direction.bottom
export const isStart = (direction: Direction) =>
direction === Direction.top || direction === Direction.left
export const isEnd = (direction: Direction) =>
direction === Direction.right || direction === Direction.bottom
export type Inline = false | string
export type Elements = string | Element | HTMLElement | NodeListOf<Element> | ReactNode
export interface Theme {
indicator?:
| ((
element: HTMLElement,
options: Options,
direction: Direction,
) => CSSProperties | void)
| CSSProperties
hide?: (indicator: HTMLSpanElement) => void | CSSProperties
show?: (indicator: HTMLSpanElement) => void | CSSProperties
arrow?: (arrow: HTMLElement, options: Options, direction: Direction) => CSSProperties | void
outerWrapper?:
| ((
element: HTMLElement,
options: Options,
table: boolean,
inline: Inline,
) => CSSProperties | void)
| CSSProperties
element?:
| ((
element: HTMLElement,
options: Options,
table: boolean,
inline: Inline,
) => CSSProperties | void)
| CSSProperties
innerWrapper?:
| ((element: HTMLElement, options: Options, table: boolean) => CSSProperties | void)
| CSSProperties
observer?:
| ((element: HTMLElement, options: Options, direction: Direction) => CSSProperties | void)
| CSSProperties
}
type ArrowPosition = 'start' | 'center' | 'end'
// Omit passing option-props to children in React component.
export const pluginOptionsProperties = [
'arrow',
'color',
'width',
'click',
'hideScrollbar',
'moveStylesToWrapper',
'inlineStyles',
'theme',
]
// Unpublished, required for React plugin.
export interface UnpublishedOptions {
outerWrapper?: HTMLElement
innerWrapper?: HTMLElement
}
export interface ClickOptions {
denominator?: number
}
export type ArrowIcon = 'arrow-rounded' | 'pointer-rounded' | 'arrow' | 'pointer'
export interface PluginArrowOptions {
position?: ArrowPosition
icon?: ArrowIcon
color?: string
image?: string
markup?: Node | string
}
export interface ArrowOptions {
position: ArrowPosition
icon: ArrowIcon
color: string
image?: string
markup?: Node | string
}
// User facing options.
export type PluginOptions = {
arrow?: boolean | PluginArrowOptions
color?: string
theme?: Theme
width?: string
click?: boolean | ClickOptions
hideScrollbar?: boolean
moveStylesToWrapper?: boolean
inlineStyles?: { [key in keyof Theme]: CSSProperties }
} & UnpublishedOptions
// Internal options extended with defaults.
export type Options = {
arrow: false | ArrowOptions
theme?: Theme
color: string
width: string
click: false | ClickOptions
hideScrollbar: boolean
moveStylesToWrapper: boolean
inlineStyles?: { [key in keyof Theme]: CSSProperties }
} & UnpublishedOptions
export interface Instance {
outerWrapper: HTMLDivElement
innerWrapper: HTMLDivElement
element: HTMLElement
indicator: {
left: HTMLSpanElement
right: HTMLSpanElement
top: HTMLSpanElement
bottom: HTMLSpanElement
}
observer: {
left: HTMLSpanElement
right: HTMLSpanElement
top: HTMLSpanElement
bottom: HTMLSpanElement
}
intersectionObserver: IntersectionObserver
options: Options
table: boolean
inline: Inline
}
export interface Visibility {
left: boolean
right: boolean
top: boolean
bottom: boolean
}
export interface CSSProperties extends Properties<string | number> {}