jsx import { jsx } from "@emotion/react" ; import dayjs from "dayjs" ; import { ago , AgoValue } from "../utils/ago" ; export interface AgoProps extends React . HTMLProps < HTMLSpanElement | HTMLDivElement > { date ? : dayjs . ConfigType ; block ? : boolean ; renderContent ? : ( result : AgoValue ) => React . ReactNode ; } export function Ago ( props ) { const { date = dayjs ( ) , block = false , renderContent , ... attrs } = props ; const agoValue = ago ( date ) ; let content = agoValue . format ; if ( typeof renderContent === "function" ) { content = renderContent ( agoValue ) ; } if ( block ) { return < div { ... ( attrs as React . HTMLProps < HTMLDivElement > ) } > { content } < /div>; } return < span { ... attrs } > { content } < /span>; }