Add basic Stimulus example

This commit is contained in:
Oliver Davies 2025-08-05 01:07:47 +01:00
commit 55388fa044

24
stimulus/basic.html Normal file
View file

@ -0,0 +1,24 @@
<script type="module">
import { Application, Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"
window.Stimulus = Application.start()
Stimulus.register("hello", class extends Controller {
static targets = [ "name", "output" ]
greet() {
this.outputTarget.textContent =
`Hello, ${this.nameTarget.value}!`
}
})
</script>
<div data-controller="hello">
<input data-hello-target="name" type="text">
<button data-action="click->hello#greet">
Greet
</button>
<span data-hello-target="output"></span>
</div>