Specialized interaction machines
Specialized interaction machines coordinate UI parts that need more than a simple open or closed state. They turn pointer, keyboard, touch, time, and layout changes into stable state and accessible output for controls such as sliders, image editors, scroll areas, timers, and QR codes. This page extends Component machines and relates to collections, geometry, and localization and interaction utilities.
Interaction model
These machines keep interaction state separate from the visual parts that render it. A component reports meaningful values such as a color, crop rectangle, panel sizes, progress value, or encoded text. The connected UI then presents that state through the framework adapter.
The machines share a small set of product-level behaviors:
- They accept both initial values and controlled values where the interaction can be owned by the caller.
- They expose change events while an interaction is active and, where useful, a second event when the interaction ends.
- They map pointer and keyboard actions to the same user-visible result.
- They expose state for disabled, read-only, focused, dragging, scrolling, or running conditions.
- They provide semantic parts so labels, values, controls, and status text can stay linked.
The following diagram shows the common relationship between an input, a specialized machine, and the rendered result.
flowchart LR
Input[Pointer, keyboard, touch, time, or prop change] --> Machine[Specialized interaction machine]
Machine --> State[Normalized interaction state]
State --> UI[Connected visual and semantic parts]
State --> Events[Value, progress, completion, or lifecycle events]
Events --> Consumer[Application state or downstream action]
Control value machines
Control value machines turn spatial input into values that applications can use. The standard slider supports one or more numeric thumbs with limits, steps, orientation, right-to-left direction, and collision rules. The angle slider applies the same idea to a circular value from 0 to 360 degrees. Both support pointer movement and keyboard changes while keeping form values and accessible value text in sync.
The color picker builds a richer value control from an area, channel sliders, text inputs, swatches, and an optional eye dropper. It can open as a positioned popover or render inline. All of these parts update one color value and can report the value in the selected color format.
| Machine | Product role | Main result |
|---|---|---|
| Slider | Select one value or a numeric range | One or more constrained numbers |
| Angle slider | Select a direction or rotation angle | An angle value and degree text |
| Color picker | Select and edit a color | A color value, format, and channel values |
These controls are useful when a visual control must also work as a form field. The caller can listen to continuous changes for live previews and to end-of-change events for actions that should run once after dragging stops.
References: packages/…/slider.types.ts• L42-167 packages/…/slider.machine.ts• L46-67 packages/…/angle-slider.types.ts• L26-79 packages/…/angle-slider.machine.ts• L41-55 packages/…/color-picker.types.ts• L62-155 packages/…/color-picker.machine.ts• L32-50
Image editing machines
The image cropper coordinates a crop selection with image transforms. It keeps the crop inside the viewport while the user moves or resizes the selection, pans the image, zooms, rotates, or flips it. Its output can be either the current crop geometry or an exported image with the transforms applied.
The crop shape can be rectangular or circular. An aspect ratio and size limits can constrain the selection. The machine also supports mouse, touch pinch, wheel zoom, and keyboard nudges so the same crop state can be reached through different input methods.
The signature pad turns a pointer stroke into reusable path data. It keeps committed strokes apart from the stroke in progress, supports controlled or initial paths, and can export the drawing as a PNG, JPEG, or SVG data URL. A clear action removes all strokes and returns the pad to its empty state.
The two machines produce different kinds of media output:
- The image cropper produces a selected image region and an optional encoded image.
- The signature pad produces vector-like path strings and an optional raster or SVG data URL.
References: packages/…/image-cropper.types.ts• L69-197 packages/…/image-cropper.types.ts• L264-421 packages/…/image-cropper.machine.ts• L185-255 packages/…/signature-pad.types.ts• L15-39 packages/…/signature-pad.types.ts• L64-111 packages/…/signature-pad.machine.ts• L58-78
Layout and viewport machines
The splitter manages a group of resizable panels. It resolves panel sizes against minimum and maximum limits, preserves the layout when the group changes size, and supports collapsible panels. Pointer dragging and keyboard resizing use the same panel-size model, so a layout can also be changed through the public API.
The scroll area manages a custom viewport and its scrollbars. It derives thumb size and position from the content and viewport sizes, tracks horizontal and vertical overflow, and reports whether the viewport is at each edge. It also provides programmatic scrolling and normalized scroll progress for controls such as scroll indicators.
The layout relationship is therefore two-way: user input changes a layout or scroll position, while a resize or content change causes the machine to recalculate the visual controls.
flowchart LR
LayoutInput[Drag or keyboard resize] --> Splitter[Splitter]
Splitter --> PanelSizes[Constrained panel sizes]
GroupResize[Panel group resize] --> Splitter
Content[Viewport content and size] --> ScrollArea[Scroll area]
ScrollInput[Wheel, thumb drag, or API call] --> ScrollArea
ScrollArea --> ScrollState[Overflow, edge, thumb, and progress state]
References: packages/…/splitter.types.ts• L16-45 packages/…/splitter.types.ts• L87-142 packages/…/splitter.types.ts• L228-297 packages/…/splitter.machine.ts• L133-231 packages/…/scroll-area.types.ts• L32-66 packages/…/scroll-area.types.ts• L107-155 packages/…/scroll-area.machine.ts• L98-128
Status and lifecycle machines
The progress machine represents work between a minimum and maximum value. A numeric value produces a percentage and localized value text. A null value represents indeterminate progress, which lets the UI show activity without claiming a known amount of work. The same state can drive linear or circular views.
The presence machine controls whether a node stays mounted while its enter or exit animation runs. It lets a caller request presence without forcing the node to disappear before the exit animation completes. Completion callbacks mark the end of the enter or exit phase.
The timer machine represents either an increasing timer or a countdown. It exposes formatted days, hours, minutes, seconds, and milliseconds. It also exposes start, pause, resume, reset, and restart actions. A target value ends the timer and calls the completion event when it is reached.
These machines serve different kinds of status:
| Machine | Status meaning | Downstream use |
|---|---|---|
| Progress | How much work is complete or whether work has a known amount | Linear or circular progress display |
| Presence | Whether a node is mounted, entering, exiting, or ready to unmount | Safe animated show and hide behavior |
| Timer | How much time has elapsed or remains | Countdown, stopwatch, and time-based progress |
References: packages/…/progress.types.ts• L15-30 packages/…/progress.types.ts• L44-89 packages/…/progress.machine.ts• L40-68 packages/…/presence.types.ts• L7-24 packages/…/presence.types.ts• L51-68 packages/…/presence.machine.ts• L50-84 packages/…/timer.types.ts• L4-16 packages/…/timer.types.ts• L39-77 packages/…/timer.machine.ts• L52-105
Encoded content machines
The QR code machine converts a string into a QR pattern and keeps the encoded output aligned with the current value and encoding options. It provides a renderable frame and pattern plus a data URL export path. A download trigger can save the result with a caller-provided image type, quality, and file name.
The value can be set at render time or controlled by the caller. The machine reports value changes so the QR code can be used as a live view of a URL, text value, or other encoded payload.
References: packages/…/qr-code.types.ts• L24-50 packages/…/qr-code.types.ts• L79-113 packages/…/qr-code.machine.ts• L6-36
Cross-machine relationships
Several machines combine naturally in product flows. The image cropper can use a slider for zoom. A timer can drive progress. A scroll area can expose progress for a reading view. A color picker can use channel sliders while keeping one shared color value. These are composition choices: each machine owns its own state, and the parent connects their public values and events.
Geometry and direction affect many of these controls. Slider orientation, crop rectangles, panel sizes, scroll edges, and pointer positions must use the same coordinate assumptions as the surrounding component. Read collections, geometry, and localization for shared data and geometry concepts. Read interaction utilities for the lower-level input and DOM behavior used by interaction machines.
Change checklist
When these files or sections are changed, remember to consider these:
- When a value shape changes, update both the continuous change event and the end-of-interaction event. Consumers may use them for different work.
- When a machine gains a new visual state, update the semantic state exposed by its connected parts. Progress, presence, scrolling, and dragging states can affect both styling and accessibility.
- When a geometry rule changes, check every input path that reaches it. Pointer, touch, keyboard, resize, and programmatic actions must produce the same constrained result.
- When a media export changes, keep the live state, geometry data, and exported data contract aligned. Crop geometry is not the same as the final transformed image.
- When a time or progress range changes, preserve the relation between minimum, maximum, target, percentage, and localized value text.
- When a QR encoding option changes, check both the rendered pattern and the data URL used by downloads.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Slider limits, step, or thumb gap cannot form a valid range | Values cannot be normalized to a usable thumb position | Validate the numeric range and gap as one configuration |
| Crop viewport or image size is not measured | Selection and pan actions have no safe bounds | Wait for a visible image and viewport before applying geometry changes |
| A crop export is treated as only an axis-aligned rectangle after rotation | The exported result can differ from the visible crop | Use the crop output that preserves the transformed corner points |
| A signature stroke ends without committed path data | The drawing appears during input but is lost after release | Keep the in-progress path separate and commit it at stroke end |
| Panel sizes violate panel limits or do not match the panel list | A splitter layout can collapse the wrong panel or produce invalid sizes | Resolve and validate sizes against the current ordered panel data |
| Scrollbar size is read before content or viewport measurement is valid | Thumb position and overflow state are wrong | Recalculate after content resize and viewport visibility |
| Progress value is outside its minimum or maximum | Percentage and status text do not describe the displayed range | Clamp updates and validate the configured range |
| Presence changes during an exit animation | A node can unmount too early or finish the wrong transition | Re-check the requested presence state before unmount and on animation end |
| Countdown or stopwatch start and target values are reversed | The timer completes at the wrong time or rejects its setup | Keep countdown starts above targets and stopwatch starts below targets |
| QR data changes without regenerating its encoded pattern | The displayed code does not match the value or downloaded image | Derive rendered and exported output from the same current value and options |
Key files
| File | Why to read it |
|---|---|
| packages/…/slider.types.ts | Defines numeric value, range, thumb, and accessibility contracts for sliders. |
| packages/…/angle-slider.types.ts | Shows the circular form of the slider value contract. |
| packages/…/color-picker.types.ts | Describes the shared color value across the area, channels, inputs, swatches, and popover. |
| packages/…/image-cropper.types.ts | Defines crop geometry, transforms, and export results. |
| packages/…/signature-pad.types.ts | Defines live strokes, committed paths, and image export behavior. |
| packages/…/splitter.types.ts | Defines panel constraints, resize results, and collapse behavior. |
| packages/…/scroll-area.types.ts | Defines overflow, edge, scrollbar, and programmatic scroll contracts. |
| packages/…/progress.types.ts | Defines determinate, indeterminate, localized, and visual progress state. |
| packages/…/presence.types.ts | Defines mount and animation lifecycle state. |
| packages/…/timer.types.ts | Defines timer modes, time parts, actions, and completion behavior. |
| packages/…/qr-code.types.ts | Defines encoded value, rendering, export, and download contracts. |