Published
Edited
Sep 16, 2022
Importers
2 stars
Insert cell
Insert cell
viewof button = ButtonToggle()
Insert cell
button
Insert cell
viewof paused = ButtonToggle({
onText: `${fas`pause`} Pause`,
offText: `${fas`play`} Play`,
value: "playing",
click: value => value === "playing" ? "paused" : "playing"
})
Insert cell
paused
Insert cell
function ButtonToggle({
onText = "On",
offText = "Off",
value = 0,
click = (value, clicks) => clicks
} = {}) {
let text = onText,
ml = html`<button>${text}</button>`,
clicks = 0,
v = value;

ml.value = v;
ml.onclick = () => {
v = click(v, ++clicks);
ml.value = v;
ml.innerHTML = clicks % 2 === 0 ? onText : offText;
}
return ml;
}
Insert cell
faStyle({solid: true})
Insert cell
import { style as faStyle, fas } from "@airbornemint/fontawesome"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more