@spectrum-web-components/button
Version:
An `<sp-button>` represents an action a user can take. sp-buttons can be clicked or tapped to perform an action or to navigate to another page. Buttons in Spectrum have several variations for different uses and multiple levels of loudness for various atte
6 lines (5 loc) • 2.35 kB
JavaScript
"use strict";var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var e=(o,i,t,n)=>{for(var r=n>1?void 0:n?u(i,t):i,s=o.length-1,l;s>=0;s--)(l=o[s])&&(r=(n?l(i,t,r):l(r))||r);return n&&r&&c(i,t,r),r};import{html as p,SizedMixin as d}from"@spectrum-web-components/base";import{property as a}from"@spectrum-web-components/base/src/decorators.js";import{ButtonBase as h}from"./ButtonBase.js";import b from"./button.css.js";import{PendingStateController as w}from"@spectrum-web-components/reactive-controllers/src/PendingState.js";export const VALID_VARIANTS=["accent","primary","secondary","negative","white","black"],VALID_STATIC_COLORS=["white","black"];export class Button extends d(h,{noDefaultSize:!0}){constructor(){super();this.pendingLabel="Pending";this.pending=!1;this._variant="accent";this.treatment="fill";this.noWrap=!1;this.pendingStateController=new w(this)}static get styles(){return[...super.styles,b]}click(){this.pending||super.click()}get variant(){return this._variant}set variant(t){if(t!==this.variant){switch(this.requestUpdate("variant",this.variant),t){case"cta":this._variant="accent";break;case"overBackground":this.removeAttribute("variant"),this.staticColor="white",this.treatment="outline";return;case"white":this.staticColor="white";return;case"black":this.staticColor="black";return;case null:return;default:VALID_VARIANTS.includes(t)?this._variant=t:this._variant="accent";break}this.setAttribute("variant",this.variant)}}set quiet(t){this.treatment=t?"outline":"fill"}get quiet(){return this.treatment==="outline"}firstUpdated(t){super.firstUpdated(t),this.hasAttribute("variant")||this.setAttribute("variant",this.variant),this.pending&&this.pendingStateController.hostUpdated()}renderButton(){return p`
${this.buttonContent}
${this.pendingStateController.renderPendingState()}
`}}e([a({type:String,attribute:"pending-label"})],Button.prototype,"pendingLabel",2),e([a({type:Boolean,reflect:!0,attribute:!0})],Button.prototype,"pending",2),e([a()],Button.prototype,"variant",1),e([a({reflect:!0,attribute:"static-color"})],Button.prototype,"staticColor",2),e([a({reflect:!0})],Button.prototype,"treatment",2),e([a({type:Boolean})],Button.prototype,"quiet",1),e([a({type:Boolean,attribute:"no-wrap",reflect:!0})],Button.prototype,"noWrap",2);
//# sourceMappingURL=Button.js.map