Skip to content

Commit

Permalink
docs: Unify getting started examples
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed May 25, 2024
1 parent 1022eb3 commit 375fd9b
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions docs/src/pages/en/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,27 @@ import traitlets
class CounterWidget(anywidget.AnyWidget):
_esm = """
function render({ model, el }) {
let getCount = () => model.get("count");
let button = document.createElement("button");
button.classList.add("counter-button");
button.innerHTML = `count is ${getCount()}`;
button.innerHTML = `count is ${model.get("value")}`;
button.addEventListener("click", () => {
model.set("count", getCount() + 1);
model.set("value", model.get("value") + 1);
model.save_changes();
});
model.on("change:count", () => {
button.innerHTML = `count is ${getCount()}`;
model.on("change:value", () => {
button.innerHTML = `count is ${model.get("value")}`;
});
el.classList.add("counter-widget");
el.appendChild(button);
}
export default { render };
export default { render };
"""
_css="""
.counter-button { background-color: #ea580c; }
.counter-button:hover { background-color: #9a3412; }
_css = """
.counter-widget button { background-color: #ea580c; }
.counter-widget button:hover { background-color: #9a3412; }
"""
count = traitlets.Int(0).tag(sync=True)
value = traitlets.Int(0).tag(sync=True)

counter = CounterWidget()
counter.count = 42
counter
CounterWidget(value=42)
```

<CounterButton size={"lg"} initialValue={42} />
Expand Down

0 comments on commit 375fd9b

Please sign in to comment.