You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update examples and imports in RSP DropZone docs (#5138)
* Update examples and imports in RSP DropZone docs
* fix typecheck
* fix typecheck again
* fix spacing
---------
Co-authored-by: Daniel Lu <dl1644@gmail.com>
A drop zone accepts an [IllustratedMessage](IllustratedMessage.html) as a child which is comprised of three areas: an illustration, a title, and a body. Each of these sections can be populated by providing the following components to the IllustratedMessage as children: a SVG, a [Heading](Heading.html) (title), and a [Content](Content.html) (body). A [FileTrigger](../react-aria/FileTrigger.html) is commonly paired with a DropZone to allow a user to choose files from their device.
64
-
65
-
```tsx example
66
-
<DropZone
67
-
maxWidth="size-3000">
68
-
<IllustratedMessage>
69
-
<Upload />
70
-
<Heading>
71
-
<Textslot="label">
72
-
Drag and drop here
73
-
</Text>
74
-
</Heading>
75
-
<Content>
76
-
<FileTrigger>
77
-
<Buttonvariant="primary">Browse</Button>
78
-
</FileTrigger>
79
-
</Content>
80
-
</IllustratedMessage>
81
-
</DropZone>
82
-
```
83
-
84
-
### Accessibility
85
-
86
-
A visual label should be provided to `DropZone` using a `Text` element with a `label` slot. If it is not provided, then an `aria-label` or `aria-labelledby` prop must be passed to identify the visually hidden button to assistive technology.
87
-
88
-
### Internationalization
89
-
90
-
In order to internationalize a drop zone, a localized string should be passed to the `Text` element with a `label` slot or to the `aria-label` prop, in addition to the `replaceMessage` prop.
91
-
92
-
## Events
93
-
94
-
`DropZone` supports drop operations via mouse, keyboard, and touch. You can handle all of these via the `onDrop` prop. In addition, the `onDropEnter`, `onDropMove`, and `onDropExit` events are fired as the user enter and exists the dropzone during a drag operation.
95
-
96
-
The following example uses an `onDrop` handler to update the filled status stored in React state.
The `Draggable` component used above is defined below. See [useDrag](../react-aria/useDrag.html) for more details and documentation.
143
75
144
76
<details>
@@ -185,14 +117,117 @@ function Draggable() {
185
117
opacity: 0.5;
186
118
}
187
119
188
-
.files{
120
+
.dropped{
189
121
margin-top: 20px;
190
122
}
191
123
```
192
-
193
124
</details>
194
125
195
126
127
+
128
+
## Content
129
+
130
+
A drop zone accepts an [IllustratedMessage](IllustratedMessage.html) as a child which is comprised of three areas: an illustration, a title, and a body. Each of these sections can be populated by providing the following components to the IllustratedMessage as children: a SVG, a [Heading](Heading.html) (title), and a [Content](Content.html) (body). A [FileTrigger](../react-aria/FileTrigger.html) is commonly paired with a DropZone to allow a user to choose files from their device.
131
+
132
+
```tsx example
133
+
import {FileTrigger} from'react-aria-components';
134
+
import {Text} from'react-aria-components';
135
+
136
+
function Example() {
137
+
let [isFilled, setIsFilled] =React.useState(false);
138
+
139
+
return (
140
+
<>
141
+
<Draggable />
142
+
<DropZone
143
+
maxWidth="size-3000"
144
+
isFilled={isFilled}
145
+
onDrop={() =>setIsFilled(true)}>
146
+
<IllustratedMessage>
147
+
<Upload />
148
+
<Heading>
149
+
<Textslot="label">
150
+
Drag and drop here
151
+
</Text>
152
+
</Heading>
153
+
<Content>
154
+
<FileTrigger
155
+
onSelect={()=>setIsFilled(true)}>
156
+
<Buttonvariant="primary">Browse</Button>
157
+
</FileTrigger>
158
+
</Content>
159
+
</IllustratedMessage>
160
+
</DropZone>
161
+
{isFilled&&
162
+
<divclassName="dropped">
163
+
You dropped something!
164
+
</div>
165
+
}
166
+
</>
167
+
)
168
+
}
169
+
```
170
+
171
+
### Accessibility
172
+
173
+
A visual label should be provided to `DropZone` using a `Text` element with a `label` slot. If it is not provided, then an `aria-label` or `aria-labelledby` prop must be passed to identify the visually hidden button to assistive technology.
174
+
175
+
### Internationalization
176
+
177
+
In order to internationalize a drop zone, a localized string should be passed to the `Text` element with a `label` slot or to the `aria-label` prop, in addition to the `replaceMessage` prop.
178
+
179
+
## Events
180
+
181
+
`DropZone` supports drop operations via mouse, keyboard, and touch. You can handle all of these via the `onDrop` prop. In addition, the `onDropEnter`, `onDropMove`, and `onDropExit` events are fired as the user enter and exists the dropzone during a drag operation.
182
+
183
+
The following example uses an `onDrop` handler to update the filled status stored in React state.
@@ -206,6 +241,8 @@ The user is responsible for both managing the filled state of a drop zone and ha
206
241
The example below demonstrates one way of styling the filled state.
207
242
208
243
```tsx example
244
+
import {Text} from'react-aria-components';
245
+
209
246
function Example() {
210
247
let [filledSrc, setFilledSrc] =React.useState(null);
211
248
let [isFilled, setIsFilled] =React.useState(false);
@@ -302,6 +339,8 @@ When a drop zone is in a filled state and has an object dragged over it, a messa
302
339
303
340
304
341
```tsx example
342
+
import {Text} from'react-aria-components';
343
+
305
344
function Example() {
306
345
let [isFilled, setIsFilled] =React.useState(false);
307
346
@@ -322,6 +361,11 @@ function Example() {
322
361
</Heading>
323
362
</IllustratedMessage>
324
363
</DropZone>
364
+
{isFilled&&
365
+
<divclassName="dropped">
366
+
You dropped something!
367
+
</div>
368
+
}
325
369
</>
326
370
);
327
371
}
@@ -332,30 +376,60 @@ function Example() {
332
376
A drop zone displays visual feedback to the user when a drag hovers over the drop target by passing the `getDropOperation` function. If a drop target only supports data of specific types (e.g. images, videos, text, etc.), then it should implement the `getDropOperation` prop and return `cancel` for types that aren't supported. This will prevent visual feedback indicating that the drop target accepts the dragged data when this is not true. [Read more about getDropOperation.](../react-aria/useDrop.html#getdropoperation)
333
377
334
378
```tsx example
379
+
import {FileTrigger} from'react-aria-components';
380
+
import {Text} from'react-aria-components';
381
+
import {FileDropItem} from'react-aria';
335
382
336
383
function Example() {
337
384
let [isFilled, setIsFilled] =React.useState(false);
385
+
let [filledSrc, setFilledSrc] =React.useState(null);
0 commit comments