switch.tsx 736 B

123456789101112131415161718192021222324
  1. "use client";
  2. import type { ComponentRenderProps } from "./types";
  3. import { baseClass, getCustomClass } from "./utils";
  4. export function Switch({ element }: ComponentRenderProps) {
  5. const { props } = element;
  6. const customClass = getCustomClass(props);
  7. return (
  8. <label
  9. className={`flex items-center justify-between gap-2 text-xs ${baseClass} ${customClass}`}
  10. >
  11. <span>{props.label as string}</span>
  12. <div
  13. className={`w-8 h-4 rounded-full relative ${props.checked ? "bg-foreground" : "bg-border"}`}
  14. >
  15. <div
  16. className={`absolute w-3 h-3 rounded-full bg-background top-0.5 transition-all ${props.checked ? "right-0.5" : "left-0.5"}`}
  17. />
  18. </div>
  19. </label>
  20. );
  21. }