2022-01-24 00:39:47 +00:00
|
|
|
import { customElement, DeesElement, TemplateResult, property, html } from '@designestate/dees-element';
|
2020-09-13 16:24:48 +00:00
|
|
|
import * as domtools from '@designestate/dees-domtools';
|
|
|
|
|
2021-03-06 15:48:02 +00:00
|
|
|
declare global {
|
|
|
|
interface HTMLElementTagNameMap {
|
|
|
|
'dees-input-dropdown': DeesInputDropdown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-13 16:24:48 +00:00
|
|
|
@customElement('dees-input-dropdown')
|
2022-01-24 00:39:47 +00:00
|
|
|
export class DeesInputDropdown extends DeesElement {
|
2020-12-09 23:05:13 +00:00
|
|
|
public static demo = () => html`<dees-input-dropdown></dees-input-dropdown>`
|
|
|
|
|
2021-08-19 22:25:14 +00:00
|
|
|
// INSTANCE
|
|
|
|
public changeSubject = new domtools.rxjs.Subject();
|
|
|
|
|
2020-09-13 16:24:48 +00:00
|
|
|
@property()
|
|
|
|
public label: string = 'Label';
|
|
|
|
|
|
|
|
@property()
|
|
|
|
public key: string;
|
|
|
|
|
|
|
|
@property()
|
|
|
|
public options: {option: string, key: string, payload?: any}[] = [];
|
|
|
|
|
|
|
|
@property()
|
|
|
|
public selectedOption: {option: string, key: string, payload?: any} = {
|
|
|
|
key: null,
|
|
|
|
option: null,
|
|
|
|
payload: null
|
|
|
|
};
|
|
|
|
|
2021-08-25 11:51:55 +00:00
|
|
|
@property({
|
|
|
|
type: Boolean
|
|
|
|
})
|
|
|
|
public required: boolean = false;
|
|
|
|
|
2021-08-26 19:30:35 +00:00
|
|
|
@property({
|
|
|
|
type: Boolean
|
|
|
|
})
|
|
|
|
public disabled: boolean = false;
|
|
|
|
|
2020-09-13 16:24:48 +00:00
|
|
|
public render(): TemplateResult {
|
|
|
|
return html`
|
|
|
|
${domtools.elementBasic.styles}
|
|
|
|
<style>
|
|
|
|
* {
|
|
|
|
box-sizing: border-box;
|
|
|
|
}
|
|
|
|
|
|
|
|
:host {
|
|
|
|
position: relative;
|
|
|
|
display: block;
|
|
|
|
height: 40px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.maincontainer {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.label {
|
|
|
|
font-size: 14px;
|
|
|
|
margin-bottom: 15px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.selectedBox {
|
|
|
|
cursor: pointer;
|
|
|
|
position: relative;
|
|
|
|
max-width: 420px;
|
|
|
|
height: 40px;
|
|
|
|
border: 1px solid #CCC;
|
|
|
|
padding: 12px;
|
|
|
|
z-index: 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.selectionBox {
|
|
|
|
pointer-events: none;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: all 0.2s ease;
|
|
|
|
opacity: 0;
|
|
|
|
position: relative;
|
|
|
|
background: #ffffff;
|
|
|
|
max-width: 420px;
|
|
|
|
box-shadow: 0px 0px 5px rgba(0,0,0,0.2);
|
|
|
|
height: 40px;
|
|
|
|
margin-top: -40px;
|
|
|
|
z-index: 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
.selectionBox.show {
|
|
|
|
pointer-events: all;
|
|
|
|
opacity: 1;
|
|
|
|
min-height: 160px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.option {
|
|
|
|
padding: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.option:hover {
|
|
|
|
background: #fafafa;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<div class="maincontainer">
|
|
|
|
<div class="selectedBox" @click="${event => {this.toggleSelectionBox();}}">
|
|
|
|
${this.selectedOption?.option}
|
|
|
|
</div>
|
|
|
|
<div class="selectionBox">
|
|
|
|
${this.options.map(option => {
|
|
|
|
return html`
|
|
|
|
<div class="option" @click=${() => {this.updateSelection(option);}}>${option.option}</div>
|
|
|
|
`
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
firstUpdated() {
|
|
|
|
this.selectedOption = this.options[0] || null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async updateSelection(selectedOption) {
|
|
|
|
this.selectedOption = selectedOption;
|
|
|
|
|
|
|
|
this.dispatchEvent(new CustomEvent('selectedOption', {
|
|
|
|
detail: selectedOption,
|
|
|
|
bubbles: true
|
|
|
|
}));
|
|
|
|
this.toggleSelectionBox();
|
2021-08-19 22:25:14 +00:00
|
|
|
this.changeSubject.next(this);
|
2020-09-13 16:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public toggleSelectionBox() {
|
|
|
|
this.shadowRoot.querySelector('.selectionBox').classList.toggle('show');
|
|
|
|
}
|
|
|
|
}
|