chore: simplify code
This commit is contained in:
@@ -4,40 +4,36 @@ export default class extends Controller {
|
|||||||
|
|
||||||
static classes = [ 'closed' ]
|
static classes = [ 'closed' ]
|
||||||
static targets = [ 'toggle', 'icon' ]
|
static targets = [ 'toggle', 'icon' ]
|
||||||
static values = { open: Boolean, iconClosed: String, iconOpen: String, spriteUrl: String }
|
static values = {
|
||||||
|
open: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
connect() {
|
initialize() {
|
||||||
this.target = this.hasToggleTarget ? this.toggleTarget : this.element
|
this.target = this.hasToggleTarget ? this.toggleTarget : this.element
|
||||||
this.openValue = !this.target.classList.contains(this.closedClass)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
this.openValue ? this._close() : this._open()
|
this.openValue = !this.openValue
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this._close()
|
|
||||||
}
|
|
||||||
|
|
||||||
_close() {
|
|
||||||
this.openValue = false
|
this.openValue = false
|
||||||
this.target.classList.add(this.closedClass)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
this._open()
|
|
||||||
}
|
|
||||||
|
|
||||||
_open() {
|
|
||||||
this.openValue = true
|
this.openValue = true
|
||||||
this.target.classList.remove(this.closedClass)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
openValueChanged() {
|
openValueChanged(open) {
|
||||||
|
this.target.classList.toggle(this.closedClass, false === open)
|
||||||
|
|
||||||
if (false === this.hasIconTarget) {
|
if (false === this.hasIconTarget) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.iconTarget.classList.toggle('rotate-90', true === this.openValue)
|
this.iconTarget.classList.toggle('rotate-90', true === open)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user