stacker.news/components/cowboy-hat.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-02-01 14:44:35 +00:00
import { Badge, OverlayTrigger, Tooltip } from 'react-bootstrap'
import CowboyHatIcon from '../svgs/cowboy.svg'
2023-05-01 21:49:47 +00:00
export default function CowboyHat ({ user, badge, className = 'ml-1', height = 16, width = 16 }) {
if (user?.streak === null || user.hideCowboyHat) {
2023-02-01 14:44:35 +00:00
return null
}
2023-05-01 21:49:47 +00:00
const streak = user.streak
2023-02-01 14:44:35 +00:00
return (
2023-02-02 19:47:09 +00:00
<HatTooltip overlayText={streak ? `${streak} days` : 'new'}>
2023-02-01 14:44:35 +00:00
{badge
? (
<Badge variant='grey-medium' className='ml-2 d-inline-flex align-items-center'>
<CowboyHatIcon className={className} height={height} width={width} />
2023-02-02 19:47:09 +00:00
<span className='ml-1'>{streak || 'new'}</span>
2023-02-01 14:44:35 +00:00
</Badge>)
: <CowboyHatIcon className={className} height={height} width={width} />}
</HatTooltip>
)
}
function HatTooltip ({ children, overlayText, placement }) {
return (
<OverlayTrigger
placement={placement || 'bottom'}
overlay={
<Tooltip>
2023-02-02 19:47:09 +00:00
{overlayText}
2023-02-01 14:44:35 +00:00
</Tooltip>
}
trigger={['hover', 'focus']}
>
{children}
</OverlayTrigger>
)
}