UNPKG

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.

138 lines 5.16 kB
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 { createMutationController } from '../common/controllers/mutation-observer.js'; import { registerComponent } from '../common/definitions/register.js'; import IgcRadioComponent from '../radio/radio.js'; import { styles } from './themes/radio-group.base.css.js'; import { styles as shared } from './themes/shared/radio-group.common.css.js'; import { all } from './themes/themes.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; } _observerCallback() { const radios = Array.from(this._radios); const setState = (state, condition) => condition ? this._internals.states.add(state) : this._internals.states.delete(state); setState('disabled', radios.every((radio) => radio.disabled)); setState('label-before', radios.some((radio) => radio.labelPosition === 'before')); } constructor() { super(); this.alignment = 'vertical'; this._internals = this.attachInternals(); this._internals.role = 'radiogroup'; createMutationController(this, { callback: this._observerCallback, filter: [IgcRadioComponent.tagName], config: { attributeFilter: ['disabled', 'label-position'], subtree: true, }, }); } 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, shared]; __decorate([ queryAssignedElements({ selector: 'igc-radio', 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(all) ], IgcRadioGroupComponent); export default IgcRadioGroupComponent; //# sourceMappingURL=radio-group.js.map