Icon.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { Flex } from "reflexbox/styled-components";
  2. import styled, { css } from "styled-components";
  3. import { prop, ifProp } from "styled-tools";
  4. import React, { FC } from "react";
  5. import Trash from "./Trash";
  6. import Spinner from "./Spinner";
  7. import Plus from "./Plus";
  8. import Lock from "./Lock";
  9. import Refresh from "./Refresh";
  10. import Zap from "./Zap";
  11. export interface IIcons {
  12. lock: JSX.Element;
  13. refresh: JSX.Element;
  14. zap: JSX.Element;
  15. plus: JSX.Element;
  16. spinner: JSX.Element;
  17. trash: JSX.Element;
  18. }
  19. const icons = {
  20. lock: Lock,
  21. refresh: Refresh,
  22. zap: Zap,
  23. plus: Plus,
  24. spinner: Spinner,
  25. trash: Trash,
  26. };
  27. interface Props extends React.ComponentProps<typeof Flex> {
  28. name: keyof typeof icons;
  29. }
  30. const CustomIcon: FC<React.ComponentProps<typeof Flex>> = styled(Flex)`
  31. position: relative;
  32. fill: ${prop("color")};
  33. svg {
  34. width: 100%;
  35. height: 100%;
  36. }
  37. ${ifProp(
  38. { as: "button" },
  39. css`
  40. border: none;
  41. outline: none;
  42. transition: transform 0.4s ease-out;
  43. background-color: transparent;
  44. cursor: pointer;
  45. box-sizing: content-box;
  46. :hover,
  47. :focus {
  48. transform: translateY(-2px) scale(1.02, 1.02);
  49. }
  50. :focus {
  51. outline: 3px solid rgba(65, 164, 245, 0.5);
  52. }
  53. `
  54. )}
  55. `;
  56. const Icon: FC<Props> = ({ name, ...rest }) => (
  57. <CustomIcon {...rest}>{React.createElement(icons[name])}</CustomIcon>
  58. );
  59. Icon.defaultProps = {
  60. size: 16,
  61. alignItems: "center",
  62. justifyContent: "center",
  63. color: "#888"
  64. };
  65. export default Icon;