Icon.tsx 2.9 KB

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