Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port @uppy/drop-target docs #59

Merged
merged 6 commits into from
Jan 24, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions docs/user-interfaces/elements/drop-target.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,104 @@
---
sidebar_position: 2
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

import UppyCdnExample from '/src/components/UppyCdnExample';

# Drop target

The `@uppy/drop-target` plugin lets your users drag-and-drop files on any
element on the page, for example the whole page, `document.body`.

Can be used together with Uppy Dashboard or Drag & Drop plugins, or your custom
solution, including plain text “please drop files here”.
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

:::tip

[Try out the live example](/examples) or take it for a spin in
[CodeSandbox](https://codesandbox.io/s/uppy-drag-drop-gyewzx?file=/src/index.js).
Comment on lines +20 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/examples doesn't exit. We should also create a codesandbox for this plugin and link it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We plan to have something at /examples don't we?

{ to: '/examples', label: 'Examples', position: 'left' },

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No as discussed we will go live without it and potentially never have it as we emphasize our existing examples repo and codesandboxes. So at least for now we need to remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also create a codesandbox for this plugin and link it here.

I don't know what's needed for this. We should probably document some guidelines around it.

No as discussed we will go live without it and potentially never have it as we emphasize our existing examples repo and codesandboxes.

There are 12 other pages linking to /examples, plus the main nav menu cited above. I don't think it makes sense to remove it from this PR. If we plan to remove them before going live, it can be done in a follow-up PR and doesn't have to block this one.


:::

## When should I use this?

When you want to allow users to drag and drop files in your own UI, rather than
in the [`Dashboard`](../dashboard) UI.
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

## Install

This plugin is published as the `@uppy/drop-target` package on the npm registry.
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

<Tabs>
<TabItem value="npm" label="NPM" default>

```shell
npm install @uppy/drop-target
```

</TabItem>

<TabItem value="yarn" label="Yarn">

```shell
yarn add @uppy/drop-target
```

</TabItem>

<TabItem value="cdn" label="CDN">
<UppyCdnExample>
{`
import { DropTarget } from "{{UPPY_JS_URL}}"
const DropTarget = new Uppy().use(DropTarget)
`}
</UppyCdnExample>
</TabItem>
</Tabs>

## Use

This module has one default export: the `DropTarget` plugin class.

```js {8-10} showLineNumbers
import Uppy from '@uppy/core';
import DropTarget from '@uppy/drop-target';

import '@uppy/core/dist/style.css';
import '@uppy/drop-target/dist/style.css';

const uppy = new Uppy();
uppy.use(DropTarget, {
target: document.body,
});
```

## API

### Options

#### `onDragLeave(event)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to leave the function name with arguments, so URLs won’t break if we change the arguments? https://transloadit.slack.com/archives/C0FMW9PSB/p1673972430908959


Event listener for the [`dragleave` event][].

#### `onDragOver(event)`

Event listener for the [`dragover` event][].

#### `onDrop(event)`

Event listener for the [`drop` event][].

#### `target`

DOM element, CSS selector, or plugin to place the drag and drop area into
(`string`, `Element`, `Function`, or `UIPlugin`, default: `null`).
Comment on lines +102 to +105
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we always put id and target on top of the list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we list the option in alphabetical order instead? That seems easier to enforce.

Copy link
Member

@Murderlon Murderlon Jan 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit all over the place currently. I can make sorting part of #45 (automate it with remark). So indeed doesn't matter that much for now


[`dragover` event]:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dragover_event
[`dragleave` event]:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dragleave_event
[`drop` event]:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/drop_event