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.
65 lines • 2.38 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 { createCounter } from '../common/util.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';
class IgcSwitchComponent extends IgcCheckboxBaseComponent {
static register() {
registerComponent(IgcSwitchComponent);
}
constructor() {
super();
this._inputId = `switch-${IgcSwitchComponent.increment()}`;
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-checked=${checked ? 'true' : 'false'}
aria-disabled=${this.disabled ? 'true' : 'false'}
aria-labelledby=${labelledBy ? labelledBy : this._labelId}
@click=${this._handleClick}
@focus=${this._handleFocus}
/>
<span
part=${partMap({
control: true,
checked,
focused: this._focusRingManager.focused,
})}
>
<span part=${partMap({ thumb: true, checked })}></span>
</span>
<span
.hidden=${this._hideLabel}
part=${partMap({ label: true, checked })}
id=${this._labelId}
>
<slot></slot>
</span>
</label>
`;
}
}
IgcSwitchComponent.tagName = 'igc-switch';
IgcSwitchComponent.styles = [styles, shared];
IgcSwitchComponent.increment = createCounter();
export default IgcSwitchComponent;
//# sourceMappingURL=switch.js.map