11/**
22 * @license
3- * Copyright 2021 Google LLC
3+ * Copyright 2022 Google LLC
44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7- import '@material/mwc- ripple/mwc- ripple.js' ;
7+ import '../../ ripple/ripple.js' ;
88
9- import { Ripple } from '@material/mwc-ripple/mwc-ripple.js' ;
10- import { RippleHandlers } from '@material/mwc-ripple/ripple-handlers.js' ;
11- import { html , LitElement , TemplateResult } from 'lit' ;
12- import { eventOptions , property , queryAsync , state } from 'lit/decorators.js' ;
9+ import { html , TemplateResult } from 'lit' ;
10+ import { property , query } from 'lit/decorators.js' ;
1311import { ClassInfo , classMap } from 'lit/directives/class-map.js' ;
1412
13+ import { ActionElement , BeginPressConfig , EndPressConfig } from '../../action-element/action-element.js' ;
14+ import { MdRipple } from '../../ripple/ripple.js' ;
15+
1516/**
16- * Fab Base class logic and template definition
1717 * @soyCompatible
1818 */
19- export class FabShared extends LitElement {
19+ export class FabShared extends ActionElement {
2020 static override shadowRootOptions :
2121 ShadowRootInit = { mode : 'open' , delegatesFocus : true } ;
2222
23- @queryAsync ( 'mwc-ripple' ) ripple ! : Promise < Ripple | null > ;
24-
2523 @property ( { type : Boolean } ) disabled = false ;
2624
2725 @property ( ) icon = '' ;
@@ -32,12 +30,7 @@ export class FabShared extends LitElement {
3230
3331 @property ( { type : Boolean } ) reducedTouchTarget = false ;
3432
35- @state ( ) protected shouldRenderRipple = false ;
36-
37- protected rippleHandlers = new RippleHandlers ( ( ) => {
38- this . shouldRenderRipple = true ;
39- return this . ripple ;
40- } ) ;
33+ @query ( 'md-ripple' ) ripple ! : MdRipple ;
4134
4235 /**
4336 * @soyTemplate
@@ -46,35 +39,29 @@ export class FabShared extends LitElement {
4639 protected override render ( ) : TemplateResult {
4740 const ariaLabel = this . label ? this . label : this . icon ;
4841
49- /*
50- * Some internal styling is sensitive to whitespace in this template, take
51- * care when modifying it.
52- */
5342 return html `
5443 < button
55- class ="md3-fab md3-surface ${ classMap ( this . getRootClasses ( ) ) } "
56- ?disabled ="${ this . disabled } "
57- aria-label ="${ ariaLabel } "
58- @mouseenter =${ this . handleRippleMouseEnter }
59- @mouseleave =${ this . handleRippleMouseLeave }
60- @focus=${ this . handleRippleFocus }
61- @blur=${ this . handleRippleBlur }
62- @mousedown=${ this . handleRippleActivate }
63- @touchstart=${ this . handleRippleStartPress }
64- @touchend=${ this . handleRippleDeactivate }
65- @touchcancel=${ this . handleRippleDeactivate } > <!--
66- --> ${ this . renderElevationOverlay ( ) } <!--
67- --> ${ this . renderRipple ( ) } <!--
68- --> < span class ="material-icons md3-fab__icon "> <!--
69- --> < slot name ="icon "> ${ this . icon } </ slot > <!--
70- --> </ span > <!--
71- --> ${ this . renderLabel ( ) } <!--
72- --> ${ this . renderTouchTarget ( ) } <!--
44+ class ="md3-fab md3-surface ${ classMap ( this . getRenderClasses ( ) ) } "
45+ ?disabled ="${ this . disabled } "
46+ aria-label ="${ ariaLabel } "
47+ @pointerdown ="${ this . handlePointerDown } "
48+ @pointerup ="${ this . handlePointerUp } "
49+ @pointercancel ="${ this . handlePointerCancel } "
50+ @pointerleave ="${ this . handlePointerLeave } "
51+ @pointerenter ="${ this . handlePointerEnter } "
52+ @click ="${ this . handleClick } "
53+ @clickmod ="${ this . handleClick } "
54+ @contextmenu ="${ this . handleContextMenu } "
55+ > ${ this . renderElevationOverlay ( ) } ${ this . renderRipple ( ) }
56+ < span class ="material-icons md3-fab__icon ">
57+ < slot name ="icon "> ${ this . icon } </ slot >
58+ </ span >
59+ ${ this . renderLabel ( ) } ${ this . renderTouchTarget ( ) }
7360 </ button > ` ;
7461 }
7562
7663 /** @soyTemplate */
77- protected getRootClasses ( ) : ClassInfo {
64+ protected getRenderClasses ( ) : ClassInfo {
7865 return { 'md3-fab--lowered' : this . lowered } ;
7966 }
8067
@@ -91,8 +78,8 @@ export class FabShared extends LitElement {
9178 }
9279
9380 /** @soyTemplate */
94- protected renderLabel ( ) : TemplateResult {
95- return html `` ;
81+ protected renderLabel ( ) : TemplateResult | string {
82+ return '' ;
9683 }
9784
9885 /** @soyTemplate */
@@ -102,47 +89,33 @@ export class FabShared extends LitElement {
10289
10390 /** @soyTemplate */
10491 protected renderRipple ( ) : TemplateResult {
105- return this . shouldRenderRipple ? html `
106- < mwc-ripple
107- class ="md3-fab__ripple "
108- internalUseStateLayerCustomProperties >
109- </ mwc-ripple > ` :
110- html `` ;
111- }
112-
113- protected handleRippleActivate ( event ?: Event ) {
114- const onUp = ( ) => {
115- window . removeEventListener ( 'mouseup' , onUp ) ;
116-
117- this . handleRippleDeactivate ( ) ;
118- } ;
119-
120- window . addEventListener ( 'mouseup' , onUp ) ;
121- this . handleRippleStartPress ( event ) ;
92+ return html `< md-ripple class ="md3-fab__ripple " .disabled ="${
93+ this . disabled } "> </ md-ripple > `;
12294 }
12395
124- @eventOptions ( { passive : true } )
125- protected handleRippleStartPress ( event ?: Event ) {
126- this . rippleHandlers . startPress ( event ) ;
96+ override beginPress ( { positionEvent} : BeginPressConfig ) {
97+ this . ripple . beginPress ( positionEvent ) ;
12798 }
12899
129- protected handleRippleDeactivate ( ) {
130- this . rippleHandlers . endPress ( ) ;
100+ override endPress ( options : EndPressConfig ) {
101+ this . ripple . endPress ( ) ;
102+ super . endPress ( options ) ;
131103 }
132104
133- protected handleRippleMouseEnter ( ) {
134- this . rippleHandlers . startHover ( ) ;
105+ override handlePointerDown ( e : PointerEvent ) {
106+ super . handlePointerDown ( e ) ;
135107 }
136108
137- protected handleRippleMouseLeave ( ) {
138- this . rippleHandlers . endHover ( ) ;
109+ override handlePointerUp ( e : PointerEvent ) {
110+ super . handlePointerUp ( e ) ;
139111 }
140112
141- protected handleRippleFocus ( ) {
142- this . rippleHandlers . startFocus ( ) ;
113+ protected handlePointerEnter ( e : PointerEvent ) {
114+ this . ripple . beginHover ( e ) ;
143115 }
144116
145- protected handleRippleBlur ( ) {
146- this . rippleHandlers . endFocus ( ) ;
117+ override handlePointerLeave ( e : PointerEvent ) {
118+ super . handlePointerLeave ( e ) ;
119+ this . ripple . endHover ( ) ;
147120 }
148121}
0 commit comments