-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat(add): ✨ added add dropdown (#177)
* feat(add): ✨ added add dropdown * feat(add): 🚧 stuck in focus issue * fix(scrapper): ⚡️ added scrapper error proceed condition * fix(add): 🐛 fixed the add focus issue * refactor(add modal): ♻️ removed add modal and unused store states
- Loading branch information
1 parent
9783dcd
commit ee8c738
Showing
11 changed files
with
164 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/components/customDropdowns.tsx/addBookmarkDropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { useRef } from "react"; | ||
import { isEmpty, isNull } from "lodash"; | ||
import { useForm, type SubmitHandler } from "react-hook-form"; | ||
|
||
import AddBoomarkInputIcon from "../../icons/miscellaneousIcons/addBoomarkInputIcon"; | ||
import PlusIconWhite from "../../icons/plusIconWhite"; | ||
import { | ||
dropdownMenuClassName, | ||
grayInputClassName, | ||
} from "../../utils/commonClassNames"; | ||
import { URL_PATTERN } from "../../utils/constants"; | ||
import { AriaDropdown } from "../ariaDropdown"; | ||
import Button from "../atoms/button"; | ||
import Input from "../atoms/input"; | ||
|
||
export type AddBookmarkDropdownTypes = { | ||
onAddBookmark: (url: string) => void; | ||
}; | ||
|
||
const AddBookmarkDropdown = ({ onAddBookmark }: AddBookmarkDropdownTypes) => { | ||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors }, | ||
reset, | ||
clearErrors, | ||
} = useForm<{ url: string }>(); | ||
const onSubmit: SubmitHandler<{ url: string }> = (data) => { | ||
onAddBookmark(data.url); | ||
reset({ url: "" }); | ||
}; | ||
|
||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const { ref, ...rest } = register("url", { | ||
required: true, | ||
pattern: URL_PATTERN, | ||
}); | ||
|
||
return ( | ||
<AriaDropdown | ||
initialFocusRef={inputRef} | ||
menuButton={ | ||
<Button | ||
className="rounded-full p-[7px] hover:bg-black" | ||
title="create" | ||
type="dark" | ||
> | ||
<figure className="h-4 w-4"> | ||
<PlusIconWhite /> | ||
</figure> | ||
</Button> | ||
} | ||
menuOpenToggle={(value) => { | ||
if (value === false) { | ||
reset({ url: "" }); | ||
clearErrors(); | ||
} | ||
}} | ||
> | ||
<div className={`relative w-[326px] ${dropdownMenuClassName}`}> | ||
<AddBoomarkInputIcon className="absolute left-[14px] top-[13px] z-[1]" /> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<Input | ||
autoFocus | ||
className={`rounded-[11px] pl-[32px] ${grayInputClassName}`} | ||
errorClassName="ml-2" | ||
{...rest} | ||
errorText="Enter valid URL" | ||
isError={!isEmpty(errors)} | ||
placeholder="Add a link or drop a file anywhere" | ||
ref={(event) => { | ||
ref(event); | ||
if (!isNull(inputRef)) { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
inputRef.current = event; | ||
} | ||
}} | ||
/> | ||
</form> | ||
</div> | ||
</AriaDropdown> | ||
); | ||
}; | ||
|
||
export default AddBookmarkDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const AddBoomarkInputIcon = ({ className = "" }) => ( | ||
<svg | ||
className={className} | ||
fill="none" | ||
height="16" | ||
viewBox="0 0 17 16" | ||
width="17" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<g clipPath="url(#clip0_8563_33222)"> | ||
<rect | ||
height="10.0149" | ||
rx="2.5" | ||
stroke="#707070" | ||
transform="rotate(7.33079 7.15575 3.55971)" | ||
width="8.58873" | ||
x="7.15575" | ||
y="3.55971" | ||
/> | ||
<rect | ||
fill="#FAFAFA" | ||
height="11.1327" | ||
rx="2.5" | ||
stroke="#707070" | ||
transform="rotate(-13.8817 0.744027 3.85372)" | ||
width="9.37244" | ||
x="0.744027" | ||
y="3.85372" | ||
/> | ||
<path d="M6.01514 5.75L7.24241 10.25" stroke="#707070" /> | ||
<path d="M8.87891 7.38672L4.37891 8.61399" stroke="#707070" /> | ||
</g> | ||
<defs> | ||
<clipPath id="clip0_8563_33222"> | ||
<rect fill="white" height="16" transform="translate(0.5)" width="16" /> | ||
</clipPath> | ||
</defs> | ||
</svg> | ||
); | ||
|
||
export default AddBoomarkInputIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.