license import { MDCComponent } from '@material/base/component' ; import { SpecificEventListener } from '@material/base/types' ; import { MDCRipple } from '@material/ripple/component' ; import { MDCIconButtonToggleAdapter } from './adapter' ; import { MDCIconButtonToggleFoundation } from './foundation' ; import { MDCIconButtonToggleEventDetail } from './types' ; const { strings } = MDCIconButtonToggleFoundation ; export class MDCIconButtonToggle extends MDCComponent < MDCIconButtonToggleFoundation > { static override attachTo ( root ) { return new MDCIconButtonToggle ( root ) ; } private readonly rippleComponent : MDCRipple = this . createRipple ( ) ; private handleClick ! : SpecificEventListener < 'click' > ; override initialSyncWithDOM ( ) { this . handleClick = ( ) => { this . foundation . handleClick ( ) ; } ; this . listen ( 'click' , this . handleClick ) ; } override destroy ( ) { this . unlisten ( 'click' , this . handleClick ) ; this . ripple . destroy ( ) ; super . destroy ( ) ; } override getDefaultFoundation ( ) { const adapter = { addClass : ( className ) => this . root . classList . add ( className ) , hasClass : ( className ) => this . root . classList . contains ( className ) , notifyChange : ( evtData ) => { this . emit < MDCIconButtonToggleEventDetail > ( strings . CHANGE_EVENT , evtData ) ; } , removeClass : ( className ) => this . root . classList . remove ( className ) , getAttr : ( attrName ) => this . root . getAttribute ( attrName ) , setAttr : ( attrName , attrValue ) => this . root . setAttribute ( attrName , attrValue ) , } ; return new MDCIconButtonToggleFoundation ( adapter ) ; } get ripple ( ) : MDCRipple { return this . rippleComponent ; } get on ( ) : boolean { return this . foundation . isOn ( ) ; } set on ( isOn ) { this . foundation . toggle ( isOn ) ; } private createRipple ( ) { const ripple = new MDCRipple ( this . root ) ; ripple . unbounded = true ; return ripple ; } }