button
look
A button that posts its action.
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": "save",
"fallback": {
"title": "save"
},
"id": "save",
"label": "save",
"style": "primary",
"type": "button"
},
{
"action": "preview",
"fallback": {
"title": "preview"
},
"id": "preview",
"label": "preview",
"style": "plain",
"type": "button"
},
{
"action": "delete",
"fallback": {
"title": "delete"
},
"id": "delete",
"label": "delete",
"style": "destructive",
"type": "button"
}
],
"fallback": {
"title": "screen"
},
"id": "button",
"type": "screen"
}Its fallback
What a renderer without
button draws: a row from the fallback the block carries.save
Style hooks
.b-buttonthe block
[data-block=button]every block of the kind
[data-id=save]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