Embroidery
Note! This library is just an experiment and not intended for production use (yet).
Install
yarn add embroideryornpm i embroidery
Usage
Add controller, target and action attributes to your HTML
<!-- HTML somewhere in your web app --> Greet
Create a controller in javascript.
// my-controller.jsconst myController = { outputtextContent = namevalue }
Register your controller in your main javascript file.
let app = Embroiderystartapp
Partials
Add a partial (async external html). This is good for inserting remote fragments into your HTML to keep page loads fast.
Actions
Default actions
Some elements have default actions, which means you don't have to specify click, submit etc. For example:
// Before <button data-action="click->hello">Hello</button>// After <button data-action="hello">Hello</button>
Element | Event |
---|---|
a | 'click' |
button | 'click' |
form | 'submit' |
input | 'input' |
select | 'change' |
textarea | 'input' |
Multiple actions
If you want to have multiple actions you can separate them with a blank space.
Do this or that
Targets
Multiple targets
If you have multiple targets you need to add []
to access them as an array in your controller. The array will be appended with <name>Targets
.
Hello to you Hello to me Hello to everyone
// hello-controller.jsconst helloController = { helloTargets }