igniteui-webcomponents
Version:
Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.
125 lines • 4.52 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var IgcRadioGroupComponent_1;
import { LitElement, html } from 'lit';
import { property, queryAssignedElements } from 'lit/decorators.js';
import { themes } from '../../theming/theming-decorator.js';
import { registerComponent } from '../common/definitions/register.js';
import IgcRadioComponent from '../radio/radio.js';
import { styles } from './radio-group.base.css.js';
import { styles as fluent } from './radio-group.fluent.css.js';
import { styles as indigo } from './radio-group.indigo.css.js';
import { styles as material } from './radio-group.material.css.js';
let IgcRadioGroupComponent = IgcRadioGroupComponent_1 = class IgcRadioGroupComponent extends LitElement {
static register() {
registerComponent(IgcRadioGroupComponent_1, IgcRadioComponent);
}
set defaultValue(value) {
this._defaultValue = value;
this._setRadiosDefaultChecked();
}
get defaultValue() {
return this._defaultValue;
}
set name(value) {
this._name = value;
this._setRadiosName();
}
get name() {
return this._name;
}
set value(value) {
this._value = value;
this._setSelectedRadio();
}
get value() {
if (this._radios.length) {
this._value =
Array.from(this._radios).find((radio) => radio.checked)?.value ?? '';
}
return this._value;
}
constructor() {
super();
this.alignment = 'vertical';
this._internals = this.attachInternals();
this._internals.role = 'radiogroup';
}
createRenderRoot() {
const root = super.createRenderRoot();
root.addEventListener('slotchange', () => this._setCSSGridVars());
return root;
}
firstUpdated() {
const radios = Array.from(this._radios);
const allRadiosUnchecked = radios.every((radio) => !radio.checked);
this._setRadiosName();
this._setRadiosDefaultChecked();
if (allRadiosUnchecked && this._value) {
this._setSelectedRadio();
this._setDefaultValue();
}
}
_setCSSGridVars() {
const slot = this.renderRoot.querySelector('slot');
if (slot) {
this.style.setProperty('--layout-count', `${slot.assignedElements({ flatten: true }).length}`);
}
}
_setRadiosDefaultChecked() {
if (this._defaultValue) {
for (const radio of this._radios) {
radio.defaultChecked = radio.value === this._defaultValue;
}
}
}
_setRadiosName() {
if (this._name) {
for (const radio of this._radios) {
radio.name = this._name;
}
}
}
_setDefaultValue() {
for (const radio of this._radios) {
radio.toggleAttribute('checked', radio.checked);
}
}
_setSelectedRadio() {
for (const radio of this._radios) {
radio.checked = radio.value === this._value;
}
}
render() {
return html `<slot></slot>`;
}
};
IgcRadioGroupComponent.tagName = 'igc-radio-group';
IgcRadioGroupComponent.styles = styles;
__decorate([
queryAssignedElements({ flatten: true })
], IgcRadioGroupComponent.prototype, "_radios", void 0);
__decorate([
property({ reflect: true })
], IgcRadioGroupComponent.prototype, "alignment", void 0);
__decorate([
property({ attribute: false })
], IgcRadioGroupComponent.prototype, "defaultValue", null);
__decorate([
property({ reflect: true })
], IgcRadioGroupComponent.prototype, "name", null);
__decorate([
property()
], IgcRadioGroupComponent.prototype, "value", null);
IgcRadioGroupComponent = IgcRadioGroupComponent_1 = __decorate([
themes({
light: { material, fluent, indigo },
dark: { material, fluent, indigo },
})
], IgcRadioGroupComponent);
export default IgcRadioGroupComponent;
//# sourceMappingURL=radio-group.js.map