choice
look
A question with options and a free answer.
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)),
]
}{
"blocks": [
{
"action": "when",
"fallback": {
"title": "When do the 0.4 notes ship?"
},
"id": "when",
"options": [
{
"label": "Ship on Friday",
"value": "friday"
},
{
"label": "Ship now",
"value": "now"
},
{
"label": "Hold for 0.5",
"value": "later"
}
],
"other": {
"placeholder": "other…"
},
"question": "When do the 0.4 notes ship?",
"recommended": "friday",
"type": "choice"
}
],
"fallback": {
"title": "screen"
},
"id": "choice",
"type": "screen"
}Its fallback
What a renderer without
choice draws: a row from the fallback the block carries.When do the 0.4 notes ship?
Style hooks
.b-choicethe block
[data-block=choice]every block of the kind
[data-id=when]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