From 1eae22769e6e1909d6f2cbcc2d98b26b319f81a8 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Tue, 1 Nov 2022 16:18:55 +0530 Subject: [PATCH 01/17] `TextFormField` explicit override to break design --- src/Components/Form/FormFields/TextFormField.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Components/Form/FormFields/TextFormField.tsx b/src/Components/Form/FormFields/TextFormField.tsx index c7e3b8c8de1..2e4e8fbb263 100644 --- a/src/Components/Form/FormFields/TextFormField.tsx +++ b/src/Components/Form/FormFields/TextFormField.tsx @@ -5,16 +5,18 @@ import { resolveFormFieldError, } from "./Utils"; -type Props = FormFieldBaseProps & { +export type TextFormFieldProps = FormFieldBaseProps & { placeholder?: string; value?: string | number; autoComplete?: string; type?: "email" | "password" | "search" | "text"; + className?: string | undefined; + removeDefaultClasses?: true | undefined; // prefixIcon?: React.ReactNode; // suffixIcon?: React.ReactNode; }; -const TextFormField = (props: Props) => { +const TextFormField = (props: TextFormFieldProps) => { const handleChange = resolveFormFieldChangeEventHandler(props); const error = resolveFormFieldError(props); @@ -25,7 +27,11 @@ const TextFormField = (props: Props) => { Date: Tue, 1 Nov 2022 16:53:11 +0530 Subject: [PATCH 02/17] `TextFormField` support leading and trailing --- .../Form/FormFields/TextFormField.tsx | 70 ++++++++++++------- src/style/index.css | 2 +- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/Components/Form/FormFields/TextFormField.tsx b/src/Components/Form/FormFields/TextFormField.tsx index 2e4e8fbb263..d826923f1a6 100644 --- a/src/Components/Form/FormFields/TextFormField.tsx +++ b/src/Components/Form/FormFields/TextFormField.tsx @@ -12,8 +12,8 @@ export type TextFormFieldProps = FormFieldBaseProps & { type?: "email" | "password" | "search" | "text"; className?: string | undefined; removeDefaultClasses?: true | undefined; - // prefixIcon?: React.ReactNode; - // suffixIcon?: React.ReactNode; + leading?: React.ReactNode | undefined; + trailing?: React.ReactNode | undefined; }; const TextFormField = (props: TextFormFieldProps) => { @@ -23,29 +23,51 @@ const TextFormField = (props: TextFormFieldProps) => { const bgColor = error ? "bg-red-50" : "bg-gray-200"; const borderColor = error ? "border-red-500" : "border-gray-200"; - return ( - - { - event.preventDefault(); - handleChange(event.target); - }} - /> - + const { leading, trailing } = props; + const hasIcon = !!(leading || trailing); + const padding = hasIcon && `${leading && "pl-8"} ${trailing && "pr-8"}`; + + let child = ( + { + event.preventDefault(); + handleChange(event.target); + }} + /> ); + + if (hasIcon) { + child = ( +
+ {leading && ( +
+ {leading} +
+ )} + {child} + {trailing && ( +
+ {trailing} +
+ )} +
+ ); + } + + return {child}; }; export default TextFormField; diff --git a/src/style/index.css b/src/style/index.css index 54b46f77248..e2bc9528385 100644 --- a/src/style/index.css +++ b/src/style/index.css @@ -723,7 +723,7 @@ button:disabled, } .form-input, .form-textarea{ - @apply text-sm block py-3 px-4 w-full rounded placeholder:text-gray-500 focus:bg-white border-2 focus:border-primary-400 outline-none ring-0 transition-all duration-200 ease-in-out !important + @apply text-sm block py-3 px-4 w-full rounded placeholder:text-gray-500 focus:bg-white border-2 focus:border-primary-400 outline-none !ring-0 transition-all duration-200 ease-in-out } .form-textarea { From 17b73be453b43644f3fb8538ea063f957432da13 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Tue, 1 Nov 2022 17:49:44 +0530 Subject: [PATCH 03/17] fix issues with inheriting `form-input` properly --- src/Components/Common/DateInputV2.tsx | 2 +- src/Components/Common/SearchBox.tsx | 2 +- src/Components/Form/FormFields/TextAreaFormField.tsx | 2 +- src/Components/Form/FormFields/TextFormField.tsx | 2 +- src/style/index.css | 8 ++------ 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Components/Common/DateInputV2.tsx b/src/Components/Common/DateInputV2.tsx index 9cd718d6a32..bca37bac84c 100644 --- a/src/Components/Common/DateInputV2.tsx +++ b/src/Components/Common/DateInputV2.tsx @@ -166,7 +166,7 @@ const DateInputV2: React.FC = ({ diff --git a/src/Components/Common/SearchBox.tsx b/src/Components/Common/SearchBox.tsx index e581bde4370..22ed1ae79bd 100644 --- a/src/Components/Common/SearchBox.tsx +++ b/src/Components/Common/SearchBox.tsx @@ -43,7 +43,7 @@ export const InputSearchBox = (props: TextFieldPropsExtended) => { name="search" type="text" {...inputProps} - className="form-input pr-8 sm:text-sm sm:leading-5 text-ellipsis" + className="text-sm block py-3 px-4 w-full rounded placeholder:text-gray-500 focus:bg-white border-2 focus:border-primary-400 outline-none ring-0 transition-all duration-200 ease-in-out pr-8 sm:text-sm sm:leading-5 text-ellipsis" /> {searchValue ? (
{