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 Clipboard from "./Clipboard";
  8. import PieChart from "./PieChart";
  9. import Refresh from "./Refresh";
  10. import Spinner from "./Spinner";
  11. import QRCode from "./QRCode";
  12. import Trash from "./Trash";
  13. import Check from "./Check";
  14. import Plus from "./Plus";
  15. import Lock from "./Lock";
  16. import Copy from "./Copy";
  17. import Send from "./Send";
  18. import Key from "./Key";
  19. import Zap from "./Zap";
  20. export interface IIcons {
  21. clipboard: JSX.Element;
  22. chevronRight: JSX.Element;
  23. chevronLeft: JSX.Element;
  24. pieChart: JSX.Element;
  25. key: JSX.Element;
  26. plus: JSX.Element;
  27. Lock: JSX.Element;
  28. copy: JSX.Element;
  29. refresh: JSX.Element;
  30. check: JSX.Element;
  31. send: JSX.Element;
  32. spinner: JSX.Element;
  33. trash: JSX.Element;
  34. zap: JSX.Element;
  35. qrcode: JSX.Element;
  36. }
  37. const icons = {
  38. clipboard: Clipboard,
  39. chevronRight: ChevronRight,
  40. chevronLeft: ChevronLeft,
  41. pieChart: PieChart,
  42. key: Key,
  43. lock: Lock,
  44. check: Check,
  45. plus: Plus,
  46. copy: Copy,
  47. refresh: Refresh,
  48. send: Send,
  49. spinner: Spinner,
  50. trash: Trash,
  51. zap: Zap,
  52. qrcode: QRCode
  53. };
  54. interface Props extends React.ComponentProps<typeof Flex> {
  55. name: keyof typeof icons;
  56. stroke?: string;
  57. fill?: string;
  58. hoverFill?: string;
  59. hoverStroke?: string;
  60. strokeWidth?: string;
  61. }
  62. const CustomIcon: FC<React.ComponentProps<typeof Flex>> = styled(Flex)`
  63. position: relative;
  64. svg {
  65. transition: all 0.2s ease-out;
  66. width: 100%;
  67. height: 100%;
  68. ${ifProp(
  69. "fill",
  70. css`
  71. fill: ${prop("fill")};
  72. `
  73. )}
  74. ${ifProp(
  75. "stroke",
  76. css`
  77. stroke: ${prop("stroke")};
  78. `
  79. )}
  80. ${ifProp(
  81. "strokeWidth",
  82. css`
  83. stroke-width: ${prop("strokeWidth")};
  84. `
  85. )}
  86. }
  87. ${ifProp(
  88. "hoverFill",
  89. css`
  90. :hover {
  91. svg {
  92. fill: ${prop("hoverFill")};
  93. }
  94. }
  95. `
  96. )}
  97. ${ifProp(
  98. "hoverStroke",
  99. css`
  100. :hover {
  101. svg {
  102. stroke: ${prop("stroke")};
  103. }
  104. }
  105. `
  106. )}
  107. ${ifProp(
  108. { as: "button" },
  109. css`
  110. border: none;
  111. outline: none;
  112. transition: transform 0.4s ease-out;
  113. border-radius: 100%;
  114. background-color: none !important;
  115. cursor: pointer;
  116. box-sizing: content-box;
  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;