Dropzone Primitive
Dropzone is a Starwind Runtime primitive in the form-value-control contract family.
Anatomy
Use the Astro primitive adapter to render Dropzone anatomy with the Runtime wiring included.
---import { Dropzone } from "@starwind-ui/astro/dropzone";---
<Dropzone.Root> <Dropzone.Input /> <Dropzone.UploadIndicator>Drop files here</Dropzone.UploadIndicator> <Dropzone.LoadingIndicator>Uploading...</Dropzone.LoadingIndicator> <Dropzone.FilesList /></Dropzone.Root>Use the React primitive adapter when Dropzone state participates in React rendering.
import { Dropzone } from "@starwind-ui/react/dropzone";
export function Example() { return ( <Dropzone.Root> <Dropzone.Input /> <Dropzone.UploadIndicator>Drop files here</Dropzone.UploadIndicator> <Dropzone.LoadingIndicator>Uploading...</Dropzone.LoadingIndicator> <Dropzone.FilesList /> </Dropzone.Root> );}Render the Dropzone data-sw-* contract yourself, then initialize createDropzone.
<label data-sw-dropzone role="button"> <input data-sw-dropzone-input type="file" tabindex="-1" class="sr-only" /> <div data-sw-dropzone-upload-indicator>Drop files here</div> <div data-sw-dropzone-loading-indicator hidden>Uploading...</div> <div data-sw-dropzone-files-list></div></label>
<script type="module"> import { createDropzone } from "@starwind-ui/runtime/dropzone";
const root = document.querySelector("[data-sw-dropzone]"); if (root) { createDropzone(root); }</script>API Reference
Root
The main element that owns the Dropzone Runtime instance.
- Default element
- label
- Discovery hook
- data-sw-dropzone
- Role
- button
Props
Prop Type Default Toggle
disabled boolean false
- Description
- Disables the Root part.
- Kind
- option
- Targets
- -
- Full type
- boolean
isUploading boolean false
- Description
- Controls whether Dropzone is uploading.
- Kind
- control
- Targets
- root, uploadIndicator, loadingIndicator
- Full type
- boolean
onFilesChange (files: File[], details: DropzoneFilesChangeDetails) => void -
- Description
- Runs when selected files change for Dropzone.
- Kind
- callback
- Targets
- -
- Full type
- (files: File[], details: DropzoneFilesChangeDetails) => void
Events
Event Callback Value Toggle
filesChange onFilesChange files: File[]
- Description
- Fires when selected files change for Dropzone.
- DOM event
- starwind:files-change
- Details type
- DropzoneFilesChangeDetails
- Timing
- -
- Cancelable
- No
State
State Type Props Toggle
uploading boolean isUploading
- Description
- Tracks whether Dropzone is uploading files.
- Initial attribute
- data-is-uploading
- Runtime getter
- getUploading
- Runtime setter
- setUploading
- State control support
- React supports controlled state with the isUploading prop. Runtime/HTML reads initial state from data-is-uploading and updates with setUploading. Astro adapters render initial/default state and report changes through Runtime DOM events.
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-dropzone - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-drag-active - Reflects the drag active state on the Root part.
data-has-files - Reflects the has files state on the Root part.
Metadata
Attribute Value Description
data-disabled - Reflects the disabled prop on the Root part.
data-is-uploading - Reflects the uploading prop on the Root part.
Input
The native input synchronized by Dropzone.
- Default element
- input
- Discovery hook
- data-sw-dropzone-input
- Role
- -
Props
Prop Type Default Toggle
accept string -
- Description
- Limits which file types can be selected.
- Kind
- attribute
- Targets
- input
- Full type
- string
multiple boolean -
- Description
- Allows multiple Dropzone values to be selected.
- Kind
- attribute
- Targets
- input
- Full type
- boolean
name string -
- Description
- Sets the submitted form field name.
- Kind
- attribute
- Targets
- input
- Full type
- string
required boolean -
- Description
- Marks the form control as required.
- Kind
- attribute
- Targets
- input
- Full type
- boolean
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-dropzone-input - Marks the Input part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-disabled - Reflects the disabled prop on the Input part.
Upload Indicator
Upload progress indicator shown by Dropzone.
- Default element
- div
- Discovery hook
- data-sw-dropzone-upload-indicator
- Role
- -
Props
Prop Type Default Toggle
isUploading boolean false
- Description
- Controls whether Dropzone is uploading.
- Kind
- control
- Targets
- root, uploadIndicator, loadingIndicator
- Full type
- boolean
State
State Type Props Toggle
uploading boolean isUploading
- Description
- Tracks whether Dropzone is uploading files.
- Initial attribute
- data-is-uploading
- Runtime getter
- getUploading
- Runtime setter
- setUploading
- State control support
- React supports controlled state with the isUploading prop. Runtime/HTML reads initial state from data-is-uploading and updates with setUploading. Astro adapters render initial/default state and report changes through Runtime DOM events.
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-dropzone-upload-indicator - Marks the Upload Indicator part so Starwind Runtime can find it.
State
Attribute Value Description
data-is-uploading - Reflects the uploading state on the Upload Indicator part.
Loading Indicator
Loading indicator shown by Dropzone.
- Default element
- div
- Discovery hook
- data-sw-dropzone-loading-indicator
- Role
- -
Props
Prop Type Default Toggle
isUploading boolean false
- Description
- Controls whether Dropzone is uploading.
- Kind
- control
- Targets
- root, uploadIndicator, loadingIndicator
- Full type
- boolean
State
State Type Props Toggle
uploading boolean isUploading
- Description
- Tracks whether Dropzone is uploading files.
- Initial attribute
- data-is-uploading
- Runtime getter
- getUploading
- Runtime setter
- setUploading
- State control support
- React supports controlled state with the isUploading prop. Runtime/HTML reads initial state from data-is-uploading and updates with setUploading. Astro adapters render initial/default state and report changes through Runtime DOM events.
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-dropzone-loading-indicator - Marks the Loading Indicator part so Starwind Runtime can find it.
State
Attribute Value Description
data-is-uploading - Reflects the uploading state on the Loading Indicator part.
Files List
Lists the selected files for Dropzone.
- Default element
- div
- Discovery hook
- data-sw-dropzone-files-list
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-dropzone-files-list - Marks the Files List part so Starwind Runtime can find it.
State
Attribute Value Description
data-has-files - Reflects the has files state on the Files List part.
Runtime API
- Factory
createDropzone- Import
@starwind-ui/runtime/dropzone- Root hook
- root
data-sw-dropzone - Option props
- disabled, isUploading, onFilesChange
Option Lifecycles
| Option | Lifecycle |
|---|---|
| disabled | setter-backed |
| isUploading | setter-backed |
| onFilesChange | constructor-only |
Runtime Setters
Method Target Description
setDisabled prop: disabled Updates whether Dropzone is disabled from Runtime code.
setUploading prop: isUploading Updates whether Dropzone is uploading files from Runtime code.
Form Participation
| Fact | Value |
|---|---|
| Form props | accept, multiple, name, required |
| Hidden input | input (file) |
| Field integration | No |
Related Styled Components
Component Relationship
Dropzone Direct primitive