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

120 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-08-13 22:39:30 -07: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-08-13 22:39:30 -07:00
const { theme } = useTheme()
2022-05-03 21:20:14 -07:00
return (
<button
onClick={onClick}
disabled={disabled}
2022-07-21 22:09:04 -07:00
className={`whitespace-nowrap rounded-md ${
secondary
2022-08-14 23:10:46 -07:00
? `border border-th-button md:hover:border-th-button-hover ${
theme === 'Light' ? 'text-th-button' : 'text-th-fgd-1'
2022-08-13 22:39:30 -07:00
}`
2022-08-14 23:10:46 -07:00
: `bg-th-button md:hover:bg-th-button-hover ${
2022-08-13 22:39:30 -07:00
theme === 'Light' ? 'text-th-bkg-1' : 'text-th-fgd-1'
}`
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-08-14 23:10:46 -07:00
} default-transition font-bold 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-08-14 04:56:19 -07:00
className={`flex ${
size === 'large'
? 'h-12 w-12'
: size === 'small'
? 'h-7 w-7'
: 'h-10 w-10'
} items-center justify-center rounded-full ${
2022-07-18 03:02:43 -07:00
hideBg ? '' : 'bg-th-bkg-4'
} text-th-fgd-1 focus:outline-none disabled:cursor-not-allowed disabled:bg-th-bkg-4
2022-08-14 04:56:19 -07:00
disabled:text-th-fgd-4 md:hover:text-th-primary 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-08-01 19:05:38 -07:00
className={`flex items-center border-0 font-bold ${
2022-07-14 22:20:20 -07:00
secondary ? 'text-th-primary' : 'text-th-fgd-2'
2022-07-15 04:09:23 -07:00
} underline focus:outline-none disabled:cursor-not-allowed disabled:underline 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