Primitives / foldkit-primitives
Find a primitive by task
| You want to | Reach for | In |
|---|---|---|
| Follow the color scheme, reduced motion or any media query | MediaQuery, PrefersDark, PrefersReducedMotion | media |
| Change the layout at named widths | Breakpoints | media |
| Know whether the tab is visible, the window's size, or the user idle | Visibility, WindowSize, Idle | events |
| Answer keyboard shortcuts, and draw their labels | keyboardEvents, matchHotkey, formatHotkey | events |
| Count ticks, or run something on an interval | Timer, Interval, ticks | time |
| Wait until typing stops, or limit how often something runs | debounce, Throttle | time |
| Say "3 minutes ago" | formatRelativeTime | time |
| Page through a list | Pagination, range | state |
| Undo and redo | history, History | state |
| Draw only the visible rows of a long list | Virtual (WindowList in foldkit-mixins-ui) | state |
| Animate a value, or let an element leave before it is removed | Tween, Spring, Presence | motion |
| Move with arrow keys through a list, grid, tree, or board | RovingTabindex, ListNavigation, GridNavigation | interaction |
| Close a popup on Escape or an outside press | DismissLayer, Overlay | interaction |
| Press, long-press, or repeat while held (a stepper) | Press, LongPress, Repeat | interaction |
| Drag a window or handle, and nudge or resize it by keys | Move, Move.nudge, Move.resizeKeys, Box | interaction |
| Reorder a list or tree by keys and by pointer | Reorder, PointerDrag | interaction |
| Select items, with Shift ranges or a lasso | Selection, Marquee | interaction |
| Swipe a row open, or settle a scroller on an item | SwipeActions, Swipe, ScrollSettle | interaction |
| Keep focus when a row goes, or return it when an overlay closes | FocusRecovery, FocusReturn, FocusScope | interaction |
| Read where the pointer is inside an element | PointerPosition | dom |
| Edit text in place | InlineEdit, EditableText | interaction |
| Tell a screen reader what changed | LiveAnnounce | interaction |
| Know whether the browser is online, or talk over a socket | Online, websocket, sse | net |
| Talk between tabs | broadcastMessages, SharedHost | net |
| Use the camera, the location or a permission | mediaStream, Geolocation, permissions | device |
| Track one element's size or visibility | Resize, Intersection, Bounds | observers |
| Focus, mask or keep an element in view | Autofocus, InputMask, KeepInView | dom |
| Copy, share, load a script or restore scroll | copyText, share, loadScript, keepScroll | dom |
Working widgets built from the interaction primitives are listed under In the examples.