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.
112 lines • 4.68 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 IgcCheckboxComponent_1;
import { html } from 'lit';
import { property } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { live } from 'lit/directives/live.js';
import { getThemeController, themes } from '../../theming/theming-decorator.js';
import { registerComponent } from '../common/definitions/register.js';
import { createCounter, partNameMap } from '../common/util.js';
import IgcValidationContainerComponent from '../validation-container/validation-container.js';
import { IgcCheckboxBaseComponent } from './checkbox-base.js';
import { all } from './themes/checkbox-themes.js';
import { styles } from './themes/checkbox.base.css.js';
import { styles as shared } from './themes/shared/checkbox/checkbox.common.css.js';
let IgcCheckboxComponent = IgcCheckboxComponent_1 = class IgcCheckboxComponent extends IgcCheckboxBaseComponent {
constructor() {
super(...arguments);
this.inputId = `checkbox-${IgcCheckboxComponent_1.increment()}`;
this.labelId = `checkbox-label-${this.inputId}`;
this.indeterminate = false;
}
static register() {
registerComponent(IgcCheckboxComponent_1, IgcValidationContainerComponent);
}
get _isIndigo() {
return getThemeController(this)?.theme === 'indigo';
}
handleClick(event) {
this.indeterminate = false;
super.handleClick(event);
}
renderValidatorContainer() {
return IgcValidationContainerComponent.create(this);
}
renderStandard() {
return html `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M4.1,12.7 9,17.6 20.3,6.3" />
</svg>
`;
}
renderIndigo() {
return html `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<rect width="18" height="4" x="3" y="10" rx="1.85" />
<path
d="M19.033 5a1.966 1.966 0 0 0-1.418.586l-8.479 8.577-2.753-2.77a1.971 1.971 0 0 0-2.8 0 1.998 1.998 0 0 0 0 2.822l4.155 4.196a1.955 1.955 0 0 0 2.8 0l9.879-9.99a1.998 1.998 0 0 0 0-2.821 1.966 1.966 0 0 0-1.384-.6Z"
/>
</svg>
`;
}
render() {
const labelledBy = this.getAttribute('aria-labelledby');
const checked = this.checked;
return html `
<label
part=${partNameMap({
base: true,
checked,
focused: this._kbFocus.focused,
})}
for=${this.inputId}
=${this._kbFocus.reset}
>
<input
id=${this.inputId}
type="checkbox"
name=${ifDefined(this.name)}
value=${ifDefined(this.value)}
.required=${this.required}
.disabled=${this.disabled}
.checked=${live(checked)}
.indeterminate=${live(this.indeterminate)}
aria-checked=${this.indeterminate && !checked ? 'mixed' : checked}
aria-disabled=${this.disabled ? 'true' : 'false'}
aria-labelledby=${labelledBy ? labelledBy : this.labelId}
=${this.handleClick}
=${this.handleBlur}
=${this.handleFocus}
/>
<span part=${partNameMap({ control: true, checked })}>
<span part=${partNameMap({ indicator: true, checked })}>
${this._isIndigo ? this.renderIndigo() : this.renderStandard()}
</span>
</span>
<span
.hidden=${this.hideLabel}
part=${partNameMap({ label: true, checked })}
id=${this.labelId}
><slot></slot>
</span>
</label>
${this.renderValidatorContainer()}
`;
}
};
IgcCheckboxComponent.tagName = 'igc-checkbox';
IgcCheckboxComponent.styles = [styles, shared];
IgcCheckboxComponent.increment = createCounter();
__decorate([
property({ type: Boolean, reflect: true })
], IgcCheckboxComponent.prototype, "indeterminate", void 0);
IgcCheckboxComponent = IgcCheckboxComponent_1 = __decorate([
themes(all, { exposeController: true })
], IgcCheckboxComponent);
export default IgcCheckboxComponent;
//# sourceMappingURL=checkbox.js.map