Core UI
Switch
A single on/off setting backed by a native checkbox, with switch semantics, optional description and controlled or local state.
$ velocityx add switch
Needs a licence key — buy lifetime access here, then
velocityx login once.
$ velocityx add switch@1.0.0
Needs a licence key — buy lifetime access here, then
velocityx login once.
Built for react.
Needs react already installed
as a peer dependency.
An Astro-only project needs @astrojs/react wired up first — this won't run on its own in plain Astro.
- Framework
- react
- Source
- 91 lines
- Switch.jsx
- Runtime
- Interactive
- runs in the browser
- Theme
- 8 tokens
- re-themes from your scale
- Dark mode
- Built in
- dark: variants
- Accessibility
- 3 ARIA
- attributes and roles
Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| checked | boolean | No | undefined | Controlled checked state. |
| defaultChecked | boolean | No | false | Initial local state. |
| onCheckedChange | undefined | No | undefined | function(nextChecked: boolean) Called after a change. |
| label | ReactNode | Yes | Required visible or accessibly named label. | |
| description | string | No | undefined | Optional supporting text, announced as description. |
| name | string | No | undefined | Form field name. |
| value | string | No | 'on' | Submitted value when checked. |
| disabled | boolean | No | false | Disables changes. |
| className | string | No | '' | Additional wrapper classes. |
Using it
The smallest call that compiles — required props only. The import is
written for your own file at src/components/Example.jsx;
adjust the relative import if yours sits elsewhere.
Everything optional is in the table above, with its default.
import Switch from './velocity/switch/Switch';
export default function Example() {
return (
<Switch
label="Product updates"
description="Receive occasional news about new features."
name="product-updates"
/>
);
} Built from Switch's own prop signature and the path the CLI installs it to, so it can't drift from either.
Accessibility
- ARIA roles
- switch
- ARIA attributes
- aria-describedby, aria-labelledby
- Keyboard
- Built on native controls — Enter/Space work as standard
- Screen readers
- Ships screen-reader-only text
- Motion
- Respects prefers-reduced-motion
Read from the source, not asserted — anything not listed simply isn't in this component's markup.
Behaviour
- Ships client JS
- Yes — this one needs to hydrate
- React hooks
- useId, useState
- Dark mode
- Carries its own dark: variants
Theming
This component paints from 8 steps of
your theme scale — no hardcoded colours, and no font-family of
its own, so your type cascade wins. Override the variables and it follows.
primary-50primary-100primary-200primary-300primary-500primary-600primary-700primary-950Get the Velocity preset and CSS theme from the public source guide. The CLI theme command is not available on npm yet.
File this creates
The CLI writes this path into your project — nothing
else moves. Paths are under your source root, which defaults to
src/; pass
--dest if yours is elsewhere.
-
src/components/velocity/switch/Switch.jsx91 lines
Copy the paths
src/components/velocity/switch/Switch.jsx Versions
2 published versions are preserved with their own access level and source hash. The CLI can pin to any version and upgrade without overwriting local edits.
- v1.0.1 Current Subscription18 Oct 2026
velocityx add switch - v1.0.0Subscription18 Oct 2026
velocityx add switch@1.0.0
Switch — questions
How do I install Switch?
Run velocityx add switch . The CLI writes the source straight into your project — it is not a runtime package dependency.
Do I need a licence for Switch?
Yes. It is part of the lifetime library — buy access at https://aidxn.com/shop/velocity-x-component-library/, authenticate once, and install it. Your lifetime licence includes future component updates.
Can I edit Switch after installing it?
Yes — the files are yours once written. The CLI compares its lockfile hash before upgrades and refuses to overwrite code you changed.
Does Switch ship JavaScript to my users?
Yes. It runs in the browser (useId, useState), so it needs to hydrate — in Astro, give it a client:* directive.
Will Switch match my brand colours?
Yes. It paints entirely from your theme scale — 8 steps of primary-* / accent-* — with no hardcoded hex values and no font-family of its own. Override the theme CSS variables and it follows your design system instead of ours.
Is Switch accessible?
It ships ARIA roles (switch), 2 ARIA attributes, native controls that are keyboard-operable by default. That is read directly from the source rather than claimed — you should still test it in the context you drop it into.
Which version of Switch should I install?
There are 2 published versions, and the default install gives you the current one. Pin an older one with velocityx add switch@<version> , or move between them later with velocityx upgrade switch — downgrades work too.
Does Switch pull in any dependencies?
No external ones. Every component in the library is built with react/react-dom or plain Astro only — no GSAP, Radix, Swiper or Headless UI — which is what makes dropping it into an existing project safe.
Set up & reference
All docs →Install this component:
$ velocityx add switch - 2. Install the theme — run this first, once per project Do this once per project, before your first component.
- The palette gotcha — this one bites silently Silent failure — the component renders, just unstyled.
- Your edits are safe by default What happens to your changes when you upgrade.
- You own the code What you are actually buying.
Related components
More from Core UI.
Expand/collapse FAQ list with measured-height animation, single or multi-open modes, and arrow-key navigation between headers.
reactAuroraMegaMenuHeader — one-bar header with a cursor-follow spotlight, an animated gradient hairline, and glass mega-menu panels with a rotating gradient border.
reactFloating button that fades in past a scroll threshold and scrolls to top, instantly under reduced motion.
reactA labelled multi-choice group built on native checkboxes, with optional descriptions, per-option disabled state, and controlled or local array values.
react