Skip to main content

Toggle

A customizable toggle switch component that provides a modern neumorphic design. It supports various sizes, custom icons, and can be used for binary state selection.

Basic Usage

import { Toggle } from "@carton-org/react-neumorphism";
import { useState } from "react";

const MyComponent = () => {
const [isChecked, setIsChecked] = useState(false);

return (
<Toggle
label="Enable notifications"
checked={isChecked}
onChange={(e) => setIsChecked(e.target.checked)}
/>
);
};

Live Example

Props

NameTypeDescriptionRequiredDefault Value
idstringUnique identifier for the toggle inputNoundefined
labelstringText label displayed next to the toggleNoundefined
size"xs" | "sm" | "md" | "lg" | "xl"Size of the toggle switchNo"md"
roundedbooleanWhether the toggle should have rounded cornersNofalse
borderbooleanWhether to show a border around the toggleNofalse
checkedbooleanWhether the toggle is checkedNofalse
disabledbooleanWhether the toggle is disabledNofalse
icons{ checkedIcon: React.ReactNode; uncheckedIcon: React.ReactNode }Custom icons for checked and unchecked statesNoundefined
onChange(event: React.ChangeEvent<HTMLInputElement>) => voidCallback fired when the toggle state changesNoundefined
labelStyleReact.CSSPropertiesCustom styles for the label elementNoundefined
toggleStyleReact.CSSPropertiesCustom styles for the toggle switch elementNoundefined

Examples

Different Sizes

With Custom Icons

☀️

Rounded Toggle

With Border

Disabled State