license import { MDCComponent } from '@material/base/component' ; import { SpecificEventListener } from '@material/base/types' ; import { MDCRippleAdapter } from '@material/ripple/adapter' ; import { MDCRipple , MDCRippleFactory } from '@material/ripple/component' ; import { MDCRippleFoundation } from '@material/ripple/foundation' ; import { MDCRippleCapableSurface } from '@material/ripple/types' ; import { MDCChipTrailingActionAdapter } from './adapter' ; import { strings } from './constants' ; import { MDCChipTrailingActionFoundation } from './foundation' ; import { MDCChipTrailingActionInteractionEventDetail , MDCChipTrailingActionNavigationEventDetail } from './types' ; /**
 * Creates a trailing action component on the given element.
 */ export type MDCChipTrailingActionFactory = ( el : Element , foundation ? : MDCChipTrailingActionFoundation ) => MDCChipTrailingAction ; export class MDCChipTrailingAction extends MDCComponent < MDCChipTrailingActionFoundation > implements MDCRippleCapableSurface { get ripple ( ) : MDCRipple { return this . rippleSurface ; } static override attachTo ( root ) { return new MDCChipTrailingAction ( root ) ; } private rippleSurface ! : MDCRipple ; private handleClick ! : SpecificEventListener < 'click' > ; private handleKeydown ! : SpecificEventListener < 'keydown' > ; override initialize ( rippleFactory = ( el , foundation ) => new MDCRipple ( el , foundation ) ) { const rippleAdapter = MDCRipple . createAdapter ( this ) ; this . rippleSurface = rippleFactory ( this . root , new MDCRippleFoundation ( rippleAdapter ) ) ; } override initialSyncWithDOM ( ) { this . handleClick = ( evt ) => { this . foundation . handleClick ( evt ) ; } ; this . handleKeydown = ( evt ) => { this . foundation . handleKeydown ( evt ) ; } ; this . listen ( 'click' , this . handleClick ) ; this . listen ( 'keydown' , this . handleKeydown ) ; } override destroy ( ) { this . rippleSurface . destroy ( ) ; this . unlisten ( 'click' , this . handleClick ) ; this . unlisten ( 'keydown' , this . handleKeydown ) ; super . destroy ( ) ; } override getDefaultFoundation ( ) { const adapter = { focus : ( ) => { ( this . root as HTMLElement ) . focus ( ) ; } , getAttribute : ( attr ) => this . root . getAttribute ( attr ) , notifyInteraction : ( trigger ) => this . emit < MDCChipTrailingActionInteractionEventDetail > ( strings . INTERACTION_EVENT , { trigger } , true ) , notifyNavigation : ( key ) => { this . emit < MDCChipTrailingActionNavigationEventDetail > ( strings . NAVIGATION_EVENT , { key } , true ) ; } , setAttribute : ( attr , value ) => { this . root . setAttribute ( attr , value ) ; } , } ; return new MDCChipTrailingActionFoundation ( adapter ) ; } isNavigable ( ) { return this . foundation . isNavigable ( ) ; } focus ( ) { this . foundation . focus ( ) ; } removeFocus ( ) { this . foundation . removeFocus ( ) ; } }