Hybrid Astro UI

A lightweight, accessible toggle component for Astro, perfect for managing binary UI states like likes, bookmarks, and switches. Fully customizable with Tailwind CSS.

Install

pnpm dlx hybrid-astro-ui@latest add toggle
npx hybrid-astro-ui@latest add toggle
yarn dlx hybrid-astro-ui@latest add toggle
bunx hybrid-astro-ui@latest add toggle

Usage

---
import Heart from "@lucide/astro/icons/heart"
import { 
    Toggle, 
    ToggleActive, 
    ToggleInactive 
} from "@/src/components/hybrid-astro-ui/toggle";

---
<Toggle id="like-btn">
    <ToggleActive>
        <Heart class="text-red-500 fill-current" />
    </ToggleActive>
    <ToggleInactive>
        <Heart />
    </ToggleInactive>
    <span>Like</span>
</Toggle>

Custom classes

---
import Menu from "@lucide/astro/icons/menu"
import X from "@lucide/astro/icons/x"
import { 
    Toggle, 
    ToggleActive, 
    ToggleInactive 
} from "@/src/components/hybrid-astro-ui/toggle";
---
<Toggle id="menu-btn" class="border-none bg-transparent [&_svg]:h-7 [&_svg]:w-7 p-0">
    <ToggleActive>
        <X />
    </ToggleActive>
    <ToggleInactive>
        <Menu />
    </ToggleInactive>
</Toggle>

Toggle (Root)

Toggle is the core component that manages the toggle state. It renders a real checkbox internally and exposes its state using CSS only, without JavaScript.

This component is responsible for:

Props

Toggle is designed as a low-level primitive and can be used for likes, bookmarks, switches, menus, and other binary UI states.


ToggleActive

ToggleActive renders its content only when the toggle is in the active (checked) state. It does not accept props and does not manage state by itself. Instead, it reacts to the internal state exposed by Toggle.

Typical use cases include:


ToggleInactive

ToggleInactive renders its content only when the toggle is in the inactive (unchecked) state. Like ToggleActive, it does not accept props and relies entirely on the parent Toggle for state.

Typical use cases include:


Design philosophy

Together, these three components form a simple but powerful pattern:

This approach keeps markup readable, avoids JavaScript by default, and fits perfectly into static and hybrid Astro projects.