1 | /*
|
2 | * Copyright 2020 Ladifire. All rights reserved.
|
3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
4 | * you may not use this file except in compliance with the License. You may obtain a copy
|
5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6 | *
|
7 | * Unless required by applicable law or agreed to in writing, software distributed under
|
8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
9 | * OF ANY KIND, either express or implied. See the License for the specific language
|
10 | * governing permissions and limitations under the License.
|
11 | */
|
12 |
|
13 | import {
|
14 | FocusEvent,
|
15 | KeyboardEvent as ReactKeyboardEvent,
|
16 | SyntheticEvent
|
17 | } from 'react';
|
18 |
|
19 | // Event bubbling can be problematic in real-world applications, so the default for React Spectrum components
|
20 | // is not to propagate. This can be overridden by calling continuePropagation() on the event.
|
21 | export type BaseEvent<T extends SyntheticEvent> = T & {
|
22 | /** @deprecated Use continuePropagation. */
|
23 | stopPropagation(): void,
|
24 | continuePropagation(): void
|
25 | }
|
26 |
|
27 | export type KeyboardEvent = BaseEvent<ReactKeyboardEvent<any>>;
|
28 |
|
29 | export type PointerType = 'mouse' | 'pen' | 'touch' | 'keyboard' | 'virtual';
|
30 |
|
31 | export interface PressEvent {
|
32 | /** The type of press event being fired. */
|
33 | type: 'pressstart' | 'pressend' | 'pressup' | 'press',
|
34 | /** The pointer type that triggered the press event. */
|
35 | pointerType: PointerType,
|
36 | /** The target element of the press event. */
|
37 | target: HTMLElement,
|
38 | /** Whether the shift keyboard modifier was held during the press event. */
|
39 | shiftKey: boolean,
|
40 | /** Whether the ctrl keyboard modifier was held during the press event. */
|
41 | ctrlKey: boolean,
|
42 | /** Whether the meta keyboard modifier was held during the press event. */
|
43 | metaKey: boolean
|
44 | }
|
45 |
|
46 | export interface HoverEvent {
|
47 | /** The type of hover event being fired. */
|
48 | type: 'hoverstart' | 'hoverend',
|
49 | /** The pointer type that triggered the hover event. */
|
50 | pointerType: 'mouse' | 'pen',
|
51 | /** The target element of the hover event. */
|
52 | target: HTMLElement
|
53 | }
|
54 |
|
55 | export interface KeyboardEvents {
|
56 | /** Handler that is called when a key is pressed. */
|
57 | onKeyDown?: (e: KeyboardEvent) => void,
|
58 | /** Handler that is called when a key is released. */
|
59 | onKeyUp?: (e: KeyboardEvent) => void
|
60 | }
|
61 |
|
62 | export interface FocusEvents {
|
63 | /** Handler that is called when the element receives focus. */
|
64 | onFocus?: (e: FocusEvent) => void,
|
65 | /** Handler that is called when the element loses focus. */
|
66 | onBlur?: (e: FocusEvent) => void,
|
67 | /** Handler that is called when the element's focus status changes. */
|
68 | onFocusChange?: (isFocused: boolean) => void
|
69 | }
|
70 |
|
71 | export interface HoverEvents {
|
72 | /** Handler that is called when a hover interaction starts. */
|
73 | onHoverStart?: (e: HoverEvent) => void,
|
74 | /** Handler that is called when a hover interaction ends. */
|
75 | onHoverEnd?: (e: HoverEvent) => void,
|
76 | /** Handler that is called when the hover state changes. */
|
77 | onHoverChange?: (isHovering: boolean) => void
|
78 | }
|
79 |
|
80 | export interface PressEvents {
|
81 | /** Handler that is called when the press is released over the target. */
|
82 | onPress?: (e: PressEvent) => void,
|
83 | /** Handler that is called when a press interaction starts. */
|
84 | onPressStart?: (e: PressEvent) => void,
|
85 | /**
|
86 | * Handler that is called when a press interaction ends, either
|
87 | * over the target or when the pointer leaves the target.
|
88 | */
|
89 | onPressEnd?: (e: PressEvent) => void,
|
90 | /** Handler that is called when the press state changes. */
|
91 | onPressChange?: (isPressed: boolean) => void,
|
92 | /**
|
93 | * Handler that is called when a press is released over the target, regardless of
|
94 | * whether it started on the target or not.
|
95 | */
|
96 | onPressUp?: (e: PressEvent) => void
|
97 | }
|
98 |
|
99 | export interface FocusableProps extends FocusEvents, KeyboardEvents {
|
100 | /** Whether the element should receive focus on render. */
|
101 | autoFocus?: boolean
|
102 | }
|