button.tsx 1.5 KB

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