From faf3e8c6188ea49f89addff088a2ec789e9c8980 Mon Sep 17 00:00:00 2001 From: Nikita Zolotykh <58661343+bocembocem@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:12:03 +0300 Subject: [PATCH] feat: update password input (#136) --- src/lib/kit/components/Inputs/Text/Text.scss | 9 -- src/lib/kit/components/Inputs/Text/Text.tsx | 105 +++++-------------- 2 files changed, 25 insertions(+), 89 deletions(-) delete mode 100644 src/lib/kit/components/Inputs/Text/Text.scss diff --git a/src/lib/kit/components/Inputs/Text/Text.scss b/src/lib/kit/components/Inputs/Text/Text.scss deleted file mode 100644 index bb0bd3e1..00000000 --- a/src/lib/kit/components/Inputs/Text/Text.scss +++ /dev/null @@ -1,9 +0,0 @@ -@import '../../../styles/variables'; - -.#{$ns}text { - display: flex; - - &__button { - --yc-button-background-color-hover: transparent; - } -} diff --git a/src/lib/kit/components/Inputs/Text/Text.tsx b/src/lib/kit/components/Inputs/Text/Text.tsx index 40c5b8a5..a3bcde03 100644 --- a/src/lib/kit/components/Inputs/Text/Text.tsx +++ b/src/lib/kit/components/Inputs/Text/Text.tsx @@ -1,87 +1,32 @@ import React from 'react'; -import {Copy, CopyCheck, Eye, EyeSlash} from '@gravity-ui/icons'; -import {Button, CopyToClipboard, CopyToClipboardStatus, Icon, TextInput} from '@gravity-ui/uikit'; +import {PasswordInput} from '@gravity-ui/components'; +import {TextInput} from '@gravity-ui/uikit'; import _ from 'lodash'; import {FieldRenderProps, NumberInputProps, StringInputProps} from '../../../../core'; -import {block} from '../../../utils'; -import './Text.scss'; - -const b = block('text'); - -export const Text = ({name, input, spec}: T) => { - const {value, onBlur, onChange, onFocus} = input; - const [hideValue, setHideValue] = React.useState(spec.viewSpec.type === 'password'); - - const handleChange = React.useCallback( - (value: string) => { - (onChange as FieldRenderProps['input']['onChange'])(value); - }, - [onChange, spec], - ); - - const type = React.useMemo(() => { - if (spec.viewSpec.type === 'password') { - return 'password'; - } - - return 'text'; - }, [spec.viewSpec.type]); - - const additionalRightContent = React.useMemo(() => { - if (type === 'password') { - const onClick = () => { - setHideValue((hideValue) => !hideValue); - }; - - return ( -
- {input.value ? ( - - {(state) => ( - - )} - - ) : null} - -
- ); - } - - return undefined; - }, [hideValue, input.value, type, value]); - - return ( - - ); +export const Text = ({ + name, + input: {value, onBlur, onChange, onFocus}, + spec, +}: T) => { + const props = { + value: _.isNil(value) ? '' : `${value}`, + hasClear: true, + onBlur: onBlur, + onFocus: onFocus, + onUpdate: onChange as FieldRenderProps['input']['onChange'], + disabled: spec.viewSpec.disabled, + placeholder: spec.viewSpec.placeholder, + qa: name, + }; + + if (spec.viewSpec.type === 'password') { + return ( + + ); + } + + return ; };