@react-types/shared 3.33.1 → 3.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/events.d.ts CHANGED
@@ -11,22 +11,19 @@
11
11
  */
12
12
 
13
13
  import {FocusableElement} from './dom';
14
- import {
15
- FocusEvent,
16
- MouseEvent,
17
- KeyboardEvent as ReactKeyboardEvent,
18
- SyntheticEvent
19
- } from 'react';
14
+ import {FocusEvent, MouseEvent, KeyboardEvent as ReactKeyboardEvent, SyntheticEvent} from 'react';
20
15
 
21
16
  // Event bubbling can be problematic in real-world applications, so the default for React Spectrum components
22
17
  // is not to propagate. This can be overridden by calling continuePropagation() on the event.
23
18
  export type BaseEvent<T extends SyntheticEvent> = T & {
24
19
  /**
25
20
  * Use continuePropagation.
26
- * @deprecated */
27
- stopPropagation(): void,
28
- continuePropagation(): void
29
- }
21
+ *
22
+ * @deprecated
23
+ */
24
+ stopPropagation(): void;
25
+ continuePropagation(): void;
26
+ };
30
27
 
31
28
  export type KeyboardEvent = BaseEvent<ReactKeyboardEvent<any>>;
32
29
 
@@ -34,157 +31,156 @@ export type PointerType = 'mouse' | 'pen' | 'touch' | 'keyboard' | 'virtual';
34
31
 
35
32
  export interface PressEvent {
36
33
  /** The type of press event being fired. */
37
- type: 'pressstart' | 'pressend' | 'pressup' | 'press',
34
+ type: 'pressstart' | 'pressend' | 'pressup' | 'press';
38
35
  /** The pointer type that triggered the press event. */
39
- pointerType: PointerType,
36
+ pointerType: PointerType;
40
37
  /** The target element of the press event. */
41
- target: Element,
38
+ target: Element;
42
39
  /** Whether the shift keyboard modifier was held during the press event. */
43
- shiftKey: boolean,
40
+ shiftKey: boolean;
44
41
  /** Whether the ctrl keyboard modifier was held during the press event. */
45
- ctrlKey: boolean,
42
+ ctrlKey: boolean;
46
43
  /** Whether the meta keyboard modifier was held during the press event. */
47
- metaKey: boolean,
44
+ metaKey: boolean;
48
45
  /** Whether the alt keyboard modifier was held during the press event. */
49
- altKey: boolean,
46
+ altKey: boolean;
50
47
  /** X position relative to the target. */
51
- x: number,
48
+ x: number;
52
49
  /** Y position relative to the target. */
53
- y: number,
50
+ y: number;
54
51
  /**
55
52
  * The key that triggered the press event, if it was triggered by a keyboard interaction.
56
53
  * This is useful for differentiating between Space and Enter key presses.
57
54
  */
58
- key?: string,
55
+ key?: string;
59
56
  /**
60
57
  * By default, press events stop propagation to parent elements.
61
58
  * In cases where a handler decides not to handle a specific event,
62
59
  * it can call `continuePropagation()` to allow a parent to handle it.
63
60
  */
64
- continuePropagation(): void
61
+ continuePropagation(): void;
65
62
  }
66
63
 
67
64
  export interface LongPressEvent extends Omit<PressEvent, 'type' | 'continuePropagation'> {
68
65
  /** The type of long press event being fired. */
69
- type: 'longpressstart' | 'longpressend' | 'longpress'
66
+ type: 'longpressstart' | 'longpressend' | 'longpress';
70
67
  }
71
68
 
72
69
  export interface HoverEvent {
73
70
  /** The type of hover event being fired. */
74
- type: 'hoverstart' | 'hoverend',
71
+ type: 'hoverstart' | 'hoverend';
75
72
  /** The pointer type that triggered the hover event. */
76
- pointerType: 'mouse' | 'pen',
73
+ pointerType: 'mouse' | 'pen';
77
74
  /** The target element of the hover event. */
78
- target: HTMLElement
75
+ target: HTMLElement;
79
76
  }
80
77
 
81
78
  export interface KeyboardEvents {
82
79
  /** Handler that is called when a key is pressed. */
83
- onKeyDown?: (e: KeyboardEvent) => void,
80
+ onKeyDown?: (e: KeyboardEvent) => void;
84
81
  /** Handler that is called when a key is released. */
85
- onKeyUp?: (e: KeyboardEvent) => void
82
+ onKeyUp?: (e: KeyboardEvent) => void;
86
83
  }
