← Back

Switch

Install

npm install @svg-animated-icons/react

CLI

Copy an icon component straight into your project — shadcn-style. Replace {icon} with an icon name like arrow-left.

terminal
npx @svg-animated-icons/cli add {icon} --react
FlagDescription
--dest <dir>Destination directory (default: components/animated-icons)

Or copy the component with the CLI

CLI
npx @svg-animated-icons/cli add switch --react

Code

React
// Generated by @svg-animated-icons/cli
// You own this file — edit it freely.

import React from "react";

type Props = {
  disableHover?: boolean;
  className?: string;
};

export function SwitchIcon({ disableHover, className }: Props) {
  const classes = [
    "ai-switch-icon",
    disableHover ? "no-hover" : "",
    className ?? "",
  ]
    .filter(Boolean)
    .join(" ");

  return (
    <>
      <style>{`
.ai-switch-icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  cursor: pointer;
  overflow: visible;
}

.ai-switch-icon * {
  transform-box: fill-box;
}

.ai-switch-icon.no-hover * {
  transform: none;
  opacity: 1;
  animation: none;
}

.ai-switch-icon .knob {
  transform-box: view-box;
  transform-origin: 7.5px 7.5px;
}

.ai-switch-icon:not(.no-hover):hover .knob {
  animation: ai-switch-toggle 700ms ease-in-out;
}

@keyframes ai-switch-toggle {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-6px); }
}
`}</style>
      <svg
        xmlns="http://www.w3.org/2000/svg"
        className={classes}
        viewBox="0 0 15 15"
        fill="none"
      >
        <rect className="track" x="0.5" y="3.5" width="14" height="8" rx="4" stroke="currentColor" fill="none"/>
        <circle className="knob" cx="10.5" cy="7.5" r="3" stroke="currentColor" fill="none"/>
      </svg>
    </>
  );
}