manifold/web/components/datetime-tooltip.tsx

32 lines
759 B
TypeScript
Raw Normal View History

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
2022-01-19 22:01:54 +00:00
text?: string
children?: React.ReactNode
}) {
2022-01-19 22:01:54 +00:00
const { time, text } = props
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
return (
<>
<span
className="tooltip hidden cursor-default sm:inline-block"
2022-01-19 22:01:54 +00:00
data-tip={toolTip}
>
{props.children}
</span>
2022-02-21 04:04:00 +00:00
<span className="sm:hidden whitespace-nowrap">{props.children}</span>
</>
)
}