Toggle

A toggle switch

Example

example.tsx

'use client';

import { useState } from 'react';

export function Toggle() {
  const [enabled, setEnabled] = useState(false);
  return (
    <button
      className={`p-3 hover:bg-[#1565C0] flex items-center justify-center rounded-md transition-colors ${
        enabled ? 'bg-[#1565C0]' : 'bg-[#0a2246]'
      }`}
      onClick={() => setEnabled((e) => !e)}
    >
      <svg
        width='15'
        height='15'
        viewBox='0 0 15 15'
        fill='none'
        xmlns='http://www.w3.org/2000/svg'
      >
        <path
          d='M5.67494 3.50017C5.67494 3.25164 5.87641 3.05017 6.12494 3.05017H10.6249C10.8735 3.05017 11.0749 3.25164 11.0749 3.50017C11.0749 3.7487 10.8735 3.95017 10.6249 3.95017H9.00587L7.2309 11.05H8.87493C9.12345 11.05 9.32493 11.2515 9.32493 11.5C9.32493 11.7486 9.12345 11.95 8.87493 11.95H4.37493C4.1264 11.95 3.92493 11.7486 3.92493 11.5C3.92493 11.2515 4.1264 11.05 4.37493 11.05H5.99397L7.76894 3.95017H6.12494C5.87641 3.95017 5.67494 3.7487 5.67494 3.50017Z'
          fill='currentColor'
          fillRule='evenodd'
          clipRule='evenodd'
        ></path>
      </svg>
    </button>
  );
}

Toggle Outline

A toggle switch with outline

Example

example.tsx

'use client';

import { useState } from 'react';

export function Toggle() {
  const [enabled, setEnabled] = useState(false);
  return (
    <button
      className={`hover:bg-[#27272A] p-3 flex items-center justify-center rounded-md transition-colors ${
        enabled ? 'bg-[#27272A]' : 'bg-transparent'
      } border-[#27272A] border-2`}
      onClick={() => setEnabled((e) => !e)}
    >
      <svg
        width='15'
        height='15'
        viewBox='0 0 15 15'
        fill='none'
        xmlns='http://www.w3.org/2000/svg'
      >
        <path
          d='M5.67494 3.50017C5.67494 3.25164 5.87641 3.05017 6.12494 3.05017H10.6249C10.8735 3.05017 11.0749 3.25164 11.0749 3.50017C11.0749 3.7487 10.8735 3.95017 10.6249 3.95017H9.00587L7.2309 11.05H8.87493C9.12345 11.05 9.32493 11.2515 9.32493 11.5C9.32493 11.7486 9.12345 11.95 8.87493 11.95H4.37493C4.1264 11.95 3.92493 11.7486 3.92493 11.5C3.92493 11.2515 4.1264 11.05 4.37493 11.05H5.99397L7.76894 3.95017H6.12494C5.87641 3.95017 5.67494 3.7487 5.67494 3.50017Z'
          fill='currentColor'
          fillRule='evenodd'
          clipRule='evenodd'
        ></path>
      </svg>
    </button>
  );
}