2022-10-11 02:56:16 +00:00
|
|
|
import clsx from 'clsx'
|
2022-10-01 20:51:08 +00:00
|
|
|
import { HeartIcon } from '@heroicons/react/outline'
|
2022-10-11 02:56:16 +00:00
|
|
|
|
2022-10-01 20:51:08 +00:00
|
|
|
import { Button } from 'web/components/button'
|
2022-10-11 02:56:16 +00:00
|
|
|
import { formatMoney, shortFormatNumber } from 'common/util/format'
|
2022-10-01 20:51:08 +00:00
|
|
|
import { Col } from 'web/components/layout/col'
|
|
|
|
import { Tooltip } from '../tooltip'
|
|
|
|
|
|
|
|
export function TipButton(props: {
|
|
|
|
tipAmount: number
|
|
|
|
totalTipped: number
|
|
|
|
onClick: () => void
|
|
|
|
userTipped: boolean
|
|
|
|
isCompact?: boolean
|
|
|
|
disabled?: boolean
|
|
|
|
}) {
|
|
|
|
const { tipAmount, totalTipped, userTipped, isCompact, onClick, disabled } =
|
|
|
|
props
|
|
|
|
|
2022-10-11 18:30:24 +00:00
|
|
|
const tipDisplay = shortFormatNumber(Math.ceil(totalTipped / 10))
|
|
|
|
|
2022-10-01 20:51:08 +00:00
|
|
|
return (
|
|
|
|
<Tooltip
|
2022-10-11 18:30:24 +00:00
|
|
|
text={
|
|
|
|
disabled
|
|
|
|
? `Tips (${formatMoney(totalTipped)})`
|
|
|
|
: `Tip ${formatMoney(tipAmount)}`
|
|
|
|
}
|
2022-10-01 20:51:08 +00:00
|
|
|
placement="bottom"
|
|
|
|
noTap
|
|
|
|
noFade
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
size={'sm'}
|
2022-10-01 21:16:34 +00:00
|
|
|
className={clsx(
|
|
|
|
'max-w-xs self-center',
|
|
|
|
isCompact && 'px-0 py-0',
|
|
|
|
disabled && 'hover:bg-inherit'
|
|
|
|
)}
|
2022-10-01 20:51:08 +00:00
|
|
|
color={'gray-white'}
|
|
|
|
onClick={onClick}
|
|
|
|
disabled={disabled}
|
|
|
|
>
|
|
|
|
<Col className={'relative items-center sm:flex-row'}>
|
|
|
|
<HeartIcon
|
|
|
|
className={clsx(
|
2022-10-01 21:00:39 +00:00
|
|
|
'h-5 w-5 sm:h-6 sm:w-6',
|
2022-10-01 20:51:08 +00:00
|
|
|
totalTipped > 0 ? 'mr-2' : '',
|
2022-10-01 20:54:14 +00:00
|
|
|
userTipped ? 'fill-green-700 text-green-700' : ''
|
2022-10-01 20:51:08 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{totalTipped > 0 && (
|
|
|
|
<div
|
|
|
|
className={clsx(
|
2022-10-01 20:54:14 +00:00
|
|
|
'bg-greyscale-5 absolute ml-3.5 mt-2 h-4 w-4 rounded-full align-middle text-white sm:mt-3 sm:h-5 sm:w-5 sm:px-1',
|
2022-10-11 18:30:24 +00:00
|
|
|
tipDisplay.length > 2
|
2022-10-01 20:51:08 +00:00
|
|
|
? 'text-[0.4rem] sm:text-[0.5rem]'
|
|
|
|
: 'sm:text-2xs text-[0.5rem]'
|
|
|
|
)}
|
|
|
|
>
|
2022-10-11 18:30:24 +00:00
|
|
|
{tipDisplay}
|
2022-10-01 20:51:08 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Col>
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
)
|
|
|
|
}
|