@synergy-design-system/components
Version:
163 lines (160 loc) • 4.98 kB
JavaScript
import {
button_styles_default
} from "./chunk.7B5F2HYP.js";
import {
radio_button_styles_default
} from "./chunk.IQMSCZYA.js";
import {
HasSlotController,
getTextContent
} from "./chunk.CHFWLQN5.js";
import {
enableDefaultSettings
} from "./chunk.WYMKPLYK.js";
import {
watch
} from "./chunk.UR2E7Y2Q.js";
import {
component_styles_default
} from "./chunk.2NT3B5WJ.js";
import {
SynergyElement
} from "./chunk.L2IYPRPF.js";
import {
__decorateClass
} from "./chunk.VK2FVWOF.js";
// src/components/radio-button/radio-button.component.ts
import { html } from "lit";
import { property, query, state } from "lit/decorators.js";
import { ifDefined } from "lit/directives/if-defined.js";
import { classMap } from "lit/directives/class-map.js";
var SynRadioButton = class extends SynergyElement {
constructor() {
super(...arguments);
this.hasSlotController = new HasSlotController(this, "[default]", "prefix", "suffix");
this.hasFocus = false;
this.iconOnly = false;
this.checked = false;
this.disabled = false;
this.readonly = false;
this.size = "medium";
}
connectedCallback() {
super.connectedCallback();
this.setAttribute("role", "presentation");
}
isDisabled() {
return this.disabled || this.readonly;
}
handleBlur() {
this.hasFocus = false;
this.emit("syn-blur");
}
handleClick(e) {
if (this.isDisabled()) {
e.preventDefault();
e.stopPropagation();
return;
}
this.checked = true;
}
handleFocus() {
this.hasFocus = true;
this.emit("syn-focus");
}
handleSlotChange() {
const textContent = getTextContent(this.defaultSlot).trim();
const assignedElements = this.defaultSlot.assignedElements({ flatten: true });
const iconOnlyElement = assignedElements.length === 1 && assignedElements[0].tagName.toLowerCase() === "syn-icon";
this.iconOnly = iconOnlyElement && textContent === "";
}
handleDisabledChange() {
this.setAttribute("aria-disabled", this.isDisabled() ? "true" : "false");
}
/** Sets focus on the radio button. */
focus(options) {
this.input.focus(options);
}
/** Removes focus from the radio button. */
blur() {
this.input.blur();
}
render() {
return html`
<div part="base" role="presentation">
<button
part="${`button${this.checked ? " button--checked" : ""}`}"
role="radio"
aria-checked="${this.checked}"
class=${classMap({
button: true,
"button--checked": this.checked,
"button--default": true,
"button--disabled": this.disabled,
"button--filled": this.checked,
"button--focused": this.hasFocus,
"button--has-label": this.hasSlotController.test("[default]"),
"button--has-prefix": this.hasSlotController.test("prefix"),
"button--has-suffix": this.hasSlotController.test("suffix"),
"button--icon-only": this.iconOnly,
"button--large": this.size === "large",
"button--medium": this.size === "medium",
"button--primary": true,
"button--readonly": this.readonly,
"button--small": this.size === "small",
"button--text": !this.checked
})}
aria-disabled=${this.disabled}
type="button"
tabindex=${ifDefined(this.disabled ? "-1" : void 0)}
value=${ifDefined(this.value)}
=${this.handleBlur}
=${this.handleFocus}
=${this.handleClick}
>
<slot name="prefix" part="prefix" class="button__prefix"></slot>
<slot part="label" class="button__label" =${this.handleSlotChange}></slot>
<slot name="suffix" part="suffix" class="button__suffix"></slot>
</button>
</div>
`;
}
};
SynRadioButton.styles = [component_styles_default, button_styles_default, radio_button_styles_default];
__decorateClass([
query(".button")
], SynRadioButton.prototype, "input", 2);
__decorateClass([
query("slot:not([name])")
], SynRadioButton.prototype, "defaultSlot", 2);
__decorateClass([
state()
], SynRadioButton.prototype, "hasFocus", 2);
__decorateClass([
state()
], SynRadioButton.prototype, "iconOnly", 2);
__decorateClass([
property({ reflect: true, type: Boolean })
], SynRadioButton.prototype, "checked", 2);
__decorateClass([
property()
], SynRadioButton.prototype, "value", 2);
__decorateClass([
property({ reflect: true, type: Boolean })
], SynRadioButton.prototype, "disabled", 2);
__decorateClass([
property({ reflect: true, type: Boolean })
], SynRadioButton.prototype, "readonly", 2);
__decorateClass([
property({ reflect: true })
], SynRadioButton.prototype, "size", 2);
__decorateClass([
watch(["disabled", "readonly"], { waitUntilFirstUpdate: true })
], SynRadioButton.prototype, "handleDisabledChange", 1);
SynRadioButton = __decorateClass([
enableDefaultSettings("SynRadioButton")
], SynRadioButton);
export {
SynRadioButton
};
//# sourceMappingURL=chunk.FBQCW73F.js.map