|
| 1 | +/* eslint-disable react/button-has-type */ |
| 2 | +import React from 'react'; |
| 3 | +import { css, useTheme } from '@emotion/react'; |
| 4 | +import PropTypes from 'prop-types'; |
| 5 | +import useComponentOverrides from '../../theme/useComponentOverrides'; |
| 6 | + |
| 7 | +const Button = ({ |
| 8 | + children, |
| 9 | + color = 'primary', |
| 10 | + className = '', |
| 11 | + style = {}, |
| 12 | + size = 'medium', |
| 13 | + ...props |
| 14 | +}) => { |
| 15 | + const { classNames, styleOverrides } = useComponentOverrides('Button'); |
| 16 | + const theme = useTheme(); |
| 17 | + const classNameButton = css` |
| 18 | + cursor: pointer; |
| 19 | + display: inline-block; |
| 20 | + background-color: ${theme.palette[color].main}; |
| 21 | + color: ${theme.palette[color].contrastText || 'currentColor'}; |
| 22 | + border-color: ${theme.palette[color].main || 'currentColor'}; |
| 23 | + border-style: solid; |
| 24 | + border-width: 1px; |
| 25 | + font-size: 0.875rem; |
| 26 | + font-weight: 500; |
| 27 | + letter-spacing: 0; |
| 28 | + line-height: 1.25rem; |
| 29 | + min-width: 80px; |
| 30 | + outline: none; |
| 31 | + overflow: hidden; |
| 32 | + padding-block: calc(18px - 0.625rem); |
| 33 | + padding: calc(18px - 0.625rem) 14px; |
| 34 | + padding-inline: 14px; |
| 35 | + text-align: center; |
| 36 | + text-decoration: none; |
| 37 | + text-overflow: ellipsis; |
| 38 | + white-space: nowrap; |
| 39 | + border-radius: 0.25rem; |
| 40 | + &.ec-button--small { |
| 41 | + font-size: 0.75rem; |
| 42 | + font-weight: 700; |
| 43 | + letter-spacing: 0; |
| 44 | + line-height: 1rem; |
| 45 | + min-width: 56px; |
| 46 | + padding-block: calc(12px - 0.5rem); |
| 47 | + padding: calc(12px - 0.5rem) 6px; |
| 48 | + padding-inline: 6px; |
| 49 | + border-radius: 0.25rem; |
| 50 | + } |
| 51 | + &.ec-button--large { |
| 52 | + font-size: 1rem; |
| 53 | + font-weight: 400; |
| 54 | + letter-spacing: 0; |
| 55 | + line-height: 1.5rem; |
| 56 | + min-width: 96px; |
| 57 | + padding-block: calc(22px - 0.75rem); |
| 58 | + padding: calc(22px - 0.75rem) 22px; |
| 59 | + padding-inline: 22px; |
| 60 | + border-radius: 0.36rem; |
| 61 | + } |
| 62 | + &:hover { |
| 63 | + filter: brightness(90%); |
| 64 | + } |
| 65 | + `; |
| 66 | + return ( |
| 67 | + <button |
| 68 | + type="button" |
| 69 | + css={classNameButton} |
| 70 | + className={`ec-button ec-button--${size} ${className} ${classNames}`} |
| 71 | + style={{ ...styleOverrides, ...style }} |
| 72 | + {...props} |
| 73 | + > |
| 74 | + {children} |
| 75 | + </button> |
| 76 | + ); |
| 77 | +}; |
| 78 | + |
| 79 | +Button.propTypes = { |
| 80 | + children: PropTypes.oneOfType([ |
| 81 | + PropTypes.arrayOf(PropTypes.node), |
| 82 | + PropTypes.node, |
| 83 | + ]), |
| 84 | + color: PropTypes.string, |
| 85 | + size: PropTypes.oneOf(['small', 'medium', 'large']), |
| 86 | + className: PropTypes.string, |
| 87 | + style: PropTypes.object, |
| 88 | +}; |
| 89 | + |
| 90 | +export default Button; |
0 commit comments