diff --git a/lib/components/PasswordInput/PasswordMeter.scss b/lib/components/PasswordInput/PasswordMeter.scss index 9ae96820..a63aa663 100644 --- a/lib/components/PasswordInput/PasswordMeter.scss +++ b/lib/components/PasswordInput/PasswordMeter.scss @@ -5,7 +5,7 @@ $ERROR: #ec3f3f; .deriv-password__meter__bar { height: 100%; border-radius: 0px 0px 4px 4px; - transition: "width 0.25s ease-in-out"; + transition: width 0.25s ease-in-out; &__initial { background-color: $NEUTRAL; diff --git a/lib/components/PasswordInput/index.tsx b/lib/components/PasswordInput/index.tsx index f0fe5764..810a8b40 100644 --- a/lib/components/PasswordInput/index.tsx +++ b/lib/components/PasswordInput/index.tsx @@ -1,6 +1,7 @@ import React, { ChangeEvent, ComponentProps, + FocusEvent, useCallback, useMemo, useState, @@ -40,11 +41,7 @@ export const validatePassword = (password: string) => { type InputProps = ComponentProps; -interface PasswordInputProps - extends Pick< - InputProps, - "value" | "onChange" | "label" | "id" | "autoComplete" - > { +interface PasswordInputProps extends Omit { hidePasswordMeter?: boolean; hint?: string; } @@ -58,13 +55,12 @@ const PasswordVariant: Record = { }; export const PasswordInput = ({ - autoComplete, - id, - label, value, + onBlur, onChange, hint, hidePasswordMeter, + ...rest }: PasswordInputProps) => { const [isTouched, setIsTouched] = useState(false); const [showPassword, setShowPassword] = useState(false); @@ -84,20 +80,21 @@ export const PasswordInput = ({ [isTouched, onChange] ); - const handleBlur = useCallback(() => { - if (!isTouched) { - setIsTouched(true); - } - }, [isTouched]); + const handleBlur = useCallback( + (e: FocusEvent) => { + onBlur?.(e); + if (!isTouched) { + setIsTouched(true); + } + }, + [isTouched, onBlur] + ); return (
: } } + {...rest} /> {!hidePasswordMeter && }
diff --git a/src/stories/PasswordInput.stories.ts b/src/stories/PasswordInput.stories.tsx similarity index 72% rename from src/stories/PasswordInput.stories.ts rename to src/stories/PasswordInput.stories.tsx index 9910c84c..822cb0d5 100644 --- a/src/stories/PasswordInput.stories.ts +++ b/src/stories/PasswordInput.stories.tsx @@ -1,5 +1,6 @@ import { StoryObj, Meta } from "@storybook/react"; import { PasswordInput } from "../../lib/main"; +import { useState } from "react"; const meta = { title: "Components/PasswordInput", @@ -7,21 +8,14 @@ const meta = { parameters: { layout: "centered" }, tags: ["autodocs"], args: { - autoComplete: "password", - id: "password", label: "Enter Password", value: "", onChange: () => {}, hidePasswordMeter: false, - hint: "Password should have lower and uppercase English letters with numbers.", + hint: "This is a hint message", }, argTypes: { - autoComplete: { - control: { - disable: true, - }, - }, - id: { + value: { control: { disable: true, }, @@ -49,5 +43,17 @@ export const Default: Story = { value: "", onChange: () => {}, hidePasswordMeter: false, + hint: "This is a hint message", + }, + render: (args) => { + const [value, setValue] = useState(""); + + return ( + setValue(e.target.value)} + /> + ); }, };