| 1 | import classNames from 'classnames' |
| 2 | import { ReactNode } from 'react' |
| 3 | |
| 4 | export type ButtonProps = { |
| 5 | children?: ReactNode |
| 6 | color?: 'primary' |
| 7 | href?: string |
| 8 | outline?: boolean |
| 9 | [key: string]: unknown |
| 10 | } |
| 11 | |
| 12 | export const Button = ({ |
| 13 | children, |
| 14 | className, |
| 15 | color, |
| 16 | href, |
| 17 | outline, |
| 18 | ...rest |
| 19 | }: ButtonProps) => { |
| 20 | const Tag = href ? 'a' : 'button' |
| 21 | const attrs = { |
| 22 | ...rest, |
| 23 | ...(Tag === 'a' ? { href, role: 'button', tabIndex: 0 } : {}), |
| 24 | } |
| 25 | |
| 26 | return ( |
| 27 | <Tag |
| 28 | {...attrs} |
| 29 | className={classNames( |
| 30 | Tag === 'a' && 'custom-anchor', |
| 31 | 'button', |
| 32 | color, |
| 33 | { btnOutline: outline }, |
| 34 | className as any |
| 35 | )} |
| 36 | > |
| 37 | {children} |
| 38 | <style jsx>{` |
| 39 | .button { |
| 40 | @apply relative inline-block select-none appearance-none rounded-full bg-white text-center font-bold no-underline shadow-md; |
| 41 | |
| 42 | padding: 0.625em 1.25em; |
| 43 | transition: color, background-color, opacity; |
| 44 | } |
| 45 | |
| 46 | @screen md { |
| 47 | .button { |
| 48 | @apply tracking-wider; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | .button:hover { |
| 53 | @apply bg-background duration-150; |
| 54 | } |
| 55 | .button:hover:active { |
| 56 | @apply duration-0 bg-gray-300 outline-none ring-1 ring-white ring-offset-2; |
| 57 | } |
| 58 | .button:focus { |
| 59 | @apply outline-none ring-1 ring-white ring-offset-2; |
| 60 | } |
| 61 | |
| 62 | /* Primary color */ |
| 63 | .button.primary { |
| 64 | @apply bg-marp-brand text-white; |
| 65 | |
| 66 | background-image: linear-gradient( |
| 67 | 30deg, |
| 68 | transparent, |
| 69 | rgba(255, 255, 255, 0.3) |
| 70 | ); |
| 71 | } |
| 72 | .button.primary:hover { |
| 73 | @apply bg-marp-darken; |
| 74 | } |
| 75 | .button.primary:hover:active { |
| 76 | @apply bg-marp-dark; |
| 77 | } |
| 78 | |
| 79 | /* Outline */ |
| 80 | .button.btnOutline { |
| 81 | @apply text-foreground; |
| 82 | } |
| 83 | .button.btnOutline::after { |
| 84 | @apply pointer-events-none absolute inset-0 block border-2 border-current; |
| 85 | |
| 86 | border-radius: inherit; |
| 87 | content: ''; |
| 88 | transition: inherit; |
| 89 | } |
| 90 | |
| 91 | .button.btnOutline.primary { |
| 92 | @apply text-marp-darken bg-white; |
| 93 | |
| 94 | background-image: none; |
| 95 | } |
| 96 | .button.btnOutline.primary:hover { |
| 97 | @apply bg-marp-darken text-white; |
| 98 | } |
| 99 | .button.btnOutline.primary:hover::after { |
| 100 | @apply opacity-0; |
| 101 | } |
| 102 | `}</style> |
| 103 | </Tag> |
| 104 | ) |
| 105 | } |
| 106 |