Top Related Projects
Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.
⚡️ Simple, Modular & Accessible UI Components for your React Applications
A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
The Accessible Foundation for React Apps and Design Systems
Quick Overview
Svelte-headlessui is a port of the popular Headless UI library for Svelte. It provides a set of completely unstyled, fully accessible UI components that can be easily customized to fit any design system. This library aims to simplify the process of building accessible and robust user interfaces in Svelte applications.
Pros
- Fully accessible components out of the box
- Highly customizable and flexible
- Seamless integration with Svelte applications
- Comprehensive documentation and examples
Cons
- Limited number of components compared to the original Headless UI
- May require additional styling effort for complex designs
- Learning curve for developers new to headless UI concepts
- Potential performance overhead for very large applications
Code Examples
- Using the Menu component:
<script>
import { Menu, MenuButton, MenuItems, MenuItem } from '@rgossiaux/svelte-headlessui';
</script>
<Menu let:open>
<MenuButton>{open ? 'Close' : 'Open'} Menu</MenuButton>
<MenuItems>
<MenuItem let:active>
<a class:active href="/account-settings">Account Settings</a>
</MenuItem>
<MenuItem let:active>
<a class:active href="/support">Support</a>
</MenuItem>
<MenuItem disabled>
<span class="opacity-75">Invite a friend (coming soon!)</span>
</MenuItem>
</MenuItems>
</Menu>
- Using the Switch component:
<script>
import { Switch } from '@rgossiaux/svelte-headlessui';
let enabled = false;
</script>
<Switch
checked={enabled}
on:change={(e) => enabled = e.detail}
class={enabled ? 'bg-blue-600' : 'bg-gray-200'}
>
<span class="sr-only">Enable notifications</span>
<span
class={`${
enabled ? 'translate-x-6' : 'translate-x-1'
} inline-block h-4 w-4 transform rounded-full bg-white transition`}
/>
</Switch>
- Using the Combobox component:
<script>
import { Combobox, ComboboxInput, ComboboxOptions, ComboboxOption } from '@rgossiaux/svelte-headlessui';
let selected = null;
let people = [
{ id: 1, name: 'Wade Cooper' },
{ id: 2, name: 'Arlene Mccoy' },
{ id: 3, name: 'Devon Webb' },
];
</script>
<Combobox bind:value={selected}>
<ComboboxInput on:change={(event) => query = event.target.value} />
<ComboboxOptions>
{#each people as person}
<ComboboxOption value={person}>
{person.name}
</ComboboxOption>
{/each}
</ComboboxOptions>
</Combobox>
Getting Started
- Install the package:
npm install @rgossiaux/svelte-headlessui
- Import and use components in your Svelte file:
<script>
import { Menu, MenuButton, MenuItems, MenuItem } from '@rgossiaux/svelte-headlessui';
</script>
<Menu>
<MenuButton>Options</MenuButton>
<MenuItems>
<MenuItem>Option 1</MenuItem>
<MenuItem>Option 2</MenuItem>
</MenuItems>
</Menu>
- Style the components as needed using your preferred CSS approach.
Competitor Comparisons
Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
Pros of Headless UI
- More comprehensive component library with a wider range of UI elements
- Better documentation and examples, making it easier for developers to implement
- Larger community and more frequent updates, ensuring better long-term support
Cons of Headless UI
- Not specifically designed for Svelte, requiring additional adaptation for Svelte projects
- Potentially heavier bundle size due to its more extensive feature set
- May require more configuration and setup compared to a Svelte-specific solution
Code Comparison
Headless UI (React):
import { Menu } from '@headlessui/react'
function MyDropdown() {
return (
<Menu>
<Menu.Button>Options</Menu.Button>
<Menu.Items>
<Menu.Item>
{({ active }) => (
<a className={`${active && 'bg-blue-500'}`} href="/account-settings">
Account settings
</a>
)}
</Menu.Item>
</Menu.Items>
</Menu>
)
}
svelte-headlessui:
<script>
import { Menu, MenuButton, MenuItems, MenuItem } from '@rgossiaux/svelte-headlessui';
</script>
<Menu let:open>
<MenuButton>Options</MenuButton>
<MenuItems>
<MenuItem let:active>
<a class:bg-blue-500={active} href="/account-settings">
Account settings
</a>
</MenuItem>
</MenuItems>
</Menu>
Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.
Pros of Primitives
- More comprehensive set of UI components and primitives
- Stronger focus on accessibility and keyboard navigation
- Larger community and more frequent updates
Cons of Primitives
- React-specific, limiting its use to React projects
- Steeper learning curve due to more complex API
Code Comparison
Primitives (React):
import * as Dialog from '@radix-ui/react-dialog';
<Dialog.Root>
<Dialog.Trigger>Open</Dialog.Trigger>
<Dialog.Content>
<Dialog.Title>Dialog Title</Dialog.Title>
<Dialog.Description>Dialog content here</Dialog.Description>
</Dialog.Content>
</Dialog.Root>
svelte-headlessui (Svelte):
<script>
import { Dialog, DialogOverlay, DialogTitle } from '@rgossiaux/svelte-headlessui';
</script>
<Dialog>
<DialogOverlay />
<DialogTitle>Dialog Title</DialogTitle>
<p>Dialog content here</p>
</Dialog>
Summary
Primitives offers a more extensive set of components with better accessibility features, but is limited to React. svelte-headlessui provides similar functionality for Svelte projects with a simpler API, but has a smaller component set and community. The choice between them largely depends on the framework being used and the specific project requirements.
⚡️ Simple, Modular & Accessible UI Components for your React Applications
Pros of Chakra UI
- Extensive component library with a wide range of pre-built UI elements
- Highly customizable with a robust theming system
- Strong TypeScript support and comprehensive documentation
Cons of Chakra UI
- Larger bundle size due to its extensive feature set
- Steeper learning curve for beginners due to its comprehensive API
- React-specific, limiting its use in other frameworks like Svelte
Code Comparison
Chakra UI (React):
import { Button, Box } from "@chakra-ui/react"
function MyComponent() {
return (
<Box>
<Button colorScheme="blue">Click me</Button>
</Box>
)
}
Svelte HeadlessUI (Svelte):
<script>
import { Button } from '@rgossiaux/svelte-headlessui'
</script>
<Button>
Click me
</Button>
Chakra UI offers a more opinionated and feature-rich approach with built-in styling, while Svelte HeadlessUI provides unstyled, accessible components that can be customized to fit any design system. Chakra UI is ideal for rapid development with consistent styling, whereas Svelte HeadlessUI offers more flexibility and a smaller footprint, particularly suited for Svelte projects.
A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
Pros of React Spectrum
- Comprehensive design system with a wide range of accessible components
- Robust documentation and extensive examples
- Strong support from Adobe and a large community
Cons of React Spectrum
- Larger bundle size due to its comprehensive nature
- Steeper learning curve for developers new to the ecosystem
- Less flexibility in customization compared to headless UI libraries
Code Comparison
React Spectrum:
import { Button } from '@adobe/react-spectrum';
function MyComponent() {
return <Button variant="cta">Click me</Button>;
}
Svelte Headless UI:
<script>
import { Button } from '@rgossiaux/svelte-headlessui';
</script>
<Button>Click me</Button>
Key Differences
- React Spectrum provides pre-styled components, while Svelte Headless UI offers unstyled, accessible components
- React Spectrum is specific to React, whereas Svelte Headless UI is for Svelte applications
- Svelte Headless UI allows for more customization but requires more work to style components
- React Spectrum offers a more cohesive design system out of the box
Use Cases
- Choose React Spectrum for rapid development of Adobe-like interfaces in React applications
- Opt for Svelte Headless UI when building custom-designed Svelte applications with a focus on accessibility
The Accessible Foundation for React Apps and Design Systems
Pros of reach-ui
- More comprehensive set of accessible UI components
- Longer development history and larger community support
- Extensive documentation and examples
Cons of reach-ui
- React-specific, limiting its use to React projects
- Potentially larger bundle size due to more components
Code Comparison
reach-ui (React):
import { Menu, MenuButton, MenuList, MenuItem } from "@reach/menu-button"
<Menu>
<MenuButton>Actions</MenuButton>
<MenuList>
<MenuItem onSelect={() => alert("Download")}>Download</MenuItem>
<MenuItem onSelect={() => alert("Copy")}>Create a Copy</MenuItem>
</MenuList>
</Menu>
svelte-headlessui (Svelte):
<script>
import { Menu, MenuButton, MenuItems, MenuItem } from '@rgossiaux/svelte-headlessui';
</script>
<Menu>
<MenuButton>Actions</MenuButton>
<MenuItems>
<MenuItem on:click={() => alert("Download")}>Download</MenuItem>
<MenuItem on:click={() => alert("Copy")}>Create a Copy</MenuItem>
</MenuItems>
</Menu>
Both libraries provide similar component structures and APIs, but reach-ui is designed for React while svelte-headlessui is tailored for Svelte applications. reach-ui offers a more extensive set of components and has been around longer, potentially providing more stability and community support. However, svelte-headlessui brings the benefits of Headless UI to Svelte developers, offering a lightweight and flexible solution for building accessible UI components in Svelte projects.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
svelte-headlessui
This is an unofficial, complete Svelte port of the Headless UI component library (https://headlessui.dev/). It contains fully accessible, feature-rich, unstyled UI components.
Documentation for this library is available at https://svelte-headlessui.goss.io
Who is this for?
This library is for you if you fall into one of two categories:
- You want unstyled yet sophisticated customizable UI components that fully follow the WAI-ARIA specs. You want a component library to handle all the messy details (keyboard navigation, focus management, aria-* attributes, and many many more), but you want to style your components yourself and not be constrained by existing design systems like Material UI.
- Alternatively, you want to implement an existing design system in Svelte, and want a powerful set of primitives to build your components on, letting you focus on styling.
- You want to use the commercial Tailwind UI component library (https://tailwindui.com/) in your Svelte project, and want a drop-in replacement for the React/Vue components which power Tailwind UI.
This project is intended to keep an API as close as possible to the React API for the base Headless UI project, with only a few small differences. While one of the primary goals is to enable using Tailwind UI in a Svelte project with as little effort as possible, neither Tailwind UI nor Tailwind CSS is required to use these components.
This project is an unofficial port. I have no affiliation with Tailwind Labs and cannot offer commercial support for this project. With that said, I intend to keep it as up to date as possible with the upstream Headless UI project, including porting new components when they are released.
Installation
npm install -D @rgossiaux/svelte-headlessui
Usage
See https://svelte-headlessui.goss.io for full documentation.
Credits
Credit for everything good about this library goes to Tailwind Labs for writing the original React/Vue versions. All bugs should be assumed to be my fault in the port (though as the codebases are so similar, bugs in upstream will likely affect this library too).
Additional thanks to https://github.com/hperrin/svelte-material-ui; this well-engineered Svelte library was the source of the action and event forwarding code, with minor modifications.
License
This library is licensed under the MIT license; see the LICENSE file for more.
Top Related Projects
Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.
⚡️ Simple, Modular & Accessible UI Components for your React Applications
A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
The Accessible Foundation for React Apps and Design Systems
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot