@react-types/shared 3.0.0-nightly-641446f65-240905
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/README.md +3 -0
- package/package.json +18 -0
- package/src/collections.d.ts +222 -0
- package/src/dna.d.ts +503 -0
- package/src/dnd.d.ts +286 -0
- package/src/dom.d.ts +215 -0
- package/src/events.d.ts +177 -0
- package/src/index.d.ts +26 -0
- package/src/inputs.d.ts +117 -0
- package/src/key.d.ts +13 -0
- package/src/labelable.d.ts +48 -0
- package/src/locale.d.ts +13 -0
- package/src/orientation.d.ts +13 -0
- package/src/refs.d.ts +35 -0
- package/src/removable.d.ts +18 -0
- package/src/selection.d.ts +50 -0
- package/src/style.d.ts +263 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-types/shared",
|
|
3
|
+
"version": "3.0.0-nightly-641446f65-240905",
|
|
4
|
+
"description": "Spectrum UI components in React",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"types": "src/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/adobe/react-spectrum"
|
|
10
|
+
},
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"stableVersion": "3.24.1"
|
|
18
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. 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 {Key} from '@react-types/shared';
|
|
14
|
+
import {LinkDOMProps} from './dom';
|
|
15
|
+
import {ReactElement, ReactNode} from 'react';
|
|
16
|
+
|
|
17
|
+
export interface ItemProps<T> extends LinkDOMProps {
|
|
18
|
+
/** Rendered contents of the item or child items. */
|
|
19
|
+
children: ReactNode,
|
|
20
|
+
/** Rendered contents of the item if `children` contains child items. */
|
|
21
|
+
title?: ReactNode, // label?? contents?
|
|
22
|
+
/** A string representation of the item's contents, used for features like typeahead. */
|
|
23
|
+
textValue?: string,
|
|
24
|
+
/** An accessibility label for this item. */
|
|
25
|
+
'aria-label'?: string,
|
|
26
|
+
/** A list of child item objects. Used for dynamic collections. */
|
|
27
|
+
childItems?: Iterable<T>,
|
|
28
|
+
/** Whether this item has children, even if not loaded yet. */
|
|
29
|
+
hasChildItems?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type ItemElement<T> = ReactElement<ItemProps<T>>;
|
|
33
|
+
export type ItemRenderer<T> = (item: T) => ItemElement<T>;
|
|
34
|
+
export type LoadingState = 'loading' | 'sorting' | 'loadingMore' | 'error' | 'idle' | 'filtering';
|
|
35
|
+
|
|
36
|
+
export interface AsyncLoadable {
|
|
37
|
+
/** Whether the items are currently loading. */
|
|
38
|
+
isLoading?: boolean, // possibly isLoadingMore
|
|
39
|
+
/** Handler that is called when more items should be loaded, e.g. while scrolling near the bottom. */
|
|
40
|
+
onLoadMore?: () => any
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SectionProps<T> {
|
|
44
|
+
/** Rendered contents of the section, e.g. a header. */
|
|
45
|
+
title?: ReactNode,
|
|
46
|
+
/** An accessibility label for the section. */
|
|
47
|
+
'aria-label'?: string,
|
|
48
|
+
/** Static child items or a function to render children. */
|
|
49
|
+
children: ItemElement<T> | ItemElement<T>[] | ItemRenderer<T>,
|
|
50
|
+
/** Item objects in the section. */
|
|
51
|
+
items?: Iterable<T>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type SectionElement<T> = ReactElement<SectionProps<T>>;
|
|
55
|
+
|
|
56
|
+
export type CollectionElement<T> = SectionElement<T> | ItemElement<T>;
|
|
57
|
+
export type CollectionChildren<T> = CollectionElement<T> | CollectionElement<T>[] | ((item: T) => CollectionElement<T>);
|
|
58
|
+
export interface CollectionBase<T> {
|
|
59
|
+
/** The contents of the collection. */
|
|
60
|
+
children: CollectionChildren<T>,
|
|
61
|
+
/** Item objects in the collection. */
|
|
62
|
+
items?: Iterable<T>,
|
|
63
|
+
/** The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with. */
|
|
64
|
+
disabledKeys?: Iterable<Key>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface CollectionStateBase<T, C extends Collection<Node<T>> = Collection<Node<T>>> extends Partial<CollectionBase<T>> {
|
|
68
|
+
/** A pre-constructed collection to use instead of building one from items and children. */
|
|
69
|
+
collection?: C
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface Expandable {
|
|
73
|
+
/** The currently expanded keys in the collection (controlled). */
|
|
74
|
+
expandedKeys?: Iterable<Key>,
|
|
75
|
+
/** The initial expanded keys in the collection (uncontrolled). */
|
|
76
|
+
defaultExpandedKeys?: Iterable<Key>,
|
|
77
|
+
/** Handler that is called when items are expanded or collapsed. */
|
|
78
|
+
onExpandedChange?: (keys: Set<Key>) => any
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface Sortable {
|
|
82
|
+
/** The current sorted column and direction. */
|
|
83
|
+
sortDescriptor?: SortDescriptor,
|
|
84
|
+
/** Handler that is called when the sorted column or direction changes. */
|
|
85
|
+
onSortChange?: (descriptor: SortDescriptor) => any
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface SortDescriptor {
|
|
89
|
+
/** The key of the column to sort by. */
|
|
90
|
+
column?: Key,
|
|
91
|
+
/** The direction to sort by. */
|
|
92
|
+
direction?: SortDirection
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type SortDirection = 'ascending' | 'descending';
|
|
96
|
+
|
|
97
|
+
export interface KeyboardDelegate {
|
|
98
|
+
/** Returns the key visually below the given one, or `null` for none. */
|
|
99
|
+
getKeyBelow?(key: Key): Key | null,
|
|
100
|
+
|
|
101
|
+
/** Returns the key visually above the given one, or `null` for none. */
|
|
102
|
+
getKeyAbove?(key: Key): Key | null,
|
|
103
|
+
|
|
104
|
+
/** Returns the key visually to the left of the given one, or `null` for none. */
|
|
105
|
+
getKeyLeftOf?(key: Key): Key | null,
|
|
106
|
+
|
|
107
|
+
/** Returns the key visually to the right of the given one, or `null` for none. */
|
|
108
|
+
getKeyRightOf?(key: Key): Key | null,
|
|
109
|
+
|
|
110
|
+
/** Returns the key visually one page below the given one, or `null` for none. */
|
|
111
|
+
getKeyPageBelow?(key: Key): Key | null,
|
|
112
|
+
|
|
113
|
+
/** Returns the key visually one page above the given one, or `null` for none. */
|
|
114
|
+
getKeyPageAbove?(key: Key): Key | null,
|
|
115
|
+
|
|
116
|
+
/** Returns the first key, or `null` for none. */
|
|
117
|
+
getFirstKey?(key?: Key, global?: boolean): Key | null,
|
|
118
|
+
|
|
119
|
+
/** Returns the last key, or `null` for none. */
|
|
120
|
+
getLastKey?(key?: Key, global?: boolean): Key | null,
|
|
121
|
+
|
|
122
|
+
/** Returns the next key after `fromKey` that matches the given search string, or `null` for none. */
|
|
123
|
+
getKeyForSearch?(search: string, fromKey?: Key): Key | null
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface Rect {
|
|
127
|
+
x: number,
|
|
128
|
+
y: number,
|
|
129
|
+
width: number,
|
|
130
|
+
height: number
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface Size {
|
|
134
|
+
width: number,
|
|
135
|
+
height: number
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A LayoutDelegate provides layout information for collection items. */
|
|
139
|
+
export interface LayoutDelegate {
|
|
140
|
+
/** Returns a rectangle for the item with the given key. */
|
|
141
|
+
getItemRect(key: Key): Rect | null,
|
|
142
|
+
/** Returns the visible rectangle of the collection. */
|
|
143
|
+
getVisibleRect(): Rect,
|
|
144
|
+
/** Returns the size of the scrollable content in the collection. */
|
|
145
|
+
getContentSize(): Size
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A generic interface to access a readonly sequential
|
|
150
|
+
* collection of unique keyed items.
|
|
151
|
+
*/
|
|
152
|
+
export interface Collection<T> extends Iterable<T> {
|
|
153
|
+
/** The number of items in the collection. */
|
|
154
|
+
readonly size: number,
|
|
155
|
+
|
|
156
|
+
/** Iterate over all keys in the collection. */
|
|
157
|
+
getKeys(): Iterable<Key>,
|
|
158
|
+
|
|
159
|
+
/** Get an item by its key. */
|
|
160
|
+
getItem(key: Key): T | null,
|
|
161
|
+
|
|
162
|
+
/** Get an item by the index of its key. */
|
|
163
|
+
at(idx: number): T | null,
|
|
164
|
+
|
|
165
|
+
/** Get the key that comes before the given key in the collection. */
|
|
166
|
+
getKeyBefore(key: Key): Key | null,
|
|
167
|
+
|
|
168
|
+
/** Get the key that comes after the given key in the collection. */
|
|
169
|
+
getKeyAfter(key: Key): Key | null,
|
|
170
|
+
|
|
171
|
+
/** Get the first key in the collection. */
|
|
172
|
+
getFirstKey(): Key | null,
|
|
173
|
+
|
|
174
|
+
/** Get the last key in the collection. */
|
|
175
|
+
getLastKey(): Key | null,
|
|
176
|
+
|
|
177
|
+
/** Iterate over the child items of the given key. */
|
|
178
|
+
getChildren?(key: Key): Iterable<T>,
|
|
179
|
+
|
|
180
|
+
/** Returns a string representation of the item's contents. */
|
|
181
|
+
getTextValue?(key: Key): string
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface Node<T> {
|
|
185
|
+
/** The type of item this node represents. */
|
|
186
|
+
type: string,
|
|
187
|
+
/** A unique key for the node. */
|
|
188
|
+
key: Key,
|
|
189
|
+
/** The object value the node was created from. */
|
|
190
|
+
value: T | null,
|
|
191
|
+
/** The level of depth this node is at in the hierarchy. */
|
|
192
|
+
level: number,
|
|
193
|
+
/** Whether this item has children, even if not loaded yet. */
|
|
194
|
+
hasChildNodes: boolean,
|
|
195
|
+
/**
|
|
196
|
+
* The loaded children of this node.
|
|
197
|
+
* @deprecated Use `collection.getChildren(node.key)` instead.
|
|
198
|
+
*/
|
|
199
|
+
childNodes: Iterable<Node<T>>,
|
|
200
|
+
/** The rendered contents of this node (e.g. JSX). */
|
|
201
|
+
rendered: ReactNode,
|
|
202
|
+
/** A string value for this node, used for features like typeahead. */
|
|
203
|
+
textValue: string,
|
|
204
|
+
/** An accessibility label for this node. */
|
|
205
|
+
'aria-label'?: string,
|
|
206
|
+
/** The index of this node within its parent. */
|
|
207
|
+
index?: number,
|
|
208
|
+
/** A function that should be called to wrap the rendered node. */
|
|
209
|
+
wrapper?: (element: ReactElement) => ReactElement,
|
|
210
|
+
/** The key of the parent node. */
|
|
211
|
+
parentKey?: Key | null,
|
|
212
|
+
/** The key of the node before this node. */
|
|
213
|
+
prevKey?: Key | null,
|
|
214
|
+
/** The key of the node after this node. */
|
|
215
|
+
nextKey?: Key | null,
|
|
216
|
+
/** Additional properties specific to a particular node type. */
|
|
217
|
+
props?: any,
|
|
218
|
+
/** @private */
|
|
219
|
+
shouldInvalidate?: (context: unknown) => boolean,
|
|
220
|
+
/** A function that renders this node to a React Element in the DOM. */
|
|
221
|
+
render?: (node: Node<any>) => ReactElement
|
|
222
|
+
}
|