index.tsx 967 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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: any) => void;
  8. onBlur?: () => void;
  9. style?: {};
  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 = false,
  20. isDisabled = false,
  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. onMouseDown={
  31. isDisabled
  32. ? (): void => {
  33. // do something
  34. }
  35. : onClick
  36. }
  37. onBlur={onBlur}
  38. />
  39. </IconWrapper>
  40. );
  41. };
  42. export default Icon;