Hold Switch
Install the component, then paste your configured usage. Your settings are included in the code below.
npx arclen-ui add hold-switch --settings eyJhY2Nlc3NpYmxlTmFtZSI6IlRvZ2dsZSBzZXR0aW5nIiwiY2hlY2tlZCI6ZmFsc2UsImRpc2FibGVkIjpmYWxzZSwid2lkdGgiOjI2MCwidHJhY2tUb3AiOiIjMzUzNTM1IiwidHJhY2tCb3R0b20iOiIjMjQyNDI0IiwidHJhY2tFZGdlIjoiIzRhNGE0YSIsImlua0NvbG9yIjoiI2I4YjhiOCIsInRodW1iVG9wIjoiI2ZmZmZmYyIsInRodW1iQm90dG9tIjoiI2U4ZTVkZiIsImRvdENvbG9yIjoiIzg3OGI5NCIsInNoYWRvd1N0cmVuZ3RoIjoxLCJpbnRlcmFjdGlvbiI6InByZXNzdXJlIiwiaG9sZER1cmF0aW9uIjoxMDAwLCJxdWlja1RhcFdpbmRvdyI6MjIwLCJyZWxlYXNlVGhyZXNob2xkIjowLjUsInByZXNzdXJlQW1vdW50IjowLjA0LCJzaG93UHJvZ3Jlc3MiOmZhbHNlLCJwcm9ncmVzc0NvbG9yIjoiI2JlYzNjYiIsInByb2dyZXNzV2lkdGgiOjIsIm1vdGlvbkR1cmF0aW9uIjo4ODAsInNwcmluZ0RhbXBpbmciOjI3LCJzdHJldGNoQW1vdW50IjowLjAzNX0import { HoldSwitch } from "@/components/hold-switch";
export default function Example() {
return <HoldSwitch {...{
"accessibleName": "Toggle setting",
"checked": false,
"disabled": false,
"width": 260,
"trackTop": "#353535",
"trackBottom": "#242424",
"trackEdge": "#4a4a4a",
"inkColor": "#b8b8b8",
"thumbTop": "#fffffc",
"thumbBottom": "#e8e5df",
"dotColor": "#878b94",
"shadowStrength": 1,
"interaction": "pressure",
"holdDuration": 1000,
"quickTapWindow": 220,
"releaseThreshold": 0.5,
"pressureAmount": 0.04,
"showProgress": false,
"progressColor": "#bec3cb",
"progressWidth": 2,
"motionDuration": 880,
"springDamping": 27,
"stretchAmount": 0.035
}} />;
}| Property | Type | Default |
|---|---|---|
accessibleNameAccessible name Name announced by assistive technology. Up to 120 characters | text | "Toggle setting" |
checkedOn Logical endpoint; external updates do not emit a user change. | boolean | false |
disabledDisabled Blocks all activation and cancels a pending hold. | boolean | false |
widthWidth Pixels; height is half the width. Shrinks proportionally inside narrower hosts. 120–520Step 2 | number | 260 |
trackTopTrack top Upper recessed track gradient stop. | color | "#35363a" |
trackBottomTrack bottom Lower recessed track gradient stop. | color | "#242529" |
trackEdgeTrack edge Fine recessed track boundary. | color | "#4a4b50" |
inkColorLiquid Grey liquid surface. | color | "#74767d" |
thumbTopThumb top Upper ivory thumb gradient stop. | color | "#fffffc" |
thumbBottomThumb bottom Lower ivory thumb gradient stop. | color | "#e8e5df" |
dotColorThumb dot Small center pressure marker. | color | "#878b94" |
shadowStrengthShadow strength Scales contact and ambient shadow; zero removes both. 0–1.5Step 0.1 | number | 1 |
interactionInteraction Pressure preserves click activation. Hold only cancels early physical releases; assistive click activation remains supported. Options: pressure (Pressure), hold (Hold only) | select | "pressure" |
holdDurationHold duration Time in milliseconds to complete one held activation. 400–1800Step 50 | number | 1000 |
quickTapWindowQuick-tap window Pressure only: releases within this window toggle as quick clicks. 50–240Step 10 | number | 220 |
releaseThresholdRelease commit point Pressure only: reached hold fraction required to commit on release after the quick-tap window. 0.25–0.9Step 0.01 | number | 0.5 |
pressureAmountPressure deformation Maximum thumb compression while holding; zero removes deformation. 0–0.24Step 0.01 | number | 0.04 |
showProgressShow progress ring Show a progress ring around the thumb while holding. | boolean | false |
progressColorProgress ring Color of the hold progress ring. | color | "#bec3cb" |
progressWidthProgress weight Ring stroke in SVG units; scales with component width. 1–5Step 0.5 | number | 2 |
motionDurationLiquid timing Scales post-commit liquid and thumb motion; hold duration is independent. 440–1400Step 20 | number | 880 |
springDampingSpring damping Higher values suppress recoil after a committed toggle. 20–38Step 0.5 | number | 27 |
stretchAmountTravel stretch Thumb stretch during committed travel; zero keeps its circle. 0–0.18Step 0.005 | number | 0.035 |
Hold Switch
An ivory and graphite liquid switch with a pressure gesture and an optional progress ring. It changes a boolean value; your application decides what the value means.
React
import { useState } from 'react';
import { HoldSwitch } from './components/hold-switch';
export function Example() {
const [checked, setChecked] = useState(false);
return <HoldSwitch checked={checked} onCheckedChange={setChecked}
accessibleName="Quiet mode" interaction="hold" showProgress />;
}Omit checked for local state. defaultChecked initializes that state; otherwise the configured manifest default applies. Component aliases HoldSwitch. Settings are individual props. className, style, and paused configure the wrapper and lifecycle. Controlled ownership can change without replacing the focused button. Controlled requests leave the displayed checked state unchanged until the parent supplies its next value.
Vanilla JavaScript
import { defaults, mount } from './components/hold-switch/src/core';
import './components/hold-switch/src/styles.css';
const controller = mount(document.querySelector('#switch')!, defaults, undefined, {
onCheckedChange(checked, detail) { console.log(checked, detail); },
});
controller.update({ width: 180 });
controller.pause();
controller.resume();
// When removing the host:
controller.destroy();update accepts partial settings and preserves omitted values. It never emits a user change. Invalid settings throw before mutation. Pass controlled: true in the mount options for external state ownership, then accept requests with update({ checked }). The option can be a live getter. The bubbling hold-switch-change event and callback both receive { checked, source, activation }. Source is pointer, keyboard, or assistive; activation is click or hold. Subscribe to one channel for each application action.
Presets and controls
Pressure supports a quick tap, a full hold, or release after the partial-hold threshold. Its defaults are a 220 ms quick-tap window, 1000 ms full hold, and 50% release threshold. A release between the quick-tap window and partial threshold cancels. Deliberate hold requires 1400 ms and shows the ring. Compact hold uses a 160 px drawing and a 650 ms hold. Both strict hold presets cancel early releases. All presets contain the complete settings vector.
holdDuration controls commitment timing. quickTapWindow and releaseThreshold apply only to Pressure. pressureAmount controls thumb compression; stretchAmount controls travel deformation. motionDuration changes decorative settling without changing hold timing; springDamping controls recoil. The default grey liquid (#74767D), silver progress ring (#BEC3CB), and graphite track are shared across all presets. The ring has independent visibility, color, and width. Track, thumb, ink, dot, and shadow controls change the material. Width scales the drawing at a 2:1 aspect ratio and respects a narrower container.
Input and accessibility
The native button has switch semantics, an accessible name, and a generated description of keyboard timing. Hold Space or Enter using the same duration as pointer input. Repeated keydown events do not repeat commitment. Each physical gesture commits at most once. Releasing early in strict hold mode, moving outside, losing pointer capture, pressing Escape, or blurring cancels pending commitment. Touch long-press selection and the context menu are suppressed only on the control.
Assistive activation without a physical press toggles directly, including in strict hold mode. This is an accessibility fallback, so this component must not be used as a security or safety confirmation barrier.
Reduced motion keeps timed progress usable while removing decorative travel and deformation. Missing animation or observation APIs retain functional hold input. Offscreen controls remain keyboard focusable. Explicit pause disables interaction; resume restores the configured disabled state without reviving a gesture. Hidden/offscreen suspension stops decorative work. There is no idle animation loop.
Static server rendering retains the name and checked semantics on a native disabled button. Mount activates it. Destroy removes listeners, observers, timers, and frame work and leaves a disabled static endpoint. Destruction is idempotent. Instances have isolated IDs and state; the component uses no storage, remote scripts, or page-level theme mutation.
The preview runs the component’s own JavaScript. It respects reduced motion and pauses when off screen. The HTML bundle includes a static fallback.
Every setting in this panel comes from the component manifest. Preview size, pause and replay stay in the inspector.