mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
docs(file-uploader): improve docs
This commit is contained in:
parent
470d74cd72
commit
85838625d2
1 changed files with 40 additions and 21 deletions
|
@ -7,23 +7,28 @@ components: ["FileUploaderButton", "FileUploader", "FileUploaderDropContainer",
|
||||||
import Preview from "../../components/Preview.svelte";
|
import Preview from "../../components/Preview.svelte";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
The `FileUploader` components provide a complete solution for file uploads, including
|
||||||
|
a button trigger, drag-and-drop container, and file list display. The components
|
||||||
|
support various states, file validation, and customization options.
|
||||||
|
|
||||||
## File uploader (button-only)
|
## File uploader (button-only)
|
||||||
|
|
||||||
By default, the file uploader only accepts one file.
|
Create a simple file upload button using `FileUploaderButton`. By default, it
|
||||||
|
accepts a single file. Set `multiple` to `true` to allow multiple file selection.
|
||||||
Set `multiple` to `true` for multiple files to be accepted.
|
|
||||||
|
|
||||||
<FileUploaderButton labelText="Add file" />
|
<FileUploaderButton labelText="Add file" />
|
||||||
|
|
||||||
## Multiple files
|
## Multiple files
|
||||||
|
|
||||||
|
Enable multiple file selection by setting the `multiple` prop to `true`. This
|
||||||
|
allows users to select multiple files at once.
|
||||||
|
|
||||||
<FileUploaderButton multiple labelText="Add files" />
|
<FileUploaderButton multiple labelText="Add files" />
|
||||||
|
|
||||||
## Custom button kind, size
|
## Custom button kind, size
|
||||||
|
|
||||||
By default, the `primary` small button kind is used.
|
Customize the button appearance using the `kind` and `size` props. The default is
|
||||||
|
a small primary button.
|
||||||
Use the `kind` and `size` props to customize the button.
|
|
||||||
|
|
||||||
<FileUploaderButton kind="secondary" size="field" />
|
<FileUploaderButton kind="secondary" size="field" />
|
||||||
<FileUploaderButton kind="tertiary" size="default" />
|
<FileUploaderButton kind="tertiary" size="default" />
|
||||||
|
@ -32,17 +37,17 @@ Use the `kind` and `size` props to customize the button.
|
||||||
|
|
||||||
## File uploader
|
## File uploader
|
||||||
|
|
||||||
The `FileUploader` wraps `FileUploaderButton` and lists out uploaded files.
|
The `FileUploader` component combines a button trigger with a list of uploaded
|
||||||
|
files. It supports file type restrictions, multiple file selection, and various
|
||||||
|
upload states.
|
||||||
|
|
||||||
The example below accepts multiple files with an extension of `.jpg` or `.jpeg`. It sets the status to `"complete"`; by default, the status is `"loading"`.
|
This example accepts multiple JPEG files and displays them in a completed state.
|
||||||
|
|
||||||
See the [item examples below](#item-uploading) for different statuses.
|
|
||||||
|
|
||||||
<FileUploader multiple labelTitle="Upload files" buttonLabel="Add files" labelDescription="Only JPEG files are accepted." accept="{['.jpg', '.jpeg']}" status="complete" />
|
<FileUploader multiple labelTitle="Upload files" buttonLabel="Add files" labelDescription="Only JPEG files are accepted." accept="{['.jpg', '.jpeg']}" status="complete" />
|
||||||
|
|
||||||
## Clear files
|
## Clear files
|
||||||
|
|
||||||
There are two ways to clear files in `FileUploader`:
|
Remove uploaded files from the `FileUploader` component in two ways:
|
||||||
|
|
||||||
<UnorderedList svx-ignore style="margin-bottom: var(--cds-spacing-08)">
|
<UnorderedList svx-ignore style="margin-bottom: var(--cds-spacing-08)">
|
||||||
<ListItem>programmatically using the <strong>clearFiles</strong> accessor</ListItem>
|
<ListItem>programmatically using the <strong>clearFiles</strong> accessor</ListItem>
|
||||||
|
@ -53,21 +58,29 @@ There are two ways to clear files in `FileUploader`:
|
||||||
|
|
||||||
## File uploader (disabled state)
|
## File uploader (disabled state)
|
||||||
|
|
||||||
|
Disable the file uploader by setting the `disabled` prop to `true`. This prevents
|
||||||
|
user interaction with the component.
|
||||||
|
|
||||||
<FileUploader disabled multiple labelTitle="Upload files" buttonLabel="Add files" labelDescription="Only JPEG files are accepted." accept="{['.jpg', '.jpeg']}" status="complete" />
|
<FileUploader disabled multiple labelTitle="Upload files" buttonLabel="Add files" labelDescription="Only JPEG files are accepted." accept="{['.jpg', '.jpeg']}" status="complete" />
|
||||||
|
|
||||||
## Item (uploading)
|
## Item (uploading)
|
||||||
|
|
||||||
|
Display a file upload in progress using the `uploading` status. This shows a
|
||||||
|
loading indicator and the file name.
|
||||||
|
|
||||||
<FileUploaderItem name="README.md" status="uploading" />
|
<FileUploaderItem name="README.md" status="uploading" />
|
||||||
|
|
||||||
## Item (complete)
|
## Item (complete)
|
||||||
|
|
||||||
|
Show a successfully uploaded file using the `complete` status. This displays a
|
||||||
|
checkmark icon next to the file name.
|
||||||
|
|
||||||
<FileUploaderItem name="README.md" status="complete" />
|
<FileUploaderItem name="README.md" status="complete" />
|
||||||
|
|
||||||
## Item (edit)
|
## Item (edit)
|
||||||
|
|
||||||
If the `status` is `"edit"`, clicking the close icon will dispatch a `delete` event.
|
Enable file deletion by setting the status to `"edit"`. Clicking the close icon
|
||||||
|
dispatches a `delete` event with the item's ID.
|
||||||
The event detail contains the item `id`.
|
|
||||||
|
|
||||||
<FileUploaderItem id="readme" name="README.md" status="edit" on:delete={(e) => {
|
<FileUploaderItem id="readme" name="README.md" status="edit" on:delete={(e) => {
|
||||||
console.log(e.detail); // "readme"
|
console.log(e.detail); // "readme"
|
||||||
|
@ -75,13 +88,15 @@ The event detail contains the item `id`.
|
||||||
|
|
||||||
## Item (edit status, invalid state)
|
## Item (edit status, invalid state)
|
||||||
|
|
||||||
An item can also have an edit status with an invalid state.
|
Mark a file as invalid while keeping it editable. This shows an error icon and
|
||||||
|
allows the user to remove the file.
|
||||||
|
|
||||||
<FileUploaderItem invalid id="readme" name="README.md" status="edit" on:delete />
|
<FileUploaderItem invalid id="readme" name="README.md" status="edit" on:delete />
|
||||||
|
|
||||||
## Item (edit status, invalid state with subject, body)
|
## Item (edit status, invalid state with subject, body)
|
||||||
|
|
||||||
Use the `errorSubject` and `errorBody` props to customize the error message.
|
Provide detailed error messages for invalid files using the `errorSubject` and
|
||||||
|
`errorBody` props. This helps users understand and resolve upload issues.
|
||||||
|
|
||||||
<FileUploaderItem
|
<FileUploaderItem
|
||||||
invalid
|
invalid
|
||||||
|
@ -95,7 +110,8 @@ Use the `errorSubject` and `errorBody` props to customize the error message.
|
||||||
|
|
||||||
## Item sizes
|
## Item sizes
|
||||||
|
|
||||||
The default `FileUploaderItem` size is "default".
|
Customize the size of file uploader items using the `size` prop. The default size
|
||||||
|
is "default".
|
||||||
|
|
||||||
<FileUploaderItem size="default" name="README.md" status="uploading" />
|
<FileUploaderItem size="default" name="README.md" status="uploading" />
|
||||||
<FileUploaderItem size="field" name="README.md" status="uploading" />
|
<FileUploaderItem size="field" name="README.md" status="uploading" />
|
||||||
|
@ -103,11 +119,11 @@ The default `FileUploaderItem` size is "default".
|
||||||
|
|
||||||
## Drop container
|
## Drop container
|
||||||
|
|
||||||
The `FileUploaderDropContainer` accepts files through click and drop events.
|
Use `FileUploaderDropContainer` for drag-and-drop file uploads. It supports file
|
||||||
|
validation and multiple file selection.
|
||||||
|
|
||||||
Use the `validateFiles` prop to filter out files before they are set.
|
This example accepts files smaller than 1 kB and logs the selected files to the
|
||||||
|
console.
|
||||||
The following example accepts files smaller than 1 kB.
|
|
||||||
|
|
||||||
<FileUploaderDropContainer
|
<FileUploaderDropContainer
|
||||||
multiple
|
multiple
|
||||||
|
@ -122,4 +138,7 @@ The following example accepts files smaller than 1 kB.
|
||||||
|
|
||||||
## Skeleton
|
## Skeleton
|
||||||
|
|
||||||
|
Display a loading state using the `FileUploaderSkeleton` component. This provides
|
||||||
|
visual feedback while the file uploader content is being loaded.
|
||||||
|
|
||||||
<FileUploaderSkeleton />
|
<FileUploaderSkeleton />
|
Loading…
Add table
Add a link
Reference in a new issue