button.tsx 1.1 KB

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