From 4e8153c77eaaffaf74f012e29ddf09b7369bd4b1 Mon Sep 17 00:00:00 2001 From: Anastasiya Date: Wed, 21 Aug 2024 17:25:18 +0300 Subject: [PATCH] fix: add outlined search bar --- .../components/SearchBar/SearchBar.styled.ts | 35 ++++++++++++++++++- .../src/components/SearchBar/SearchBar.tsx | 29 ++++++++++++--- .../frontend/src/pages/project/Project.tsx | 29 +++++++++++++-- 3 files changed, 84 insertions(+), 9 deletions(-) diff --git a/application/frontend/src/components/SearchBar/SearchBar.styled.ts b/application/frontend/src/components/SearchBar/SearchBar.styled.ts index 50e5c51..4599a88 100644 --- a/application/frontend/src/components/SearchBar/SearchBar.styled.ts +++ b/application/frontend/src/components/SearchBar/SearchBar.styled.ts @@ -5,12 +5,16 @@ import { Grid, IconButton, TextField } from "@mui/material" export const SearchContainer = styled(Grid)` margin-bottom: 32px; align-items: center; + width: 100%; ` -export const SearchInput = styled(TextField)` +export const StandardSearchInput = styled(TextField)` width: 100%; .MuiInputBase-root { border-bottom: 1px solid #ccc; + display: flex; + align-items: center; + gap: 4px; &:hover { border-bottom: 1px solid #000; } @@ -26,6 +30,35 @@ export const SearchInput = styled(TextField)` } ` +export const OutlinedSearchInput = styled(TextField)` + width: 100%; + background-color: rgba(238, 238, 238, 1); + border-radius: 28px; + .MuiOutlinedInput-root { + padding: 4px; + display: flex; + align-items: center; + gap: 4px; + & fieldset { + border-color: transparent; + } + &:hover fieldset { + border-color: transparent; + } + &.Mui-focused fieldset { + border-color: transparent; + } + } +` + +export const InputAdornmentIcon = styled.div` + width: 48px; + height: 48px; + display: flex; + align-items: center; + justify-content: center; +` + export const ClearButton = styled(IconButton)` padding: 8px; color: #999; diff --git a/application/frontend/src/components/SearchBar/SearchBar.tsx b/application/frontend/src/components/SearchBar/SearchBar.tsx index fb1633f..ac26869 100644 --- a/application/frontend/src/components/SearchBar/SearchBar.tsx +++ b/application/frontend/src/components/SearchBar/SearchBar.tsx @@ -3,7 +3,13 @@ import React from "react" import ClearIcon from "@mui/icons-material/Clear" import { Grid, InputAdornment } from "@mui/material" -import { ClearButton, SearchContainer, SearchInput } from "./SearchBar.styled" +import { + ClearButton, + InputAdornmentIcon, + OutlinedSearchInput, + SearchContainer, + StandardSearchInput, +} from "./SearchBar.styled" interface SearchBarProps { searchQuery: string @@ -11,22 +17,35 @@ interface SearchBarProps { viewMode: "list" | "grid" | "timeline" onToggleViewMode: () => void onClearSearch: () => void + variant?: "standard" | "outlined" + startIcon?: React.ReactNode + placeholder?: string } export const SearchBar: React.FC = ({ searchQuery, onSearchChange, onClearSearch, + variant = "standard", + startIcon, + placeholder = "Search", }) => { + const InputComponent = variant === "outlined" ? OutlinedSearchInput : StandardSearchInput + return ( - - + + {startIcon} + + ) : null, endAdornment: searchQuery ? ( diff --git a/application/frontend/src/pages/project/Project.tsx b/application/frontend/src/pages/project/Project.tsx index 3a1308f..5d17815 100644 --- a/application/frontend/src/pages/project/Project.tsx +++ b/application/frontend/src/pages/project/Project.tsx @@ -1,11 +1,13 @@ -import React from "react" +import React, { useState } from "react" import HomeIcon from "@mui/icons-material/Home" +import SearchIcon from "@mui/icons-material/Search" import settings from "src/assets/settings.svg" import { CreateProjectButton } from "src/components/CreateProjectButton" import { NavButton } from "src/components/NavButton" import { ProjectCard } from "src/components/ProjectCard" +import { SearchBar } from "src/components/SearchBar" import { Container, @@ -22,6 +24,20 @@ const projects = [ ] export const ProjectPage: React.FC = () => { + const [searchQuery, setSearchQuery] = useState("") + + const handleSearchChange = (e: React.ChangeEvent) => { + setSearchQuery(e.target.value) + } + + const handleClearSearch = () => { + setSearchQuery("") + } + + const filteredProjects = projects.filter((project) => + project.name.toLowerCase().includes(searchQuery.toLowerCase()), + ) + return ( }> @@ -37,9 +53,16 @@ export const ProjectPage: React.FC = () => { console.log("Create Project")} /> - + } + placeholder="Search" + /> - {projects.map((project) => ( + {filteredProjects.map((project) => ( ))}