Actions
What a click can do.
Actions
Pass an action to a component's
on_click. The first argument is the name of a State.
Button("Increment", on_click=Action.increment("count", 1))Action | Notes |
|---|---|
Action.increment | Adds a delta (default 1) to a numeric state. |
Action.decrement | Subtracts a delta (default 1) from a numeric state. |
Action.set | Takes a value. A Bind(...) value is read from state when the action runs. |
Action.reset | Puts a state back to the initial value it was declared with. Needs no argument. |
Action.append | Takes a value. A Bind(...) value is read from state when the action runs. |
Action.remove | Removes the item at a given index from list-valued state (index-based, not value-based). |
Action.toggle_bool | No arguments beyond the state name. |
Action.geolocate | Asks the browser for the visitor's location and stores a {lat, lng} object in state once they answer the permission prompt. |
These are the actions present in v0.70.1. Run
arklight search Action.<name>for each one's exact arguments.
Click behaviors
For disclosures and scrolling you don't need an action at all. Behaviors are validated against a fixed vocabulary at build time:
copy,
dismiss,
paste,
scroll-to,
toggle.
Button(
"Show details",
on_click="toggle",
behavior_target="#more-details",
toggle_class="hidden",
)toggleflips a class on the target. Start the target with
class_name="hidden"and the button reveals it.
