manifold/web/components/datetime-tooltip.tsx
2022-01-19 16:01:54 -06:00

32 lines
741 B
TypeScript

import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'
import advanced from 'dayjs/plugin/advancedFormat'
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(advanced)
export function DateTimeTooltip(props: {
time: number
text?: string
children?: React.ReactNode
}) {
const { time, text } = props
const formattedTime = dayjs(time).format('MMM DD, YYYY hh:mm a z')
const toolTip = text ? `${text} ${formattedTime}` : formattedTime
return (
<>
<span
className="tooltip cursor-default hidden sm:inline-block"
data-tip={toolTip}
>
{props.children}
</span>
<span className="sm:hidden">{props.children}</span>
</>
)
}