UNPKG

@shoelace-style/shoelace

Version:

A forward-thinking library of web components.

127 lines (124 loc) 3.46 kB
import { icon_button_styles_default } from "./chunk.6I2T3DLI.js"; import { SlIcon } from "./chunk.E6QAPUBK.js"; import { component_styles_default } from "./chunk.TUVJKY7S.js"; import { ShoelaceElement } from "./chunk.UYAO2JRR.js"; import { __decorateClass } from "./chunk.B3BW2AY6.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 SlIconButton = class extends ShoelaceElement { constructor() { super(...arguments); this.hasFocus = false; this.label = ""; this.disabled = false; } handleBlur() { this.hasFocus = false; this.emit("sl-blur"); } handleFocus() { this.hasFocus = true; this.emit("sl-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(); } render() { const isLink = this.href ? true : false; 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 })} ?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} > <sl-icon class="icon-button__icon" name=${ifDefined(this.name)} library=${ifDefined(this.library)} src=${ifDefined(this.src)} aria-hidden="true" ></sl-icon> </${tag}> `; } }; SlIconButton.styles = [component_styles_default, icon_button_styles_default]; SlIconButton.dependencies = { "sl-icon": SlIcon }; __decorateClass([ query(".icon-button") ], SlIconButton.prototype, "button", 2); __decorateClass([ state() ], SlIconButton.prototype, "hasFocus", 2); __decorateClass([ property() ], SlIconButton.prototype, "name", 2); __decorateClass([ property() ], SlIconButton.prototype, "library", 2); __decorateClass([ property() ], SlIconButton.prototype, "src", 2); __decorateClass([ property() ], SlIconButton.prototype, "href", 2); __decorateClass([ property() ], SlIconButton.prototype, "target", 2); __decorateClass([ property() ], SlIconButton.prototype, "download", 2); __decorateClass([ property() ], SlIconButton.prototype, "label", 2); __decorateClass([ property({ type: Boolean, reflect: true }) ], SlIconButton.prototype, "disabled", 2); export { SlIconButton };