Svelte components

A wrapper renders a component's structure and writes its classes from props. It brings the behaviour too — focus, keyboard, ARIA, fetching for the data components — so a functional piece is one line in a page.

Axes and flags are props

An axis is a prop that takes one of its values; a flag is a boolean. Every other attribute reaches the element, and class is added to the component's own.

<Button color="primary" size="sm" variant="outline">Save</Button>
<!-- renders <button class="btn btn-primary btn-sm btn-outline"> -->

<Button active>Bold</Button>         <!-- a flag is a boolean: btn-active -->
<Button class="my-own">…</Button>    <!-- your classes are added, never replaced -->

What you can bind

A prop is bindable when its value is the component's state: value, checked, open, page. A value the component reads off the DOM — a carousel's index, read from its scroll — is not: the component gives commands to change it (through bind:this) and a callback to learn it.

<script>
  let name = $state();
  let open = $state(false);
</script>

<Input bind:value={name} />
<Dialog bind:open onvalue={(v) => console.log('closed with', v)}>…</Dialog>
<Carousel bind:this={carousel} onindex={(i) => (shown = i)} />

Callbacks and native events

Native events are never taken over. onchange, oninput, onclose reach the element with their Event, even when the component listens to them too. What the component adds is a lowercase callback named after what it hands over: onvalue(value), onpage(page), onopen(open), ondismiss().

<Select
  onchange={(e) => console.log(e.target)}   /* the native event, untouched */
  onvalue={(value) => (picked = value)}      /* what the component adds */
/>

Types follow the family

Each family's stylesheet comes with its types, daisy.css.d.ts. Importing the stylesheet, from any file of your project, narrows every component's props to what the family ships. Switching family is changing that import; svelte-check then lists what the new family lacks. The runtime never changes.

import '@sepale/style/daisy.css';   /* registers what daisy draws */

<Button variant="surface" />   /* a compile error if daisy has no surface variant */
  • No family imported: the props are generic, every variant of every family.
  • Several families imported: a prop accepts what any of them draws.
  • Portable: register the families and declare it, and a prop accepts only what all of them draw.
/* Stay valid in every family you might switch to */
import type {} from '@sepale/style/cosmos.css';
import type {} from '@sepale/style/peony.css';

declare global {
  namespace Sepale {
    interface Config { portable: true }
  }
}

A family that is not in the package — a private one, one made on the Create a family page — works the same once its types sit beside its stylesheet. Derive them, never write them by hand:

npx sepale-types my-family.css   /* -> my-family.css.d.ts */