File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
packages/react/src/RelativeTime Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react'
12import { RelativeTimeElement } from '@github/relative-time-element'
2- import type { ComponentProps } from '../utils/types'
33import { createComponent } from '../utils/custom-element'
44
5- const RelativeTime = createComponent ( RelativeTimeElement , 'relative-time' )
5+ const RelativeTimeComponent = createComponent ( RelativeTimeElement , 'relative-time' )
6+
7+ export type RelativeTimeProps = ComponentProps < typeof RelativeTimeComponent >
8+
9+ const localeOptions : Intl . DateTimeFormatOptions = { month : 'short' , day : 'numeric' , year : 'numeric' }
10+ function RelativeTime ( { date, ...props } : RelativeTimeProps ) {
11+ return (
12+ < RelativeTimeComponent { ...props } date = { date } >
13+ ${ date ?. toLocaleDateString ( 'en' , localeOptions ) || '' }
14+ </ RelativeTimeComponent >
15+ )
16+ }
617
7- export type RelativeTimeProps = ComponentProps < typeof RelativeTime >
818export default RelativeTime
You can’t perform that action at this time.
0 commit comments