1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
use *;
use ;
use component_doc;
use inject_style;
use ;
use UploadConfig;
/// File selection trigger wired to a hidden native file input.
///
/// Upload wires a hidden file input to whatever trigger you provide — a button, icon, or [`UploadDragger`](crate::UploadDragger) drop zone. Set `accept` and `multiple` on [`UploadConfig`], then handle selected files in `on_change`. Orbital does not upload to a server, show progress, or manage a file list. You own validation, preview, and network calls.
///
/// # When to use
///
/// - File selection with a custom trigger (button, drop zone, icon)
/// - Drag-and-drop selection affordances via [`UploadDragger`](crate::UploadDragger)
/// - Form-associated file inputs with `config.name` / `config.id`
///
/// # Scope
///
/// Upload is selection-only. For progress bars, thumbnails, or managed file lists, compose [`Upload`] with your own UI and network layer.
///
/// # Usage
///
/// 1. Provide trigger UI as children (button or [`UploadDragger`](crate::UploadDragger)).
/// 2. Handle selected files in `on_change`.
/// 3. Set `config.accept` and `config.multiple` to constrain selection.
///
/// # Best Practices
///
/// ## Do's
///
/// * Use [`UploadDragger`](crate::UploadDragger) for drop-zone affordances
/// * Validate file type and size in `on_change` before uploading
///
/// ## Don'ts
///
/// * Do not rely on the hidden input alone for UX — always provide a visible trigger
/// * Do not expect built-in upload progress or file-list UI — implement those in app code
///
/// # Examples
///
/// ## Basic button trigger
/// Hidden file input with a button trigger; `on_change` receives the selected files.
/// <!-- preview -->
/// ```rust
/// use crate::{Upload, UploadConfig, Button, ButtonAppearance};
/// use orbital_base_components::{Handler, UploadFileList};
/// view! {
/// <div data-testid="upload-preview">
/// <Upload config=UploadConfig::accept("image/*") on_change=Handler::on(|_files: UploadFileList| {})>
/// <Button appearance=ButtonAppearance::Secondary>"Choose file"</Button>
/// </Upload>
/// </div>
/// }
/// ```
///
/// ## Multiple files
/// Input exposes the `multiple` attribute for multi-select dialogs.
/// <!-- preview -->
/// ```rust
/// use crate::{Upload, UploadConfig, Button, ButtonAppearance};
/// use leptos::prelude::*;
/// use orbital_base_components::{Handler, UploadFileList};
/// view! {
/// <div data-testid="upload-multiple">
/// <Upload
/// config=UploadConfig { multiple: true.into(), ..UploadConfig::accept("image/*") }
/// on_change=Handler::on(|_files: UploadFileList| {})
/// >
/// <Button appearance=ButtonAppearance::Secondary>"Choose files"</Button>
/// </Upload>
/// </div>
/// }
/// ```
///
/// ## Accept filter
/// Restricts the picker to image MIME types via `accept`.
/// <!-- preview -->
/// ```rust
/// use crate::{Upload, UploadConfig, Button, ButtonAppearance};
/// use orbital_base_components::{Handler, UploadFileList};
/// view! {
/// <div data-testid="upload-accept">
/// <Upload config=UploadConfig::accept("image/*") on_change=Handler::on(|_files: UploadFileList| {})>
/// <Button appearance=ButtonAppearance::Secondary>"Images only"</Button>
/// </Upload>
/// </div>
/// }
/// ```
///
/// ## Drop zone
/// [`UploadDragger`] provides a dashed drop target that highlights on drag-over.
/// <!-- preview -->
/// ```rust
/// use crate::{Upload, UploadConfig, UploadDragger};
/// use orbital_base_components::{Handler, UploadFileList};
/// view! {
/// <div data-testid="upload-dragger" style="width: 100%; max-width: 420px;">
/// <Upload config=UploadConfig::default() on_change=Handler::on(|_files: UploadFileList| {})>
/// <UploadDragger>"Drop files here or click to browse"</UploadDragger>
/// </Upload>
/// </div>
/// }
/// ```
///
/// ## Custom trigger
/// [`UploadDragger`] can wrap any trigger content, including native buttons.
/// <!-- preview -->
/// ```rust
/// use crate::{Upload, UploadConfig, UploadDragger, Button, ButtonAppearance};
/// use orbital_base_components::{Handler, UploadFileList};
/// view! {
/// <div data-testid="upload-custom" style="width: 100%; max-width: 420px;">
/// <Upload config=UploadConfig::default() on_change=Handler::on(|_files: UploadFileList| {})>
/// <UploadDragger>
/// <Button appearance=ButtonAppearance::Primary>"Browse files"</Button>
/// </UploadDragger>
/// </Upload>
/// </div>
/// }
/// ```
///
/// ## Callback with selected files
/// `on_change` receives the browser [`FileList`](crate::FileList) when files are selected.
/// <!-- preview -->
/// ```rust
/// use crate::{Upload, UploadConfig, Button, ButtonAppearance};
/// use orbital_base_components::{Handler, UploadFileList};
/// view! {
/// <div data-testid="upload-callback">
/// <Upload
/// config=UploadConfig { multiple: true.into(), ..Default::default() }
/// on_change=Handler::on(|files: UploadFileList| {
/// let _count = files.length();
/// })
/// >
/// <Button appearance=ButtonAppearance::Secondary>"Select files"</Button>
/// </Upload>
/// <p data-testid="upload-file-list">"Choose files to populate the list"</p>
/// </div>
/// }
/// ```
///
/// ## Theme stroke
/// Drop-zone border uses neutral stroke tokens from the theme.
/// <!-- preview -->
/// ```rust
/// use crate::{Upload, UploadConfig, UploadDragger};
/// use orbital_base_components::{Handler, UploadFileList};
/// view! {
/// <div data-testid="upload-theme" style="width: 100%; max-width: 420px;">
/// <Upload config=UploadConfig::default() on_change=Handler::on(|_files: UploadFileList| {})>
/// <div data-testid="upload-theme-dragger">
/// <UploadDragger>"Themed drop zone"</UploadDragger>
/// </div>
/// </Upload>
/// </div>
/// }
/// ```
]
config: UploadConfig,
/// Handler invoked when files are selected or dropped.
on_change: ,
/// Extra CSS class names merged onto the hidden file input wrapper.
class: ,
/// Trigger UI (button, [`UploadDragger`](crate::UploadDragger), etc.).
children: Children,
)