Skip to content

Commit

Permalink
Status Bar and Dashboard: add “done” after upload is complete (#2653)
Browse files Browse the repository at this point in the history
* add Done button

* move doneButtonHandler to options in Dashboard

* update docs

* revert for speed
  • Loading branch information
arturi authored Nov 25, 2020
1 parent 449798d commit d40ad5d
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 10 deletions.
7 changes: 6 additions & 1 deletion packages/@uppy/dashboard/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ module.exports = class Dashboard extends Plugin {
hideRetryButton: false,
hidePauseResumeButton: false,
hideProgressAfterFinish: false,
doneButtonHandler: () => {
this.uppy.reset()
this.requestCloseModal()
},
note: null,
closeModalOnClickOutside: false,
closeAfterFinish: false,
Expand Down Expand Up @@ -993,7 +997,8 @@ module.exports = class Dashboard extends Plugin {
hideCancelButton: this.opts.hideCancelButton,
showProgressDetails: this.opts.showProgressDetails,
hideAfterFinish: this.opts.hideProgressAfterFinish,
locale: this.opts.locale
locale: this.opts.locale,
doneButtonHandler: this.opts.doneButtonHandler
})
}

Expand Down
17 changes: 17 additions & 0 deletions packages/@uppy/status-bar/src/StatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ module.exports = (props) => {

const showRetryBtn = error && !hideRetryButton

const showDoneBtn = props.doneButtonHandler && uploadState === statusBarStates.STATE_COMPLETE

const progressClassNames = `uppy-StatusBar-progress
${progressMode ? 'is-' + progressMode : ''}`

Expand All @@ -134,6 +136,7 @@ module.exports = (props) => {
{showRetryBtn ? <RetryBtn {...props} /> : null}
{showPauseResumeBtn ? <PauseResumeButton {...props} /> : null}
{showCancelBtn ? <CancelBtn {...props} /> : null}
{showDoneBtn ? <DoneBtn {...props} /> : null}
</div>
</div>
)
Expand Down Expand Up @@ -232,6 +235,20 @@ const PauseResumeButton = (props) => {
)
}

const DoneBtn = (props) => {
const { i18n } = props
return (
<button
type="button"
class="uppy-u-reset uppy-c-btn uppy-StatusBar-actionBtn uppy-StatusBar-actionBtn--done"
onClick={props.doneButtonHandler}
data-uppy-super-focusable
>
{i18n('done')}
</button>
)
}

const LoadingSpinner = () => {
return (
<svg class="uppy-StatusBar-spinner" aria-hidden="true" focusable="false" width="14" height="14">
Expand Down
5 changes: 4 additions & 1 deletion packages/@uppy/status-bar/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = class StatusBar extends Plugin {
cancel: 'Cancel',
pause: 'Pause',
resume: 'Resume',
done: 'Done',
filesUploadedOfTotal: {
0: '%{complete} of %{smart_count} file uploaded',
1: '%{complete} of %{smart_count} files uploaded'
Expand Down Expand Up @@ -59,7 +60,8 @@ module.exports = class StatusBar extends Plugin {
hidePauseResumeButton: false,
hideCancelButton: false,
showProgressDetails: false,
hideAfterFinish: true
hideAfterFinish: true,
doneButtonHandler: null
}

this.opts = { ...defaultOptions, ...opts }
Expand Down Expand Up @@ -226,6 +228,7 @@ module.exports = class StatusBar extends Plugin {
retryAll: this.uppy.retryAll,
cancelAll: this.uppy.cancelAll,
startUpload: this.startUpload,
doneButtonHandler: this.opts.doneButtonHandler,
resumableUploads,
supportsUploadProgress,
showProgressDetails: this.opts.showProgressDetails,
Expand Down
15 changes: 15 additions & 0 deletions packages/@uppy/status-bar/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
}
}

.uppy-StatusBar-actionBtn--done {
@include highlight-focus;
line-height: 1;
border-radius: 3px;
padding: 7px 8px;

[data-uppy-theme="dark"] & {
color: $highlight--dark;
}
}

.uppy-size--md .uppy-StatusBar-actionBtn--done {
font-size: 14px;
}

.uppy-StatusBar-details {
line-height: 12px;
width: 13px;
Expand Down
17 changes: 17 additions & 0 deletions website/src/docs/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ uppy.use(Dashboard, {
hidePauseResumeButton: false,
hideCancelButton: false,
hideProgressAfterFinish: false,
doneButtonHandler: () => {
this.uppy.reset()
this.requestCloseModal()
},
note: null,
closeModalOnClickOutside: false,
closeAfterFinish: false,
Expand Down Expand Up @@ -184,6 +188,19 @@ Use this if you are providing a custom retry button somewhere, and using the `up

Hide Status Bar after the upload has finished.

### `doneButtonHandler`

This option is passed to the StatusBar, and will render a “Done” button in place of pause/resume/cancel buttons, once the upload/encoding is done. The behaviour of this “Done” button is defined by the handler function — can be used to close file picker modals or clear the upload state. This is what the Dashboard sets by default:

```js
doneButtonHandler: () => {
this.uppy.reset()
this.requestCloseModal()
}
```

Set to `null` to disable the “Done” button.

### `showSelectedFiles: true`

Show the list (grid) of selected files with preview and file name. In case you are showing selected files in your own app’s UI and want the Uppy Dashboard to just be a picker, the list can be hidden with this option.
Expand Down
26 changes: 18 additions & 8 deletions website/src/docs/statusbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ uppy.use(StatusBar, {
hideRetryButton: false,
hidePauseResumeButton: false,
hideCancelButton: false,
doneButtonHandler: null,
locale: {}
})
```
Expand Down Expand Up @@ -104,6 +105,17 @@ Hide pause/resume buttons (for resumable uploads, via [tus](http://tus.io), for

Hide the cancel button. Use this if you are providing a custom retry button somewhere, and using the `uppy.cancelAll()` API.

### `doneButtonHandler`

If passed a function, Status Bar will render a “Done” button in place of pause/resume/cancel buttons, once the upload/encoding is done. The behaviour of this “Done” button is defined by the handler function — can be used to close file picker modals or clear the upload state. This is what the Dashboard plugin, which uses Status Bar internally, sets:

```js
doneButtonHandler: () => {
this.uppy.reset()
this.requestCloseModal()
}
```

### `locale: {}`

Localize text that is shown to the user.
Expand All @@ -124,14 +136,12 @@ strings: {
retry: 'Retry',
// Used as the label for the button that cancels an upload.
cancel: 'Cancel',
// Used as the screen reader label for the button that retries an upload.
retryUpload: 'Retry upload',
// Used as the screen reader label for the button that pauses an upload.
pauseUpload: 'Pause upload',
// Used as the screen reader label for the button that resumes a paused upload.
resumeUpload: 'Resume upload',
// Used as the screen reader label for the button that cancels an upload.
cancelUpload: 'Cancel upload',
// Used as the label for the button that pauses an upload.
pause: 'Pause',
// Used as the label for the button that resumes an upload.
resume: 'Resume',
// Used as the label for the button that resets the upload state after an upload
done: 'Done',
// When `showProgressDetails` is set, shows the number of files that have been fully uploaded so far.
filesUploadedOfTotal: {
0: '%{complete} of %{smart_count} file uploaded',
Expand Down

0 comments on commit d40ad5d

Please sign in to comment.