React
@hydrateless/react wraps every Hydrateless component in an idiomatic React component. Components render the same semantic markup as the core CSS, so they look right before hydration, and the enhancer that adds keyboard navigation, ARIA wiring, and focus management is attached and disposed with the component lifecycle (Strict Mode's double-invoke included).
Install
npm install hydrateless @hydrateless/reactRequires React 18 or later. Import the CSS once at your app entry:
import 'hydrateless/hydrateless.css';Components
Composable primitives use a compound API: a parent plus named parts you arrange yourself.
import { Tabs, TabList, Tab, TabPanel } from '@hydrateless/react';
export function Example() {
return (
<Tabs defaultValue="overview">
<TabList>
<Tab value="overview">Overview</Tab>
<Tab value="install">Install</Tab>
</TabList>
<TabPanel>Zero runtime by default.</TabPanel>
<TabPanel>npm install hydrateless</TabPanel>
</Tabs>
);
}Tabs renders role="tablist", aria-selected, tabindex, and hidden during render, so server output is already correct and there's no flash when the enhancer attaches.
Controlled and uncontrolled
Every stateful component follows the native-input convention:
- Uncontrolled: pass
defaultValue(ordefaultOpen,defaultQuery) and let the component own its state. - Controlled: pass
value+onValueChange(oropen+onOpenChange,query+onQueryChange) and own the state yourself. Programmatic prop updates sync into the enhancer silently without echoing your callback, while user-driven interactions (clicks, keyboard selection, Escape, backdrop click, outside click) always notify you. If your parent ignores or vetoes a change, the DOM reconciles back to your controlled prop.
import { useState } from 'react';
import { Tabs, TabList, Tab, TabPanel } from '@hydrateless/react';
export function Controlled() {
const [tab, setTab] = useState('overview');
return (
<Tabs value={tab} onValueChange={setTab}>
<TabList>
<Tab value="overview">Overview</Tab>
<Tab value="install">Install</Tab>
</TabList>
<TabPanel>...</TabPanel>
<TabPanel>...</TabPanel>
</Tabs>
);
}import { useState } from 'react';
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from '@hydrateless/react';
export function Confirm() {
const [open, setOpen] = useState(false);
return (
<>
<Button onClick={() => setOpen(true)}>Delete</Button>
<Modal open={open} onOpenChange={setOpen}>
<ModalHeader>
<h2>Delete project?</h2>
</ModalHeader>
<ModalBody>This can't be undone.</ModalBody>
<ModalFooter>
<Button variant="ghost" onClick={() => setOpen(false)}>
Cancel
</Button>
<Button intent="danger">Delete</Button>
</ModalFooter>
</Modal>
</>
);
}Which prop is "the value" per component:
| Component | State props | Extra callbacks |
|---|---|---|
Tabs | value / defaultValue / onValueChange (string) | |
Accordion | value / defaultValue / onValueChange (string[]), allowMultiple | |
Menu | value / defaultValue / onValueChange (open submenu or null) | onSelect(value, item, checked?) |
Dropdown | open / defaultOpen / onOpenChange, closeOnSelect, placement | onSelect(value, item, checked?) |
Modal, Drawer | open / defaultOpen / onOpenChange, closeOnBackdrop; Drawer side="start" | "end" | |
Popover | open / defaultOpen / onOpenChange, placement, hover | |
Tooltip | content, open / onOpenChange, placement, showDelay, hideDelay | |
Combobox | value / defaultValue / onValueChange, open / defaultOpen / onOpenChange, filter, autoHighlight | |
Command | query / defaultQuery / onQueryChange, hotkey | onCommand(value, item) |
SegmentedControl | options, value / defaultValue / onValueChange (defaults to the first option) | |
Switch, Checkbox, Input | Native: checked / defaultChecked / onChange, value / defaultValue / onChange |
Dropdown with checkable items
DropdownItem accepts role="menuitemcheckbox" | "menuitemradio" and checked; DropdownGroup wraps a labeled role="group". The trigger renders popovertarget and the menu renders popover, so the menu opens before JavaScript loads.
import {
Dropdown,
DropdownTrigger,
DropdownMenu,
DropdownGroup,
DropdownItem,
DropdownSeparator,
} from '@hydrateless/react';
<Dropdown onSelect={(value, item, checked) => console.log(value, checked)}>
<DropdownTrigger>View</DropdownTrigger>
<DropdownMenu>
<DropdownGroup label="Show">
<DropdownItem value="grid" role="menuitemradio" checked>
Grid
</DropdownItem>
<DropdownItem value="list" role="menuitemradio">
List
</DropdownItem>
</DropdownGroup>
<DropdownSeparator />
<DropdownItem value="hidden" role="menuitemcheckbox">
Show hidden files
</DropdownItem>
<DropdownItem value="reset" disabled>
Reset view
</DropdownItem>
</DropdownMenu>
</Dropdown>;Pre-hydration overlay triggers
ModalTrigger, DrawerTrigger, and PopoverTrigger render native HTML invoker buttons (command + commandfor, or popovertarget + popovertargetaction), so modals, drawers, and popovers open and close before React hydrates and without extra client state:
import { Modal, ModalTrigger, ModalHeader, ModalBody, ModalFooter } from '@hydrateless/react';
export function Confirm() {
return (
<>
<ModalTrigger target="delete-modal" className="hl-button">
Delete
</ModalTrigger>
<Modal id="delete-modal">
<ModalHeader>
<h2>Delete project?</h2>
</ModalHeader>
<ModalBody>This can't be undone.</ModalBody>
<ModalFooter>
<ModalTrigger
target="delete-modal"
command="close"
className="hl-button"
data-hl-variant="ghost"
>
Cancel
</ModalTrigger>
<ModalTrigger
target="delete-modal"
command="close"
className="hl-button"
data-hl-intent="danger"
>
Delete
</ModalTrigger>
</ModalFooter>
</Modal>
</>
);
}Available components
| Group | Components |
|---|---|
| Disclosure | Accordion, AccordionItem, Disclosure, Tabs, TabList, Tab, TabPanel |
| Overlays | Dropdown (+ DropdownTrigger, DropdownMenu, DropdownGroup, DropdownItem, DropdownSeparator), Menu, MenuItem, MenuSubmenu, Modal, ModalTrigger, Drawer, DrawerTrigger (+ Header/Body/Footer), Popover, PopoverTrigger, Tooltip |
| Forms | Field, FieldLabel, FieldHelp, FieldError, Fieldset, Input, Textarea, Select, Checkbox, Switch, Slider, RadioGroup, Radio, SegmentedControl, Button |
| Combobox | Combobox, ComboboxInput, ComboboxList, ComboboxOption |
| Command | Command, CommandInput, CommandList, CommandGroup, CommandItem, CommandEmpty |
| Feedback | Alert, Badge, Progress, Spinner, Skeleton, ToastRegion |
| Data display | Card (+ CardHeader, CardBody, CardFooter, CardTitle, CardDescription), Avatar, AvatarGroup, Kbd, Separator, Table |
| Navigation | Breadcrumb, BreadcrumbItem, Pagination, Toc, SkipLink |
Every component forwards className, id, ref, and rest props to its root element.
Forms and useField
Field provides a shared id so FieldLabel, FieldHelp, and FieldError wire htmlFor and aria-describedby for you. The built-in controls read that context automatically, and work without it.
import { Field, Input } from '@hydrateless/react';
<Field label="Email" description="We never share it." error={errors.email} required>
<Input type="email" name="email" />
</Field>;For a custom control, useField() returns { id, describedBy, invalid, required } inside a Field and null outside one:
import { useField } from '@hydrateless/react';
function ColorPicker(props) {
const field = useField();
return (
<input
type="color"
id={field?.id}
aria-describedby={field?.describedBy}
aria-invalid={field?.invalid || undefined}
required={field?.required}
{...props}
/>
);
}See Forms for validation states and native constraint validation.
Toasts and useToast
useToast() returns { show(message, { duration, intent }), dismiss(toast), dismissAll() } and works from any component with no provider. The first show() creates a polite live region at the end of <body>; render <ToastRegion /> once if you want to control where toasts appear.
import { ToastRegion, useToast } from '@hydrateless/react';
function SaveButton() {
const toast = useToast();
return <button onClick={() => toast.show('Saved', { intent: 'success' })}>Save</button>;
}
export function App() {
return (
<>
<SaveButton />
<ToastRegion />
</>
);
}intent is one of info, success, warning, or danger; danger toasts are announced assertively.
useEnhancer
The one low-level escape hatch. Attach any enhancer to your own markup and get back a ref to its imperative API:
import { useRef } from 'react';
import { useEnhancer } from '@hydrateless/react';
import { enhanceTabs } from '@hydrateless/enhancers';
export function MyTabs() {
const ref = useRef<HTMLDivElement>(null);
const api = useEnhancer(ref, enhanceTabs, {
activation: 'automatic',
onValueChange: console.log,
});
// api.current?.setValue('install')
return (
<div ref={ref} className="hl-tabs" data-hl-tabs>
{/* your own tablist and tabpanel markup */}
</div>
);
}Signature: useEnhancer(ref, enhancer, options?, deps?).
- The instance attaches once on mount and is destroyed on unmount. When
depschange, options are updated in place viahandle.update()so open overlays and active state are preserved instead of torn down. - Function-valued options (
onValueChange,onOpenChange, and so on) always call the handler from the latest render, so they never need to be indeps. - List non-function options that should update the enhancer in
deps.
All shipped components are built on this hook, so custom wrappers behave exactly like the built-in ones. See Composing for writing an enhancer to attach.
Server components
@hydrateless/react splits static, hook-free primitives from client-enhanced components so React Server Components (such as Next.js App Router) never pay for a client boundary on static markup:
@hydrateless/react/serverexports pure server-safe components with no'use client'directive and zero React hooks (Alert,Avatar,AvatarGroup,Badge,Breadcrumb,BreadcrumbItem,Button,Cardand its parts,Fieldset,Kbd,ModalTrigger,DrawerTrigger,PopoverTrigger,ModalHeader/Body/Footer,DrawerHeader/Body/Footer,Pagination,Progress,Separator,Skeleton,SkipLink,Spinner, andTable).@hydrateless/react/clientcarries'use client'at the top of the bundle and exports stateful, hook-driven, and enhancer-backed components (Tabs,Modal,Drawer,Popover,Dropdown,Menu,Tooltip,Combobox,Command,Field, form inputs,useEnhancer,useField,useToast).- The root entry
@hydrateless/reactre-exports both without'use client'on the barrel, so bundlers preserve server-only imports for static components while marking interactive ones as client modules automatically.
TypeScript
Full type definitions ship with the package. Every component's props (TabsProps, DropdownItemProps, ModalProps, TableProps, and so on) and the enhancer API types (TabsApi, ModalApi, ToastApi, ToastIntent) are exported for reuse.