button.tsx 1.2 KB

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