button.tsx 842 B

123456789101112131415161718192021222324252627
  1. "use client";
  2. import type { ComponentRenderProps } from "./types";
  3. import { baseClass, getCustomClass } from "./utils";
  4. export function Button({ element }: ComponentRenderProps) {
  5. const { props } = element;
  6. const customClass = getCustomClass(props);
  7. const variant = props.variant as string;
  8. const btnClass =
  9. variant === "danger"
  10. ? "bg-red-500 text-white"
  11. : variant === "secondary"
  12. ? "bg-card border border-border text-foreground"
  13. : "bg-foreground text-background";
  14. return (
  15. <button
  16. onClick={() =>
  17. (window as unknown as { __demoAction?: () => void }).__demoAction?.()
  18. }
  19. className={`self-start px-3 py-1.5 rounded text-xs font-medium hover:opacity-90 transition-opacity ${btnClass} ${baseClass} ${customClass}`}
  20. >
  21. {props.label as string}
  22. </button>
  23. );
  24. }