Icon.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { Flex } from "rebass/styled-components";
  2. import styled, { css } from "styled-components";
  3. import { prop, ifProp } from "styled-tools";
  4. import React, { FC } from "react";
  5. import ChevronRight from "./ChevronRight";
  6. import ChevronLeft from "./ChevronLeft";
  7. import { Colors } from "../../consts";
  8. import Clipboard from "./Clipboard";
  9. import ArrowLeft from "./ArrowLeft";
  10. import PieChart from "./PieChart";
  11. import Refresh from "./Refresh";
  12. import Spinner from "./Spinner";
  13. import Shuffle from "./Shuffle";
  14. import EditAlt from "./EditAlt";
  15. import QRCode from "./QRCode";
  16. import Signup from "./Signup";
  17. import Trash from "./Trash";
  18. import Check from "./Check";
  19. import Login from "./Login";
  20. import Heart from "./Heart";
  21. import Stop from "./Stop";
  22. import Plus from "./Plus";
  23. import Lock from "./Lock";
  24. import Edit from "./Edit";
  25. import Copy from "./Copy";
  26. import Send from "./Send";
  27. import Key from "./Key";
  28. import Zap from "./Zap";
  29. import X from "./X";
  30. const icons = {
  31. arrowLeft: ArrowLeft,
  32. check: Check,
  33. chevronLeft: ChevronLeft,
  34. chevronRight: ChevronRight,
  35. clipboard: Clipboard,
  36. copy: Copy,
  37. edit: Edit,
  38. editAlt: EditAlt,
  39. heart: Heart,
  40. key: Key,
  41. lock: Lock,
  42. login: Login,
  43. pieChart: PieChart,
  44. plus: Plus,
  45. qrcode: QRCode,
  46. refresh: Refresh,
  47. send: Send,
  48. shuffle: Shuffle,
  49. signup: Signup,
  50. spinner: Spinner,
  51. stop: Stop,
  52. trash: Trash,
  53. x: X,
  54. zap: Zap
  55. };
  56. export type Icons = keyof typeof icons;
  57. interface Props extends React.ComponentProps<typeof Flex> {
  58. name: Icons;
  59. stroke?: string;
  60. fill?: string;
  61. hoverFill?: string;
  62. hoverStroke?: string;
  63. strokeWidth?: string;
  64. }
  65. const CustomIcon: FC<React.ComponentProps<typeof Flex>> = styled(Flex)`
  66. position: relative;
  67. svg {
  68. transition: all 0.2s ease-out;
  69. width: 100%;
  70. height: 100%;
  71. ${ifProp(
  72. "fill",
  73. css`
  74. fill: ${prop("fill")};
  75. `
  76. )}
  77. ${ifProp(
  78. "stroke",
  79. css`
  80. stroke: ${prop("stroke")};
  81. `
  82. )}
  83. ${ifProp(
  84. "strokeWidth",
  85. css`
  86. stroke-width: ${prop("strokeWidth")};
  87. `
  88. )}
  89. }
  90. ${ifProp(
  91. "hoverFill",
  92. css`
  93. :hover {
  94. svg {
  95. fill: ${prop("hoverFill")};
  96. }
  97. }
  98. `
  99. )}
  100. ${ifProp(
  101. "hoverStroke",
  102. css`
  103. :hover {
  104. svg {
  105. stroke: ${prop("stroke")};
  106. }
  107. }
  108. `
  109. )}
  110. ${ifProp(
  111. { as: "button" },
  112. css`
  113. border: none;
  114. outline: none;
  115. transition: transform 0.4s ease-out;
  116. border-radius: 100%;
  117. background-color: none !important;
  118. cursor: pointer;
  119. box-sizing: border-box;
  120. box-shadow: 0 2px 1px ${Colors.IconShadow};
  121. :hover,
  122. :focus {
  123. transform: translateY(-2px) scale(1.02, 1.02);
  124. }
  125. :focus {
  126. outline: 3px solid rgba(65, 164, 245, 0.5);
  127. }
  128. `
  129. )}
  130. `;
  131. const Icon: FC<Props> = ({ name, ...rest }) => (
  132. <CustomIcon {...rest}>{React.createElement(icons[name])}</CustomIcon>
  133. );
  134. Icon.defaultProps = {
  135. size: 16,
  136. alignItems: "center",
  137. justifyContent: "center"
  138. };
  139. export default Icon;