Skip to content

@loke/ui

To install dependencies:

loke-ui

169 linesSource

Entry point and router for @loke/ui headless React UI primitives. Subpath imports only — never import from @loke/ui directly. Components across overlays (Dialog, AlertDialog, Popover, Tooltip, DropdownMenu), forms (Checkbox, RadioGroup, Select, Switch, Label), navigation (Accordion, Tabs, Collapsible, Command), and composition (Primitive+Slot, Context+Collection, Overlay Infrastructure, Hooks). All are thin shells over 4 shared infrastructure patterns: DismissableLayer, FocusScope, Presence, useControllableState.

@loke/ui

Headless, unstyled React UI primitives with granular subpath exports. Every component ships accessible behavior, keyboard navigation, and ARIA semantics. Styling is entirely your responsibility.

Import Rule

ALWAYS import from the component subpath. Never from the root package or Radix paths.

tsx
// CORRECT
import { Dialog, DialogContent, DialogTitle } from "@loke/ui/dialog";
import { Select, SelectItem, SelectItemText } from "@loke/ui/select";

// WRONG — these all fail
import { Dialog } from "@loke/ui";
import { Dialog } from "@radix-ui/react-dialog";
import { Dialog } from "@loke/design-system";

Mental Model

All components are thin shells over 4 shared infrastructure patterns. Learn these once and every component becomes readable:

InfrastructureWhat it doesComponents that use it
DismissableLayerStacked dismiss logic, outside-click, escape keyDialog, Popover, Tooltip, DropdownMenu
FocusScopeFocus trapping, looping, auto-focus on openDialog, AlertDialog, Popover (modal)
PresenceAnimation state machine — delays unmount for exit transitionsAll overlays with forceMount
useControllableStateControlled/uncontrolled dual-mode with dev warningsAll stateful components

Sub-Skills

Route to the skill that matches what you're building:

Need to…Skill
Build a modal or non-modal dialogdialog
Build a destructive confirmation dialogalert-dialog
Build a floating panel anchored to a triggerpopover
Add hover/focus tooltipstooltip
Build a trigger-based dropdown menudropdown-menu
Build accessible checkboxes (incl. indeterminate)checkbox
Build a single-selection radio groupradio-group
Build a listbox-style select for formsselect
Build an on/off toggle switchswitch
Label a form control accessiblylabel
Build expandable section groupsaccordion
Build a tabbed interfacetabs
Build a single collapsible sectioncollapsible
Build a command palette or searchable listcommand
Use asChild / delegate element renderingprimitive-and-slot
Build compound components with scoped contextcontext-and-collection
Build a custom overlay from scratchoverlay-infrastructure
Use shared hooks (controllable state, size, etc.)hooks
Unsure which component to usechoosing-the-right-component

Quick Decision Tree

plaintext
Need floating/overlay UI?
├─ Triggered by hover/focus only + non-interactive content → Tooltip
├─ Triggered by click + interactive content (forms, buttons) → Popover
├─ Triggered by click + list of actions → DropdownMenu
├─ Triggered by click + form value selection (static list) → Select
├─ Triggered by click + searchable/async option list → Popover + Command
├─ Full overlay with title + description
│  ├─ Destructive action confirmation → AlertDialog
│  └─ General purpose modal/sheet → Dialog
└─ Nothing floats, just expand/collapse
   ├─ Single section → Collapsible
   ├─ Multiple coordinated sections → Accordion
   └─ Tabbed panel switching → Tabs

Need a form control?
├─ Boolean on/off toggle → Switch
├─ Multi-select or tri-state (indeterminate) → Checkbox
├─ Single selection from a group → RadioGroup
├─ Pick a value, submit in a form → Select
└─ Any control needs an accessible name → Label

All Subpath Imports

tsx
import { ... } from "@loke/ui/accordion";
import { ... } from "@loke/ui/alert-dialog";
import { ... } from "@loke/ui/arrow";
import { ... } from "@loke/ui/avatar";
import { ... } from "@loke/ui/checkbox";
import { ... } from "@loke/ui/collapsible";
import { ... } from "@loke/ui/collection";
import { ... } from "@loke/ui/command";
import { ... } from "@loke/ui/compose-events";
import { ... } from "@loke/ui/compose-refs";
import { ... } from "@loke/ui/context";
import { ... } from "@loke/ui/dialog";
import { ... } from "@loke/ui/dismissable-layer";
import { ... } from "@loke/ui/drawer";
import { ... } from "@loke/ui/dropdown-menu";
import { ... } from "@loke/ui/focus-guards";
import { ... } from "@loke/ui/focus-scope";
import { ... } from "@loke/ui/label";
import { ... } from "@loke/ui/menu";
import { ... } from "@loke/ui/number";
import { ... } from "@loke/ui/popper";
import { ... } from "@loke/ui/popover";
import { ... } from "@loke/ui/portal";
import { ... } from "@loke/ui/presence";
import { ... } from "@loke/ui/primitive";
import { ... } from "@loke/ui/radio-group";
import { ... } from "@loke/ui/rect";
import { ... } from "@loke/ui/roving-focus";
import { ... } from "@loke/ui/select";
import { ... } from "@loke/ui/separator";
import { ... } from "@loke/ui/slot";
import { ... } from "@loke/ui/switch";
import { ... } from "@loke/ui/tabs";
import { ... } from "@loke/ui/tooltip";
import { ... } from "@loke/ui/use-callback-ref";
import { ... } from "@loke/ui/use-controllable-state";
import { ... } from "@loke/ui/use-direction";
import { ... } from "@loke/ui/use-escape-keydown";
import { ... } from "@loke/ui/use-id";
import { ... } from "@loke/ui/use-is-document-hidden";
import { ... } from "@loke/ui/use-is-hydrated";
import { ... } from "@loke/ui/use-layout-effect";
import { ... } from "@loke/ui/use-previous";
import { ... } from "@loke/ui/use-size";
import { ... } from "@loke/ui/visually-hidden";

Key Patterns

Exit animations need no extra props. Presence keeps the element mounted until a CSS @keyframes animation on data-state="closed" finishes (transitions do not delay unmount). forceMount keeps it mounted permanently, for JS animation libraries that control visibility themselves:

tsx
<DialogPortal>
  <DialogOverlay className="animate-fade-out data-[state=open]:animate-fade-in" />
  <DialogContent className="animate-slide-out data-[state=open]:animate-slide-in">
    ...
  </DialogContent>
</DialogPortal>

All stateful components support controlled and uncontrolled mode:

tsx
// Uncontrolled (internal state)
<Dialog defaultOpen={false}>...</Dialog>

// Controlled (external state)
<Dialog open={open} onOpenChange={setOpen}>...</Dialog>

Do not mix controlled and uncontrolled. Switching at runtime triggers dev warnings and loses state.