button.tsx 987 B

1234567891011121314151617181920212223242526272829303132
  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 label = props.label as string;
  9. const actionText = (props.actionText as string) || label;
  10. const btnClass =
  11. variant === "danger"
  12. ? "bg-red-500 text-white"
  13. : variant === "secondary"
  14. ? "bg-card border border-border text-foreground"
  15. : "bg-foreground text-background";
  16. return (
  17. <button
  18. type="button"
  19. onClick={() =>
  20. (
  21. window as unknown as { __demoAction?: (text: string) => void }
  22. ).__demoAction?.(actionText)
  23. }
  24. className={`self-start px-3 py-1.5 rounded text-xs font-medium hover:opacity-90 transition-opacity ${btnClass} ${baseClass} ${customClass}`}
  25. >
  26. {label}
  27. </button>
  28. );
  29. }