Formsswitchneumorphism
Neumorphic Switch
Soft UI switch toggle with realistic tactile depth.
Live Preview
Usage
Copy and paste this code into your React component:
tsx
import { NeumorphicSwitch } from 'react-component-kit-ui/forms';
<NeumorphicSwitch id="notify" label="Enable Notifications" checked />Manual Installation
If you are not using the npm package, create a new file and paste the following code: src/components/NeumorphicSwitch.tsx + NeumorphicSwitch.css:
NeumorphicSwitch.tsx
'use client';
import './NeumorphicSwitch.css';
/**
* NeumorphicSwitch โ A soft-UI checkbox toggle with realistic inset and outset shadow states.
*
* @param {string} label - Optional descriptive text suffix.
* @param {string} id - HTML ID for input linkage.
* @param {string} name - HTML name binding.
* @param {boolean} checked - Initial toggle state. Default is false.
*/
export interface NeumorphicSwitchProps {
label?: string;
id?: string;
name?: string;
checked?: boolean;
}
export function NeumorphicSwitch({ label, id, name, checked = false }: NeumorphicSwitchProps) {
return (
<>
<div className="neu-switch-wrapper" data-rk-3cc0c3="">
<label className="neu-switch" data-rk-3cc0c3="">
<input type="checkbox" id={id} name={name} defaultChecked={checked} data-rk-3cc0c3="" />
<span className="slider" data-rk-3cc0c3=""></span>
</label>
{label && <label htmlFor={id} className="neu-label" data-rk-3cc0c3="">{label}</label>}
</div>
</>
);
}
export default NeumorphicSwitch;NeumorphicSwitch.css
/* NeumorphicSwitch โ ported from astro-component-kit (forms/NeumorphicSwitch.astro) */
.neu-switch-wrapper:where([data-rk-3cc0c3]) { display: flex; align-items: center; gap: var(--sp-3, 0.75rem); }
.neu-switch:where([data-rk-3cc0c3]) {
position: relative;
display: inline-block;
width: 60px;
height: 32px;
flex-shrink: 0;
}
.neu-label:where([data-rk-3cc0c3]) { font-size: 0.9rem; color: var(--c-text-2, #94a3b8); cursor: pointer; }
.neu-switch:where([data-rk-3cc0c3]) input:where([data-rk-3cc0c3]) {
opacity: 0;
width: 0;
height: 0;
}
.slider:where([data-rk-3cc0c3]) {
position: absolute;
cursor: pointer;
inset: 0;
background: var(--c-bg, #1a1f2e);
transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
border-radius: 34px;
border: 1px solid var(--c-border, rgba(255, 255, 255, 0.05));
box-shadow:
inset 2px 2px 5px rgba(0, 0, 0, 0.5),
inset -2px -2px 5px rgba(255, 255, 255, 0.04);
}
.slider:where([data-rk-3cc0c3]):before {
position: absolute;
content: "";
height: 24px;
width: 24px;
left: 4px;
bottom: 3px;
background: #374151;
transition: 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
border-radius: 50%;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}
input:checked:where([data-rk-3cc0c3]) + .slider:where([data-rk-3cc0c3]) {
background: rgba(99, 102, 241, 0.1);
border-color: rgba(99, 102, 241, 0.2);
}
input:checked:where([data-rk-3cc0c3]) + .slider:where([data-rk-3cc0c3]):before {
transform: translateX(28px);
background: var(--c-primary, #818cf8);
box-shadow: 0 0 15px rgba(129, 140, 248, 0.5);
}Quick Info
- Category
- Forms
- Filename
NeumorphicSwitch.tsx- Dependencies
- None โ pure React + CSS
- Tags
- switchneumorphism