Slime switch
A Radix switch with a liquid surface and four color presets.
Color presets
Blue
OnPink
OnPurple
OnSource and registry are built locally. Copy setup installs from this preview’s registry; the public release has not been published.
Install
In a React project configured with shadcn/Radix, this command copies the component and its required stylesheet. Use the preview’s running URL until the public registry release is published.
npx shadcn@latest add https://civilian.studio/r/slime-switch.jsonLabel layouts
Compact controls or full-width settings rows. Supporting text is optional. Enable it in Controls to preview the spacing below the drips.
Hugged
Label and switch stay together. Fits toolbars and compact panels.
Stretched
The row fills its container. Fits preferences and settings lists.
Disabled
Dried, matte slime with retracted drips and a locked thumb. The saved value remains visible.
State response
Off keeps a muted, glossy surface with short attached drips. On restores the saturated palette and expands the liquid motion. Disabled dries the material without changing the saved state.
Focus and input
Tab or Shift+Tab to an enabled switch to see its focus ring. Space or Enter toggles it. Fine-pointer hover lifts the thumb highlight; pressing compresses it. Touch uses the full 44px hit area.
Labels and state
Use a visible setting label that stays the same when toggled. Optional On / Off text is decorative; Radix announces the checked state to assistive technology.
Release status
Reusable source, registry packaging, and interaction checks are part of this local build. Manual screen-reader review and live publication verification remain release checks.
API reference
SlimeSwitch styles Radix Root and Thumb. SlimeSwitchField adds a visible label, description, and layout.
"use client"
import { useState } from "react"
import { SlimeSwitchField } from "@/components/ui/slime-switch"
export function MemorySetting() {
const [enabled, setEnabled] = useState(true)
return (
<SlimeSwitchField
label="Agent Slop"
checked={enabled}
onCheckedChange={setEnabled}
/>
)
}"use client"
import { SlimeSwitchField } from "@/components/ui/slime-switch"
export function MemorySetting() {
return (
<SlimeSwitchField
label="Agent Slop"
defaultChecked
name="memory"
value="enabled"
/>
)
}| Prop | Type / default | Description |
|---|---|---|
checked | booleanDefault: — | Controlled state: the parent owns the value. Pair with onCheckedChange; do not also set defaultChecked. |
defaultChecked | booleanDefault: false | Initial uncontrolled state: Radix owns the value and onCheckedChange can observe changes. |
onCheckedChange | (checked: boolean) => voidDefault: — | Called with the next state immediately, without waiting for the animation. |
disabled | booleanDefault: false | Blocks interaction, removes keyboard focus, and dries the material. Preserves the saved value. |
required | booleanDefault: false | Native form validation requires the switch to be checked. |
name | stringDefault: — | Form field name. Only checked, enabled switches submit a value. |
value | string | number | readonly string[]Default: "on" | Native button value type inherited from Radix. Use a string for the checked form value. |
form | stringDefault: — | ID of a form to associate with, including a form outside the component. |
| Prop | Type / default | Description |
|---|---|---|
slimeColor | "green" | "blue" | "pink" | "purple"Default: "green" | Material palette. Disabled uses a shared neutral dried surface. |
treatment | "slime" | "subtle"Default: "slime" | Full liquid silhouette or restrained material. |
animate | booleanDefault: true | Continuous ooze. Disabled, reduced-motion preferences, hidden tabs, and offscreen visibility take precedence. |
stateText | { checked: string; unchecked: string }Default: — | Optional engraved state text. Decorative; keep it short, around three characters. Longer text clips. |
| Prop | Type / default | Description |
|---|---|---|
label | stringDefault: Required | Visible, clickable accessible name. Keep it stable when the state changes. |
description | ReactNodeDefault: — | Optional text below the drip clearance. Omitted by default; associated with aria-describedby. |
layout | "hugged" | "stretched"Default: "hugged" | Keep label and switch together, or fill the container with the switch at the end. |
fieldClassName | stringDefault: — | Style the surrounding field. className still applies to the switch button. |
Field accepts the switch’s behavior, material, native props and ref, except aria-label and aria-labelledby: its visible label supplies the accessible name.
| Prop | Type / default | Description |
|---|---|---|
id | stringDefault: Generated by Field | Button ID. The primitive needs an external label association; Field generates one. |
ref | React.Ref<HTMLButtonElement>Default: — | Ref to the interactive button; forwarded through Field. |
className / style | string / React.CSSPropertiesDefault: — | Customize the switch and its material tokens. |
aria-label / aria-labelledby | stringDefault: — | Available on SlimeSwitch. Field owns these attributes through its visible label. |
aria-describedby | stringDefault: — | Space-separated description IDs. Field merges them with its own description. |
Native button attributes and events | Inherited from Radix RootDefault: Radix defaults | Includes dir, title, tabIndex, type, data attributes, onClick, onKeyDown and focus/pointer events. Consumer preventDefault cancellation is respected. Radix sets type=button by default. |
Radix differences
Radix Root supports asChild and custom children. Slime excludes both because it owns the liquid surface and Thumb. There is no separate public Thumb or unstable Radix parts API. See the Radix Switch reference.
Keyboard and forms
Tab and Shift+Tab move between enabled controls; disabled switches are skipped. Space or Enter toggles the focused switch. Safari follows the platform keyboard-navigation setting; Option+Tab also reaches controls. Radix supplies role=switch and aria-checked. Its hidden input handles form submission and validation. A checked disabled switch keeps its displayed value but does not submit it.
Styling hooks
The button exposes data-slot=switch, data-state, data-disabled, data-treatment, data-slime-color and data-animate. Field exposes data-slot=slime-switch-field, data-layout and data-disabled; its parts use slime-switch-row, slime-switch-label and slime-switch-description slots.
Material tokens
Override --slime-light, --slime-mid, --slime-dark, --slime-ink and --slime-glint using style or className. --slime-focus customizes the keyboard outline. --slime-control-edge sets the gradient thumb rim’s shaded color; --slime-state-ink sets decorative text. Set --slime-label-font on the field or an ancestor to customize rounded field and state typography. --slime-description-gap controls clearance below drips. Disabled uses a shared matte palette. Direction follows native dir, including RTL.