stacker.news/components/cowboy-hat.js

37 lines
1022 B
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'
export default function CowboyHat ({ streak, badge, className = 'ml-1', height = 16, width = 16 }) {
2023-02-02 19:47:09 +00:00
if (streak === null) {
2023-02-01 14:44:35 +00:00
return null
}
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>
)
}