Button.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import styled, { css } from 'styled-components';
  4. import SVG from 'react-inlinesvg';
  5. import { spin } from '../../helpers/animations';
  6. const StyledButton = styled.button`
  7. position: relative;
  8. height: 40px;
  9. display: flex;
  10. align-items: center;
  11. justify-content: center;
  12. padding: 0px 32px;
  13. font-size: 13px;
  14. font-weight: normal;
  15. text-align: center;
  16. line-height: 1;
  17. word-break: keep-all;
  18. color: white;
  19. background: linear-gradient(to right, #42a5f5, #2979ff);
  20. box-shadow: 0 5px 6px rgba(66, 165, 245, 0.5);
  21. border: none;
  22. border-radius: 100px;
  23. transition: all 0.4s ease-out;
  24. cursor: pointer;
  25. overflow: hidden;
  26. :hover,
  27. :focus {
  28. outline: none;
  29. box-shadow: 0 6px 15px rgba(66, 165, 245, 0.5);
  30. transform: translateY(-2px) scale(1.02, 1.02);
  31. }
  32. a & {
  33. text-decoration: none;
  34. border: none;
  35. }
  36. @media only screen and (max-width: 448px) {
  37. height: 32px;
  38. padding: 0 24px;
  39. font-size: 12px;
  40. }
  41. ${({ color }) => {
  42. if (color === 'purple') {
  43. return css`
  44. background: linear-gradient(to right, #7e57c2, #6200ea);
  45. box-shadow: 0 5px 6px rgba(81, 45, 168, 0.5);
  46. :focus,
  47. :hover {
  48. box-shadow: 0 6px 15px rgba(81, 45, 168, 0.5);
  49. }
  50. `;
  51. }
  52. if (color === 'gray') {
  53. return css`
  54. color: black;
  55. background: linear-gradient(to right, #e0e0e0, #bdbdbd);
  56. box-shadow: 0 5px 6px rgba(160, 160, 160, 0.5);
  57. :focus,
  58. :hover {
  59. box-shadow: 0 6px 15px rgba(160, 160, 160, 0.5);
  60. }
  61. `;
  62. }
  63. return null;
  64. }};
  65. ${({ big }) =>
  66. big &&
  67. css`
  68. height: 56px;
  69. @media only screen and (max-width: 448px) {
  70. height: 40px;
  71. }
  72. `};
  73. `;
  74. const Icon = styled(SVG)`
  75. svg {
  76. width: 16px;
  77. height: 16px;
  78. margin-right: 12px;
  79. stroke: #fff;
  80. ${({ type }) =>
  81. type === 'loader' &&
  82. css`
  83. width: 20px;
  84. height: 20px;
  85. margin: 0;
  86. animation: ${spin} 1s linear infinite;
  87. `};
  88. ${({ round }) =>
  89. round &&
  90. css`
  91. width: 15px;
  92. height: 15px;
  93. margin: 0;
  94. `};
  95. ${({ color }) =>
  96. color === 'gray' &&
  97. css`
  98. stroke: #444;
  99. `};
  100. @media only screen and (max-width: 768px) {
  101. width: 12px;
  102. height: 12px;
  103. margin-right: 6px;
  104. }
  105. }
  106. `;
  107. const Button = props => {
  108. const SVGIcon = props.icon ? (
  109. <Icon
  110. type={props.icon}
  111. round={props.round}
  112. color={props.color}
  113. src={`/images/${props.icon}.svg`}
  114. />
  115. ) : (
  116. ''
  117. );
  118. return (
  119. <StyledButton {...props}>
  120. {SVGIcon}
  121. {props.icon !== 'loader' && props.children}
  122. </StyledButton>
  123. );
  124. };
  125. Button.propTypes = {
  126. children: PropTypes.node.isRequired,
  127. color: PropTypes.string,
  128. icon: PropTypes.string,
  129. round: PropTypes.bool,
  130. type: PropTypes.string,
  131. };
  132. Button.defaultProps = {
  133. color: 'blue',
  134. icon: '',
  135. type: '',
  136. round: false,
  137. };
  138. export default Button;