87
84
 
88
85
  export interface FocusEvents<Target = Element> {
89
86
  /** Handler that is called when the element receives focus. */
90
- onFocus?: (e: FocusEvent<Target>) => void,
87
+ onFocus?: (e: FocusEvent<Target>) => void;
91
88
  /** Handler that is called when the element loses focus. */
92
- onBlur?: (e: FocusEvent<Target>) => void,
89
+ onBlur?: (e: FocusEvent<Target>) => void;
93
90
  /** Handler that is called when the element's focus status changes. */
94
- onFocusChange?: (isFocused: boolean) => void
91
+ onFocusChange?: (isFocused: boolean) => void;
95
92
  }
96
93
 
97
94
  export interface HoverEvents {
98
95
  /** Handler that is called when a hover interaction starts. */
99
- onHoverStart?: (e: HoverEvent) => void,
96
+ onHoverStart?: (e: HoverEvent) => void;
100
97
  /** Handler that is called when a hover interaction ends. */
101
- onHoverEnd?: (e: HoverEvent) => void,
98
+ onHoverEnd?: (e: HoverEvent) => void;
102
99
  /** Handler that is called when the hover state changes. */
103
- onHoverChange?: (isHovering: boolean) => void
100
+ onHoverChange?: (isHovering: boolean) => void;
104
101
  }
105
102
 
106
103
  export interface PressEvents {
107
104
  /** Handler that is called when the press is released over the target. */
108
- onPress?: (e: PressEvent) => void,
105
+ onPress?: (e: PressEvent) => void;
109
106
  /** Handler that is called when a press interaction starts. */
110
- onPressStart?: (e: PressEvent) => void,
107
+ onPressStart?: (e: PressEvent) => void;
111
108
  /**
112
109
  * Handler that is called when a press interaction ends, either
113
110
  * over the target or when the pointer leaves the target.
114
111
  */
115
- onPressEnd?: (e: PressEvent) => void,
112
+ onPressEnd?: (e: PressEvent) => void;
116
113
  /** Handler that is called when the press state changes. */
117
- onPressChange?: (isPressed: boolean) => void,
114
+ onPressChange?: (isPressed: boolean) => void;
118
115
  /**
119
116
  * Handler that is called when a press is released over the target, regardless of
120
117
  * whether it started on the target or not.
121
118
  */
122
- onPressUp?: (e: PressEvent) => void,
119
+ onPressUp?: (e: PressEvent) => void;
123
120
  /**
124
121
  * **Not recommended – use `onPress` instead.** `onClick` is an alias for `onPress`
125
- * provided for compatibility with other libraries. `onPress` provides
122
+ * provided for compatibility with other libraries. `onPress` provides
126
123
  * additional event details for non-mouse interactions.
127
124
  */
128
- onClick?: (e: MouseEvent<FocusableElement>) => void
125
+ onClick?: (e: MouseEvent<FocusableElement>) => void;
129
126
  }
130
127
 
131
128
  export interface FocusableProps<Target = Element> extends FocusEvents<Target>, KeyboardEvents {
132
129
  /** Whether the element should receive focus on render. */
133
- autoFocus?: boolean
130
+ autoFocus?: boolean;
134
131
  }
135
132
 
136
133
  interface BaseMoveEvent {
137
134
  /** The pointer type that triggered the move event. */
138
- pointerType: PointerType,
135
+ pointerType: PointerType;
139
136
  /** Whether the shift keyboard modifier was held during the move event. */
140
- shiftKey: boolean,
137
+ shiftKey: boolean;
141
138
  /** Whether the ctrl keyboard modifier was held during the move event. */
142
- ctrlKey: boolean,
139
+ ctrlKey: boolean;
143
140
  /** Whether the meta keyboard modifier was held during the move event. */
144
- metaKey: boolean,
141
+ metaKey: boolean;
145
142
  /** Whether the alt keyboard modifier was held during the move event. */
146
- altKey: boolean
143
+ altKey: boolean;
147
144
  }
148
145
 
149
146
  export interface MoveStartEvent extends BaseMoveEvent {
150
147
  /** The type of move event being fired. */
151
- type: 'movestart'
148
+ type: 'movestart';
152
149
  }
153
150
 
