fix search field behavior
This commit is contained in:
parent
30c138d13f
commit
5c3c74b32e
4 changed files with 19 additions and 15 deletions
|
|
@ -28,6 +28,10 @@
|
||||||
@apply font-semibold mb-2 mt-4;
|
@apply font-semibold mb-2 mt-4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
@apply text-gray-600
|
||||||
|
}
|
||||||
|
|
||||||
/* buttons */
|
/* buttons */
|
||||||
.primary-button {
|
.primary-button {
|
||||||
@apply bg-blue-300 px-4 py-2 shadow-md rounded-lg hover:bg-blue-400 text-gray-600 whitespace-nowrap
|
@apply bg-blue-300 px-4 py-2 shadow-md rounded-lg hover:bg-blue-400 text-gray-600 whitespace-nowrap
|
||||||
|
|
@ -41,15 +45,11 @@
|
||||||
@apply bg-gray-600 hover:bg-gray-800 text-white shadow-md rounded px-4 py-2 whitespace-nowrap
|
@apply bg-gray-600 hover:bg-gray-800 text-white shadow-md rounded px-4 py-2 whitespace-nowrap
|
||||||
}
|
}
|
||||||
|
|
||||||
/* input field */
|
/* input fields like input and textarea */
|
||||||
.input-field {
|
.input-field {
|
||||||
@apply p-2 w-full border rounded-md placeholder-gray-400 border-gray-600 hover:border-blue-600 transition-colors text-gray-600 focus:outline-none focus:border-blue-800;
|
@apply p-2 w-full border rounded-md placeholder-gray-400 border-gray-600 hover:border-blue-600 transition-colors text-gray-600 focus:outline-none focus:border-blue-800;
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-area {
|
|
||||||
@apply border p-2 w-full mb-2 rounded placeholder-gray-400;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* groups */
|
/* groups */
|
||||||
.button-group{
|
.button-group{
|
||||||
@apply flex gap-4 mt-4;
|
@apply flex gap-4 mt-4;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom search field component including a clear search functionality
|
* Custom search field component including a clear search functionality
|
||||||
*/
|
*/
|
||||||
type SearchFieldProps = {
|
type SearchFieldProps = {
|
||||||
searchString : string
|
|
||||||
onSearchStringChanged: (searchString : string) => void
|
onSearchStringChanged: (searchString : string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -10,10 +11,13 @@ type SearchFieldProps = {
|
||||||
* @param SearchFieldProps consisting of an initial searchString and an onSearchStringChanged handler
|
* @param SearchFieldProps consisting of an initial searchString and an onSearchStringChanged handler
|
||||||
* @returns Custom search field component
|
* @returns Custom search field component
|
||||||
*/
|
*/
|
||||||
export default function SearchField({searchString, onSearchStringChanged} : SearchFieldProps){
|
export default function SearchField({onSearchStringChanged} : SearchFieldProps){
|
||||||
const setSearchString = (newSearchString : string) => {
|
const [currentSearchString, setCurrentSearchString] = useState<string>("")
|
||||||
searchString = newSearchString;
|
|
||||||
onSearchStringChanged(searchString)
|
const changeSearchString = (newSearchString : string) => {
|
||||||
|
console.log(newSearchString);
|
||||||
|
setCurrentSearchString(newSearchString);
|
||||||
|
onSearchStringChanged(newSearchString)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -26,15 +30,15 @@ export default function SearchField({searchString, onSearchStringChanged} : Sear
|
||||||
className="input-field pl-10 pr-10"
|
className="input-field pl-10 pr-10"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search"
|
placeholder="Search"
|
||||||
value={searchString}
|
value={currentSearchString}
|
||||||
onChange={ e => setSearchString(e.target.value) }
|
onChange={ e => changeSearchString(e.target.value) }
|
||||||
/>
|
/>
|
||||||
{/* Right icon: X
|
{/* Right icon: X
|
||||||
Clears search string on click
|
Clears search string on click
|
||||||
*/}
|
*/}
|
||||||
<button
|
<button
|
||||||
className="absolute right-0 inset-y-0 flex items-center"
|
className="absolute right-0 inset-y-0 flex items-center"
|
||||||
onClick = { () => setSearchString("") }
|
onClick = { () => changeSearchString("") }
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { Link } from "react-router-dom"
|
||||||
type RecipeListItemProps = {
|
type RecipeListItemProps = {
|
||||||
title: string
|
title: string
|
||||||
targetPath: string
|
targetPath: string
|
||||||
imageUrl?: string
|
imageUrl?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ export default function RecipeListPage() {
|
||||||
<h1 className="content-title text-blue-900">Recipes</h1>
|
<h1 className="content-title text-blue-900">Recipes</h1>
|
||||||
<div className="flex columns-4 content-stretch gap-2 items-center">
|
<div className="flex columns-4 content-stretch gap-2 items-center">
|
||||||
{/* Number of recipes inlist */}
|
{/* Number of recipes inlist */}
|
||||||
<label className="text-gray-500 w-2/3">{recipeList.length} Recipes</label>
|
<label className="label w-2/3">{recipeList.length} Recipes</label>
|
||||||
{/* Search field */}
|
{/* Search field */}
|
||||||
<SearchField
|
<SearchField
|
||||||
searchString=""
|
searchString=""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue