Korbs/Contour
Archived
Template
1
Fork 0
This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
Contour/public/@shoelace-style/shoelace/cdn/chunks/chunk.7GGMETWH.js
2024-01-30 10:59:28 -05:00

221 lines
5.6 KiB
JavaScript

import {
switch_styles_default
} from "./chunk.5MHKN5YK.js";
import {
l
} from "./chunk.MB643KRE.js";
import {
defaultValue
} from "./chunk.RQ7JZ4R7.js";
import {
FormControlController
} from "./chunk.NMS6LWK4.js";
import {
o
} from "./chunk.2URMUHDY.js";
import {
e
} from "./chunk.UZVKBFXH.js";
import {
watch
} from "./chunk.FA5RT4K4.js";
import {
ShoelaceElement,
e as e2,
n,
r
} from "./chunk.SEXBCYCU.js";
import {
x
} from "./chunk.CXZZ2LVK.js";
import {
__decorateClass
} from "./chunk.KIILAQWQ.js";
// src/components/switch/switch.component.ts
var SlSwitch = class extends ShoelaceElement {
constructor() {
super(...arguments);
this.formControlController = new FormControlController(this, {
value: (control) => control.checked ? control.value || "on" : void 0,
defaultValue: (control) => control.defaultChecked,
setValue: (control, checked) => control.checked = checked
});
this.hasFocus = false;
this.title = "";
this.name = "";
this.size = "medium";
this.disabled = false;
this.checked = false;
this.defaultChecked = false;
this.form = "";
this.required = false;
}
/** Gets the validity state object */
get validity() {
return this.input.validity;
}
/** Gets the validation message */
get validationMessage() {
return this.input.validationMessage;
}
firstUpdated() {
this.formControlController.updateValidity();
}
handleBlur() {
this.hasFocus = false;
this.emit("sl-blur");
}
handleInput() {
this.emit("sl-input");
}
handleInvalid(event) {
this.formControlController.setValidity(false);
this.formControlController.emitInvalidEvent(event);
}
handleClick() {
this.checked = !this.checked;
this.emit("sl-change");
}
handleFocus() {
this.hasFocus = true;
this.emit("sl-focus");
}
handleKeyDown(event) {
if (event.key === "ArrowLeft") {
event.preventDefault();
this.checked = false;
this.emit("sl-change");
this.emit("sl-input");
}
if (event.key === "ArrowRight") {
event.preventDefault();
this.checked = true;
this.emit("sl-change");
this.emit("sl-input");
}
}
handleCheckedChange() {
this.input.checked = this.checked;
this.formControlController.updateValidity();
}
handleDisabledChange() {
this.formControlController.setValidity(true);
}
/** Simulates a click on the switch. */
click() {
this.input.click();
}
/** Sets focus on the switch. */
focus(options) {
this.input.focus(options);
}
/** Removes focus from the switch. */
blur() {
this.input.blur();
}
/** Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. */
checkValidity() {
return this.input.checkValidity();
}
/** Gets the associated form, if one exists. */
getForm() {
return this.formControlController.getForm();
}
/** Checks for validity and shows the browser's validation message if the control is invalid. */
reportValidity() {
return this.input.reportValidity();
}
/** Sets a custom validation message. Pass an empty string to restore validity. */
setCustomValidity(message) {
this.input.setCustomValidity(message);
this.formControlController.updateValidity();
}
render() {
return x`
<label
part="base"
class=${e({
switch: true,
"switch--checked": this.checked,
"switch--disabled": this.disabled,
"switch--focused": this.hasFocus,
"switch--small": this.size === "small",
"switch--medium": this.size === "medium",
"switch--large": this.size === "large"
})}
>
<input
class="switch__input"
type="checkbox"
title=${this.title}
name=${this.name}
value=${o(this.value)}
.checked=${l(this.checked)}
.disabled=${this.disabled}
.required=${this.required}
role="switch"
aria-checked=${this.checked ? "true" : "false"}
@click=${this.handleClick}
@input=${this.handleInput}
@invalid=${this.handleInvalid}
@blur=${this.handleBlur}
@focus=${this.handleFocus}
@keydown=${this.handleKeyDown}
/>
<span part="control" class="switch__control">
<span part="thumb" class="switch__thumb"></span>
</span>
<div part="label" class="switch__label">
<slot></slot>
</div>
</label>
`;
}
};
SlSwitch.styles = switch_styles_default;
__decorateClass([
e2('input[type="checkbox"]')
], SlSwitch.prototype, "input", 2);
__decorateClass([
r()
], SlSwitch.prototype, "hasFocus", 2);
__decorateClass([
n()
], SlSwitch.prototype, "title", 2);
__decorateClass([
n()
], SlSwitch.prototype, "name", 2);
__decorateClass([
n()
], SlSwitch.prototype, "value", 2);
__decorateClass([
n({ reflect: true })
], SlSwitch.prototype, "size", 2);
__decorateClass([
n({ type: Boolean, reflect: true })
], SlSwitch.prototype, "disabled", 2);
__decorateClass([
n({ type: Boolean, reflect: true })
], SlSwitch.prototype, "checked", 2);
__decorateClass([
defaultValue("checked")
], SlSwitch.prototype, "defaultChecked", 2);
__decorateClass([
n({ reflect: true })
], SlSwitch.prototype, "form", 2);
__decorateClass([
n({ type: Boolean, reflect: true })
], SlSwitch.prototype, "required", 2);
__decorateClass([
watch("checked", { waitUntilFirstUpdate: true })
], SlSwitch.prototype, "handleCheckedChange", 1);
__decorateClass([
watch("disabled", { waitUntilFirstUpdate: true })
], SlSwitch.prototype, "handleDisabledChange", 1);
export {
SlSwitch
};