Skip to content

Commit

Permalink
Merge pull request #189 from github/add-setters-for-all-attributes
Browse files Browse the repository at this point in the history
add setters for all attributes
  • Loading branch information
keithamus committed Oct 26, 2022
2 parents 6a5a9e7 + ce3e7c7 commit 96babbb
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/relative-time-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,38 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
const minute = this.getAttribute('minute')
if (minute === 'numeric' || minute === '2-digit') return minute
}

set minute(value: 'numeric' | '2-digit' | undefined) {
this.setAttribute('minute', value || '')
}

get hour() {
const hour = this.getAttribute('hour')
if (hour === 'numeric' || hour === '2-digit') return hour
}

set hour(value: 'numeric' | '2-digit' | undefined) {
this.setAttribute('hour', value || '')
}

get day() {
const day = this.getAttribute('day') ?? 'numeric'
if (day === 'numeric' || day === '2-digit') return day
}

set day(value: 'numeric' | '2-digit' | undefined) {
this.setAttribute('day', value || '')
}

get month() {
const month = this.getAttribute('month') ?? 'short'
if (month === 'numeric' || month === '2-digit' || month === 'short' || month === 'long' || month === 'narrow')
if (month === 'numeric' || month === '2-digit' || month === 'short' || month === 'long' || month === 'narrow') {
return month
}
}

set month(value: 'numeric' | '2-digit' | 'short' | 'long' | 'narrow' | undefined) {
this.setAttribute('month', value || '')
}

get year() {
Expand All @@ -112,6 +130,10 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
}
}

set year(value: 'numeric' | '2-digit' | undefined) {
this.setAttribute('day', value || '')
}

get timeZoneName() {
const name = this.getAttribute('time-zone-name')
if (
Expand All @@ -126,6 +148,12 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
}
}

set timeZoneName(
value: 'long' | 'short' | 'shortOffset' | 'longOffset' | 'shortGeneric' | 'longGeneric' | undefined
) {
this.setAttribute('time-zone-name', value || '')
}

/** @deprecated */
get prefix(): string {
return this.getAttribute('prefix') ?? 'on'
Expand Down

0 comments on commit 96babbb

Please sign in to comment.