From b396e3d526d0b742d634e591c3b126914d9ef267 Mon Sep 17 00:00:00 2001 From: Waseem Date: Mon, 13 Jan 2025 15:52:45 +0100 Subject: [PATCH 1/2] chore: input component modified to be used as masked input as well --- src/components/basic/Input/Input.mdx | 13 ++++++++ src/components/basic/Input/index.tsx | 48 ++++++++++++++++++---------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/components/basic/Input/Input.mdx b/src/components/basic/Input/Input.mdx index de3063bd..d4d1f57a 100644 --- a/src/components/basic/Input/Input.mdx +++ b/src/components/basic/Input/Input.mdx @@ -64,6 +64,19 @@ import { Input } from '.' disabled={true} error={false} /> + + {' '} + +
+### Masked Input + + +

diff --git a/src/components/basic/Input/index.tsx b/src/components/basic/Input/index.tsx index c1ea527f..ada4adce 100644 --- a/src/components/basic/Input/index.tsx +++ b/src/components/basic/Input/index.tsx @@ -18,6 +18,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +import { Visibility, VisibilityOff } from '@mui/icons-material' import ErrorOutline from '@mui/icons-material/ErrorOutline' import HelpOutlineIcon from '@mui/icons-material/HelpOutline' import { @@ -28,12 +29,15 @@ import { InputAdornment, Box, FormControl, + IconButton, } from '@mui/material' +import { useState } from 'react' import { Tooltips } from '../ToolTips' interface InputProps extends Omit { variant?: 'filled' tooltipMessage?: string + showToggle?: boolean } export const Input = ({ @@ -43,8 +47,14 @@ export const Input = ({ helperText, error = false, tooltipMessage, + showToggle = false, ...props }: InputProps) => { + const [showPassword, setShowPassword] = useState(false) + + const handleToggleVisibility = () => { + setShowPassword((prev) => !prev) + } return ( - - - ), - } - : {} - } + type={showToggle ? (!showPassword ? 'password' : 'text') : 'text'} + InputProps={{ + endAdornment: ( + + {showToggle ? ( + + {showPassword ? : } + + ) : error ? ( + + ) : null} + + ), + }} {...props} /> {error && helperText && ( From 584770dc3c0acd875db9b053d086c90997555fd6 Mon Sep 17 00:00:00 2001 From: Waseem Date: Tue, 14 Jan 2025 13:17:41 +0100 Subject: [PATCH 2/2] chore: resolved sonarcloud issues --- src/components/basic/Input/index.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/basic/Input/index.tsx b/src/components/basic/Input/index.tsx index ada4adce..7524109d 100644 --- a/src/components/basic/Input/index.tsx +++ b/src/components/basic/Input/index.tsx @@ -99,11 +99,11 @@ export const Input = ({ variant={variant} placeholder={placeholder} error={error} - type={showToggle ? (!showPassword ? 'password' : 'text') : 'text'} + type={showToggle && !showPassword ? 'password' : 'text'} InputProps={{ endAdornment: ( - {showToggle ? ( + {showToggle && ( {showPassword ? : } - ) : error ? ( + )} + {error && ( - ) : null} + )} ), }}