Skip to content

Getting Started

This guide takes you from installation to a working Ornata component in an HTML-first environment.

Terminal window
npm install ornata

If you want to enhance a page without a bundler, load the browser build from a CDN instead:

<script src="https://cdn.jsdelivr.net/npm/ornata@latest/dist/index.global.js"></script>
<script>
const { defineComponent } = window.Ornata;
</script>

Write the initial markup for the desired component.

<section data-counter>
<h2>Counter</h2>
<p>
Count:
<span data-count-value>0</span>
</p>
<button type="button" data-count-button>Increment</button>
</section>
import { defineComponent } from 'ornata';
const Counter = defineComponent({
name: 'Counter',
state: {
count: { default: 0 },
},
elements: {
value: { query: '[data-count-value]' },
button: { query: '[data-count-button]' },
},
methods: {
increment() {
this.state.count += 1;
},
},
render: {
value() {
return {
text: String(this.state.count),
};
},
button() {
return {
events: {
click: () => this.methods.increment(),
},
};
},
},
});
Counter.mount('[data-counter]');

When mount() runs, Ornata:

  • resolves the required root element
  • reads and prepares state
  • resolves configured elements
  • binds methods to the internal component instance
  • runs the mount lifecycle hook if present
  • performs an initial render pass for each state property