Skip to content

Commit 3fa5831

Browse files
committed
Add properties
1 parent 33cde64 commit 3fa5831

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/relative-time-element.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
198198
month: this.month,
199199
year: this.year,
200200
timeZoneName: this.timeZoneName,
201+
dateStyle: this.dateStyle,
202+
timeStyle: this.timeStyle,
201203
})
202204
return `${this.prefix} ${formatter.format(date)}`.trim()
203205
}
@@ -326,6 +328,38 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
326328
this.setAttribute('time-zone-name', value || '')
327329
}
328330

331+
get dateStyle() {
332+
const dateStyle = this.getAttribute('date-style')
333+
334+
if (dateStyle === 'short' || dateStyle === 'long' || dateStyle === 'full' || dateStyle === 'medium') {
335+
return dateStyle
336+
}
337+
}
338+
339+
set dateStyle(value: 'short' | 'long' | 'full' | 'medium' | undefined) {
340+
if (value) {
341+
this.setAttribute('date-style', value)
342+
} else {
343+
this.removeAttribute('date-style')
344+
}
345+
}
346+
347+
get timeStyle() {
348+
const timeStyle = this.getAttribute('time-style')
349+
350+
if (timeStyle === 'short' || timeStyle === 'long' || timeStyle === 'full' || timeStyle === 'medium') {
351+
return timeStyle
352+
}
353+
}
354+
355+
set timeStyle(value: 'short' | 'long' | 'full' | 'medium' | undefined) {
356+
if (value) {
357+
this.setAttribute('time-style', value)
358+
} else {
359+
this.removeAttribute('time-style')
360+
}
361+
}
362+
329363
/** @deprecated */
330364
get prefix(): string {
331365
return this.getAttribute('prefix') ?? (this.format === 'datetime' ? '' : 'on')

0 commit comments

Comments
 (0)