mango-v4-ui/components/shared/Button.tsx

122 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-12-05 02:59:10 -08:00
import { useTheme } from 'next-themes'
2022-05-03 21:20:14 -07:00
import { FunctionComponent, ReactNode } from 'react'
2022-07-20 21:50:56 -07:00
interface AllButtonProps {
2022-05-03 21:20:14 -07:00
onClick?: (e?: React.MouseEvent) => void
disabled?: boolean
className?: string
2022-07-14 22:20:20 -07:00
secondary?: boolean
2022-05-03 21:20:14 -07:00
children?: ReactNode
}
2022-07-20 21:50:56 -07:00
interface ButtonProps {
size?: 'large' | 'medium' | 'small'
}
type ButtonCombinedProps = AllButtonProps & ButtonProps
const Button: FunctionComponent<ButtonCombinedProps> = ({
2022-05-03 21:20:14 -07:00
children,
onClick,
disabled = false,
className,
2022-07-14 22:20:20 -07:00
secondary,
2022-07-20 21:50:56 -07:00
size = 'medium',
2022-05-03 21:20:14 -07:00
...props
}) => {
2022-12-05 02:59:10 -08:00
const { theme } = useTheme()
2022-05-03 21:20:14 -07:00
return (
<button
onClick={onClick}
disabled={disabled}
2023-01-06 02:55:51 -08:00
className={`rounded-md ${
2022-07-21 22:09:04 -07:00
secondary
2022-12-02 03:28:46 -08:00
? 'border border-th-button md:hover:border-th-button-hover'
: 'bg-th-button md:hover:bg-th-button-hover'
2022-07-20 21:50:56 -07:00
} ${
size === 'medium'
? 'h-10 px-4'
: size === 'large'
? 'h-12 px-6'
: 'h-8 px-3'
2022-12-13 15:16:50 -08:00
} default-transition font-display ${
2022-12-05 02:59:10 -08:00
theme === 'High Contrast' && !secondary
? 'text-th-bkg-1'
: 'text-th-fgd-1'
} focus:outline-none disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:brightness-100 ${className}`}
2022-07-05 20:37:49 -07:00
{...props}
>
{children}
</button>
)
}
2022-07-18 03:02:43 -07:00
interface IconButtonProps {
hideBg?: boolean
2022-08-14 04:56:19 -07:00
size?: 'small' | 'medium' | 'large'
2022-07-18 03:02:43 -07:00
}
2022-07-20 21:50:56 -07:00
type IconButtonCombinedProps = AllButtonProps & IconButtonProps
2022-07-18 03:02:43 -07:00
export const IconButton: FunctionComponent<IconButtonCombinedProps> = ({
2022-07-05 20:37:49 -07:00
children,
onClick,
disabled = false,
className,
2022-07-18 03:02:43 -07:00
hideBg,
2022-08-14 04:56:19 -07:00
size = 'medium',
2022-07-05 20:37:49 -07:00
...props
}) => {
return (
<button
onClick={onClick}
disabled={disabled}
2022-11-22 15:43:25 -08:00
className={`flex flex-shrink-0 ${
2022-08-14 04:56:19 -07:00
size === 'large'
? 'h-12 w-12'
: size === 'small'
2022-10-29 04:38:40 -07:00
? 'h-8 w-8'
2022-08-14 04:56:19 -07:00
: 'h-10 w-10'
2022-10-29 03:56:04 -07:00
} default-transition items-center justify-center rounded-full ${
2022-12-02 03:28:46 -08:00
hideBg
? 'md:hover:text-th-active'
: 'border border-th-button md:hover:border-th-button-hover'
2022-07-18 03:02:43 -07:00
} text-th-fgd-1 focus:outline-none disabled:cursor-not-allowed disabled:bg-th-bkg-4
2022-10-29 03:56:04 -07:00
disabled:text-th-fgd-4 md:disabled:hover:text-th-fgd-4 ${className}`}
2022-05-03 21:20:14 -07:00
{...props}
>
{children}
</button>
)
}
2022-08-01 19:05:38 -07:00
interface LinkButtonProps {
icon?: ReactNode
}
type LinkButtonCombinedProps = AllButtonProps & LinkButtonProps
export const LinkButton: FunctionComponent<LinkButtonCombinedProps> = ({
2022-07-14 16:36:31 -07:00
children,
onClick,
disabled = false,
className,
2022-07-14 22:20:20 -07:00
secondary,
2022-07-14 16:36:31 -07:00
...props
}) => {
return (
<button
onClick={onClick}
disabled={disabled}
2022-12-16 03:26:42 -08:00
className={`default-transition flex items-center border-0 font-bold ${
2022-11-30 19:32:32 -08:00
secondary ? 'text-th-active' : 'text-th-fgd-2'
2022-11-16 19:51:08 -08:00
} underline focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 md:hover:no-underline ${className}`}
2022-07-14 16:36:31 -07:00
{...props}
>
2022-08-02 12:20:27 -07:00
{children}
2022-07-14 16:36:31 -07:00
</button>
)
}
2022-05-03 21:20:14 -07:00
export default Button