ToggleButton

January 26, 2026 ยท View on GitHub

A customizable toggle button component that supports various states and styling options.

Usage

import { ToggleButton } from "@docspace/ui-kit/components/toggle-button";

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

  const handleChange = (e) => {
    setIsChecked(e.target.checked);
  };

  return (
    <ToggleButton
      label="Toggle me"
      isChecked={isChecked}
      onChange={handleChange}
    />
  );
};

Properties

NameTypeDefaultDescription
idstring-Element ID
classNamestring-CSS class name
styleCSSProperties-Inline styles
namestring-Input name attribute
labelstring-Label text
isCheckedbooleanfalseChecked state
isDisabledbooleanfalseDisabled state
isLoadingbooleanfalseLoading state
noAnimationbooleanfalseDisables animation effects
onChange(e: ChangeEvent) => void-Change event handler
fontWeightnumber-Label font weight
fontSizestring-Label font size
dataTestIdstring-Test ID for the component
dataTooltipIdstring-Tooltip ID for the component

Styling

The component uses CSS modules with CSS variables for theming. Key variables include:

--toggle-button-fill-color-default
--toggle-button-fill-color-off
--toggle-button-hover-fill-color-off
--toggle-button-fill-circle-color
--toggle-button-fill-circle-color-off
--toggle-button-text-color
--toggle-button-text-disable-color

Examples

Basic Usage

<ToggleButton label="Basic toggle" />

With Custom Styling

<ToggleButton
  label="Custom styled"
  fontSize="16px"
  fontWeight={600}
  style={{ padding: "8px" }}
/>

Disabled State

<ToggleButton
  label="Disabled toggle"
  isDisabled={true}
/>

Loading State

<ToggleButton
  label="Loading"
  isLoading={true}
/>

Without Animation

<ToggleButton
  label="No animation"
  noAnimation={true}
/>