@zephora/primitives
v1.0.0
Published
Headless, accessible behavior primitives for Zephora UI — focus management, dismissable layers, positioning, roving focus and state utilities.
Maintainers
Readme
@zephora/primitives
Headless, accessible behavior primitives for Zephora UI (Web). The unstyled logic layer the styled components are built on — usable on its own to build your own accessible components.
Install
npm install @zephora/primitivesRequires React ≥ 18.
What's inside
useControllableState— controlled/uncontrolled state in one hookuseDisclosure— open/close state for overlaysPortal— synchronous portal (measures before paint)FocusTrap/useRovingFocus— focus managementuseDismiss— outside-press / Escape dismissal for layersusePosition— anchored positioning with flip, shift and arrow coordsusePresence— mount/unmount with exit animations (reduced-motion aware)VisuallyHidden— accessible visually-hidden content
Example
import { useDisclosure, Portal, useDismiss } from "@zephora/primitives";
function Popover() {
const { isOpen, toggle, close } = useDisclosure();
const ref = React.useRef<HTMLDivElement>(null);
useDismiss({ enabled: isOpen, refs: [ref], onDismiss: close });
return (
<>
<button onClick={toggle}>Toggle</button>
{isOpen && (
<Portal>
<div ref={ref} role="dialog">…</div>
</Portal>
)}
</>
);
}