From bc897a6bfb2973fa38c5c610fb3405bee5c5aff7 Mon Sep 17 00:00:00 2001 From: phntxx Date: Sun, 21 Mar 2021 10:55:27 +0100 Subject: [PATCH 1/4] Added disappearing buttons to submit and clear --- src/components/elements.tsx | 3 +- src/components/searchBar.tsx | 61 +++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/components/elements.tsx b/src/components/elements.tsx index 4756c99..4a01e32 100644 --- a/src/components/elements.tsx +++ b/src/components/elements.tsx @@ -50,7 +50,8 @@ export const Button = styled.button` border: 1px solid ${selectedTheme.mainColor}; color: ${selectedTheme.mainColor}; background: none; - min-height: 3em; + + min-height: 2rem; height: 100%; &:hover { diff --git a/src/components/searchBar.tsx b/src/components/searchBar.tsx index b12fb64..b842c73 100644 --- a/src/components/searchBar.tsx +++ b/src/components/searchBar.tsx @@ -1,22 +1,43 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import styled from "styled-components"; import selectedTheme from "./themeManager"; +import { Button } from "./elements"; + +const Search = styled.form` + width: 100%; + height: 2rem; + + display: flex; + + padding-top: 0.25rem; +`; + const SearchInput = styled.input` width: 100%; + font-size: 1rem; + border: none; border-bottom: 1px solid ${selectedTheme.accentColor}; + background: none; border-radius: 0; color: ${selectedTheme.mainColor}; + margin: 0px; + :focus { outline: none; } `; +const SearchButton = styled(Button)` + margin: 0px 2px; + min-height: 0; +`; + export interface ISearchProviderProps { name: string; url: string; @@ -28,10 +49,15 @@ interface ISearchBarProps { } const SearchBar = ({ providers }: ISearchBarProps) => { - let [input, setInput] = useState(""); + let [input, setInput] = useState(""); + let [buttonsHidden, setButtonsHidden] = useState(true); + + useEffect(() => { + setButtonsHidden(input === ""); + }, [input]); const handleSearchQuery = (e: React.FormEvent) => { - var query = input || ""; + var query: string = input || ""; if (query.split(" ")[0].includes("/")) { handleQueryWithProvider(query); @@ -43,13 +69,14 @@ const SearchBar = ({ providers }: ISearchBarProps) => { }; const handleQueryWithProvider = (query: string) => { - let queryArray = query.split(" "); - let prefix = queryArray[0]; + let queryArray: Array = query.split(" "); + let prefix: string = queryArray[0]; + queryArray.shift(); - let searchQuery = queryArray.join(" "); + let searchQuery: string = queryArray.join(" "); - let providerFound = false; + let providerFound: boolean = false; if (providers) { providers.forEach((provider: ISearchProviderProps) => { if (provider.prefix === prefix) { @@ -64,13 +91,25 @@ const SearchBar = ({ providers }: ISearchBarProps) => { }; return ( -
handleSearchQuery(e)}> + handleSearchQuery(e)}> setInput(e.target.value)} + value={input} + onChange={(e: React.ChangeEvent) => + setInput(e.target.value) + } > -