form
look
Fields and a submit.
Drawn
The sample
fn input() -> Vec<Block> {
let option = |value: &str, label: &str| ChoiceOption {
value: value.into(),
label: label.into(),
..ChoiceOption::default()
};
let choice = Choice::new(
"when",
vec![
option("friday", "Ship on Friday"),
option("now", "Ship now"),
option("later", "Hold for 0.5"),
],
)
.id("when")
.question("When do the 0.4 notes ship?")
.recommended("friday")
.other(Other {
placeholder: Some("other…".into()),
r#for: None,
});
let form = Form::new(vec![
field("name", "Name", FieldValue::Text("Ada Lovelace".into())),
field("email", "Email", FieldValue::Text("ada@example.com".into())),
picker("plan", "Plan", &["team", "solo", "school"]),
toggle("updates", "Updates", true),
])
.id("signup")
.submit(Submit {
label: "sign up".into(),
action: "sign-up".into(),
..Submit::default()
});
let pick = |name: &str, all: &[&str]| ComposerChip {
name: name.into(),
cur: all.first().map(|s| (*s).to_string()),
all: all.iter().map(|s| (*s).to_string()).collect(),
};
let composer = Composer::new("say")
.id("say")
.label("send")
.placeholder("message the team")
.chips(vec![
pick("model", &["fast", "deep"]),
pick("effort", &["medium", "high"]),
])
.queued(vec![Queued {
q: 1,
text: "rerun the bench on main".into(),
}]);
let run = Run::new("approve", "cargo test --workspace --release", "4f2a9c1")
.id("tests")
.dir("crates")
.touches("the test target only");
vec![
button("save", "save", ButtonStyle::Primary),
button("preview", "preview", ButtonStyle::Plain),
button("delete", "delete", ButtonStyle::Destructive),
b!(Choice(choice)),
b!(Form(form)),
b!(Composer(composer)),
b!(Run(run)),
]
}fn paperwork() -> Block {
let photos = UploadField::new("photos")
.label("Photos of the damage")
.accept(vec![Accept::Image])
.capture(true)
.many(true)
.mb(10u32);
let note = ScanField::new("note").label("Delivery note").max(20u32);
let pin = SecretField::new("pin").label("Order PIN").placeholder("4 digits");
b!(Form(
Form::new(vec![photos.into(), note.into(), pin.into()])
.id("claim")
.submit(Submit {
label: "send claim".into(),
action: "send-claim".into(),
..Submit::default()
})
))
}{
"blocks": [
{
"fallback": {
"title": "form"
},
"fields": [
{
"label": "Name",
"name": "name",
"type": "text",
"value": "Ada Lovelace"
},
{
"label": "Email",
"name": "email",
"type": "text",
"value": "ada@example.com"
},
{
"label": "Plan",
"name": "plan",
"options": [
"team",
"solo",
"school"
],
"type": "picker",
"value": "team"
},
{
"label": "Updates",
"name": "updates",
"type": "toggle",
"value": true
}
],
"id": "signup",
"submit": {
"action": "sign-up",
"label": "sign up"
},
"type": "form"
},
{
"fallback": {
"title": "form"
},
"fields": [
{
"accept": [
"image"
],
"capture": true,
"label": "Photos of the damage",
"many": true,
"mb": 10,
"name": "photos",
"type": "upload"
},
{
"label": "Delivery note",
"max": 20,
"name": "note",
"type": "scan"
},
{
"label": "Order PIN",
"name": "pin",
"placeholder": "4 digits",
"type": "secret"
}
],
"id": "claim",
"submit": {
"action": "send-claim",
"label": "send claim"
},
"type": "form"
}
],
"fallback": {
"title": "screen"
},
"id": "form",
"type": "screen"
}Its fallback
What a renderer without
form draws: a row from the fallback the block carries.form
Style hooks
.b-formthe block
[data-block=form]every block of the kind
[data-id=signup]this one block
Every page here is a blocks
Screen, written by site::page: no hand-written HTML. Source: https://github.com/jirathip-dev/blocks