Advertisement
Soty89

button

Nov 12th, 2021
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import PropTypes from 'prop-types';
  2. import React from 'react';
  3. import styled, { css } from 'styled-components';
  4.  
  5. const ButtonNew = ({ children, className, variant = 'primary', type = 'button', disabled, onClick }) => {
  6.   return (
  7.     <StyledButton variant={variant} type={type} className={className} disabled={disabled} onClick={onClick}>
  8.       {children}
  9.     </StyledButton>
  10.   );
  11. };
  12.  
  13. const StyledButton = styled.button`
  14.   border-radius: 5px;
  15.   width: 100%;
  16.   padding: 9px;
  17.   transition: all 0.3s ease-in-out;
  18.   border: ${({ variant }) => BUTTON_BORDER[variant]};
  19.   background-color: ${({ variant }) => BUTTON_COLOR[variant]};
  20.   color: ${({ variant }) => BUTTON_TEXT_COLOR[variant]};
  21.  
  22.   :hover {
  23.     ${({ variant }) => BUTTON_HOVER[variant]};
  24.   }
  25.  
  26.   :active {
  27.     transform: translateY(-5px);
  28.     box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  29.     ${({ variant }) => BUTTON_ACTIVE[variant]};
  30.   }
  31.  
  32.   :disabled {
  33.     ${({ variant }) => BUTTON_DISABLED[variant]};
  34.   }
  35. `;
  36.  
  37. const BUTTON_BORDER = {
  38.   primary: 'none',
  39.   secondary: '1px solid var(--cs-ui--switch-bg-color)',
  40. };
  41.  
  42. const BUTTON_COLOR = {
  43.   primary: 'var(--cs-general--second-color)',
  44.   secondary: 'transparent',
  45. };
  46.  
  47. const BUTTON_TEXT_COLOR = {
  48.   primary: 'var(--cs-general--navigation-line-color)',
  49.   secondary: 'var(--cs-general--brand-color)',
  50. };
  51.  
  52. const BUTTON_HOVER = {
  53.   primary: css`
  54.     background-color: var(--cs-general--brand-color);
  55.   `,
  56.   secondary: css`
  57.     border-color: var(--cs-general--second-color);
  58.   `,
  59. };
  60.  
  61. const BUTTON_ACTIVE = {
  62.   primary: css`
  63.     background-color: var(--cs-ui--button-hover-color);
  64.   `,
  65.   secondary: css`
  66.     background-color: var(--cs-ui--button-active-color);
  67.   `,
  68. };
  69.  
  70. const BUTTON_DISABLED = {
  71.   primary: css`
  72.     background-color: var(--cs-ui--button-hover-color);
  73.     color: var(--cs-general--second-color);
  74.   `,
  75.   secondary: css`
  76.     border-color: var(--cs-ui--select-bg-color);
  77.     color: var(--cs-fonts--text-color);
  78.   `,
  79. };
  80.  
  81. ButtonNew.propTypes = {
  82.   children: PropTypes.oneOfType([PropTypes.element, PropTypes.string]),
  83.   className: PropTypes.string,
  84.   variant: PropTypes.oneOf(['primary', 'secondary']),
  85.   type: PropTypes.oneOf(['button', 'submit']),
  86.   disabled: PropTypes.bool,
  87.   onClick: PropTypes.func,
  88. };
  89.  
  90. export default ButtonNew;
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement