13
13
//
14
14
// You should have received a copy of the GNU Affero General Public License
15
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- import React from "react" ;
16
+ import React , { useState } from "react" ;
17
17
import {
18
18
Grid ,
19
19
IconButton ,
@@ -24,6 +24,8 @@ import {
24
24
} from "@mui/material" ;
25
25
import { OutlinedInputProps } from "@mui/material/OutlinedInput" ;
26
26
import { InputProps as StandardInputProps } from "@mui/material/Input" ;
27
+ import VisibilityOffIcon from "@mui/icons-material/VisibilityOff" ;
28
+ import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye" ;
27
29
import { Theme } from "@mui/material/styles" ;
28
30
import createStyles from "@mui/styles/createStyles" ;
29
31
import makeStyles from "@mui/styles/makeStyles" ;
@@ -137,6 +139,7 @@ const InputBoxWrapper = ({
137
139
onFocus,
138
140
} : InputBoxProps ) => {
139
141
let inputProps : any = { "data-index" : index , ...extraInputProps } ;
142
+ const [ toggleTextInput , setToggleTextInput ] = useState < boolean > ( false ) ;
140
143
141
144
if ( type === "number" && min ) {
142
145
inputProps [ "min" ] = min ;
@@ -150,6 +153,18 @@ const InputBoxWrapper = ({
150
153
inputProps [ "pattern" ] = pattern ;
151
154
}
152
155
156
+ let inputBoxWrapperIcon = overlayIcon ;
157
+ let inputBoxWrapperType = type ;
158
+
159
+ if ( type === "password" && overlayIcon === null ) {
160
+ inputBoxWrapperIcon = toggleTextInput ? (
161
+ < VisibilityOffIcon />
162
+ ) : (
163
+ < RemoveRedEyeIcon />
164
+ ) ;
165
+ inputBoxWrapperType = toggleTextInput ? "text" : "password" ;
166
+ }
167
+
153
168
return (
154
169
< React . Fragment >
155
170
< Grid
@@ -191,7 +206,7 @@ const InputBoxWrapper = ({
191
206
autoFocus = { autoFocus }
192
207
disabled = { disabled }
193
208
onChange = { onChange }
194
- type = { type }
209
+ type = { inputBoxWrapperType }
195
210
multiline = { multiline }
196
211
autoComplete = { autoComplete }
197
212
inputProps = { inputProps }
@@ -202,7 +217,7 @@ const InputBoxWrapper = ({
202
217
onKeyPress = { onKeyPress }
203
218
onFocus = { onFocus }
204
219
/>
205
- { overlayIcon && (
220
+ { inputBoxWrapperIcon && (
206
221
< div
207
222
className = { `${ classes . overlayAction } ${
208
223
label !== "" ? "withLabel" : ""
@@ -214,15 +229,15 @@ const InputBoxWrapper = ({
214
229
? ( ) => {
215
230
overlayAction ( ) ;
216
231
}
217
- : ( ) => null
232
+ : ( ) => setToggleTextInput ( ! toggleTextInput )
218
233
}
219
234
id = { overlayId }
220
235
size = { "small" }
221
236
disableFocusRipple = { false }
222
237
disableRipple = { false }
223
238
disableTouchRipple = { false }
224
239
>
225
- { overlayIcon }
240
+ { inputBoxWrapperIcon }
226
241
</ IconButton >
227
242
</ div >
228
243
) }
0 commit comments