index.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import { IconWrapper, ClickZone } from './styled';
  3. import data from './data';
  4. type Props = {
  5. id?: string;
  6. glyph: string;
  7. onClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
  8. onBlur?: () => void;
  9. style?: Record<string, string>;
  10. isActive?: boolean;
  11. isDisabled?: boolean;
  12. };
  13. const Icon: React.FC<Props> = ({
  14. glyph,
  15. id,
  16. onClick,
  17. onBlur,
  18. style,
  19. isActive,
  20. isDisabled,
  21. }: Props) => {
  22. const { Normal, Hover } = data[glyph];
  23. return (
  24. <IconWrapper isHover={!!Hover} style={style} isDisabled={isDisabled}>
  25. {Normal && <Normal data-status="normal" />}
  26. {Hover && <Hover data-status="hover" />}
  27. {isActive && Hover ? <Hover data-status="active" /> : null}
  28. <ClickZone
  29. id={id}
  30. onClick={
  31. isDisabled
  32. ? (): void => {
  33. // do something
  34. }
  35. : onClick
  36. }
  37. onMouseDown={(e) => {
  38. e.preventDefault();
  39. }}
  40. onBlur={onBlur}
  41. />
  42. </IconWrapper>
  43. );
  44. };
  45. Icon.defaultProps = {
  46. id: '',
  47. onClick: () => {
  48. // do something
  49. },
  50. onBlur: () => {
  51. // do something
  52. },
  53. style: {},
  54. isActive: false,
  55. isDisabled: false,
  56. };
  57. export default Icon;