2023-08-07 18:02:18 +00:00
|
|
|
import {customElement, DeesElement, type TemplateResult, property, html, type CSSResult,} from '@design.estate/dees-element';
|
2023-08-07 17:13:29 +00:00
|
|
|
import * as domtools from '@design.estate/dees-domtools';
|
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')
|
2022-01-24 00:39:47 +00:00
|
|
|
export class DeesInputRadio extends DeesElement {
|
2020-09-13 16:24:48 +00:00
|
|
|
public static demo = () => html`<dees-input-radio></dees-input-radio>`;
|
|
|
|
|
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 key: string;
|
|
|
|
|
|
|
|
@property()
|
|
|
|
public label: string = 'Label';
|
|
|
|
|
|
|
|
@property()
|
|
|
|
public value: boolean = false;
|
|
|
|
|
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;
|
|
|
|
|
2021-08-25 11:51:55 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
2020-09-13 16:24:48 +00:00
|
|
|
public render(): TemplateResult {
|
|
|
|
return html `
|
|
|
|
<style>
|
|
|
|
* {
|
|
|
|
box-sizing: border-box;
|
|
|
|
}
|
|
|
|
|
|
|
|
:host {
|
|
|
|
display: block;
|
|
|
|
position: relative;
|
|
|
|
margin: 20px 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.maincontainer {
|
|
|
|
transition: all 0.3s;
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: 25px auto;
|
|
|
|
padding: 5px 0px;
|
|
|
|
color: #ccc;
|
|
|
|
}
|
|
|
|
|
|
|
|
.maincontainer:hover {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
.label {
|
|
|
|
margin-left: 15px;
|
|
|
|
line-height: 25px;
|
|
|
|
font-size: 14px;
|
|
|
|
font-weight: normal;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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 04:11:55 +00: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;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<div class="maincontainer" @click="${this.toggleSelected}">
|
|
|
|
<div class="checkbox ${this.value ? 'selected' : ''}">
|
|
|
|
${this.value ? html`<div class="innercircle"></div>`: html``}
|
|
|
|
</div>
|
|
|
|
<div class="label">${this.label}</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async toggleSelected () {
|
|
|
|
this.value = !this.value;
|
|
|
|
this.dispatchEvent(new CustomEvent('newValue', {
|
|
|
|
detail: this.value,
|
|
|
|
bubbles: true
|
|
|
|
}));
|
2021-08-19 22:25:14 +00:00
|
|
|
this.changeSubject.next(this);
|
2020-09-13 16:24:48 +00:00
|
|
|
}
|
|
|
|
}
|