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