button.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. aria?: string;
  19. }) {
  20. return (
  21. <button
  22. className={
  23. styles["icon-button"] +
  24. ` ${props.bordered && styles.border} ${props.shadow && styles.shadow} ${
  25. props.className ?? ""
  26. } clickable ${styles[props.type ?? ""]}`
  27. }
  28. onClick={props.onClick}
  29. title={props.title}
  30. disabled={props.disabled}
  31. role="button"
  32. tabIndex={props.tabIndex}
  33. autoFocus={props.autoFocus}
  34. style={props.style}
  35. aria-label={props.aria}
  36. >
  37. {props.icon && (
  38. <div
  39. aria-label={props.text || props.title}
  40. className={
  41. styles["icon-button-icon"] +
  42. ` ${props.type === "primary" && "no-dark"}`
  43. }
  44. >
  45. {props.icon}
  46. </div>
  47. )}
  48. {props.text && (
  49. <div
  50. aria-label={props.text || props.title}
  51. className={styles["icon-button-text"]}
  52. >
  53. {props.text}
  54. </div>
  55. )}
  56. </button>
  57. );
  58. }