diff --git a/luna/src/components/Input/Input.stories.tsx b/luna/src/components/Input/Input.stories.tsx index 4d6b519c..e78b80c4 100644 --- a/luna/src/components/Input/Input.stories.tsx +++ b/luna/src/components/Input/Input.stories.tsx @@ -29,6 +29,16 @@ export const Idle: StoryObj = { }, }; +export const IdelWithValue: StoryObj = { + args: { + id: "name", + label: ar["global.form.email.label"], + placeholder: ar["global.form.email.placeholder"], + value: "لايت اسبيس", + onChange: () => {}, + }, +}; + export const Error: StoryObj = { args: { id: "name", @@ -38,4 +48,15 @@ export const Error: StoryObj = { }, }; +export const ErrorWithValue: StoryObj = { + args: { + id: "name", + label: ar["global.form.email.label"], + placeholder: ar["global.form.email.placeholder"], + error: ar["errors.email.invlaid"], + value: "لايت اسبيس", + onChange: () => {}, + }, +}; + export default meta; diff --git a/luna/src/components/Input/Input.tsx b/luna/src/components/Input/Input.tsx index 51635241..4fa759d4 100644 --- a/luna/src/components/Input/Input.tsx +++ b/luna/src/components/Input/Input.tsx @@ -1,7 +1,8 @@ -import React from "react"; +import React, { useMemo } from "react"; import { ChangeHandler } from "react-hook-form"; import { motion, AnimatePresence } from "framer-motion"; import cn from "classnames"; +import ErrorOutlined from "@/icons/ErrorOutlined"; export const Input: React.FC<{ id: string; @@ -13,6 +14,7 @@ export const Input: React.FC<{ onBlur?: ChangeHandler; name?: string; error?: string | null; + value?: string; }> = ({ label, type, @@ -23,6 +25,7 @@ export const Input: React.FC<{ onBlur, name, error, + value, }) => { return (
@@ -34,24 +37,28 @@ export const Input: React.FC<{ > {label} - +
+ + +
{error ? : null} @@ -59,17 +66,36 @@ export const Input: React.FC<{ ); }; +function framerError(y: string | number) { + return { + initial: { opacity: 0, y: 10 }, + animate: { opacity: 1, y }, + exit: { opacity: 0, y: 10 }, + transition: { duration: 0.2 }, + }; +} + const InputError: React.FC<{ message: string }> = ({ message }) => { + const framer = useMemo(() => framerError(0), []); return ( - + {message} ); }; -const framerError = { - initial: { opacity: 0, y: 10 }, - animate: { opacity: 1, y: 0 }, - exit: { opacity: 0, y: 10 }, - transition: { duration: 0.2 }, -} as const; +const ErrorIcon: React.FC<{ error: boolean }> = ({ error }) => { + const framer = useMemo(() => framerError("-50%"), []); + return ( + + {error ? ( + + + + ) : null} + + ); +}; diff --git a/luna/src/icons/ErrorOutlined.tsx b/luna/src/icons/ErrorOutlined.tsx new file mode 100644 index 00000000..b3142218 --- /dev/null +++ b/luna/src/icons/ErrorOutlined.tsx @@ -0,0 +1,17 @@ +import { SVGProps } from "react"; + +const ErrorOutlined = (props: SVGProps) => ( + + + +); +export default ErrorOutlined;