Icon.tsx 2.9 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 PieChart from "./PieChart";
  10. import Refresh from "./Refresh";
  11. import Spinner from "./Spinner";
  12. import QRCode from "./QRCode";
  13. import Trash from "./Trash";
  14. import Check from "./Check";
  15. import Plus from "./Plus";
  16. import Lock from "./Lock";
  17. import Copy from "./Copy";
  18. import Send from "./Send";
  19. import Key from "./Key";
  20. import Zap from "./Zap";
  21. export interface IIcons {
  22. clipboard: JSX.Element;
  23. chevronRight: JSX.Element;
  24. chevronLeft: JSX.Element;
  25. pieChart: JSX.Element;
  26. key: JSX.Element;
  27. plus: JSX.Element;
  28. Lock: JSX.Element;
  29. copy: JSX.Element;
  30. refresh: JSX.Element;
  31. check: JSX.Element;
  32. send: JSX.Element;
  33. spinner: JSX.Element;
  34. trash: JSX.Element;
  35. zap: JSX.Element;
  36. qrcode: JSX.Element;
  37. }
  38. const icons = {
  39. clipboard: Clipboard,
  40. chevronRight: ChevronRight,
  41. chevronLeft: ChevronLeft,
  42. pieChart: PieChart,
  43. key: Key,
  44. lock: Lock,
  45. check: Check,
  46. plus: Plus,
  47. copy: Copy,
  48. refresh: Refresh,
  49. send: Send,
  50. spinner: Spinner,
  51. trash: Trash,
  52. zap: Zap,
  53. qrcode: QRCode
  54. };
  55. interface Props extends React.ComponentProps<typeof Flex> {
  56. name: keyof typeof 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;