From 30c138d13f1de812e98e71238169ce0dd4220040 Mon Sep 17 00:00:00 2001 From: Anika Raemer Date: Sun, 14 Sep 2025 14:10:46 +0200 Subject: [PATCH] add custom search field component --- frontend/src/App.css | 2 +- .../src/components/basics/SearchField.tsx | 73 +++++++++++++++++++ .../src/components/recipes/RecipeEditor.tsx | 2 +- .../src/components/recipes/RecipeListPage.tsx | 16 ++-- 4 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 frontend/src/components/basics/SearchField.tsx diff --git a/frontend/src/App.css b/frontend/src/App.css index ae4e583..79dc4f9 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -43,7 +43,7 @@ /* input field */ .input-field { - @apply border p-2 w-full rounded placeholder-gray-400; + @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 { diff --git a/frontend/src/components/basics/SearchField.tsx b/frontend/src/components/basics/SearchField.tsx new file mode 100644 index 0000000..acce6a7 --- /dev/null +++ b/frontend/src/components/basics/SearchField.tsx @@ -0,0 +1,73 @@ +/** + * Custom search field component including a clear search functionality + */ +type SearchFieldProps = { + searchString : string + onSearchStringChanged: (searchString : string) => void +} + +/** + * @param SearchFieldProps consisting of an initial searchString and an onSearchStringChanged handler + * @returns Custom search field component + */ +export default function SearchField({searchString, onSearchStringChanged} : SearchFieldProps){ + const setSearchString = (newSearchString : string) => { + searchString = newSearchString; + onSearchStringChanged(searchString) + } + + return ( +
+ {/* Input of searchfield + Defines border and behavior. Requires extra padding at both sides to + accomodate the icons + */} + setSearchString(e.target.value) } + /> + {/* Right icon: X + Clears search string on click + */} + + {/* Left icon: Looking glass */} +
+ + + +
+
+ ) +} diff --git a/frontend/src/components/recipes/RecipeEditor.tsx b/frontend/src/components/recipes/RecipeEditor.tsx index ea8540d..040fc5b 100644 --- a/frontend/src/components/recipes/RecipeEditor.tsx +++ b/frontend/src/components/recipes/RecipeEditor.tsx @@ -121,7 +121,7 @@ export default function RecipeEditor({ recipe, onSave, onCancel }: RecipeEditorP

Instructions

{/* Instructions */}