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 { SegmentDetail } from '../types' ; import { MDCSegmentedButtonSegmentAdapter } from './adapter' ; import { events } from './constants' ; import { MDCSegmentedButtonSegmentFoundation } from './foundation' ; /**
 * MDCSegmentedButtonSegment factory type.
 */ export type MDCSegmentedButtonSegmentFactory = ( el : Element , foundation ? : MDCSegmentedButtonSegmentFoundation ) => MDCSegmentedButtonSegment ; /**
 * Implementation of MDCSegmentedButtonSegmentFoundation
 */ export class MDCSegmentedButtonSegment extends MDCComponent < MDCSegmentedButtonSegmentFoundation > implements MDCRippleCapableSurface { get ripple ( ) : MDCRipple { return this . rippleComponent ; } static override attachTo ( root ) { return new MDCSegmentedButtonSegment ( root ) ; } private index ! : number ; private isSingleSelect ! : boolean ; private rippleComponent ! : MDCRipple ; private handleClick ! : SpecificEventListener < 'click' > ; override initialize ( rippleFactory = ( el , foundation ) => new MDCRipple ( el , foundation ) ) { const rippleAdapter = { ... MDCRipple . createAdapter ( this ) , computeBoundingRect : ( ) => this . foundation . getDimensions ( ) } ; this . rippleComponent = rippleFactory ( this . root , new MDCRippleFoundation ( rippleAdapter ) ) ; } override initialSyncWithDOM ( ) { this . handleClick = ( ) => { this . foundation . handleClick ( ) ; } ; this . listen ( events . CLICK , this . handleClick ) ; } override destroy ( ) { this . ripple . destroy ( ) ; this . unlisten ( events . CLICK , this . handleClick ) ; super . destroy ( ) ; } override getDefaultFoundation ( ) { const adapter = { isSingleSelect : ( ) => { return this . isSingleSelect ; } , getAttr : ( attrName ) => { return this . root . getAttribute ( attrName ) ; } , setAttr : ( attrName , value ) => { this . root . setAttribute ( attrName , value ) ; } , addClass : ( className ) => { this . root . classList . add ( className ) ; } , removeClass : ( className ) => { this . root . classList . remove ( className ) ; } , hasClass : ( className ) => { return this . root . classList . contains ( className ) ; } , notifySelectedChange : ( selected ) => { this . emit < SegmentDetail > ( events . SELECTED , { index : this . index , selected , segmentId : this . getSegmentId ( ) } , true ) ; } , getRootBoundingClientRect : ( ) => { return this . root . getBoundingClientRect ( ) ; } } ; return new MDCSegmentedButtonSegmentFoundation ( adapter ) ; } param index setIndex ( index ) { this . index = index ; } param isSingleSelect setIsSingleSelect ( isSingleSelect ) { this . isSingleSelect = isSingleSelect ; } return isSelected ( ) { return this . foundation . isSelected ( ) ; } /**
     * Sets segment to be selected
     */ setSelected ( ) { this . foundation . setSelected ( ) ; } /**
     * Sets segment to be not selected
     */ setUnselected ( ) { this . foundation . setUnselected ( ) ; } return getSegmentId ( ) { return this . foundation . getSegmentId ( ) ; } }