Files
dees-catalog/ts_web/elements/dees-input-radio.ts

113 lines
2.5 KiB
TypeScript
Raw Normal View History

import {customElement, type TemplateResult, property, html, css, cssManager} from '@design.estate/dees-element';
import { DeesInputBase } from './dees-input-base.js';
import { demoFunc } from './dees-input-radio.demo.js';
2020-09-13 16:24:48 +00:00
2021-03-06 15:48:02 +00:00
declare global {
interface HTMLElementTagNameMap {
'dees-input-radio': DeesInputRadio;
}
}
2020-09-13 16:24:48 +00:00
@customElement('dees-input-radio')
export class DeesInputRadio extends DeesInputBase<DeesInputRadio> {
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()
public value: boolean = false;
2021-08-26 21:30:35 +02:00
2021-08-25 13:51:55 +02:00
constructor() {
super();
this.labelPosition = 'right'; // Radio buttons default to label on the right
2021-08-25 13:51:55 +02:00
}
public static styles = [
...DeesInputBase.baseStyles,
cssManager.defaultStyles,
css`
2020-09-13 16:24:48 +00:00
* {
box-sizing: border-box;
}
:host {
position: relative;
}
.maincontainer {
transition: all 0.3s;
padding: 5px 0px;
color: #ccc;
}
.maincontainer:hover {
color: #fff;
}
input:focus {
outline: none;
border-bottom: 1px solid #e4002b;
}
.checkbox {
transition: all 0.3s;
box-sizing: border-box;
border-radius: 20px;
border: 1px solid #999;
height: 24px;
width: 24px;
display: inline-block;
background: #222;
}
.checkbox.selected {
2024-01-10 05:11:55 +01:00
background: #0050b9;
border: 1px solid #0050b9;
2020-09-13 16:24:48 +00:00
}
.maincontainer:hover .checkbox.selected {
background: #03A9F4;
}
.innercircle {
transition: all 0.3s;
margin: 6px 0px 0px 6px;
background: #222;
width: 10px;
height: 10px;
border-radius: 10px;
}
`,
];
public render(): TemplateResult {
return html`
<div class="input-wrapper">
<div class="maincontainer" @click="${this.toggleSelected}">
<div class="checkbox ${this.value ? 'selected' : ''}">
${this.value ? html`<div class="innercircle"></div>`: html``}
</div>
2020-09-13 16:24:48 +00:00
</div>
<dees-label .label=${this.label}></dees-label>
2020-09-13 16:24:48 +00:00
</div>
`;
}
public async toggleSelected () {
this.value = !this.value;
this.dispatchEvent(new CustomEvent('newValue', {
detail: this.value,
bubbles: true
}));
2021-08-20 00:25:14 +02:00
this.changeSubject.next(this);
2020-09-13 16:24:48 +00:00
}
public getValue(): boolean {
return this.value;
}
public setValue(value: boolean): void {
this.value = value;
}
2020-09-13 16:24:48 +00:00
}