import { LitElement, html, unsafeCSS, svg } from 'lit';
import { property } from 'lit/decorators.js';
import { theme } from '../styles/theme.js';
export class Radio extends LitElement {
@property({ type: Boolean }) checked = false;
@property({ type: Boolean }) disabled = false;
@property({ type: String }) color: 'primary' | 'secondary' | 'error' | 'warning' | 'info' | 'success' = 'primary';
@property({ type: String }) size: 'small' | 'medium' = 'medium';
@property({ type: String }) value = '';
static styles = unsafeCSS`
:host {
display: inline-block;
}
.radio-wrapper {
display: inline-flex;
align-items: center;
justify-content: center;
position: relative;
cursor: pointer;
user-select: none;
}
.radio-wrapper.disabled {
cursor: default;
pointer-events: none;
}
input {
position: absolute;
opacity: 0;
cursor: pointer;
}
.radio {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 50%;
transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.medium .radio { width: 42px; height: 42px; }
.small .radio { width: 38px; height: 38px; }
.radio:hover {
background-color: rgba(25, 118, 210, 0.04);
}
svg { width: 24px; height: 24px; }
.small svg { width: 20px; height: 20px; }
.icon-unchecked { fill: rgba(0, 0, 0, 0.54); }
.icon-checked.primary { fill: ${theme.palette.primary.main}; }
.icon-checked.secondary { fill: ${theme.palette.secondary.main}; }
.icon-checked.error { fill: ${theme.palette.error.main}; }
.icon-checked.warning { fill: ${theme.palette.warning.main}; }
.icon-checked.info { fill: ${theme.palette.info.main}; }
.icon-checked.success { fill: ${theme.palette.success.main}; }
.disabled .icon-unchecked,
.disabled .icon-checked {
fill: rgba(0, 0, 0, 0.26);
}
`;
private handleChange(e: Event) {
if (this.disabled) return;
const input = e.target as HTMLInputElement;
this.checked = input.checked;
this.dispatchEvent(new CustomEvent('change', {
detail: { checked: this.checked, value: this.value },
bubbles: true,
composed: true
}));
}
render() {
return html`
`;
}
}