Skip to content

Commit 35fea18

Browse files
committed
fix: change types and added stylings to Input and PasswordInput
1 parent c401ee1 commit 35fea18

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

lib/components/Input/Input.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ $border: 1px solid;
8686
}
8787

8888
&__helper-message {
89-
top: 100%;
89+
top: calc(100% + 2px);
9090
position: absolute;
9191
left: 16px;
9292
line-height: 1;

lib/components/PasswordInput/index.tsx

+27-13
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,50 @@ export const validatePassword = (password: string) => {
3838
return { errorMessage, score };
3939
};
4040

41-
const PasswordVariant: Record<TScore, PasswordInputProps["variant"]> = {
41+
type InputProps = ComponentProps<typeof Input>;
42+
43+
interface PasswordInputProps
44+
extends Pick<
45+
InputProps,
46+
"value" | "onChange" | "label" | "id" | "autoComplete"
47+
> {
48+
hidePasswordMeter?: boolean;
49+
hint?: string;
50+
}
51+
52+
const PasswordVariant: Record<TScore, InputProps["variant"]> = {
4253
0: "error",
4354
1: "error",
4455
2: "warning",
4556
3: "success",
4657
4: "success",
4758
};
4859

49-
interface PasswordInputProps extends ComponentProps<typeof Input> {
50-
hidePasswordMeter?: boolean;
51-
}
52-
5360
export const PasswordInput = ({
61+
autoComplete,
62+
id,
63+
label,
64+
value,
65+
onChange,
66+
hint,
5467
hidePasswordMeter,
55-
...rest
5668
}: PasswordInputProps) => {
5769
const [isTouched, setIsTouched] = useState(false);
5870
const [showPassword, setShowPassword] = useState(false);
5971

6072
const { errorMessage, score } = useMemo(
61-
() => validatePassword(rest.value as string),
62-
[rest.value]
73+
() => validatePassword(value as string),
74+
[value]
6375
);
6476

6577
const handleChange = useCallback(
6678
(e: ChangeEvent<HTMLInputElement>) => {
67-
rest.onChange?.(e);
79+
onChange?.(e);
6880
if (!isTouched) {
6981
setIsTouched(true);
7082
}
7183
},
72-
[isTouched, rest.onChange]
84+
[isTouched, onChange]
7385
);
7486

7587
const handleBlur = useCallback(() => {
@@ -81,9 +93,12 @@ export const PasswordInput = ({
8193
return (
8294
<div className="deriv-password">
8395
<Input
96+
autoComplete={autoComplete}
97+
id={id}
98+
label={label}
8499
type={showPassword ? "text" : "password"}
85-
value={rest.value}
86-
message={isTouched ? errorMessage : ""}
100+
value={value}
101+
message={isTouched ? errorMessage : "" || hint}
87102
onChange={handleChange}
88103
onBlur={handleBlur}
89104
variant={isTouched ? PasswordVariant[score as TScore] : "general"}
@@ -95,7 +110,6 @@ export const PasswordInput = ({
95110
{showPassword ? <EyeIcon /> : <EyeIconSlash />}
96111
</button>
97112
}
98-
{...rest}
99113
/>
100114
{!hidePasswordMeter && <PasswordMeter score={score as TScore} />}
101115
</div>

lib/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export { ToggleSwitch } from "./components/ToggleSwitch";
99
export { Tooltip } from "./components/Tooltip";
1010
export { useDevice } from "./hooks/useDevice";
1111
export { useOnClickOutside } from "./hooks/useOnClickOutside";
12+
export { PasswordInput } from "./components/PasswordInput";

0 commit comments

Comments
 (0)