154
151
  export interface MoveMoveEvent extends BaseMoveEvent {
155
152
  /** The type of move event being fired. */
156
- type: 'move',
153
+ type: 'move';
157
154
  /** The amount moved in the X direction since the last event. */
158
- deltaX: number,
155
+ deltaX: number;
159
156
  /** The amount moved in the Y direction since the last event. */
160
- deltaY: number
161
-
157
+ deltaY: number;
162
158
  }
163
159
 
164
160
  export interface MoveEndEvent extends BaseMoveEvent {
165
161
  /** The type of move event being fired. */
166
- type: 'moveend'
162
+ type: 'moveend';
167
163
  }
168
164
 
169
165
  export type MoveEvent = MoveStartEvent | MoveMoveEvent | MoveEndEvent;
170
166
 
171
167
  export interface MoveEvents {
172
168
  /** Handler that is called when a move interaction starts. */
173
- onMoveStart?: (e: MoveStartEvent) => void,
169
+ onMoveStart?: (e: MoveStartEvent) => void;
174
170
  /** Handler that is called when the element is moved. */
175
- onMove?: (e: MoveMoveEvent) => void,
171
+ onMove?: (e: MoveMoveEvent) => void;
176
172
  /** Handler that is called when a move interaction ends. */
177
- onMoveEnd?: (e: MoveEndEvent) => void
173
+ onMoveEnd?: (e: MoveEndEvent) => void;
178
174
  }
179
175
 
180
176
  export interface ScrollEvent {
181
177
  /** The amount moved in the X direction since the last event. */
182
- deltaX: number,
178
+ deltaX: number;
183
179
  /** The amount moved in the Y direction since the last event. */
184
- deltaY: number
180
+ deltaY: number;
185
181
  }
186
182
 
187
183
  export interface ScrollEvents {
188
184
  /** Handler that is called when the scroll wheel moves. */
189
- onScroll?: (e: ScrollEvent) => void
185
+ onScroll?: (e: ScrollEvent) => void;
190
186
  }
package/src/inputs.d.ts CHANGED
@@ -20,98 +20,103 @@ export type ValidationFunction<T> = (value: T) => ValidationError | true | null
20
20
 
21
21
  export interface Validation<T = unknown> {
22
22
  /** Whether user input is required on the input before form submission. */
23
- isRequired?: boolean,
23
+ isRequired?: boolean;
24
24
  /** Whether the input value is invalid. */
25
- isInvalid?: boolean,
25
+ isInvalid?: boolean;
26
26
  /** @deprecated Use `isInvalid` instead. */
27
- validationState?: ValidationState,
27
+ validationState?: ValidationState;
28
28
  /**
29
29
  * Whether to use native HTML form validation to prevent form submission
30
30
  * when the value is missing or invalid, or mark the field as required
31
31
  * or invalid via ARIA.
32
+ *
32
33
  * @default 'aria'
33
34
  */
34
- validationBehavior?: 'aria' | 'native',
35
+ validationBehavior?: 'aria' | 'native';
35
36
  /**
36
37
  * A function that returns an error message if a given value is invalid.
37
38
  * Validation errors are displayed to the user when the form is submitted
38
39
  * if `validationBehavior="native"`. For realtime validation, use the `isInvalid`
39
40
  * prop instead.
40
41
  */
41
- validate?: (value: T) => ValidationError | true | null | undefined
42
+ validate?: (value: T) => ValidationError | true | null | undefined;
42
43
  }
43
44
 
44
45
  export interface ValidationResult {
45
46
  /** Whether the input value is invalid. */
46
- isInvalid: boolean,
47
+ isInvalid: boolean;
47
48
  /** The current error messages for the input if it is invalid, otherwise an empty array. */
48
- validationErrors: string[],
49
+ validationErrors: string[];
49
50
  /** The native validation details for the input. */
50
- validationDetails: ValidityState
51
+ validationDetails: ValidityState;
51
52
  }
52
53
 
