Getting Started
This guide takes you from installation to a working Ornata component in an HTML-first environment.
Install
Section titled “Install”npm install ornataIf 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>Start with HTML
Section titled “Start with HTML”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>Define a component
Section titled “Define a component”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(), }, }; }, },});import { defineComponent } from 'ornata';
interface CounterState { count: number;}
const Counter = defineComponent<{ state: CounterState; elements: { value: Element | null; button: Element | null; }; methods: { increment(): void; };}>({ 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(), }, }; }, },});Mount it
Section titled “Mount it”Counter.mount('[data-counter]');What happens when it mounts
Section titled “What happens when it mounts”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
Where to go next
Section titled “Where to go next”- Read Your First Component for a deeper walkthrough
- Read State to understand initialization, reactivity, and safety controls
- Read Mounting Instances to compare
mount()andmountAll() - Read Component Anatomy for the full shape of
defineComponent()