1
1
import React , { useState } from 'react' ;
2
2
import clsx from 'clsx' ;
3
3
import type { ButtonProps } from './types' ;
4
+ import MDBRipple from '../../methods/Ripple/Ripple' ;
4
5
5
6
const MDBBtn : React . FC < ButtonProps > = React . forwardRef < HTMLAllCollection , ButtonProps > (
6
7
(
@@ -17,6 +18,7 @@ const MDBBtn: React.FC<ButtonProps> = React.forwardRef<HTMLAllCollection, Button
17
18
block,
18
19
active,
19
20
toggle,
21
+ noRipple,
20
22
tag : Tag ,
21
23
...props
22
24
} ,
@@ -25,6 +27,7 @@ const MDBBtn: React.FC<ButtonProps> = React.forwardRef<HTMLAllCollection, Button
25
27
const [ isActive , setActive ] = useState ( active ? active : false ) ;
26
28
27
29
let btnColor ;
30
+ const waveColor = ( color && [ 'light' , 'link' ] . includes ( color as string ) ) || outline ? 'dark' : 'light' ;
28
31
29
32
if ( color !== 'none' ) {
30
33
if ( outline ) {
@@ -58,7 +61,7 @@ const MDBBtn: React.FC<ButtonProps> = React.forwardRef<HTMLAllCollection, Button
58
61
Tag = 'a' ;
59
62
}
60
63
61
- return (
64
+ return [ 'hr' , 'img' , 'input' ] . includes ( Tag ) || noRipple ? (
62
65
< Tag
63
66
className = { classes }
64
67
onClick = {
@@ -75,10 +78,29 @@ const MDBBtn: React.FC<ButtonProps> = React.forwardRef<HTMLAllCollection, Button
75
78
>
76
79
{ children }
77
80
</ Tag >
81
+ ) : (
82
+ < MDBRipple
83
+ rippleTag = { Tag }
84
+ rippleColor = { waveColor }
85
+ className = { classes }
86
+ onClick = {
87
+ toggle
88
+ ? ( ) => {
89
+ setActive ( ! isActive ) ;
90
+ }
91
+ : undefined
92
+ }
93
+ disabled = { disabled && Tag === 'button' ? true : undefined }
94
+ href = { href }
95
+ ref = { ref }
96
+ { ...props }
97
+ >
98
+ { children }
99
+ </ MDBRipple >
78
100
) ;
79
101
}
80
102
) ;
81
103
82
- MDBBtn . defaultProps = { tag : 'button' , type : 'button' , role : 'button' } ;
104
+ MDBBtn . defaultProps = { tag : 'button' , type : 'button' , role : 'button' , color : 'primary' } ;
83
105
84
106
export default MDBBtn ;
0 commit comments