UNPKG

@synergy-design-system/components

Version:
146 lines (143 loc) 4.1 kB
import { icon_button_styles_default } from "./chunk.3U6C42N7.js"; import { SynIcon } from "./chunk.KODS2CCZ.js"; import { enableDefaultSettings } from "./chunk.WYMKPLYK.js"; import { component_styles_default } from "./chunk.2NT3B5WJ.js"; import { SynergyElement } from "./chunk.L2IYPRPF.js"; import { __decorateClass } from "./chunk.VK2FVWOF.js"; // src/components/icon-button/icon-button.component.ts import { classMap } from "lit/directives/class-map.js"; import { html, literal } from "lit/static-html.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { property, query, state } from "lit/decorators.js"; var SynIconButton = class extends SynergyElement { constructor() { super(...arguments); this.hasFocus = false; this.label = ""; this.size = "inherit"; this.color = "currentColor"; this.disabled = false; } handleBlur() { this.hasFocus = false; this.emit("syn-blur"); } handleFocus() { this.hasFocus = true; this.emit("syn-focus"); } handleClick(event) { if (this.disabled) { event.preventDefault(); event.stopPropagation(); } } /** Simulates a click on the icon button. */ click() { this.button.click(); } /** Sets focus on the icon button. */ focus(options) { this.button.focus(options); } /** Removes focus from the icon button. */ blur() { this.button.blur(); } // eslint-disable-next-line complexity render() { const isLink = !!this.href; const tag = isLink ? literal`a` : literal`button`; return html` <${tag} part="base" class=${classMap({ "icon-button": true, "icon-button--disabled": !isLink && this.disabled, "icon-button--focused": this.hasFocus, "icon-button--large": this.size === "large", "icon-button--medium": this.size === "medium", "icon-button--small": this.size === "small" })} ?disabled=${ifDefined(isLink ? void 0 : this.disabled)} type=${ifDefined(isLink ? void 0 : "button")} href=${ifDefined(isLink ? this.href : void 0)} target=${ifDefined(isLink ? this.target : void 0)} download=${ifDefined(isLink ? this.download : void 0)} rel=${ifDefined(isLink && this.target ? "noreferrer noopener" : void 0)} role=${ifDefined(isLink ? void 0 : "button")} aria-disabled=${this.disabled ? "true" : "false"} aria-label="${this.label}" tabindex=${this.disabled ? "-1" : "0"} @blur=${this.handleBlur} @focus=${this.handleFocus} @click=${this.handleClick} > <syn-icon class="icon-button__icon" name=${ifDefined(this.name)} library=${ifDefined(this.library)} src=${ifDefined(this.src)} aria-hidden="true" ></syn-icon> </${tag}> `; } }; SynIconButton.styles = [component_styles_default, icon_button_styles_default]; SynIconButton.dependencies = { "syn-icon": SynIcon }; __decorateClass([ query(".icon-button") ], SynIconButton.prototype, "button", 2); __decorateClass([ state() ], SynIconButton.prototype, "hasFocus", 2); __decorateClass([ property() ], SynIconButton.prototype, "name", 2); __decorateClass([ property() ], SynIconButton.prototype, "library", 2); __decorateClass([ property() ], SynIconButton.prototype, "src", 2); __decorateClass([ property() ], SynIconButton.prototype, "href", 2); __decorateClass([ property() ], SynIconButton.prototype, "target", 2); __decorateClass([ property() ], SynIconButton.prototype, "download", 2); __decorateClass([ property() ], SynIconButton.prototype, "label", 2); __decorateClass([ property({ reflect: true }) ], SynIconButton.prototype, "size", 2); __decorateClass([ property({ reflect: true }) ], SynIconButton.prototype, "color", 2); __decorateClass([ property({ reflect: true, type: Boolean }) ], SynIconButton.prototype, "disabled", 2); SynIconButton = __decorateClass([ enableDefaultSettings("SynIconButton") ], SynIconButton); export { SynIconButton }; //# sourceMappingURL=chunk.5XHXH7QA.js.map