import type { Meta, StoryObj } from "@storybook/react" import { Time } from "./Time" // Define a fixed timestamp string to avoid rendering issues in Storybook const TIMESTAMP = new Date() /** * Displays formatted dates and times using the HTML time element. */ const meta = { title: "base/communication/Time", component: Time, tags: ["autodocs"], parameters: { layout: "centered", }, argTypes: { dateTimeFormatStr: { control: "text", description: "Format string for the datetime attribute", }, formatStr: { control: "text", description: "Format string for displaying the date", }, }, args: { // This is a placeholder for Storybook - the actual component will use new Date(TIMESTAMP) children: TIMESTAMP, }, } satisfies Meta export default meta type Story = StoryObj /** * The default implementation of the Time component. */ export const Default: Story = { render: () => , } /** * Shows the date with a short format. */ export const ShortFormat: Story = { render: () => { const date = new Date(TIMESTAMP) const format = "P" return }, } /** * Shows the date with a long format including time. */ export const LongFormat: Story = { render: () => { const date = new Date(TIMESTAMP) const format = "PPPppp" return }, } /** * Examples of different date format strings. */ export const DateFormats: Story = { args: { children: TIMESTAMP, }, render: () => { const date = new Date(TIMESTAMP) return (
Format: "PP" Format: "PPP" Format: "PPPP" Format: "p" Format: "pp" Format: "dd MMM yyyy" Format: "MM/dd/yyyy" Format: "yyyy-MM-dd"
) }, } /** * Shows different timestamps with the same format. */ export const DifferentDates: Story = { args: { children: TIMESTAMP, }, render: () => { const today = new Date(TIMESTAMP) const yesterday = new Date(today) yesterday.setDate(yesterday.getDate() - 1) const lastWeek = new Date(today) lastWeek.setDate(lastWeek.getDate() - 7) const lastMonth = new Date(today) lastMonth.setMonth(lastMonth.getMonth() - 1) const nextWeek = new Date(today) nextWeek.setDate(nextWeek.getDate() + 7) return (
Today Yesterday Last Week Last Month Next Week
) }, } /** * Example showing Time components in a list context. */ export const InContext: Story = { args: { children: TIMESTAMP, }, render: () => { const today = new Date(TIMESTAMP) const yesterday = new Date(today) yesterday.setDate(yesterday.getDate() - 1) const twoDaysAgo = new Date(today) twoDaysAgo.setDate(twoDaysAgo.getDate() - 2) return (

Recent Activity

  • Document updated
  • Comment added
  • Project created
) }, } /** * Example showing custom styling. */ export const CustomStyling: Story = { args: { children: TIMESTAMP, }, render: () => { const today = new Date(TIMESTAMP) return (
) }, }