license import { MDCComponent } from '@material/base/component' ; import { MDCRippleAdapter } from '@material/ripple/adapter' ; import { MDCRipple } from '@material/ripple/component' ; import { MDCRippleFoundation } from '@material/ripple/foundation' ; import { MDCRippleCapableSurface } from '@material/ripple/types' ; import { MDCSwitchRenderAdapter , MDCSwitchState } from './adapter' ; import { Selectors } from './constants' ; import { MDCSwitchRenderFoundation } from './foundation' ; /**
 * `MDCSwitch` provides a component implementation of a Material Design switch.
 */ export class MDCSwitch extends MDCComponent < MDCSwitchRenderFoundation > implements MDCSwitchState , MDCRippleCapableSurface { param root return static override attachTo ( root ) { return new MDCSwitch ( root ) ; } disabled ! : boolean ; processing ! : boolean ; selected ! : boolean ; ripple ! : MDCRipple ; private rippleElement ! : Element ; constructor ( public override root , foundation ? ) { super ( root , foundation ) ; } override initialize ( ) { this . ripple = new MDCRipple ( this . root , this . createRippleFoundation ( ) ) ; } override initialSyncWithDOM ( ) { const rippleElement = this . root . querySelector ( Selectors . RIPPLE ) ; if ( ! rippleElement ) { throw new Error ( `Switch ${ Selectors . RIPPLE } element is required.` ) ; } this . rippleElement = rippleElement ; this . root . addEventListener ( 'click' , this . foundation . handleClick ) ; this . foundation . initFromDOM ( ) ; } override destroy ( ) { super . destroy ( ) ; this . ripple . destroy ( ) ; this . root . removeEventListener ( 'click' , this . foundation . handleClick ) ; } override getDefaultFoundation ( ) { return new MDCSwitchRenderFoundation ( this . createAdapter ( ) ) ; } protected createAdapter ( ) { return { addClass : className => { this . root . classList . add ( className ) ; } , hasClass : className => this . root . classList . contains ( className ) , isDisabled : ( ) => this . root . disabled , removeClass : className => { this . root . classList . remove ( className ) ; } , setAriaChecked : ariaChecked => this . root . setAttribute ( 'aria-checked' , ariaChecked ) , setDisabled : disabled => { this . root . disabled = disabled ; } , state : this , } ; } protected createRippleFoundation ( ) { return new MDCRippleFoundation ( this . createRippleAdapter ( ) ) ; } protected createRippleAdapter ( ) { return { ... MDCRipple . createAdapter ( this ) , computeBoundingRect : ( ) => this . rippleElement . getBoundingClientRect ( ) , isUnbounded : ( ) => true , } ; } }