-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from msqd/feat_search_bar
Feat search bar
- Loading branch information
Showing
23 changed files
with
351 additions
and
66 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
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
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
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
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
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
9 changes: 9 additions & 0 deletions
9
harp_apps/dashboard/frontend/src/ui/Components/SearchBar/SearchBar.stories.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,9 @@ | ||
import { SearchBar } from "./SearchBar" | ||
|
||
export const Default = () => { | ||
return ( | ||
<> | ||
<SearchBar placeHolder="Search" className="w-1/2" /> | ||
</> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
harp_apps/dashboard/frontend/src/ui/Components/SearchBar/SearchBar.test.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,11 @@ | ||
import { render } from "@testing-library/react" | ||
import { expect, describe, it } from "vitest" | ||
|
||
import { SearchBar } from "./SearchBar" | ||
|
||
describe("SearchBar", () => { | ||
it("renders correctly", () => { | ||
const { container } = render(<SearchBar />) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
}) |
55 changes: 55 additions & 0 deletions
55
harp_apps/dashboard/frontend/src/ui/Components/SearchBar/SearchBar.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,55 @@ | ||
import { useRef } from "react" | ||
|
||
interface SearchBarProps { | ||
label?: string | ||
placeHolder?: string | ||
setSearch?: (value: string) => void | ||
className?: string | ||
} | ||
|
||
export const SearchBar = ({ label, setSearch, className, placeHolder }: SearchBarProps) => { | ||
const inputRef = useRef<HTMLInputElement>(null) | ||
|
||
const handleKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === "Enter") { | ||
if (setSearch) { | ||
setSearch(e.currentTarget.value) | ||
} | ||
} | ||
} | ||
|
||
const handleSearchClick = () => { | ||
if (inputRef.current) { | ||
if (setSearch) { | ||
setSearch(inputRef.current.value) | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<div className={className}> | ||
{label && ( | ||
<label htmlFor="search" className="block text-sm font-medium leading-6 text-gray-900"> | ||
{label} | ||
</label> | ||
)} | ||
<div className="mt-2 space-x-1 py-1 pl-1.5 flex text-base items-center rounded ring-1 text-gray-900 ring-inset ring-gray-200 placeholder:text-gray-400"> | ||
<input | ||
ref={inputRef} | ||
type="text" | ||
autoComplete="off" | ||
name="search" | ||
id="search" | ||
placeholder={placeHolder} | ||
onKeyDown={handleKeyPress} | ||
className="overflow-ellipsis w-full !border-0 !p-0 focus:!ring-0 !ml-1" | ||
/> | ||
<div onClick={handleSearchClick} className="inset-y-0 right-0 flex py-1.5 pr-1.5 hover:cursor-pointer"> | ||
<kbd className="inline-flex items-center rounded border border-gray-200 px-1 py-0.5 font-sans text-sm text-gray-400"> | ||
Enter | ||
</kbd> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.