aiellie

Search

Find a component, template or page

GitHub
Components

Timestamps

When a message was sent, worded by how long ago, beside it or across the thread.

fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/timestamps"

shadcn needs the @aiellie registry in components.json first. npx aiellie add timestamps adds it on its first run, then installs the same way.

Timestamps says when a message was sent, worded by how long ago. Within the hour it says the gap, like "4 minutes ago". Earlier the same day it says the time, and before that the day. format picks one of those wordings for good.

TimestampRow puts it beside a message, and can keep it hidden until the row is hovered or focused, holding its space so the message never moves.

Getting started

  1. Put it beside a message

    live keeps a relative label current, ticking every minute.

    components/stamped-message.tsx
    import {
      Message,
      MessageContent,
      MessagePart,
    } from "@/components/aiellie/message"
    import { Timestamp, TimestampRow } from "@/components/aiellie/timestamps"
    
    export function StampedMessage({ text, sentAt }: { text: string; sentAt: Date }) {
      return (
        <TimestampRow align="end" reveal="hover">
          <Message align="end">
            <MessageContent>
              <MessagePart>{text}</MessagePart>
            </MessageContent>
          </Message>
          <Timestamp date={sentAt} live />
        </TimestampRow>
      )
    }
  2. Or across the thread

    components/thread.tsx
    <Timestamp date={sentAt} format="datetime" variant="separator" />

Anatomy

<div data-slot="timestamp-row" data-align="end" data-reveal="hover">
  {/* the message */}
  <time data-slot="timestamp" dateTime="…" title="…"> {/* marker */}
    <span data-slot="marker-content" />
  </time>
</div>

It's a time element with the full date as its title. The wording is worked out in the browser only, since the server doesn't know the reader's clock or time zone.

Every live timestamp ticking at the same rate shares one timer.

Examples

Formats

The same moment, three hours ago, in each format.

API reference

Timestamp

PropTypeDefaultDescription
dateDate | string | numberrequired
format"auto" | "relative" | "time" | "day" | "datetime""auto"
variant"default" | "separator" | "border""default"The marker's look.
liveboolean | numberfalseKeeps it current: every minute, or every so many milliseconds.
locale, hour12the reader's
iconReactNodeBefore the label.
childrenReactNodeYour own label.

All other marker props are forwarded. formatTimestamp(date, options) gives the label as a string.

TimestampRow

PropTypeDefaultDescription
align"start" | "end""start"Which side the message sits on.
reveal"always" | "hover""always"Shows the timestamp only on hover or focus.