mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-03-11 20:55:16 +09:00
60 lines
1.1 KiB
JavaScript
60 lines
1.1 KiB
JavaScript
import { generateUUID, synchronize } from "lib/autocomplete/helpers"
|
|
|
|
export default class extends HTMLElement {
|
|
constructor() {
|
|
super(...arguments)
|
|
this.flash = synchronize(this.flash)
|
|
}
|
|
|
|
connectedCallback() {
|
|
this.id ||= `option-${generateUUID()}`
|
|
}
|
|
|
|
get selectElement() {
|
|
return this.closest("suggestion-select")
|
|
}
|
|
|
|
get index() {
|
|
if (this.selectElement) {
|
|
return Array.from(this.selectElement.optionElements).indexOf(this)
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
|
|
get selected() {
|
|
return this.hasAttribute("selected")
|
|
}
|
|
|
|
set selected(value) {
|
|
if (value) {
|
|
this.setAttribute("selected", "")
|
|
} else {
|
|
this.removeAttribute("selected")
|
|
}
|
|
}
|
|
|
|
get value() {
|
|
return this.getAttribute("value")
|
|
}
|
|
|
|
flash(callback) {
|
|
const drawFrame = (frame = 0) => {
|
|
requestAnimationFrame(() => {
|
|
if (frame == 0) {
|
|
this.classList.add("flashing-off")
|
|
} else if (frame == 4) {
|
|
this.classList.remove("flashing-off")
|
|
}
|
|
|
|
if (frame == 7) {
|
|
callback()
|
|
} else {
|
|
drawFrame(frame + 1)
|
|
}
|
|
})
|
|
}
|
|
drawFrame(0)
|
|
}
|
|
}
|