diff --git a/src/components/ui/checkbox/checkbox.tsx b/src/components/ui/checkbox/checkbox.tsx index 738611d..ba88e1d 100644 --- a/src/components/ui/checkbox/checkbox.tsx +++ b/src/components/ui/checkbox/checkbox.tsx @@ -1,4 +1,4 @@ -import { ComponentPropsWithoutRef, FC } from 'react' +import { ComponentPropsWithoutRef } from 'react' import { Check } from '@/assets/icons' import { Typography } from '@/components' @@ -13,13 +13,13 @@ export type CheckboxProps = { position?: 'default' | 'left' } & ComponentPropsWithoutRef -export const Checkbox: FC = ({ +export const Checkbox = ({ className, disabled, label, position = 'default', ...rest -}) => { +}: CheckboxProps) => { const classNames = { buttonWrapper: clsx(s.buttonWrapper, disabled && s.disabled, position === 'left' && s.left), container: clsx(s.container, className), diff --git a/src/components/ui/text-field/text-field.tsx b/src/components/ui/text-field/text-field.tsx index 2bd8611..30bef3e 100644 --- a/src/components/ui/text-field/text-field.tsx +++ b/src/components/ui/text-field/text-field.tsx @@ -1,4 +1,12 @@ -import { ChangeEvent, ComponentProps, ComponentPropsWithoutRef, forwardRef, useState } from 'react' +import { + ChangeEvent, + ComponentProps, + ComponentPropsWithoutRef, + forwardRef, + memo, + useCallback, + useState, +} from 'react' import { Eye, VisibilityOff } from '@/assets' import { Typography } from '@/components' @@ -14,7 +22,7 @@ export type TextFieldProps = { onValueChange?: (value: string) => void } & ComponentPropsWithoutRef<'input'> -export const TextField = forwardRef( +const RawTextField = forwardRef( ( { className, @@ -30,25 +38,32 @@ export const TextField = forwardRef( }, ref ) => { - const [showPassword, setShowPassword] = useState(false) + const [revealPassword, setRevealPassword] = useState(false) - const isShowPasswordButtonShown = type === 'password' + const isRevealPasswordButtonShown = type === 'password' - const finalType = getFinalType(type, showPassword) - - function handleChange(e: ChangeEvent) { - onChange?.(e) - onValueChange?.(e.target.value) - } + const finalType = getFinalType(type, revealPassword) const classNames = { error: clsx(s.error), - field: clsx(s.field, !!errorMessage && s.error, className), + field: clsx(s.field, errorMessage && s.error, className), fieldContainer: clsx(s.fieldContainer), label: clsx(s.label, labelProps?.className), root: clsx(s.root, containerProps?.className), } + const handleChange = useCallback( + (e: ChangeEvent) => { + onChange?.(e) + onValueChange?.(e.target.value) + }, + [onChange, onValueChange] + ) + + const handleShowPasswordClick = useCallback(() => { + setRevealPassword(prev => !prev) + }, []) + return (
{label && ( @@ -56,6 +71,7 @@ export const TextField = forwardRef( {label} )} +
( type={finalType} {...restProps} /> - {isShowPasswordButtonShown && ( - )}
- - {errorMessage} - + {errorMessage && ( + + {errorMessage} + + )}
) } @@ -91,3 +105,7 @@ function getFinalType(type: ComponentProps<'input'>['type'], showPassword: boole return type } + +export const TextField = memo(RawTextField) + +TextField.displayName = 'TextField'