Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setters for all attributes #189

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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