Component: Relative Time

未关闭
#92 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, tailwindcss, typescript

调研方向

Read the existing components under src/registry/components/, then check their exports in src/registry/components/index.ts and entries in src/registry/registry.ts. Build the Relative Time component around the listed API and timing requirements, and add tests in test/ for past and future dates, unit selection, locales, and timer cleanup. It is done when the component, registry entry, tests, and a page in content/docs/components/ are complete.

由索引模型根据 Issue 内容生成。

描述

component date-time good first issue

Component: Relative Time

Show how long ago (or until) a date is, in the user's language: "3 minutes ago", "vor 3 Minuten", "in 2 days".

A first version was removed in #66 until it could be a real component. This issue is for doing it properly.

Requirements
  • TypeScript-first with exported props interface
  • Uses Intl.RelativeTimeFormat, picking the largest sensible unit (seconds → minutes → hours → days → weeks → months → years)
  • numeric="auto" by default, so you get "yesterday" / "gestern" rather than "1 day ago"
  • Renders a semantic <time dateTime="…"> with the absolute date as a title
  • Updates itself while on screen, at a rate that fits the distance (every second near "now", every minute after that, …), and stops when unmounted
  • now prop for tests and SSR, so the server and client render the same text
  • Forwarded ref and ...rest like the other components
  • Tailwind CSS compatible
Expected API
<RelativeTime date={comment.createdAt} locale="de" />
// → <time dateTime="2026-10-28T10:00:00.000Z" title="28. Oktober 2026, 11:00">vor 3 Minuten</time>
Deliverables
  • Component source in src/registry/components/
  • Export in src/registry/components/index.ts and entry in src/registry/registry.ts
  • Tests in test/ covering past and future dates, unit selection, numeric="auto", at least en, de and ar, and that the timer is cleared on unmount
  • Documentation page in content/docs/components/

See CONTRIBUTING.md and the Contributor Rulebook.

主要语言
TypeScript
星标
39
派生
16
平均合并
18 小时 14 分钟
30 天内合并 PR
35

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

babelize/babelize-elements 的其他 Issue

查看 babelize/babelize-elements 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。