11import { FC , useId } from "react" ;
22import { BiError } from "react-icons/bi" ;
33import { HiOutlineInformationCircle } from "react-icons/hi" ;
4+ import { MdOutlineClear } from "react-icons/md" ;
5+ import { twMerge } from "tailwind-merge" ;
46
57interface InputProps {
68 label : string ;
@@ -18,7 +20,12 @@ const Input: FC<InputProps> = (props) => {
1820 const isError = props . validate ( props . value ) . trim ( ) !== "" ;
1921
2022 return (
21- < div className = { `${ props . className } w-full flex flex-col gap-1` } >
23+ < div
24+ className = { twMerge (
25+ "w-full flex flex-col gap-1 relative" ,
26+ props . className
27+ ) }
28+ >
2229 < label
2330 htmlFor = { id }
2431 className = "text-sm text-gh-text-secondary font-semibold w-fit
@@ -40,22 +47,37 @@ const Input: FC<InputProps> = (props) => {
4047 ) }
4148 </ label >
4249
43- < input
44- name = { id }
45- id = { id }
46- value = { props . value }
47- placeholder = { props . placeholder }
48- onChange = { ( e ) => props . setValue ( e . target . value ) }
49- autoComplete = "off"
50- type = "text"
51- className = { `text-base bg-gh-bg border border-solid rounded-md px-2 py-1
52- leading-none placeholder:text-gh-text-secondary text-gh-text
53- outline-none transition-all duration-150 ${
54- isError
55- ? "border-red-500"
56- : "focus:border-gh-blue active:border-gh-blue border-gh-border"
57- } `}
58- />
50+ < div className = "relative w-full" >
51+ < input
52+ name = { id }
53+ id = { id }
54+ value = { props . value }
55+ placeholder = { props . placeholder }
56+ onChange = { ( e ) => props . setValue ( e . target . value ) }
57+ autoComplete = "off"
58+ type = "text"
59+ className = { `text-base bg-gh-bg border border-solid rounded-md pl-2 pr-2
60+ py-1 focus:pr-7 active:pr-7 leading-none placeholder:text-gh-text-secondary
61+ text-gh-text outline-none transition-all duration-150 peer w-full ${
62+ isError
63+ ? "border-red-500"
64+ : "focus:border-gh-blue active:border-gh-blue border-gh-border"
65+ } `}
66+ />
67+
68+ < button
69+ type = "button"
70+ onMouseDown = { ( ) => props . setValue ( "" ) }
71+ className = { twMerge (
72+ `absolute top-1/2 -translate-y-1/2 cursor-pointer right-2
73+ peer-focus:scale-100 peer-active:scale-100 scale-0
74+ transition-all duration-150` ,
75+ isError ? "text-red-500" : "text-gh-blue"
76+ ) }
77+ >
78+ < MdOutlineClear />
79+ </ button >
80+ </ div >
5981
6082 { ! isError && props . helperText && (
6183 < div className = "flex items-center gap-1 text-[.8rem] italic text-gh-text-secondary" >
0 commit comments