diff --git a/src/components/input/index.tsx b/src/components/input/index.tsx index d5211edd0..2caca9f75 100644 --- a/src/components/input/index.tsx +++ b/src/components/input/index.tsx @@ -1,14 +1,15 @@ import { Box, Flex } from 'rebass'; -import { forwardRef } from 'react'; +import { forwardRef, useState } from 'react'; import { InputProps as RebassInputProps } from 'rebass__forms'; import Label, { LabelProps } from '../label'; import InputInfo from '../input-info'; import { Intents } from '../intents'; -import getStyles, { getIconStyle } from './input.styles'; +import getStyles, { getIconStyle, passwordStyles } from './input.styles'; import Labeling from '../typography/labeling'; import Tooltip from '../tooltip'; import { GetIcon, IconName } from '../icon'; +import TooltipPositions from '../tooltip/positions'; export interface InputProps extends Omit { variant?: 'primary' | 'white'; @@ -55,6 +56,7 @@ const Input = forwardRef( ref, ) => { const isTextArea = type === 'textarea'; + const [isShowPassword, setIsShow] = useState(false); const actions = (labelAction || tooltipInfo || optional) && ( @@ -82,7 +84,7 @@ const Input = forwardRef( )} {rightIcon && rightIcon} + {type === 'password' && ( + setIsShow(true)} + onMouseUp={() => setIsShow(false)} + onMouseOut={() => setIsShow(false)} + sx={passwordStyles(isShowPassword, !props.value)} + > + + + + + )} {suffix && ( diff --git a/src/components/input/input.styles.ts b/src/components/input/input.styles.ts index d8d21311d..fbc3ed006 100644 --- a/src/components/input/input.styles.ts +++ b/src/components/input/input.styles.ts @@ -29,6 +29,8 @@ const getStyles = (intent: Intents, isTextArea: boolean): SxStyleProp => ({ ...(isTextArea && { resize: 'vertical' }), }); +export default getStyles; + export const getIconStyle = { left: '8px', position: 'absolute', @@ -36,4 +38,30 @@ export const getIconStyle = { fontSize: '14px', }; -export default getStyles; +export const passwordStyles = (isShow: boolean, disabled: boolean) => ({ + border: 'none', + right: '5px', + position: 'absolute', + top: '16px', + transform: 'translateY(-50%)', + fontSize: '14px', + userSelect: 'none', + + cursor: 'pointer', + + div: { + ': hover': { + backgroundColor: 'grayShade2', + }, + height: '25px', + border: 'none', + backgroundColor: 'grayShade3', + + svg: { + path: { + // eslint-disable-next-line no-nested-ternary + fill: disabled ? 'gray' : isShow ? 'primary' : 'black', + }, + }, + }, +}); diff --git a/src/components/input/stories.tsx b/src/components/input/stories.tsx index 6a6a52c0c..1c4591fe7 100644 --- a/src/components/input/stories.tsx +++ b/src/components/input/stories.tsx @@ -59,9 +59,9 @@ const meta: Meta = { description: 'Input intent (error border)', }, type: { + options: ['textarea', 'text', 'number', 'password'], control: { type: 'select', - options: ['textarea', 'text', 'number'], }, required: false, },