Skip to content

Commit

Permalink
document inputs for vanilla, notebook and framework contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed May 22, 2024
1 parent 130d8cf commit 6063e07
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Observable Inputs

**Observable Inputs** are lightweight user interface components — buttons, sliders, dropdowns, tables, and the like — to help you explore data and build interactive displays in [Observable notebooks](https://observablehq.com). Each input can be used as an [Observable view](https://observablehq.com/@observablehq/introduction-to-views). For example, to allow a number *x* to be manipulated by a slider:
**Observable Inputs** are lightweight user interface components — buttons, sliders, dropdowns, tables, and the like — to help you explore data and build interactive displays in [Observable](https://observablehq.com). Each input exposes a _value_ property that reflects its current value, and emits an _input_ event when the value changes. For example, to allow a number *x* to be manipulated by a slider:

```js
const slider = Inputs.range([0, 100]);
slider.addEventListener((event) => {
// do something with event.value
});
```

In Observable notebooks, the [`viewof`](https://observablehq.com/@observablehq/introduction-to-views) keyword can be used as a shortcut to display the view and create its reactive value *x* as a generator:

```js
viewof x = Inputs.range([0, 100])
Expand All @@ -12,10 +21,18 @@ Now you can reference the live value of *x* in any cell, *e.g.*:
md`The value of *x* is ${x}.`
```

Any cell that references *x* will run automatically when the *viewof x* slider is moved. For live examples, see:
Any cell that references *x* will run automatically when the slider is moved. For live examples, see:

https://observablehq.com/@observablehq/inputs

In [Observable Framework](https://observablehq/com/framework), the reactivity is ensured with the *view* function, that both displays the input and returns the value generator. Write:

```js
const x = view(Inputs.range([0, 100]));
```

For live examples, see the [Framework Reactivity](https://observablehq.com/framework/reactivity#inputs) documentation.

Observable Inputs provides basic inputs:

* [Button](#button) - do something when a button is clicked
Expand Down

0 comments on commit 6063e07

Please sign in to comment.