Icon.tsx 3.0 KB

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