Button.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import styled, { css } from "styled-components";
  2. import { switchProp, prop, ifProp } from "styled-tools";
  3. import { Flex, BoxProps } from "reflexbox/styled-components";
  4. interface Props extends BoxProps {
  5. color?: "purple" | "gray" | "blue" | "red";
  6. disabled?: boolean;
  7. icon?: string; // TODO: better typing
  8. isRound?: boolean;
  9. onClick?: any; // TODO: better typing
  10. type?: "button" | "submit" | "reset";
  11. }
  12. export const Button = styled(Flex)<Props>`
  13. position: relative;
  14. align-items: center;
  15. justify-content: center;
  16. font-weight: normal;
  17. text-align: center;
  18. line-height: 1;
  19. word-break: keep-all;
  20. color: ${switchProp(prop("color", "blue"), {
  21. blue: "white",
  22. red: "white",
  23. purple: "white",
  24. gray: "#444"
  25. })};
  26. background: ${switchProp(prop("color", "blue"), {
  27. blue: "linear-gradient(to right, #42a5f5, #2979ff)",
  28. red: "linear-gradient(to right, #ee3b3b, #e11c1c)",
  29. purple: "linear-gradient(to right, #7e57c2, #6200ea)",
  30. gray: "linear-gradient(to right, #e0e0e0, #bdbdbd)"
  31. })};
  32. box-shadow: ${switchProp(prop("color", "blue"), {
  33. blue: "0 5px 6px rgba(66, 165, 245, 0.5)",
  34. red: "0 5px 6px rgba(168, 45, 45, 0.5)",
  35. purple: "0 5px 6px rgba(81, 45, 168, 0.5)",
  36. gray: "0 5px 6px rgba(160, 160, 160, 0.5)"
  37. })};
  38. border: none;
  39. border-radius: 100px;
  40. transition: all 0.4s ease-out;
  41. cursor: pointer;
  42. overflow: hidden;
  43. :hover,
  44. :focus {
  45. outline: none;
  46. box-shadow: ${switchProp(prop("color", "blue"), {
  47. blue: "0 6px 15px rgba(66, 165, 245, 0.5)",
  48. red: "0 6px 15px rgba(168, 45, 45, 0.5)",
  49. purple: "0 6px 15px rgba(81, 45, 168, 0.5)",
  50. gray: "0 6px 15px rgba(160, 160, 160, 0.5)"
  51. })};
  52. transform: translateY(-2px) scale(1.02, 1.02);
  53. }
  54. `;
  55. Button.defaultProps = {
  56. as: "button",
  57. width: "auto",
  58. flex: "0 0 auto",
  59. height: [36, 40],
  60. py: 0,
  61. px: [24, 32],
  62. fontSize: [12, 13],
  63. color: "blue",
  64. icon: "",
  65. isRound: false
  66. };
  67. interface NavButtonProps extends BoxProps {
  68. disabled?: boolean;
  69. onClick?: any; // TODO: better typing
  70. type?: "button" | "submit" | "reset";
  71. key?: string;
  72. }
  73. export const NavButton = styled(Flex)<NavButtonProps>`
  74. display: flex;
  75. border: none;
  76. border-radius: 4px;
  77. box-shadow: 0 0px 10px rgba(100, 100, 100, 0.1);
  78. background-color: white;
  79. cursor: pointer;
  80. transition: all 0.2s ease-out;
  81. box-sizing: border-box;
  82. :hover {
  83. transform: translateY(-2px);
  84. }
  85. ${ifProp(
  86. "disabled",
  87. css`
  88. background-color: #f6f6f6;
  89. box-shadow: 0 0px 5px rgba(150, 150, 150, 0.1);
  90. cursor: default;
  91. :hover {
  92. transform: none;
  93. }
  94. `
  95. )}
  96. `;
  97. NavButton.defaultProps = {
  98. as: "button",
  99. type: "button",
  100. flex: "0 0 auto",
  101. alignItems: "center",
  102. justifyContent: "center",
  103. width: "auto",
  104. height: [26, 28],
  105. py: 0,
  106. px: ["6px", "8px"],
  107. fontSize: [12]
  108. };