MainButton.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import * as React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ButtonUnstyled, { buttonUnstyledClasses } from '@mui/base/ButtonUnstyled';
  4. import { styled } from '@mui/system';
  5. const ButtonRoot = React.forwardRef(function ButtonRoot(props, ref) {
  6. const { children, ...other } = props;
  7. return (
  8. <svg
  9. width="150"
  10. height="50"
  11. {...other}
  12. ref={ref}
  13. >
  14. <polygon
  15. points="0,50 0,0 150,0 150,50"
  16. className="bg"
  17. />
  18. <polygon
  19. points="0,50 0,0 150,0 150,50"
  20. className="borderEffect"
  21. />
  22. <foreignObject
  23. x="0" y="0"
  24. width="150"
  25. height="50"
  26. >
  27. <div
  28. className="content"
  29. >
  30. {children}
  31. </div>
  32. </foreignObject>
  33. </svg>
  34. );
  35. });
  36. ButtonRoot.propTypes = {
  37. children: PropTypes.node,
  38. };
  39. const CustomButtonRoot = styled(ButtonRoot)(
  40. ({ theme }) => `
  41. overflow: visible;
  42. cursor: pointer;
  43. --main-color: ${
  44. theme.palette.mode === 'light' ? 'rgb(25,118,210)' : 'rgb(144,202,249)'
  45. };
  46. --hover-color: ${
  47. theme.palette.mode === 'light'
  48. ? 'rgba(25,118,210,0.04)'
  49. : 'rgba(144,202,249,0.08)'
  50. };
  51. --active-color: ${
  52. theme.palette.mode === 'light'
  53. ? 'rgba(25,118,210,0.12)'
  54. : 'rgba(144,202,249,0.24)'
  55. };
  56. & polygon {
  57. fill: transparent;
  58. transition: all 800ms ease;
  59. pointer-events: none;
  60. }
  61. & .bg {
  62. stroke: var(--main-color);
  63. stroke-width: 0.5;
  64. filter: drop-shadow(0 4px 20px rgba(0, 0, 0, 0.1));
  65. fill: transparent;
  66. }
  67. & .borderEffect {
  68. stroke: var(--main-color);
  69. stroke-width: 2;
  70. stroke-dasharray: 150 600;
  71. stroke-dashoffset: 150;
  72. fill: transparent;
  73. }
  74. &:hover,
  75. &.${buttonUnstyledClasses.focusVisible} {
  76. .borderEffect {
  77. stroke-dashoffset: -600;
  78. }
  79. .bg {
  80. fill: var(--hover-color);
  81. }
  82. }
  83. &:focus,
  84. &.${buttonUnstyledClasses.focusVisible} {
  85. outline: none;
  86. }
  87. &.${buttonUnstyledClasses.active} {
  88. & .bg {
  89. fill: var(--active-color);
  90. transition: fill 300ms ease-out;
  91. }
  92. }
  93. & foreignObject {
  94. pointer-events: none;
  95. & .content {
  96. font-family: Helvetica, Inter, Arial, sans-serif;
  97. font-size: 14px;
  98. font-weight: 200;
  99. height: 100%;
  100. display: flex;
  101. align-items: center;
  102. justify-content: center;
  103. color: var(--main-color);
  104. text-transform: uppercase;
  105. }
  106. & svg {
  107. margin: 0 5px;
  108. }
  109. }`,
  110. );
  111. const SvgButton = React.forwardRef(function SvgButton(props, ref) {
  112. return (
  113. <ButtonUnstyled
  114. {...props}
  115. component={CustomButtonRoot}
  116. ref={ref}
  117. />
  118. )
  119. });
  120. export default function UnstyledButtonCustom({text, onClick, disabled}) {
  121. return (
  122. <SvgButton
  123. disabled={disabled}
  124. onClick={onClick}
  125. >
  126. {text}
  127. </SvgButton>
  128. )
  129. }