Swirski UI

Hooks

Behavior helpers.

Swirski hooks are small client-side utilities for the behavior that shows up across components: disclosure state, controlled state, outside clicks, keyboard escape, clipboard, storage and responsive preferences.

Hook entries

10

documented hooks, exported from @swirski/ui and installable through the registry CLI.

Install

Import or copy.

Hooks can be imported from the package or copied into an app with the registry CLI. Copied hooks follow dependency metadata, so `useDisclosure` also brings `useControllableState`.

import { useDisclosure, useClipboard } from "@swirski/ui";
swirski add use-disclosure use-clipboard

Recipes

Where hooks fit.

These hooks are deliberately small. They cover the behavioral patterns that repeat across Swirski components and app screens.

HookUse it for
useDisclosureDialogs, drawers, popovers, accordions and custom show/hide UI.
useControllableStateComponents that support both controlled and uncontrolled props.
useClickOutsideMenus, custom selects, floating panels and dismissible surfaces.
useClipboardCopy buttons, registry commands, install snippets and code blocks.
useIsPathnameActiveNavigation links, sidebars, breadcrumbs and active route styling.

Example

Disclosure state.

`useDisclosure` is the everyday hook for open/close UI. It returns the current boolean state and a small handler object.

Open hook docs
const [opened, handlers] = useDisclosure(false);

return (
  <>
    <Button onClick={handlers.open}>Open</Button>
    <Button onClick={handlers.close}>Close</Button>
    <Button onClick={handlers.toggle}>Toggle</Button>
  </>
);
Hook

useDisclosure

Boolean open/close/toggle state for dialogs, drawers, popovers and custom disclosure UI.

Hook

useControllableState

A small helper for components that support both controlled and uncontrolled state.

Hook

useClickOutside

Runs a callback when pointer events happen outside a referenced element.

Hook

useEscapeKey

Runs a callback when Escape is pressed.

Hook

useIsPathnameActive

Checks whether a pathname matches the current URL path, including nested routes.

Hook

useLocalStorage

Persists React state in localStorage with serializer hooks.

Hook

useMediaQuery

Tracks a CSS media query in React state.

Hook

useReducedMotion

Reads the user preference for reduced motion.

Hook

useClipboard

Copies text to the clipboard and tracks copied/error state.

Hook

usePortalRoot

Returns the document body once the app has mounted so portal components can render safely.