-
-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathSelect.types.ts
More file actions
69 lines (61 loc) · 1.92 KB
/
Copy pathSelect.types.ts
File metadata and controls
69 lines (61 loc) · 1.92 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
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
import React from 'react';
import { HTMLDataAttributes } from '../types';
type SelectChangeEventTargetValue<T> = { value: T; name: string | undefined };
export type SelectChangeEvent<T> =
| (Omit<React.ChangeEvent<HTMLSelectElement>, 'target'> & {
target: Omit<
React.ChangeEvent<HTMLSelectElement>['target'],
'name' | 'value'
> &
SelectChangeEventTargetValue<T>;
})
| (Omit<React.MouseEvent, 'target'> & {
target: Omit<React.MouseEvent['target'], 'name' | 'value'> &
SelectChangeEventTargetValue<T>;
});
export type SelectOption<T> = {
label?: string;
value: T;
};
export type SelectRef = Pick<HTMLInputElement, 'value' | 'focus'> & {
node: HTMLInputElement | null;
};
export type SelectVariants = 'default' | 'flat';
export type SelectFormatDisplayCallback<T> = (
option: SelectOption<T>
) => string;
export type SelectCommonProps<T> = {
'aria-label'?: string;
'aria-labelledby'?: string;
className?: string;
defaultValue?: T;
disabled?: boolean;
name?: string;
onChange?: (
selectedOption: SelectOption<T>,
options: {
fromEvent: Event | React.SyntheticEvent;
}
) => void;
options?: (SelectOption<T> | null | undefined)[];
readOnly?: boolean;
shadow?: boolean;
style?: React.CSSProperties;
value?: T;
variant?: SelectVariants;
width?: React.CSSProperties['width'];
};
export type SelectInnerProps<T> = {
formatDisplay?: SelectFormatDisplayCallback<T>;
inputProps?: React.HTMLAttributes<HTMLInputElement> & HTMLDataAttributes;
/** @deprecated Use `aria-labelledby` instead */
labelId?: string;
menuMaxHeight?: string | number;
onClose?: (options: { fromEvent: Event | React.SyntheticEvent }) => void;
onOpen?: (options: { fromEvent: Event | React.SyntheticEvent }) => void;
open?: boolean;
} & Pick<
React.HTMLAttributes<HTMLDivElement>,
'onBlur' | 'onFocus' | 'onKeyDown' | 'onMouseDown'
> &
SelectCommonProps<T>;