2022-10-11 02:56:16 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
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'
|
2022-10-13 06:53:26 +00:00
|
|
|
import TipJar from 'web/public/custom-components/tipJar'
|
|
|
|
import { useState } from 'react'
|
2022-10-14 06:47:51 +00:00
|
|
|
import Coin from 'web/public/custom-components/coin'
|
2022-10-01 20:51:08 +00:00
|
|
|
|
|
|
|
export function TipButton(props: {
|
|
|
|
tipAmount: number
|
|
|
|
totalTipped: number
|
|
|
|
onClick: () => void
|
|
|
|
userTipped: boolean
|
|
|
|
isCompact?: boolean
|
|
|
|
disabled?: boolean
|
|
|
|
}) {
|
2022-10-13 06:53:26 +00:00
|
|
|
const { tipAmount, totalTipped, userTipped, onClick, disabled } = props
|
2022-10-01 20:51:08 +00:00
|
|
|
|
2022-10-11 18:30:24 +00:00
|
|
|
const tipDisplay = shortFormatNumber(Math.ceil(totalTipped / 10))
|
|
|
|
|
2022-10-13 06:53:26 +00:00
|
|
|
const [hover, setHover] = useState(false)
|
|
|
|
|
2022-10-01 20:51:08 +00:00
|
|
|
return (
|
|
|
|
<Tooltip
|
2022-10-11 18:30:24 +00:00
|
|
|
text={
|
|
|
|
disabled
|
2022-10-14 06:47:51 +00:00
|
|
|
? `Total tips ${formatMoney(totalTipped)}`
|
2022-10-11 18:30:24 +00:00
|
|
|
: `Tip ${formatMoney(tipAmount)}`
|
|
|
|
}
|
2022-10-01 20:51:08 +00:00
|
|
|
placement="bottom"
|
|
|
|
noTap
|
|
|
|
noFade
|
|
|
|
>
|
2022-10-13 06:53:26 +00:00
|
|
|
<button
|
2022-10-01 20:51:08 +00:00
|
|
|
onClick={onClick}
|
|
|
|
disabled={disabled}
|
2022-10-13 06:53:26 +00:00
|
|
|
className={clsx(
|
|
|
|
'px-2 py-1 text-xs', //2xs button
|
2022-10-14 06:47:51 +00:00
|
|
|
'text-greyscale-5 transition-transform disabled:cursor-not-allowed',
|
|
|
|
!disabled ? 'hover:text-greyscale-6' : ''
|
2022-10-13 06:53:26 +00:00
|
|
|
)}
|
2022-10-14 06:47:51 +00:00
|
|
|
onMouseOver={() => {
|
|
|
|
if (!disabled) {
|
|
|
|
setHover(true)
|
|
|
|
}
|
|
|
|
}}
|
2022-10-13 06:53:26 +00:00
|
|
|
onMouseLeave={() => setHover(false)}
|
2022-10-01 20:51:08 +00:00
|
|
|
>
|
2022-10-14 06:47:51 +00:00
|
|
|
<Col className={clsx('relative')}>
|
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'absolute transition-all',
|
|
|
|
hover ? 'left-[6px] -top-[9px]' : 'left-[8px] -top-[10px]'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Coin
|
|
|
|
size={10}
|
|
|
|
color={
|
|
|
|
hover && !userTipped
|
|
|
|
? '#66667C'
|
|
|
|
: userTipped
|
|
|
|
? '#4f46e5'
|
|
|
|
: '#9191a7'
|
|
|
|
}
|
|
|
|
strokeWidth={2}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-10-13 06:53:26 +00:00
|
|
|
<TipJar
|
|
|
|
size={18}
|
2022-10-14 06:47:51 +00:00
|
|
|
color={
|
|
|
|
hover && !disabled && !userTipped
|
|
|
|
? '#66667C'
|
|
|
|
: userTipped
|
|
|
|
? '#4f46e5'
|
|
|
|
: '#9191a7'
|
|
|
|
}
|
2022-10-13 06:53:26 +00:00
|
|
|
/>
|
|
|
|
<div
|
2022-10-01 20:51:08 +00:00
|
|
|
className={clsx(
|
2022-10-13 19:33:41 +00:00
|
|
|
userTipped && 'text-indigo-600',
|
2022-10-13 06:53:26 +00:00
|
|
|
' absolute top-[2px] text-[0.5rem]',
|
|
|
|
tipDisplay.length === 1
|
|
|
|
? 'left-[7px]'
|
|
|
|
: tipDisplay.length === 2
|
|
|
|
? 'left-[4.5px]'
|
|
|
|
: tipDisplay.length > 2
|
|
|
|
? 'left-[4px] top-[2.5px] text-[0.35rem]'
|
|
|
|
: ''
|
2022-10-01 20:51:08 +00:00
|
|
|
)}
|
2022-10-13 06:53:26 +00:00
|
|
|
>
|
|
|
|
{totalTipped > 0 ? tipDisplay : ''}
|
|
|
|
</div>
|
2022-10-01 20:51:08 +00:00
|
|
|
</Col>
|
2022-10-13 06:53:26 +00:00
|
|
|
</button>
|
2022-10-01 20:51:08 +00:00
|
|
|
</Tooltip>
|
|
|
|
)
|
|
|
|
}
|