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

Implement #104: Make file upload return an array of files #276

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Changed

- Updated dependencies and cleaned up test config.
- **Breaking**: `six-file-upload` on upload success now returns a `FileList` regardless of the value of
the `multiple` property

### Fixed

Expand Down
11 changes: 6 additions & 5 deletions docs/components/six-file-upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
let counter = 0;

fileUpload.addEventListener('six-file-upload-success', ({ detail }) => {
const file = detail.file;
// Since multiple is by default false, we know the array contains only one element
const file = detail.files[0];

const item = Object.assign(document.createElement('six-file-list-item'), {
id: String(counter++),
Expand Down Expand Up @@ -181,10 +182,10 @@ When using the `error-text` slot, it is recommended to use the `six-error` compo

## Events

| Event | Description | Type |
| ------------------------- | ------------------------------------------------------------------------ | -------------------------------------------- |
| `six-file-upload-failure` | Triggers when an uploaded file doesn't match MIME type or max file size. | `CustomEvent<SixFileUploadFailurePayload>` |
| `six-file-upload-success` | Triggers when a file is added. | `CustomEvent<IMultipleFiles \| ISingleFile>` |
| Event | Description | Type |
| ------------------------- | ------------------------------------------------------------------------ | ------------------------------------------ |
| `six-file-upload-failure` | Triggers when an uploaded file doesn't match MIME type or max file size. | `CustomEvent<SixFileUploadFailurePayload>` |
| `six-file-upload-success` | Triggers when a file is added. | `CustomEvent<SixFileUploadSuccessPayload>` |


## Slots
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ <h2>Simple File Upload</h2>
let counter = 0;

fileUpload.addEventListener('six-file-upload-success', ({ detail }) => {
const file = detail.file;
// Since multiple is by default false, we know the array contains only one element
const file = detail.files[0];

const item = Object.assign(document.createElement('six-file-list-item'), {
id: String(counter++),
Expand Down
8 changes: 4 additions & 4 deletions libraries/ui-library/src/components/six-file-upload/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

## Events

| Event | Description | Type |
| ------------------------- | ------------------------------------------------------------------------ | -------------------------------------------- |
| `six-file-upload-failure` | Triggers when an uploaded file doesn't match MIME type or max file size. | `CustomEvent<SixFileUploadFailurePayload>` |
| `six-file-upload-success` | Triggers when a file is added. | `CustomEvent<IMultipleFiles \| ISingleFile>` |
| Event | Description | Type |
| ------------------------- | ------------------------------------------------------------------------ | ------------------------------------------ |
| `six-file-upload-failure` | Triggers when an uploaded file doesn't match MIME type or max file size. | `CustomEvent<SixFileUploadFailurePayload>` |
| `six-file-upload-success` | Triggers when a file is added. | `CustomEvent<SixFileUploadSuccessPayload>` |


## Slots
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { Component, Element, Event, EventEmitter, h, Listen, Prop, State } from '@stencil/core';
import { hasSlot } from '../../utils/slot';

interface ISingleFile {
file: File;
}

interface IMultipleFiles {
export interface SixFileUploadSuccessPayload {
files: FileList;
}

export type SixFileUploadSuccessPayload = ISingleFile | IMultipleFiles;

export interface SixFileUploadFailurePayload {
reason: string;
}
Expand Down Expand Up @@ -143,8 +137,7 @@ export class SixFileUpload {
}
}

const eventPayload: SixFileUploadSuccessPayload = this.multiple ? { files } : { file: files[0] };
this.success.emit(eventPayload);
this.success.emit({ files } as SixFileUploadSuccessPayload);
};

componentWillLoad() {
Expand Down
Loading