-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
types.ts
200 lines (169 loc) · 4.99 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import { CSSObject } from '@emotion/react';
import { Props } from './Select';
import { StylesProps } from './styles';
export interface GroupBase<Option> {
readonly options: readonly Option[];
readonly label?: string;
}
export type OptionsOrGroups<Option, Group extends GroupBase<Option>> =
readonly (Option | Group)[];
export type Options<Option> = readonly Option[];
export type SingleValue<Option> = Option | null;
export type MultiValue<Option> = readonly Option[];
export type PropsValue<Option> = MultiValue<Option> | SingleValue<Option>;
export type OnChangeValue<Option, IsMulti extends boolean> =
IsMulti extends true ? MultiValue<Option> : SingleValue<Option>;
export interface Colors {
primary: string;
primary75: string;
primary50: string;
primary25: string;
danger: string;
dangerLight: string;
neutral0: string;
neutral5: string;
neutral10: string;
neutral20: string;
neutral30: string;
neutral40: string;
neutral50: string;
neutral60: string;
neutral70: string;
neutral80: string;
neutral90: string;
}
export interface ThemeSpacing {
baseUnit: number;
controlHeight: number;
menuGutter: number;
}
export interface Theme {
borderRadius: number;
colors: Colors;
spacing: ThemeSpacing;
}
export type ClassNamesState = { [key: string]: boolean };
export type CX = (
state: ClassNamesState,
...classNames: (string | undefined)[]
) => string;
export type GetStyles<
Option,
IsMulti extends boolean,
Group extends GroupBase<Option>
> = <Key extends keyof StylesProps<Option, IsMulti, Group>>(
propertyName: Key,
props: StylesProps<Option, IsMulti, Group>[Key]
) => CSSObjectWithLabel;
export interface CommonProps<
Option,
IsMulti extends boolean,
Group extends GroupBase<Option>
> {
clearValue: () => void;
cx: CX;
/**
Get the styles of a particular part of the select. Pass in the name of the
property as the first argument, and the current props as the second argument.
See the `styles` object for the properties available.
*/
getStyles: GetStyles<Option, IsMulti, Group>;
getClassNames: <Key extends keyof StylesProps<Option, IsMulti, Group>>(
propertyName: Key,
props: StylesProps<Option, IsMulti, Group>[Key]
) => string | undefined;
getValue: () => Options<Option>;
hasValue: boolean;
isMulti: boolean;
isRtl: boolean;
options: OptionsOrGroups<Option, Group>;
selectOption: (newValue: Option) => void;
selectProps: Props<Option, IsMulti, Group>;
setValue: (
newValue: OnChangeValue<Option, IsMulti>,
action: SetValueAction,
option?: Option
) => void;
theme: Theme;
}
export interface CommonPropsAndClassName<
Option,
IsMulti extends boolean,
Group extends GroupBase<Option>
> extends CommonProps<Option, IsMulti, Group> {
className?: string | undefined;
}
export interface ActionMetaBase<Option> {
option?: Option | undefined;
removedValue?: Option;
removedValues?: Options<Option>;
name?: string;
}
export interface SelectOptionActionMeta<Option> extends ActionMetaBase<Option> {
action: 'select-option';
option: Option | undefined;
name?: string;
}
export interface DeselectOptionActionMeta<Option>
extends ActionMetaBase<Option> {
action: 'deselect-option';
option: Option | undefined;
name?: string;
}
export interface RemoveValueActionMeta<Option> extends ActionMetaBase<Option> {
action: 'remove-value';
removedValue: Option;
name?: string;
}
export interface PopValueActionMeta<Option> extends ActionMetaBase<Option> {
action: 'pop-value';
removedValue: Option;
name?: string;
}
export interface ClearActionMeta<Option> extends ActionMetaBase<Option> {
action: 'clear';
removedValues: Options<Option>;
name?: string;
}
export interface CreateOptionActionMeta<Option> extends ActionMetaBase<Option> {
action: 'create-option';
name?: string;
option: Option;
}
export interface InitialInputFocusedActionMeta<Option, IsMulti extends boolean>
extends ActionMetaBase<Option> {
action: 'initial-input-focus';
value: OnChangeValue<Option, IsMulti>;
options?: Options<Option>;
}
export type ActionMeta<Option> =
| SelectOptionActionMeta<Option>
| DeselectOptionActionMeta<Option>
| RemoveValueActionMeta<Option>
| PopValueActionMeta<Option>
| ClearActionMeta<Option>
| CreateOptionActionMeta<Option>;
export type SetValueAction = 'select-option' | 'deselect-option';
export type InputAction =
| 'set-value'
| 'input-change'
| 'input-blur'
| 'menu-close';
export interface InputActionMeta {
action: InputAction;
/** The previous value of the search input. */
prevInputValue: string;
}
export type MenuPlacement = 'auto' | 'bottom' | 'top';
export type CoercedMenuPlacement = 'bottom' | 'top';
export type MenuPosition = 'absolute' | 'fixed';
export type FocusDirection =
| 'up'
| 'down'
| 'pageup'
| 'pagedown'
| 'first'
| 'last';
export type GetOptionLabel<Option> = (option: Option) => string;
export type GetOptionValue<Option> = (option: Option) => string;
export type CSSObjectWithLabel = CSSObject & { label?: string };