mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
parent
826b7096c8
commit
7586b2a10f
6 changed files with 39 additions and 8 deletions
|
@ -1263,7 +1263,7 @@ None.
|
||||||
|
|
||||||
| Prop name | Kind | Reactive | Type | Default value | Description |
|
| Prop name | Kind | Reactive | Type | Default value | Description |
|
||||||
| :--------------- | :----------------- | :------- | :----------------------------------------------------------------------------------------- | --------------------------------------- | ----------------------------------------------------------- |
|
| :--------------- | :----------------- | :------- | :----------------------------------------------------------------------------------------- | --------------------------------------- | ----------------------------------------------------------- |
|
||||||
| files | <code>let</code> | Yes | <code>File[]</code> | <code>[]</code> | Obtain the uploaded file names |
|
| files | <code>let</code> | Yes | <code>File[]</code> | <code>[]</code> | Obtain a reference to the uploaded files |
|
||||||
| status | <code>let</code> | No | <code>"uploading" | "edit" | "complete"</code> | <code>"uploading"</code> | Specify the file uploader status |
|
| status | <code>let</code> | No | <code>"uploading" | "edit" | "complete"</code> | <code>"uploading"</code> | Specify the file uploader status |
|
||||||
| accept | <code>let</code> | No | <code>string[]</code> | <code>[]</code> | Specify the accepted file types |
|
| accept | <code>let</code> | No | <code>string[]</code> | <code>[]</code> | Specify the accepted file types |
|
||||||
| multiple | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to allow multiple files |
|
| multiple | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to allow multiple files |
|
||||||
|
@ -1300,6 +1300,7 @@ None.
|
||||||
| :------------------ | :--------------- | :------- | :----------------------------------------------------------------------------------------- | ------------------------------------------------ | -------------------------------------------- |
|
| :------------------ | :--------------- | :------- | :----------------------------------------------------------------------------------------- | ------------------------------------------------ | -------------------------------------------- |
|
||||||
| ref | <code>let</code> | Yes | <code>null | HTMLInputElement</code> | <code>null</code> | Obtain a reference to the input HTML element |
|
| ref | <code>let</code> | Yes | <code>null | HTMLInputElement</code> | <code>null</code> | Obtain a reference to the input HTML element |
|
||||||
| labelText | <code>let</code> | Yes | <code>string</code> | <code>"Add file"</code> | Specify the label text |
|
| labelText | <code>let</code> | Yes | <code>string</code> | <code>"Add file"</code> | Specify the label text |
|
||||||
|
| files | <code>let</code> | Yes | <code>File[]</code> | <code>[]</code> | Obtain a reference to the uploaded files |
|
||||||
| accept | <code>let</code> | No | <code>string[]</code> | <code>[]</code> | Specify the accepted file types |
|
| accept | <code>let</code> | No | <code>string[]</code> | <code>[]</code> | Specify the accepted file types |
|
||||||
| multiple | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to allow multiple files |
|
| multiple | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to allow multiple files |
|
||||||
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the input |
|
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the input |
|
||||||
|
|
|
@ -3481,7 +3481,7 @@
|
||||||
{
|
{
|
||||||
"name": "files",
|
"name": "files",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
"description": "Obtain the uploaded file names",
|
"description": "Obtain a reference to the uploaded files",
|
||||||
"type": "File[]",
|
"type": "File[]",
|
||||||
"value": "[]",
|
"value": "[]",
|
||||||
"isFunction": false,
|
"isFunction": false,
|
||||||
|
@ -3607,6 +3607,17 @@
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": false
|
"reactive": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "files",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Obtain a reference to the uploaded files",
|
||||||
|
"type": "File[]",
|
||||||
|
"value": "[]",
|
||||||
|
"isFunction": false,
|
||||||
|
"isFunctionDeclaration": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "multiple",
|
"name": "multiple",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
export let accept = [];
|
export let accept = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the uploaded file names
|
* Obtain a reference to the uploaded files
|
||||||
* @type {File[]}
|
* @type {File[]}
|
||||||
*/
|
*/
|
||||||
export let files = [];
|
export let files = [];
|
||||||
|
|
|
@ -9,6 +9,12 @@
|
||||||
*/
|
*/
|
||||||
export let accept = [];
|
export let accept = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain a reference to the uploaded files
|
||||||
|
* @type {File[]}
|
||||||
|
*/
|
||||||
|
export let files = [];
|
||||||
|
|
||||||
/** Set to `true` to allow multiple files */
|
/** Set to `true` to allow multiple files */
|
||||||
export let multiple = false;
|
export let multiple = false;
|
||||||
|
|
||||||
|
@ -45,6 +51,13 @@
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let initialLabelText = labelText;
|
||||||
|
|
||||||
|
$: if (ref && files.length === 0) {
|
||||||
|
labelText = initialLabelText;
|
||||||
|
ref.value = null;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
|
@ -80,13 +93,13 @@
|
||||||
class:bx--visually-hidden="{true}"
|
class:bx--visually-hidden="{true}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
on:change|stopPropagation="{({ target }) => {
|
on:change|stopPropagation="{({ target }) => {
|
||||||
const files = target.files;
|
files = [...target.files];
|
||||||
const length = files.length;
|
|
||||||
if (files && !disableLabelChanges) {
|
if (files && !disableLabelChanges) {
|
||||||
labelText = length > 1 ? `${length} files` : files[0].name;
|
labelText = files.length > 1 ? `${files.length} files` : files[0].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch('change', [...files]);
|
dispatch('change', files);
|
||||||
}}"
|
}}"
|
||||||
on:click
|
on:click
|
||||||
on:click="{({ target }) => {
|
on:click="{({ target }) => {
|
||||||
|
|
2
types/FileUploader/FileUploader.svelte.d.ts
vendored
2
types/FileUploader/FileUploader.svelte.d.ts
vendored
|
@ -16,7 +16,7 @@ export interface FileUploaderProps
|
||||||
accept?: string[];
|
accept?: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the uploaded file names
|
* Obtain a reference to the uploaded files
|
||||||
* @default []
|
* @default []
|
||||||
*/
|
*/
|
||||||
files?: File[];
|
files?: File[];
|
||||||
|
|
|
@ -9,6 +9,12 @@ export interface FileUploaderButtonProps
|
||||||
*/
|
*/
|
||||||
accept?: string[];
|
accept?: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain a reference to the uploaded files
|
||||||
|
* @default []
|
||||||
|
*/
|
||||||
|
files?: File[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to `true` to allow multiple files
|
* Set to `true` to allow multiple files
|
||||||
* @default false
|
* @default false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue