Projects selector

This commit is contained in:
2025-07-15 22:46:28 +03:00
parent 434b5b184e
commit 991ff51aae
11 changed files with 202 additions and 4 deletions
+4
View File
@@ -4,3 +4,7 @@ import "controllers"
import "trix"
import "@rails/actiontext"
import {ProjectsSelector} from 'elements/project_selector'
customElements.define('projects-selector', ProjectsSelector)
@@ -0,0 +1,40 @@
import {html, css, LitElement} from 'lit'
export class ProjectsSelector extends LitElement {
static style=css`
slot {
display: none;
}
`
static properties = {
frame: {type: String},
_options: {type: Array, state: true}
}
render() {
return html`
<slot @slotchange=${this._handleUpdatedElements} style="display: none"></slot>
<select @change=${this._handleSelect}>
${(this._options || []).map(option => this._renderOption(option))}
</select>
`
}
_handleUpdatedElements(e) {
const childNodes = e.target.assignedElements({flatten: true})
this._options = childNodes.map(e => {
return {name: e.innerText, href: e.getAttribute('href'), selected: !!e.getAttribute('selected')}
})
}
_renderOption(option) {
const {name, href, selected} = option
return html`<option value="${href}" ?selected="${selected}">${name}</option>`
}
_handleSelect(e) {
const href = e.target.value
Turbo.visit(href, {action: 'advance', frame: this.frame})
}
}