import { Component, Event, EventEmitter, Method, Prop, State, h } from '@stencil/core'; /** * @since 1.0 * @status stable * * @slot - The button's label. * @slot prefix - Used to prepend an icon or similar element to the button. * @slot suffix - Used to append an icon or similar element to the button. * * @part base - The component's base wrapper. * @part prefix - The prefix container. * @part label - The button's label. * @part suffix - The suffix container. * @part caret - The button's caret. */ @Component({ tag: 'sl-button', styleUrl: 'button.scss', shadow: true }) export class Button { constructor() { this.handleBlur = this.handleBlur.bind(this); this.handleFocus = this.handleFocus.bind(this); this.handleClick = this.handleClick.bind(this); } button: HTMLButtonElement; @State() hasFocus = false; /** The button's type. */ @Prop() type: 'default' | 'primary' | 'success' | 'info' | 'warning' | 'danger' | 'text' = 'default'; /** The button's size. */ @Prop() size: 'small' | 'medium' | 'large' = 'medium'; /** Set to true to draw the button with a caret for use with dropdowns, popovers, etc. */ @Prop() caret = false; /** Set to true to disable the button. */ @Prop() disabled = false; /** Set to true to draw the button in a loading state. */ @Prop() loading = false; /** An optional name for the button. */ @Prop() name: string; /** Set to true to draw a pill-style button with rounded edges. */ @Prop() pill = false; /** Set to true to draw a circle button. */ @Prop() circle = false; /** An optional value for the button. */ @Prop() value: string; /** Indicates if activating the button should submit the form. */ @Prop() submit = false; /** Emitted when the button loses focus. */ @Event() slBlur: EventEmitter; /** Emitted when the button gains focus. */ @Event() slFocus: EventEmitter; /** Sets focus on the button. */ @Method() async setFocus() { this.button.focus(); } /** Removes focus from the button. */ @Method() async removeFocus() { this.button.blur(); } handleBlur() { this.hasFocus = false; this.slBlur.emit(); } handleFocus() { this.hasFocus = true; this.slFocus.emit(); } handleClick(event: MouseEvent) { if (this.disabled || this.loading) { event.preventDefault(); event.stopPropagation(); } } render() { return ( ); } }