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.
62 lines • 2.16 kB
JavaScript
import { html } from 'lit';
import { ifDefined } from 'lit/directives/if-defined.js';
import { live } from 'lit/directives/live.js';
import { addThemingController } from '../../theming/theming-controller.js';
import { registerComponent } from '../common/definitions/register.js';
import { partMap } from '../common/part-map.js';
import { IgcCheckboxBaseComponent } from './checkbox-base.js';
import { styles as shared } from './themes/shared/switch/switch.common.css.js';
import { styles } from './themes/switch.base.css.js';
import { all } from './themes/switch-themes.js';
let nextId = 1;
class IgcSwitchComponent extends IgcCheckboxBaseComponent {
static register() {
registerComponent(IgcSwitchComponent);
}
constructor() {
super();
this._inputId = `switch-${nextId++}`;
this._labelId = `switch-label-${this._inputId}`;
addThemingController(this, all);
}
render() {
const labelledBy = this.getAttribute('aria-labelledby');
const checked = this.checked;
return html `
<label part=${partMap({ base: true, checked })} for=${this._inputId}>
<input
id=${this._inputId}
type="checkbox"
name=${ifDefined(this.name)}
value=${ifDefined(this.value)}
?required=${this.required}
?disabled=${this.disabled}
.checked=${live(checked)}
aria-labelledby=${labelledBy ? labelledBy : this._labelId}
@click=${this._handleClick}
@blur=${this._handleBlur}
/>
<span
part=${partMap({
control: true,
checked,
focused: this._focusRingManager.focused,
})}
>
<span part=${partMap({ thumb: true, checked })}></span>
</span>
<span
id=${this._labelId}
part=${partMap({ label: true, checked })}
?hidden=${this._hideLabel}
>
<slot></slot>
</span>
</label>
`;
}
}
IgcSwitchComponent.tagName = 'igc-switch';
IgcSwitchComponent.styles = [styles, shared];
export default IgcSwitchComponent;
//# sourceMappingURL=switch.js.map