2025-06-19 11:39:16 +00:00
|
|
|
import { customElement, property, html, type TemplateResult, css, cssManager } from '@design.estate/dees-element';
|
2023-08-07 19:13:29 +02:00
|
|
|
import * as domtools from '@design.estate/dees-domtools';
|
2025-06-19 11:39:16 +00:00
|
|
|
import { DeesInputBase } from './dees-input-base.js';
|
|
|
|
import { demoFunc } from './dees-input-quantityselector.demo.js';
|
2020-09-13 16:24:48 +00:00
|
|
|
|
2021-03-06 15:48:02 +00:00
|
|
|
declare global {
|
|
|
|
interface HTMLElementTagNameMap {
|
|
|
|
'dees-input-quantityselector': DeesInputQuantitySelector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-13 16:24:48 +00:00
|
|
|
@customElement('dees-input-quantityselector')
|
2025-06-19 11:39:16 +00:00
|
|
|
export class DeesInputQuantitySelector extends DeesInputBase<DeesInputQuantitySelector> {
|
|
|
|
public static demo = demoFunc;
|
2020-09-13 16:24:48 +00:00
|
|
|
|
2021-08-20 00:25:14 +02:00
|
|
|
// INSTANCE
|
2020-09-13 16:24:48 +00:00
|
|
|
|
|
|
|
@property({
|
|
|
|
type: Number
|
|
|
|
})
|
|
|
|
public value: number = 1;
|
|
|
|
|
2021-08-26 21:30:35 +02:00
|
|
|
|
2021-08-25 13:51:55 +02:00
|
|
|
|
2025-06-19 11:39:16 +00:00
|
|
|
public static styles = [
|
|
|
|
...DeesInputBase.baseStyles,
|
|
|
|
cssManager.defaultStyles,
|
|
|
|
css`
|
2020-09-13 16:24:48 +00:00
|
|
|
:host {
|
2025-06-19 11:39:16 +00:00
|
|
|
width: auto;
|
2020-09-13 16:24:48 +00:00
|
|
|
user-select: none;
|
|
|
|
}
|
2025-06-19 11:39:16 +00:00
|
|
|
|
|
|
|
.quantity-container {
|
2020-09-13 16:24:48 +00:00
|
|
|
transition: all 0.1s;
|
|
|
|
font-size: 14px;
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: 33% 34% 33%;
|
|
|
|
text-align: center;
|
2025-06-19 11:39:16 +00:00
|
|
|
background: ${cssManager.bdTheme('#fafafa', '#222222')};
|
2020-09-13 16:24:48 +00:00
|
|
|
line-height: 40px;
|
|
|
|
padding: 0px;
|
2025-06-19 11:39:16 +00:00
|
|
|
min-width: 110px;
|
|
|
|
color: ${cssManager.bdTheme('#666', '#CCC')};
|
|
|
|
border: 1px solid ${cssManager.bdTheme('#CCC', '#444')};
|
2022-12-07 02:28:31 +01:00
|
|
|
border-radius: 4px;
|
2020-12-09 23:05:13 +00:00
|
|
|
}
|
2025-06-19 11:39:16 +00:00
|
|
|
|
|
|
|
.quantity-container.disabled {
|
|
|
|
opacity: 0.5;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2020-12-09 23:05:13 +00:00
|
|
|
|
2025-06-19 11:39:16 +00:00
|
|
|
.quantity-container:hover {
|
|
|
|
color: ${cssManager.bdTheme('#333', '#fff')};
|
|
|
|
border-color: ${cssManager.bdTheme('#999', '#666')};
|
2020-09-13 16:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.minus {
|
|
|
|
padding-left: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.plus {
|
|
|
|
padding-right: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.selector {
|
|
|
|
text-align: center;
|
|
|
|
font-size: 20px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.selector:hover {
|
|
|
|
}
|
|
|
|
|
|
|
|
.quantity {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
2025-06-19 11:39:16 +00:00
|
|
|
`,
|
|
|
|
];
|
2020-09-13 16:24:48 +00:00
|
|
|
|
2025-06-19 11:39:16 +00:00
|
|
|
public render(): TemplateResult {
|
|
|
|
return html`
|
|
|
|
<div class="input-wrapper">
|
|
|
|
<dees-label .label=${this.label}></dees-label>
|
|
|
|
<div class="quantity-container ${this.disabled ? 'disabled' : ''}">
|
|
|
|
<div class="selector minus" @click="${() => {this.decrease();}}">-</div>
|
2020-09-13 16:24:48 +00:00
|
|
|
<div class="quantity">${this.value}</div>
|
2025-06-19 11:39:16 +00:00
|
|
|
<div class="selector plus" @click="${() => {this.increase();}}">+</div>
|
|
|
|
</div>
|
2020-09-13 16:24:48 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2025-06-19 11:39:16 +00:00
|
|
|
public increase() {
|
|
|
|
if (!this.disabled) {
|
|
|
|
this.value++;
|
|
|
|
this.changeSubject.next(this);
|
|
|
|
}
|
2020-09-13 16:24:48 +00:00
|
|
|
}
|
|
|
|
|
2025-06-19 11:39:16 +00:00
|
|
|
public decrease() {
|
|
|
|
if (!this.disabled && this.value > 0) {
|
2020-09-13 16:24:48 +00:00
|
|
|
this.value--;
|
2025-06-19 11:39:16 +00:00
|
|
|
this.changeSubject.next(this);
|
2020-09-13 16:24:48 +00:00
|
|
|
}
|
2025-06-19 11:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public getValue(): number {
|
|
|
|
return this.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public setValue(value: number): void {
|
|
|
|
this.value = value;
|
2020-09-13 16:24:48 +00:00
|
|
|
}
|
|
|
|
}
|