2022-05-26 21:41:24 +00:00
|
|
|
import React from 'react'
|
2022-01-16 09:16:15 +00:00
|
|
|
import dayjs from 'dayjs'
|
|
|
|
import utc from 'dayjs/plugin/utc'
|
|
|
|
import timezone from 'dayjs/plugin/timezone'
|
|
|
|
import advanced from 'dayjs/plugin/advancedFormat'
|
2022-03-03 07:51:58 +00:00
|
|
|
import { ClientRender } from './client-render'
|
2022-01-16 09:16:15 +00:00
|
|
|
|
|
|
|
dayjs.extend(utc)
|
|
|
|
dayjs.extend(timezone)
|
|
|
|
dayjs.extend(advanced)
|
|
|
|
|
|
|
|
export function DateTimeTooltip(props: {
|
|
|
|
time: number
|
2022-01-19 22:01:54 +00:00
|
|
|
text?: string
|
2022-01-16 09:16:15 +00:00
|
|
|
children?: React.ReactNode
|
|
|
|
}) {
|
2022-01-19 22:01:54 +00:00
|
|
|
const { time, text } = props
|
|
|
|
|
2022-02-22 21:14:52 +00:00
|
|
|
const formattedTime = dayjs(time).format('MMM DD, YYYY hh:mm a z')
|
2022-01-19 22:01:54 +00:00
|
|
|
const toolTip = text ? `${text} ${formattedTime}` : formattedTime
|
|
|
|
|
2022-01-16 09:16:15 +00:00
|
|
|
return (
|
2022-01-18 00:08:50 +00:00
|
|
|
<>
|
2022-03-03 07:51:58 +00:00
|
|
|
<ClientRender>
|
|
|
|
<span
|
|
|
|
className="tooltip hidden cursor-default sm:inline-block"
|
|
|
|
data-tip={toolTip}
|
|
|
|
>
|
|
|
|
{props.children}
|
|
|
|
</span>
|
|
|
|
</ClientRender>
|
|
|
|
<span className="whitespace-nowrap sm:hidden">{props.children}</span>
|
2022-01-18 00:08:50 +00:00
|
|
|
</>
|
2022-01-16 09:16:15 +00:00
|
|
|
)
|
|
|
|
}
|