pub struct Kv<M = ()>(/* private fields */);Expand description
kv: an aligned key/value list.
Implementations§
Source§impl<M> Kv<M>
impl<M> Kv<M>
Sourcepub fn key(self, key: impl Into<NodeKey>) -> Self
pub fn key(self, key: impl Into<NodeKey>) -> Self
Identity among siblings: keeps the node’s id (and Tern’s view state) across reorders. A string, or an integer.
Examples found in repository?
1024fn detail(
1025 page: Page,
1026 id: &'static str,
1027 meta: impl Into<Text>,
1028 kv: ui::Kv<Msg>,
1029 action: Option<&'static str>,
1030 risk: &Risk,
1031) -> ui::Card<Msg> {
1032 let mut card = ui::card().head(id).meta(meta);
1033 if let Some(label) = action {
1034 card = card.end(
1035 ui::button(label)
1036 .key("act")
1037 .variant("primary")
1038 .keys(["a"])
1039 .on_click(Msg::Act(page, id.into())),
1040 );
1041 }
1042 let mut trigger = ui::button(risk.button)
1043 .key("risk")
1044 .variant("danger")
1045 .on_click(Msg::Ask(page, id.into()));
1046 if let Some(why) = risk.blocked {
1047 trigger = trigger.disabled(why);
1048 }
1049 card
1050 .child(kv.key("kv"))
1051 .child(ui::row().key("bar").child(trigger))
1052}Sourcepub fn role(self, role: impl Into<String>) -> Self
pub fn role(self, role: impl Into<String>) -> Self
A name of yours, exposed to CSS as data-role.
Keeps the node mounted but not laid out.
Sourcepub fn mark(self, mark: impl Into<Mark>) -> Self
pub fn mark(self, mark: impl Into<Mark>) -> Self
A transient selection mark drawn over the node.
Sourcepub fn aria(self, aria: impl Into<String>) -> Self
pub fn aria(self, aria: impl Into<String>) -> Self
The accessible name of a node that shows no text.
Sourcepub fn hovercard<N>(self, card: impl Into<Node<N>>) -> Self
pub fn hovercard<N>(self, card: impl Into<Node<N>>) -> Self
A floating card of card’s tree shown while the pointer rests on
the node, in place of title. Sent id-less (ids, keys and handlers
inside are ignored); an older Tern ignores it.
Sourcepub fn href(self, href: impl Into<String>) -> Self
pub fn href(self, href: impl Into<String>) -> Self
A link: ⌘-click opens it; copy and open use it.
Sourcepub fn basis(self, basis: impl Into<Basis>) -> Self
pub fn basis(self, basis: impl Into<Basis>) -> Self
Flex basis: a fraction of the parent, or the content’s size.
Sourcepub fn prop(self, name: &str, value: impl Serialize) -> Self
pub fn prop(self, name: &str, value: impl Serialize) -> Self
Sets any prop untyped; null removes it.
Sourcepub fn on_click(self, msg: M) -> Self
pub fn on_click(self, msg: M) -> Self
Sends msg on a click (sets actions.click to "click" unless
the node names its click action itself).
Sourcepub fn on_dblclick(self, msg: M) -> Self
pub fn on_dblclick(self, msg: M) -> Self
Sends msg on a double click (sets actions.dblclick to
"dblclick" unless the node names it).
Adds act to the context menu and sends msg when it is picked.
Sourcepub fn on_action(self, act: impl Into<String>, msg: M) -> Self
pub fn on_action(self, act: impl Into<String>, msg: M) -> Self
Sends msg on action events whose action is act (name or
name=value).
Sourcepub fn on_action_with(
self,
act: impl Into<String>,
f: impl Fn(&Action) -> M + Send + Sync + 'static,
) -> Self
pub fn on_action_with( self, act: impl Into<String>, f: impl Fn(&Action) -> M + Send + Sync + 'static, ) -> Self
Maps action events whose action is act to a message.
Sourcepub fn on_toggle(self, f: impl Fn(bool) -> M + Send + Sync + 'static) -> Self
pub fn on_toggle(self, f: impl Fn(bool) -> M + Send + Sync + 'static) -> Self
Maps toggle events (the new collapsed; a menu, select or trace
line that opened is not collapsed) to a message.
Sourcepub fn on_select(self, f: impl Fn(&str) -> M + Send + Sync + 'static) -> Self
pub fn on_select(self, f: impl Fn(&str) -> M + Send + Sync + 'static) -> Self
Maps select events (the item) to a message. On a list’s item the
item’s own handler runs first.
Sourcepub fn on_activate(self, f: impl Fn(&str) -> M + Send + Sync + 'static) -> Self
pub fn on_activate(self, f: impl Fn(&str) -> M + Send + Sync + 'static) -> Self
Maps activate events (the item) to a message.
Sourcepub fn on_change(self, f: impl Fn(&Change) -> M + Send + Sync + 'static) -> Self
pub fn on_change(self, f: impl Fn(&Change) -> M + Send + Sync + 'static) -> Self
Maps change events to a message.
Sourcepub fn on_edit(self, f: impl Fn(&Edit) -> M + Send + Sync + 'static) -> Self
pub fn on_edit(self, f: impl Fn(&Edit) -> M + Send + Sync + 'static) -> Self
Maps edit events (native editing) to a message.
Source§impl<M> Kv<M>
impl<M> Kv<M>
Sourcepub fn item(self, k: impl Into<Text>, v: impl Into<Text>) -> Self
pub fn item(self, k: impl Into<Text>, v: impl Into<Text>) -> Self
Adds a pair.
Examples found in repository?
1055fn service_card(s: &Service) -> ui::Card<Msg> {
1056 let (label, _) = s.health.look();
1057 let rps = s.rps.last().copied().unwrap_or_default();
1058 let kv = ui::kv()
1059 .item("Health", ui::span(label).style("strong"))
1060 .item("Version", mono(s.version))
1061 .item("Replicas", mono(s.replicas.to_string()))
1062 .item("Traffic", mono(format!("{rps:.0} req/s")))
1063 .item("p95", mono(format!("{:.0} ms", s.p95)))
1064 .item("Errors", mono(format!("{:.1}%", s.errors)));
1065 detail(Page::Services, s.id, s.region, kv, Some(s.action()), &s.risk())
1066}
1067
1068/// The selected deploy's detail card.
1069fn deploy_card(d: &Deploy) -> ui::Card<Msg> {
1070 let (label, _) = d.state.look();
1071 let rps = d.rps.last().copied().unwrap_or_default();
1072 let kv = ui::kv()
1073 .item("State", ui::span(label).style("strong"))
1074 .item("Service", d.service)
1075 .item("Commit", mono(d.commit))
1076 .item("Rollout", mono(format!("{:.0}%", d.done * 100.0)))
1077 .item("Traffic", mono(format!("{rps:.0} req/s")));
1078 detail(Page::Deploys, d.id, d.region, kv, d.action(), &d.risk())
1079}
1080
1081/// The selected incident's detail card.
1082fn incident_card(i: &Incident) -> ui::Card<Msg> {
1083 let (phase, _) = i.phase.look();
1084 let (sev, _) = i.severity.look();
1085 let kv = ui::kv()
1086 .item("State", ui::span(phase).style("strong"))
1087 .item("What", i.title)
1088 .item("Service", i.service)
1089 .item("Severity", sev)
1090 .item("Open for", mono(ago(i.age)));
1091 detail(Page::Incidents, i.id, i.service, kv, i.action(), &i.risk())
1092}