dees-catalog/ts_web/elements/dees-input-dropdown.ts

169 lines
4.1 KiB
TypeScript
Raw Normal View History

2023-08-07 18:02:18 +00:00
import { customElement, DeesElement, type TemplateResult, property, html, css, cssManager, type CSSResult, } from '@design.estate/dees-element';
2023-08-07 17:13:29 +00:00
import * as domtools from '@design.estate/dees-domtools';
2023-11-29 16:20:32 +00:00
import { demoFunc } from './dees-input-dropdown.demo.js';
2020-09-13 16:24:48 +00:00
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 {
2023-11-29 16:20:32 +00:00
public static demo = demoFunc
2020-12-09 23:05:13 +00:00
2021-08-19 22:25:14 +00:00
// INSTANCE
2023-10-23 15:26:03 +00:00
public changeSubject = new domtools.plugins.smartrx.rxjs.Subject();
2021-08-19 22:25:14 +00:00
2023-08-28 07:49:51 +00:00
@property({
type: String,
reflect: true,
})
2020-09-13 16:24:48 +00:00
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;
2023-03-25 16:30:41 +00:00
public static styles = [
cssManager.defaultStyles,
css`
* {
2020-09-13 16:24:48 +00:00
box-sizing: border-box;
}
:host {
position: relative;
display: block;
height: 40px;
2023-03-25 16:30:41 +00:00
color: ${cssManager.bdTheme('#222', '#fff')};
2020-09-13 16:24:48 +00:00
}
.maincontainer {
display: block;
}
.label {
font-size: 14px;
margin-bottom: 15px;
}
.selectedBox {
cursor: pointer;
position: relative;
max-width: 420px;
height: 40px;
2023-03-25 16:30:41 +00:00
line-height: 40px;
padding: 0px 8px;
2020-09-13 16:24:48 +00:00
z-index: 0px;
2023-03-25 19:56:12 +00:00
background: ${cssManager.bdTheme('#ffffff', '#333333')};
box-shadow: ${cssManager.bdTheme('0px 1px 4px rgba(0,0,0,0.3)', 'none')};
border-radius: 3px;
border-top: 1px solid #CCCCCC00;
border-bottom: 1px solid #66666600;
}
.selectedBox.show {
border-top: 1px solid ${cssManager.bdTheme('#ffffff', '#666666')};
border-bottom: 1px solid ${cssManager.bdTheme('#fafafa', '#222222')};
2020-09-13 16:24:48 +00:00
}
.selectionBox {
2023-03-25 19:56:12 +00:00
will-change:transform;
2020-09-13 16:24:48 +00:00
pointer-events: none;
cursor: pointer;
transition: all 0.2s ease;
opacity: 0;
2023-11-29 16:20:32 +00:00
position: absolute;
2023-03-25 16:30:41 +00:00
background: ${cssManager.bdTheme('#ffffff', '#222222')};
2020-09-13 16:24:48 +00:00
max-width: 420px;
box-shadow: 0px 0px 5px rgba(0,0,0,0.2);
2023-03-25 19:56:12 +00:00
min-height: 40px;
2020-09-13 16:24:48 +00:00
z-index: 100;
2023-03-25 16:30:41 +00:00
border-radius: 3px;
padding: 4px;
2023-03-25 19:56:12 +00:00
transform: scale(0.99,0.99);
2020-09-13 16:24:48 +00:00
}
.selectionBox.show {
pointer-events: all;
opacity: 1;
2023-03-25 19:56:12 +00:00
transform: scale(1,1);
2020-09-13 16:24:48 +00:00
}
.option {
2023-03-25 19:56:12 +00:00
transition: all 0.1s;
2023-03-25 16:30:41 +00:00
line-height: 40px;
padding: 0px 4px;
border-radius: 3px;
2020-09-13 16:24:48 +00:00
}
.option:hover {
2023-03-25 19:56:12 +00:00
color: #fff;
padding-left: 8px;
background: #0277bd;
2020-09-13 16:24:48 +00:00
}
2023-03-25 16:30:41 +00:00
`
]
public render(): TemplateResult {
return html`
2020-09-13 16:24:48 +00:00
<div class="maincontainer">
2023-11-29 16:20:32 +00:00
<div class="selectedBox show" @click="${event => {this.openSelectionBox();}}">
2020-09-13 16:24:48 +00:00
${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
}));
2023-11-29 16:20:32 +00:00
this.openSelectionBox();
2021-08-19 22:25:14 +00:00
this.changeSubject.next(this);
2020-09-13 16:24:48 +00:00
}
2023-11-29 16:20:32 +00:00
public openSelectionBox() {
2023-03-25 19:56:12 +00:00
this.shadowRoot.querySelector('.selectedBox').classList.toggle('show');
2020-09-13 16:24:48 +00:00
this.shadowRoot.querySelector('.selectionBox').classList.toggle('show');
}
2023-11-29 16:20:32 +00:00
public closeSelectionBox() {
}
2020-09-13 16:24:48 +00:00
}