license import { MDCFoundation } from '@material/base/foundation' ; import { MDCSegmentedButtonSegmentAdapter } from './adapter' ; import { attributes , booleans , cssClasses } from './constants' ; const emptyClientRect = { bottom : 0 , height : 0 , left : 0 , right : 0 , top : 0 , width : 0 , } as any ; export class MDCSegmentedButtonSegmentFoundation extends MDCFoundation < MDCSegmentedButtonSegmentAdapter > { static override get defaultAdapter ( ) : MDCSegmentedButtonSegmentAdapter { return { isSingleSelect : ( ) => false , getAttr : ( ) => '' , setAttr : ( ) => undefined , addClass : ( ) => undefined , removeClass : ( ) => undefined , hasClass : ( ) => false , notifySelectedChange : ( ) => undefined , getRootBoundingClientRect : ( ) => emptyClientRect , } ; } constructor ( adapter ? ) { super ( { ... MDCSegmentedButtonSegmentFoundation . defaultAdapter , ... adapter } ) ; } return isSelected ( ) { return this . adapter . hasClass ( cssClasses . SELECTED ) ; } /**
     * Sets segment to be selected
     */ setSelected ( ) { this . adapter . addClass ( cssClasses . SELECTED ) ; this . setAriaAttr ( booleans . TRUE ) ; } /**
     * Sets segment to be not selected
     */ setUnselected ( ) { this . adapter . removeClass ( cssClasses . SELECTED ) ; this . setAriaAttr ( booleans . FALSE ) ; } return getSegmentId ( ) { return this . adapter . getAttr ( attributes . DATA_SEGMENT_ID ) ?? undefined ; } event handleClick ( ) { if ( this . adapter . isSingleSelect ( ) ) { this . setSelected ( ) ; } else { this . toggleSelection ( ) ; } this . adapter . notifySelectedChange ( this . isSelected ( ) ) ; } return getDimensions ( ) { return this . adapter . getRootBoundingClientRect ( ) ; } /**
     * Sets segment from not selected to selected, or selected to not selected
     */ private toggleSelection ( ) { if ( this . isSelected ( ) ) { this . setUnselected ( ) ; } else { this . setSelected ( ) ; } } param value private setAriaAttr ( value ) { if ( this . adapter . isSingleSelect ( ) ) { this . adapter . setAttr ( attributes . ARIA_CHECKED , value ) ; } else { this . adapter . setAttr ( attributes . ARIA_PRESSED , value ) ; } } }