1- import { html , LitElement } from 'lit' ;
2-
1+ import { LitElement , nothing } from 'lit' ;
32import { registerComponent } from '../common/definitions/register.js' ;
4- import { addSafeEventListener } from '../common/util.js' ;
3+ import {
4+ addSafeEventListener ,
5+ getScaleFactor ,
6+ setStyles ,
7+ } from '../common/util.js' ;
58import { styles } from './ripple.material.css.js' ;
69
710const rippleFrames : Keyframe [ ] = [
@@ -17,7 +20,7 @@ const rippleAnimation: KeyframeAnimationOptions = {
1720
1821let rippleElement : HTMLElement ;
1922
20- function getRippleElement ( ) {
23+ function getRippleElement ( ) : HTMLSpanElement {
2124 if ( ! rippleElement ) {
2225 rippleElement = document . createElement ( 'span' ) ;
2326 }
@@ -41,12 +44,19 @@ export default class IgcRippleComponent extends LitElement {
4144
4245 constructor ( ) {
4346 super ( ) ;
44- addSafeEventListener ( this , 'pointerdown' , this . handler ) ;
47+ addSafeEventListener ( this , 'pointerdown' , this . _handler ) ;
4548 }
4649
47- private handler = ( { clientX, clientY } : PointerEvent ) => {
50+ private async _handler ( event : PointerEvent ) : Promise < void > {
51+ if ( event . button !== 0 ) {
52+ return ;
53+ }
54+
4855 const element = getRippleElement ( ) ;
49- const { radius, top, left } = this . getDimensions ( clientX , clientY ) ;
56+ const { radius, top, left } = this . _getDimensions (
57+ event . clientX ,
58+ event . clientY
59+ ) ;
5060
5161 const styles : Partial < CSSStyleDeclaration > = {
5262 position : 'absolute' ,
@@ -55,8 +65,8 @@ export default class IgcRippleComponent extends LitElement {
5565 transformOrigin : 'center' ,
5666 transform : 'translate3d(0, 0, 0) scale(0)' ,
5767 willChange : 'opacity, transform' ,
58- margin : '0 !important ' ,
59- border : 'none !important ' ,
68+ margin : '0' ,
69+ border : 'none' ,
6070 width : `${ radius } px` ,
6171 height : `${ radius } px` ,
6272 borderRadius : '50%' ,
@@ -65,28 +75,28 @@ export default class IgcRippleComponent extends LitElement {
6575 background : 'var(--color, var(--ig-gray-800))' ,
6676 } ;
6777
68- Object . assign ( element . style , styles ) ;
78+ setStyles ( element , styles ) ;
6979 this . renderRoot . appendChild ( element ) ;
7080
71- element
72- . animate ( rippleFrames , rippleAnimation )
73- . finished . then ( ( ) => element . remove ( ) ) ;
74- } ;
81+ await element . animate ( rippleFrames , rippleAnimation ) . finished ;
82+ element . remove ( ) ;
83+ }
7584
76- private getDimensions ( x : number , y : number ) {
85+ private _getDimensions ( x : number , y : number ) {
7786 const rect = this . getBoundingClientRect ( ) ;
87+ const factor = getScaleFactor ( this ) ;
7888 const radius = Math . max ( rect . width , rect . height ) ;
7989 const halfRadius = radius / 2 ;
8090
8191 return {
8292 radius,
83- top : Math . round ( y - rect . top - halfRadius ) ,
84- left : Math . round ( x - rect . left - halfRadius ) ,
93+ top : Math . round ( ( y - rect . top ) * factor . y - halfRadius ) ,
94+ left : Math . round ( ( x - rect . left ) * factor . x - halfRadius ) ,
8595 } ;
8696 }
8797
8898 protected override render ( ) {
89- return html `` ;
99+ return nothing ;
90100 }
91101}
92102
0 commit comments