@sandlada/mdc
Version:
@sandlada/mdc is an open source component library that follows the Material Design 3 design specifications.
8 lines • 3.01 kB
JavaScript
import{customElement as e}from"../../node_modules/@lit/reactive-element/decorators/custom-element.js";import{property as t}from"../../node_modules/@lit/reactive-element/decorators/property.js";import"../../node_modules/lit/decorators.js";import"../../node_modules/lit/index.js";import{internals as n}from"../../utils/behaviors/element-internals.js";import{composeMixin as r}from"../../utils/compose-mixin/compose-mixin.js";import i from"../../_virtual/_@oxc-project_runtime@0.144.0/helpers/esm/decorate.js";import{BaseButton as a}from"./internal/base-button.js";import{getFormState as o,getFormValue as s,mixinFormAssociated as c}from"../../utils/form/form-associated.js";import{createValidator as l,getValidityAnchor as u,mixinConstraintValidation as d}from"../../utils/behaviors/constraint-validation.js";import{CheckboxValidator as f}from"../../utils/behaviors/validators/checkbox-validator.js";import{RadioValidator as p}from"../../utils/behaviors/validators/radio-validator.js";import{SelectionController as m}from"../../utils/controller/selection-controller.js";
/**
* @license
* Copyright 2025 Kai-Orion & Sandlada
* SPDX-License-Identifier: MIT
*/
let h=class extends r(d,c)(a){static{this.shadowRootOptions={mode:`open`,delegatesFocus:!0}}constructor(){super(),this.type=`checkbox`,this.value=`on`,this.required=!1,this.variant=`filled`,this.checked=!1,this.selectionController=new m(this,{multiple:this.type===`checkbox`,canCancel:this.type===`checkbox`,preventSelectionDuringInitialFocus:this.type===`checkbox`,preventSelectionDuringSwitching:this.type===`checkbox`,getFocusableElement:e=>e}),this.tabIndex=0,this[n].role=this.type}connectedCallback(){super.connectedCallback(),this.hasAttribute(`default-checked`)&&(this.checked=!0)}willUpdate(e){if(super.willUpdate(e),e.has(`type`)){let e=this.type===`checkbox`;this.selectionController.configure({multiple:e,canCancel:e,preventSelectionDuringInitialFocus:e,preventSelectionDuringSwitching:e}),this[n].role=this.type}e.has(`checked`)&&(this[n].ariaChecked=String(this.checked)),e.has(`required`)&&(this[n].ariaRequired=String(this.required))}getRenderClasses(){return{...super.getRenderClasses(),togglable:!0,selected:this.checked,unselected:!this.checked}}[s](){return this.checked?this.value:null}[o](){return String(this.checked)}formResetCallback(){this.checked=this.hasAttribute(`default-checked`)}formStateRestoreCallback(e){this.checked=e===`true`}[l](){return this.type===`radio`?new p(()=>this.selectionController?.controls??[this]):new f(()=>({checked:this.checked??!1,required:this.required??!1}))}[u](){return this.buttonElement}};i([t({type:String,reflect:!0})],h.prototype,`type`,void 0),i([t({type:String})],h.prototype,`value`,void 0),i([t({type:Boolean,reflect:!0})],h.prototype,`required`,void 0),i([t({type:String,reflect:!1})],h.prototype,`variant`,void 0),i([t({type:Boolean,reflect:!0})],h.prototype,`checked`,void 0),h=i([e(`mdc-toggle-button`)],h);export{h as MDCTogglableButton};
//# sourceMappingURL=toggle-button.js.map