Counter

The smallest Keeno app: a state, two derived values and a few buttons.

App.kn
<script lang="ts">
  // state() creates a signal. Read it like a value; write it with .set().
  const count = state(0)
  // derived() recomputes only when what it reads changes.
  const doubled = derived(() => count * 2)
  const parity = derived(() => (count % 2 === 0 ? 'even' : 'odd'))
</script>

<div class="counter">
  <p class="value">{count}</p>
  <p class="meta">doubled is {doubled} · {parity}</p>
  <div class="row">
    <button onClick={() => count.set(count - 1)}>−1</button>
    <button onClick={() => count.set(0)} disabled={count === 0}>Reset</button>
    <button class="primary" onClick={() => count.set(count + 1)}>+1</button>
  </div>
</div>

<style>
  .counter {
    display: grid;
    justify-items: center;
    gap: 0.5rem;
    padding: 1rem;
  }
  .value {
    margin: 0;
    font-size: 4.5rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.05em;
    font-variant-numeric: tabular-nums;
  }
  .meta {
    margin: 0 0 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--muted);
  }
  .row {
    display: flex;
    gap: 0.5rem;
  }
  .row button {
    min-width: 3rem;
  }
  .primary {
    border-color: var(--fg);
    background: var(--fg);
    color: var(--bg);
  }
  .primary:hover:not(:disabled) {
    border-color: var(--fg);
    background: color-mix(in srgb, var(--fg) 85%, var(--bg));
  }
</style>