diff --git a/lib/components/Input/HelperMessage.tsx b/lib/components/Input/HelperMessage.tsx new file mode 100644 index 00000000..2bb5fdd6 --- /dev/null +++ b/lib/components/Input/HelperMessage.tsx @@ -0,0 +1,20 @@ +import React from "react"; +import clsx from "clsx"; +import "./Input.scss"; + +export interface HelperMessageProps { + message?: string; + hasError?: boolean; +} + +const HelperMessage = ({ message, hasError }: HelperMessageProps) => ( +

+ {message} +

+); + +export default HelperMessage; diff --git a/lib/components/Input/Input.scss b/lib/components/Input/Input.scss index 6b7ff7d0..b69b7e2d 100644 --- a/lib/components/Input/Input.scss +++ b/lib/components/Input/Input.scss @@ -65,6 +65,12 @@ $border: 1px solid; color: $error_field; } } + + &--helper-message { + position: absolute; + left: 16px; + margin-top: 2px; + } } .deriv-input--field:disabled + .deriv-input--label { @@ -79,3 +85,14 @@ $border: 1px solid; .deriv-input--field__error:focus + .deriv-input--label { color: $error_field; } + +.deriv-helper-message { + font-size: 12px; + font-style: normal; + font-weight: 400; + line-height: 18px; + color: $inactive_color; + &__error { + color: $error_field; + } +} diff --git a/lib/components/Input/index.tsx b/lib/components/Input/index.tsx index 3d958d83..a489e5c5 100644 --- a/lib/components/Input/index.tsx +++ b/lib/components/Input/index.tsx @@ -1,25 +1,36 @@ -import React, { ChangeEvent, ComponentProps, useState } from "react"; +import React, { ChangeEvent, ComponentProps, ReactNode, useState } from "react"; import clsx from "clsx"; +import HelperMessage, { HelperMessageProps } from "./HelperMessage"; import "./Input.scss"; interface InputProps - extends Omit, "style" | "placeholder"> { + extends Omit, "style" | "placeholder">, + HelperMessageProps { label?: string; - helperMessage?: string; - error?: boolean; + hasError?: boolean; + hasRightPlaceholder?: ReactNode; } -export const Input = ({ label, id, error, ...rest }: InputProps) => { +export const Input = ({ + label, + id, + hasError, + message, + hasRightPlaceholder, + ...rest +}: InputProps) => { const [value, setValue] = useState(""); const handleChange = (e: ChangeEvent) => { setValue(e.target.value); + rest.onChange?.(e); }; return (
{ /> + {hasRightPlaceholder && ( +
{hasRightPlaceholder}
+ )} +
+ {message && } +
); };