1
+ import { BaseDirective } from 'primevue/basedirective' ;
1
2
import { DomHandler } from 'primevue/utils' ;
2
3
3
4
let timeout ;
@@ -10,16 +11,23 @@ function unbindEvents(el) {
10
11
el . removeEventListener ( 'mousedown' , onMouseDown ) ;
11
12
}
12
13
13
- function create ( el ) {
14
+ function create ( el , binding ) {
14
15
let ink = document . createElement ( 'span' ) ;
15
16
16
- ink . className = 'p-ink' ;
17
+ ! el . $_prippleUnstyled && ( ink . className = 'p-ink' ) ;
18
+ ink . setAttribute ( 'data-pc-name' , 'ripple' ) ;
19
+ ink . setAttribute ( 'data-pc-section' , 'root' ) ;
17
20
ink . setAttribute ( 'role' , 'presentation' ) ;
18
21
ink . setAttribute ( 'aria-hidden' , 'true' ) ;
19
22
ink . setAttribute ( 'data-p-ink' , 'true' ) ;
23
+ ink . setAttribute ( 'data-p-ink-active' , 'false' ) ;
20
24
el . appendChild ( ink ) ;
25
+ el . $_pDirectiveElement = ink ;
21
26
22
27
ink . addEventListener ( 'animationend' , onAnimationEnd ) ;
28
+
29
+ BaseDirective . directiveElement = ink ;
30
+ BaseDirective . handleCSS ( 'ripple' , ink , binding ) ;
23
31
}
24
32
25
33
function remove ( el ) {
@@ -40,7 +48,8 @@ function onMouseDown(event) {
40
48
return ;
41
49
}
42
50
43
- DomHandler . removeClass ( ink , 'p-ink-active' ) ;
51
+ ! target . $_prippleUnstyled && DomHandler . removeClass ( ink , 'p-ink-active' ) ;
52
+ ink . setAttribute ( 'data-p-ink-active' , 'false' ) ;
44
53
45
54
if ( ! DomHandler . getHeight ( ink ) && ! DomHandler . getWidth ( ink ) ) {
46
55
let d = Math . max ( DomHandler . getOuterWidth ( target ) , DomHandler . getOuterHeight ( target ) ) ;
@@ -55,11 +64,14 @@ function onMouseDown(event) {
55
64
56
65
ink . style . top = y + 'px' ;
57
66
ink . style . left = x + 'px' ;
58
- DomHandler . addClass ( ink , 'p-ink-active' ) ;
67
+
68
+ ! target . $_prippleUnstyled && DomHandler . addClass ( ink , 'p-ink-active' ) ;
69
+ ink . setAttribute ( 'data-p-ink-active' , 'true' ) ;
59
70
60
71
timeout = setTimeout ( ( ) => {
61
72
if ( ink ) {
62
- DomHandler . removeClass ( ink , 'p-ink-active' ) ;
73
+ ! target . $_prippleUnstyled && DomHandler . removeClass ( ink , 'p-ink-active' ) ;
74
+ ink . setAttribute ( 'data-p-ink-active' , 'false' ) ;
63
75
}
64
76
} , 401 ) ;
65
77
}
@@ -69,29 +81,35 @@ function onAnimationEnd(event) {
69
81
clearTimeout ( timeout ) ;
70
82
}
71
83
72
- DomHandler . removeClass ( event . currentTarget , 'p-ink-active' ) ;
84
+ ! event . currentTarget . $_prippleUnstyled && DomHandler . removeClass ( event . currentTarget , 'p-ink-active' ) ;
85
+ event . currentTarget . setAttribute ( 'data-p-ink-active' , 'false' ) ;
73
86
}
74
87
75
88
function getInk ( el ) {
76
89
for ( let i = 0 ; i < el . children . length ; i ++ ) {
77
- if ( typeof el . children [ i ] . className === 'string' && el . children [ i ] . className . indexOf ( 'p-ink ') !== - 1 ) {
90
+ if ( el . children [ i ] . getAttribute ( 'data-pc-name ') === 'ripple' ) {
78
91
return el . children [ i ] ;
79
92
}
80
93
}
81
94
82
95
return null ;
83
96
}
84
97
85
- const Ripple = {
98
+ const Ripple = BaseDirective . extend ( 'ripple' , {
86
99
mounted ( el , binding ) {
87
- if ( binding . instance . $primevue && binding . instance . $primevue . config && binding . instance . $primevue . config . ripple ) {
88
- create ( el ) ;
100
+ const primevue = binding . instance . $primevue ;
101
+
102
+ if ( primevue && primevue . config && primevue . config . ripple ) {
103
+ el . $_prippleUnstyled = primevue . config . unstyled || false ;
104
+
105
+ create ( el , binding ) ;
89
106
bindEvents ( el ) ;
90
107
}
91
108
} ,
109
+
92
110
unmounted ( el ) {
93
111
remove ( el ) ;
94
112
}
95
- } ;
113
+ } ) ;
96
114
97
115
export default Ripple ;
0 commit comments