Files
Ely-GPUI-Components/examples/gallery/pages/forms/files.rs
T
ZacharyZhang-NY 2cd2ca8bc1 T44d Web · What a browser cannot do says why; fonts resolve; the bundle builds
Demos that open a second window, take files, move the window, read the
clipboard or set native menus show a note on the web in the blocked style.
IBM Plex Sans Regular joins the assets, unmodified, where gpui's svg
renderer loads it: gpui_web answers .SystemUIFont with it. The gallery's
web entry registers a Hebrew cut of Noto Sans Hebrew. scripts/web.sh builds
the bundle with wasm-bindgen and wasm-opt -Oz, 20.0 MB, and fails past 25 MiB.
2026-09-29 19:16:41 -04:00

89 lines
2.6 KiB
Rust

use std::path::PathBuf;
use ely_gpui_component::forms::{DropZone, FileInput};
use gpui::{App, IntoElement, ParentElement, Styled, Window, div, px};
use crate::{
probe::probe,
ui::{NO_FILES, keep, section, set, specimen, specimens, web_note},
};
fn names(paths: &[PathBuf]) -> String {
let names: Vec<String> = paths
.iter()
.map(|path| {
path.file_name()
.expect("a file has a name")
.to_string_lossy()
.into_owned()
})
.collect();
names.join(", ")
}
pub fn files(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
let one = keep("file-one", Vec::<PathBuf>::new, window, cx);
let many = keep(
"file-many",
|| {
["Cargo.toml", "README.md", "AGENTS.md"]
.map(PathBuf::from)
.to_vec()
},
window,
cx,
);
let taken = keep("drop-taken", Vec::<PathBuf>::new, window, cx);
let (one_now, many_now, taken_now) = (
one.read(cx).clone(),
many.read(cx).clone(),
taken.read(cx).clone(),
);
section(
"FileInput / DropZone",
"Click a field or Browse for the system's dialog, or drop files from Finder. A folder, or two files on a one-file target, turns it red.",
cx,
)
.children(web_note(NO_FILES, cx))
.child(
specimens()
.child(specimen(
"one file",
probe(
"file-one",
div().w(px(260.0)).child(
FileInput::new("file-one", one_now)
.on_change(move |next, _, cx| set(&one, next, cx)),
),
),
cx,
))
.child(specimen(
"several",
div().w(px(260.0)).child(
FileInput::new("file-many", many_now)
.multiple()
.on_change(move |next, _, cx| set(&many, next, cx)),
),
cx,
)),
)
.child(specimen(
if taken_now.is_empty() {
"nothing dropped yet".to_string()
} else {
format!("took {}", names(&taken_now))
},
probe(
"drop-zone",
div().w(px(420.0)).child(
DropZone::new("drop-zone")
.multiple()
.hint("Any kind of file")
.on_drop(move |next, _, cx| set(&taken, next, cx)),
),
),
cx,
))
}