UNPKG

@universal-material/web

Version:
101 lines (100 loc) 3.58 kB
import { __decorate } from "tslib"; import { html } from 'lit'; import { customElement, property, query, state } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { styles } from './button.styles.js'; import { UmToggleButton } from './toggle-button.js'; import '../ripple/ripple.js'; let UmButton = class UmButton extends UmToggleButton { constructor() { super(...arguments); /** * The Button variant to render */ this.variant = 'filled'; this.trailingIcon = false; /** * Whether the button has icon or not * * _Note:_ Readonly */ this.hasIcon = false; this.hasSelectionLabel = false; this.animateTextChange = false; } static { this.styles = [UmToggleButton.styles, styles]; } #textSizeObserver; firstUpdated(changedProperties) { super.firstUpdated(changedProperties); this.#textSizeObserver = new ResizeObserver(() => this.#setTextWrapperWidth()); this.#textSizeObserver.observe(this._text); this.#setTextWrapperWidth(); } #setTextWrapperWidth() { const width = `${this._text.offsetWidth}px`; this._textWrapper.style.width = width; const animateTextChange = !!parseInt(width, 10); if (this.animateTextChange === animateTextChange) { return; } setTimeout(() => this.animateTextChange = animateTextChange); } renderContent() { const labelContainerClasses = { animate: this.animateTextChange }; return html ` <span class="icon-container" aria-hidden="true"> <span class="icon icon-default"> <slot name="icon" @slotchange="${this.handleIconSlotChange}"></slot> </span> <span class="icon icon-selected"> <slot name="icon-selected" @slotchange="${this.handleSelectedIconSlotChange}"></slot> </span> </span> <span class="label-container ${classMap(labelContainerClasses)}"> <span id="label"> <span class="label label-default"> <slot></slot> </span> <span class="label label-selected"> <slot name="label-selected" @slotchange="${this.handleSelectedLabelSlotChange}"></slot> </span> </span> </span> `; } handleIconSlotChange(e) { this.hasIcon = e.target.assignedElements({ flatten: true }).length > 0; } handleSelectedLabelSlotChange(e) { this.hasSelectionLabel = e.target.assignedElements({ flatten: true }).length > 0; } }; __decorate([ property({ reflect: true }) ], UmButton.prototype, "variant", void 0); __decorate([ property({ reflect: true }) ], UmButton.prototype, "color", void 0); __decorate([ property({ type: Boolean, attribute: 'trailing-icon', reflect: true }) ], UmButton.prototype, "trailingIcon", void 0); __decorate([ property({ type: Boolean, attribute: 'has-icon', reflect: true }) ], UmButton.prototype, "hasIcon", void 0); __decorate([ property({ type: Boolean, attribute: 'has-selection-label', reflect: true }) ], UmButton.prototype, "hasSelectionLabel", void 0); __decorate([ state() ], UmButton.prototype, "animateTextChange", void 0); __decorate([ query('.label-container', true) ], UmButton.prototype, "_textWrapper", void 0); __decorate([ query('#label', true) ], UmButton.prototype, "_text", void 0); UmButton = __decorate([ customElement('u-button') ], UmButton); export { UmButton }; //# sourceMappingURL=button.js.map