Skip to content
coatx
Esc
↑↓navigate↵open⌘Jpreview
On this page

Ilha UI SDK & Astro

Pair coatx recipes with @ilha/ui-sdk headless behaviors and hydrate islands in Astro with @ilha/astro.

coatx has zero runtime coupling to @ilha/ui-sdk, yet every recipe maps cleanly onto @ilha/ui-sdk state callbacks (state.checked, state.selected, state.highlighted, state.pressed, state.open).

Install with Ilha

bun add coatx ilha @ilha/ui-sdk @ui-sdk/core@0.1.0-beta.23 effect

Pass recipe .class values from part state callbacks so server HTML and hydrated DOM stay in sync with zero hydration mismatches:

import "coatx/styles.css";
import {
  SegmentedControl,
  SegmentedControlItem,
} from "@ilha/ui-sdk/segmented-control";
import {
  segmentedControl,
  segmentedControlItem,
} from "coatx/segmented-control";
import { theme } from "coatx/themes.stylex";

export const Appearance = () => (
  <div {...theme("dark")}>
    <SegmentedControl
      aria-label="Appearance"
      defaultValue="system"
      {...segmentedControl()}
    >
      <SegmentedControlItem
        value="system"
        class={(state) =>
          segmentedControlItem({ checked: state.checked }).class
        }
      >
        System
      </SegmentedControlItem>
      <SegmentedControlItem
        value="dark"
        class={(state) =>
          segmentedControlItem({ checked: state.checked }).class
        }
      >
        Dark
      </SegmentedControlItem>
    </SegmentedControl>
  </div>
);

Hydrating islands in Astro (@ilha/astro)

Install @ilha/astro to render Ilha + coatx components on the server and hydrate them selectively in .astro or .mdx pages:

bun add @ilha/astro astro ilha

Register ilha() in astro.config.mjs (or blume.config.ts):

import { defineConfig } from "astro/config";
import ilha from "@ilha/astro";

export default defineConfig({
  integrations: [ilha()],
});

Configure TypeScript to emit Ilha JSX in tsconfig.json:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "ilha"
  }
}

Then mount any island with an Astro client directive (client:load, client:idle, client:visible, client:media, or client:only="@ilha/astro"):

---
import "coatx/styles.css";
import { Appearance } from "../islands/Appearance";
---

<Appearance client:load />

Note: Ilha components do not forward Astro <slot /> children — pass data through props instead.

Was this page helpful?