53
- export interface SpectrumFieldValidation<T> extends Omit<Validation<T>, 'isInvalid' | 'validationState'> {
54
+ export interface SpectrumFieldValidation<T> extends Omit<
55
+ Validation<T>,
56
+ 'isInvalid' | 'validationState'
57
+ > {
54
58
  /** Whether the input should display its "valid" or "invalid" visual styling. */
55
- validationState?: ValidationState
59
+ validationState?: ValidationState;
56
60
  }
57
61
 
58
62
  export interface InputBase {
59
63
  /** Whether the input is disabled. */
60
- isDisabled?: boolean,
64
+ isDisabled?: boolean;
61
65
  /** Whether the input can be selected but not changed by the user. */
62
- isReadOnly?: boolean
66
+ isReadOnly?: boolean;
63
67
  }
64
68
 
65
69
  export interface ValueBase<T, C = T> {
66
70
  /** The current value (controlled). */
67
- value?: T,
71
+ value?: T;
68
72
  /** The default value (uncontrolled). */
69
- defaultValue?: T,
73
+ defaultValue?: T;
70
74
  /** Handler that is called when the value changes. */
71
- onChange?: (value: C) => void
75
+ onChange?: (value: C) => void;
72
76
  }
73
77
 
74
78
  export interface TextInputBase {
75
79
  /** Temporary text that occupies the text input when it is empty. */
76
- placeholder?: string
80
+ placeholder?: string;
77
81
  }
78
82
 
79
83
  export interface SpectrumTextInputBase {
80
84
  /**
81
85
  * Temporary text that occupies the text input when it is empty.
82
86
  * Please use help text instead.
87
+ *
83
88
  * @deprecated
84
- **/
85
- placeholder?: string
89
+ */
90
+ placeholder?: string;
86
91
  }
87
92
 
88
93
  export interface RangeValue<T> {
89
94
  /** The start value of the range. */
90
- start: T,
95
+ start: T;
91
96
  /** The end value of the range. */
92
- end: T
97
+ end: T;
93
98
  }
94
99
 
95
100
  export interface RangeInputBase<T> {
96
101
  /** The smallest value allowed for the input. */
97
- minValue?: T,
102
+ minValue?: T;
98
103
  /** The largest value allowed for the input. */
99
- maxValue?: T,
104
+ maxValue?: T;
100
105
  /** The amount that the input value changes with each increment or decrement "tick". */
101
- step?: T // ??
106
+ step?: T; // ??
102
107
  }
103
108
 
104
109
  export interface HelpTextProps {
105
110
  /** A description for the field. Provides a hint such as specific requirements for what to choose. */
106
- description?: ReactNode,
111
+ description?: ReactNode;
107
112
  /** An error message for the field. */
108
- errorMessage?: ReactNode | ((v: ValidationResult) => ReactNode)
113
+ errorMessage?: ReactNode | ((v: ValidationResult) => ReactNode);
109
114
  }
110
115
 
111
116
  // Spectrum specific types. Extends `Validation` so that the `validationState` prop is available.
112
117
  export interface SpectrumHelpTextProps extends HelpTextProps {
113
118
  /** Whether the description is displayed with lighter text. */
114
- isDisabled?: boolean,
119
+ isDisabled?: boolean;
115
120
  /** Whether an error icon is rendered. */
116
- showErrorIcon?: boolean
121
+ showErrorIcon?: boolean;
117
122
  }
@@ -18,31 +18,34 @@ export type NecessityIndicator = 'icon' | 'label';
18
18
 
19
19
  export interface LabelableProps {
20
20
  /** The content to display as the label. */
21
- label?: ReactNode
21
+ label?: ReactNode;
22
22
  }
23
23
 
24
24
  export interface SpectrumLabelableProps extends LabelableProps {
25
25
  /**
26
26
  * The label's overall position relative to the element it is labeling.
27
+ *
27
28
  * @default 'top'
28
29
  */
29
- labelPosition?: LabelPosition,
30
+ labelPosition?: LabelPosition;
30
31
  /**
31
32
  * The label's horizontal alignment relative to the element it is labeling.
33
+ *
32
34
  * @default 'start'
33
35
  */
34
- labelAlign?: Alignment,
36
+ labelAlign?: Alignment;
35
37
  /**
36
38
  * Whether the required state should be shown as an icon or text.
39
+ *
37
40
  * @default 'icon'
38
41
  */
39
- necessityIndicator?: NecessityIndicator,
42
+ necessityIndicator?: NecessityIndicator;
40
43
  /**
41
44
  * Whether the label is labeling a required field or group.
42
45
  */
43
- isRequired?: boolean,
46
+ isRequired?: boolean;
44
47
  /**
45
48
  * A ContextualHelp element to place next to the label.
46
49
  */
47
- contextualHelp?: ReactNode
50
+ contextualHelp?: ReactNode;
48
51
  }
package/src/refs.d.ts CHANGED
@@ -13,18 +13,23 @@
13
13
  import {ReactElement, Ref, RefAttributes} from 'react';
14
14
 
15
15
  export interface DOMRefValue<T extends HTMLElement = HTMLElement> {
16
- UNSAFE_getDOMNode(): T | null
16
+ UNSAFE_getDOMNode(): T | null;
17
17
  }
18
18
 
19
- export interface FocusableRefValue<T extends HTMLElement = HTMLElement, D extends HTMLElement = T> extends DOMRefValue<D> {
20
- focus(): void
19
+ export interface FocusableRefValue<
20
+ T extends HTMLElement = HTMLElement,
21
+ D extends HTMLElement = T
22
+ > extends DOMRefValue<D> {
23
+ focus(): void;
21
24
  }
22
25
 
23
26
  export type DOMRef<T extends HTMLElement = HTMLElement> = Ref<DOMRefValue<T>>;
24
- export type FocusableRef<T extends HTMLElement = HTMLElement> = Ref<FocusableRefValue<T>>;
27
+ export type FocusableRef<T extends HTMLElement = HTMLElement, D extends HTMLElement = T> = Ref<
28
+ FocusableRefValue<T, D>
29
+ >;
25
30
 
26
31
  export interface RefObject<T> {
27
- current: T
32
+ current: T;
28
33
  }
29
34
 
30
35
  // Override forwardRef types so generics work.
@@ -13,6 +13,6 @@
13
13
  import {SyntheticEvent} from 'react';
14
14
 
15
15
  export interface Removable<T, R> {
16
- isRemovable?: boolean,
17
- onRemove?: (value: T, event?: SyntheticEvent) => R
16
+ isRemovable?: boolean;
17
+ onRemove?: (value: T, event?: SyntheticEvent) => R;
18
18
  }
@@ -14,13 +14,13 @@ import {Key} from '@react-types/shared';
14
14
 
15
15
  export interface SingleSelection {
16
16
  /** Whether the collection allows empty selection. */
17
- disallowEmptySelection?: boolean,
17
+ disallowEmptySelection?: boolean;
18
18
  /** The currently selected key in the collection (controlled). */
19
- selectedKey?: Key | null,
19
+ selectedKey?: Key | null;
20
20
  /** The initial selected key in the collection (uncontrolled). */
21
- defaultSelectedKey?: Key | null,
21
+ defaultSelectedKey?: Key | null;
22
22
  /** Handler that is called when the selection changes. */
23
- onSelectionChange?: (key: Key | null) => void
23
+ onSelectionChange?: (key: Key | null) => void;
24
24
  }
25
25
 
26
26
  export type SelectionMode = 'none' | 'single' | 'multiple';
@@ -28,22 +28,22 @@ export type SelectionBehavior = 'toggle' | 'replace';
28
28
  export type Selection = 'all' | Set<Key>;
29
29
  export interface MultipleSelection {
30
30
  /** The type of selection that is allowed in the collection. */
31
- selectionMode?: SelectionMode,
31
+ selectionMode?: SelectionMode;
32
32
  /** Whether the collection allows empty selection. */
33
- disallowEmptySelection?: boolean,
33
+ disallowEmptySelection?: boolean;
34
34
  /** The currently selected keys in the collection (controlled). */
35
- selectedKeys?: 'all' | Iterable<Key>,
35
+ selectedKeys?: 'all' | Iterable<Key>;
36
36
  /** The initial selected keys in the collection (uncontrolled). */
37
- defaultSelectedKeys?: 'all' | Iterable<Key>,
37
+ defaultSelectedKeys?: 'all' | Iterable<Key>;
38
38
  /** Handler that is called when the selection changes. */
39
- onSelectionChange?: (keys: Selection) => void,
39
+ onSelectionChange?: (keys: Selection) => void;
40
40
  /** The currently disabled keys in the collection (controlled). */
41
- disabledKeys?: Iterable<Key>
41
+ disabledKeys?: Iterable<Key>;
42
42
  }
43
43
 
44
44
  export interface SpectrumSelectionProps {
45
45
  /** How selection should be displayed. */
46
- selectionStyle?: 'checkbox' | 'highlight'
46
+ selectionStyle?: 'checkbox' | 'highlight';
47
47
  }
48
48
 
49
49
  export type FocusStrategy = 'first' | 'last';