button.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import * as React from "react";
  2. import styles from "./button.module.scss";
  3. export function IconButton(props: {
  4. onClick?: () => void;
  5. icon?: JSX.Element;
  6. type?: "primary" | "danger";
  7. text?: string;
  8. bordered?: boolean;
  9. shadow?: boolean;
  10. className?: string;
  11. title?: string;
  12. disabled?: boolean;
  13. tabIndex?: number;
  14. autoFocus?: boolean;
  15. }) {
  16. return (
  17. <button
  18. className={
  19. styles["icon-button"] +
  20. ` ${props.bordered && styles.border} ${props.shadow && styles.shadow} ${
  21. props.className ?? ""
  22. } clickable ${styles[props.type ?? ""]}`
  23. }
  24. onClick={props.onClick}
  25. title={props.title}
  26. disabled={props.disabled}
  27. role="button"
  28. tabIndex={props.tabIndex}
  29. autoFocus={props.autoFocus}
  30. >
  31. {props.icon && (
  32. <div
  33. className={
  34. styles["icon-button-icon"] +
  35. ` ${props.type === "primary" && "no-dark"}`
  36. }
  37. >
  38. {props.icon}
  39. </div>
  40. )}
  41. {props.text && (
  42. <div className={styles["icon-button-text"]}>{props.text}</div>
  43. )}
  44. </button>
  45. );
  46. }