UNPKG

@synergy-design-system/components

Version:

This package provides the base of the Synergy Design System as native web components. It uses [lit](https://www.lit.dev) and parts of [shoelace](https://shoelace.style/). Synergy officially supports the latest two versions of all major browsers (as define

142 lines (139 loc) 4.12 kB
import { radio_button_styles_default } from "./chunk.4BRJ5OJE.js"; import { HasSlotController } from "./chunk.WVVQK5TE.js"; import { enableDefaultSettings } from "./chunk.HYFCK7MM.js"; import { watch } from "./chunk.BVZQ6QSY.js"; import { component_styles_default } from "./chunk.NLYVOJGK.js"; import { SynergyElement } from "./chunk.3THJTCRO.js"; import { __decorateClass } from "./chunk.Z4XV3SMG.js"; // src/components/radio-button/radio-button.component.ts import { classMap } from "lit/directives/class-map.js"; import { html } from "lit/static-html.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { property, query, state } from "lit/decorators.js"; var SynRadioButton = class extends SynergyElement { constructor() { super(...arguments); this.hasSlotController = new HasSlotController(this, "[default]", "prefix", "suffix"); this.hasFocus = false; this.checked = false; this.disabled = false; this.size = "medium"; this.pill = false; } connectedCallback() { super.connectedCallback(); this.setAttribute("role", "presentation"); } handleBlur() { this.hasFocus = false; this.emit("syn-blur"); } handleClick(e) { if (this.disabled) { e.preventDefault(); e.stopPropagation(); return; } this.checked = true; } handleFocus() { this.hasFocus = true; this.emit("syn-focus"); } handleDisabledChange() { this.setAttribute("aria-disabled", this.disabled ? "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--default": true, "button--small": this.size === "small", "button--medium": this.size === "medium", "button--large": this.size === "large", "button--checked": this.checked, "button--disabled": this.disabled, "button--focused": this.hasFocus, "button--outline": true, "button--pill": this.pill, "button--has-label": this.hasSlotController.test("[default]"), "button--has-prefix": this.hasSlotController.test("prefix"), "button--has-suffix": this.hasSlotController.test("suffix") })} aria-disabled=${this.disabled} type="button" value=${ifDefined(this.value)} @blur=${this.handleBlur} @focus=${this.handleFocus} @click=${this.handleClick} > <slot name="prefix" part="prefix" class="button__prefix"></slot> <slot part="label" class="button__label"></slot> <slot name="suffix" part="suffix" class="button__suffix"></slot> </button> </div> `; } }; SynRadioButton.styles = [component_styles_default, radio_button_styles_default]; __decorateClass([ query(".button") ], SynRadioButton.prototype, "input", 2); __decorateClass([ query(".hidden-input") ], SynRadioButton.prototype, "hiddenInput", 2); __decorateClass([ state() ], SynRadioButton.prototype, "hasFocus", 2); __decorateClass([ property({ type: Boolean, reflect: true }) ], SynRadioButton.prototype, "checked", 2); __decorateClass([ property() ], SynRadioButton.prototype, "value", 2); __decorateClass([ property({ type: Boolean, reflect: true }) ], SynRadioButton.prototype, "disabled", 2); __decorateClass([ property({ reflect: true }) ], SynRadioButton.prototype, "size", 2); __decorateClass([ property({ type: Boolean, reflect: true }) ], SynRadioButton.prototype, "pill", 2); __decorateClass([ watch("disabled", { waitUntilFirstUpdate: true }) ], SynRadioButton.prototype, "handleDisabledChange", 1); SynRadioButton = __decorateClass([ enableDefaultSettings("SynRadioButton") ], SynRadioButton); export { SynRadioButton }; //# sourceMappingURL=chunk.WHX74UIY.js.map