-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add search bar functionality #27
Merged
+107
−17
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
717db4f
feat: add SearchBar component
hestro 227552a
feat: style SearchBar
hestro 9fa61d0
feat: add SearchBar to BookGrid
hestro 7a91e7e
feat: add name and aria-label to search input
hestro aac16c4
feat: add responsive styling to SearchBar
hestro f245c20
feat: add useDebounce hook
hestro c9adfe3
feat: use debounced search query in BookGrid
hestro 463ad94
fix: keep SearchBar visible in all BookGrid states
hestro 00a50e0
Merge branch 'main' into feat/search-bar
hestro 9f5f1f2
style: rename camelCase class name to kebab-case
hestro acedad2
docs: credit Stack Overflow source in useDebounce
hestro 6f099bf
Merge branch 'main' into feat/search-bar
martakam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,21 @@ | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| // Debounce pattern largely adapted from this Stack Overflow post: | ||
| // https://stackoverflow.com/questions/75556418/how-to-use-debounce-hooks-in-react | ||
| function useDebounce<T>(value: T, delay: number): T { | ||
| const [debouncedValue, setDebouncedValue] = useState(value); | ||
|
|
||
| useEffect(() => { | ||
| const timeoutId = window.setTimeout(() => { | ||
| setDebouncedValue(value); | ||
| }, delay); | ||
|
|
||
| return () => { | ||
| window.clearTimeout(timeoutId); | ||
| }; | ||
| }, [value, delay]); | ||
|
|
||
| return debouncedValue; | ||
| } | ||
|
|
||
| export { useDebounce }; |
This file contains hidden or 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,22 @@ | ||
| .search-bar { | ||
| display: block; | ||
| width: 100%; | ||
| max-width: 500px; | ||
| padding: 10px 16px; | ||
| margin: 80px auto 0 auto; | ||
|
|
||
| border: 1px solid var(--border-color); | ||
| border-radius: var(--border-radius); | ||
| font-size: 1rem; | ||
| font-family: inherit; | ||
|
|
||
| &:hover { | ||
| border-color: var(--theme-color); | ||
| } | ||
|
|
||
| @media only screen and (max-width: 600px) { | ||
| width: calc(100% - 80px); /* Adjust width to account for the margins*/ | ||
| margin: 40px 40px 0 40px; | ||
| max-width: none; | ||
| } | ||
| } |
This file contains hidden or 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,22 @@ | ||
| import styles from "./SearchBar.module.css"; | ||
|
|
||
| interface SearchBarProps { | ||
| query: string; | ||
| onQueryChange: (newQuery: string) => void; | ||
| } | ||
|
|
||
| function SearchBar({ query, onQueryChange }: SearchBarProps) { | ||
| return ( | ||
| <input | ||
| type="search" | ||
| name="search" | ||
| aria-label="Search for books" | ||
| className={styles.searchBar} | ||
| placeholder="Search books..." | ||
| value={query} | ||
| onChange={(e) => onQueryChange(e.target.value)} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export { SearchBar }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.