Skip to content

Commit

Permalink
feat(client): Implement custom search input (closes #184)
Browse files Browse the repository at this point in the history
  • Loading branch information
dusty3ntity committed Aug 25, 2020
1 parent 4bde7b1 commit 108e419
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,5 @@
.filters-btn {
border-radius: 1.3rem;
}

.group-by-date-btn {
padding: 0 8px;
}
}
}
46 changes: 19 additions & 27 deletions client-app/src/app/styles/global/inputs/search-input.less
Original file line number Diff line number Diff line change
@@ -1,49 +1,41 @@
.ant-input-affix-wrapper {
max-height: unset;
}

.ant-input-search {
height: 100%;
width: 100%;
.search-input {
display: flex;
padding: 6px 16px;
border-radius: 20px;
border: 1px solid @body-background;
border-top-color: #dcdadab0;
border-left-color: #e4d8d84f;

padding: 4px 16px !important;
transition: all 0.3s;

box-shadow: -1px -1px 2px #ccd5dc80, 1px 1px 2px rgba(250, 255, 255, 0.3),
inset 3px 3px 8px rgba(204, 213, 220, 0.9), inset -3px -3px 6px rgba(250, 255, 255, 0.9),
inset 3px -3px 6px rgba(204, 213, 220, 0.2), inset -3px 3px 6px rgba(204, 213, 220, 0.2);

&:focus-within {
&:focus-within,
&:hover {
border: 1px solid @primary-color;
border-style: solid;
}

.anticon-search {
color: @primary-color;
font-size: 16px;
}

.ant-input {
input {
flex-grow: 2;
border: none;
outline: none;
padding: 2px 0;
font-size: 20px;
background: none;
text-overflow: ellipsis;

background: transparent;

&::placeholder {
color: #909aa4cc;
}
}

.ant-input-suffix {
.search-btn {
padding: 4px;
margin-left: 16px;
}

.ant-input-search-icon {
margin: 0;
padding: 6px;
border-radius: 50%;
background: @body-background;
box-shadow: 1px 1px 3px rgba(204, 213, 221, 0.9), -1px -1px 2px rgba(250, 255, 255, 0.9),
1px -1px 2px rgba(204, 213, 221, 0.2), -1px 1px 2px rgba(204, 213, 221, 0.2),
Expand All @@ -58,10 +50,10 @@
inset 1px 1px 3px rgba(204, 213, 220, 0.9), inset -1px -1px 2px rgba(250, 255, 255, 0.9),
inset 1px -1px 2px rgba(204, 213, 220, 0.2), inset -1px 1px 2px rgba(204, 213, 220, 0.2);
}
}

.ant-input-search-icon::before,
.ant-input-search-icon::after {
display: none;
.icon {
height: 18px;
width: 18px;
}
}
}
37 changes: 37 additions & 0 deletions client-app/src/components/common/inputs/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { useState } from "react";

import Button from "./Button";
import SearchIcon from "../../icons/SearchIcon";

interface IProps {
onSearch: (value: string) => void;
loading?: boolean;
defaultValue: string;
placeholder?: string;
}

const SearchInput: React.FC<IProps> = ({ onSearch, loading, defaultValue, placeholder }) => {
const [searchValue, setSearchValue] = useState(defaultValue);

const handleSearch = () => {
onSearch(searchValue);
};

return (
<div className="search-input">
<input
type="text"
autoComplete="off"
placeholder={placeholder || ""}
value={searchValue}
onChange={(e) => setSearchValue(e.target.value)}
onKeyPress={(e) => {
if (e.key === "Enter") handleSearch();
}}
/>
<Button icon={<SearchIcon />} className="search-btn" onClick={handleSearch} loading={loading} />
</div>
);
};

export default SearchInput;
18 changes: 18 additions & 0 deletions client-app/src/components/icons/SearchIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";

// search-black-24dp

interface IProps {
className?: string;
}

const SearchIcon: React.FC<IProps> = ({ className }) => {
return (
<svg className={"icon search-icon " + className} viewBox="0 0 24 24">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M15.5 14h-.79l-.28-.27c1.2-1.4 1.82-3.31 1.48-5.34-.47-2.78-2.79-5-5.59-5.34-4.23-.52-7.79 3.04-7.27 7.27.34 2.8 2.56 5.12 5.34 5.59 2.03.34 3.94-.28 5.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" />
</svg>
);
};

export default SearchIcon;
11 changes: 5 additions & 6 deletions client-app/src/components/items-list/items-list/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useContext } from "react";
import { observer } from "mobx-react-lite";
import Search from "antd/lib/input/Search";

import { RootStoreContext } from "../../../app/stores/rootStore";
import FilterIcon from "../../icons/FilterIcon";
Expand All @@ -9,6 +8,7 @@ import { fireAnalyticsEvent } from "../../../app/common/analytics/analytics";
import Button from "../../common/inputs/Button";
import StarIcon from "../../icons/StarIcon";
import Tooltip from "../../common/tooltips/Tooltip";
import SearchInput from "../../common/inputs/SearchInput";

const Header = () => {
const rootStore = useContext(RootStoreContext);
Expand Down Expand Up @@ -81,13 +81,12 @@ const Header = () => {
analyticsAction="Opened the item filters drawer"
/>

<Search
<SearchInput
key={rootStore.dictionaryStore.activeDictionaryId}
id="item-search"
placeholder="item..."
loading={loadingInitial || loadingNext}
defaultValue={predicate.get("search") ?? ""}
onSearch={handleSearch}
loading={loadingInitial || loadingNext}
defaultValue={predicate.get("search")}
placeholder="item..."
/>
</div>
</div>
Expand Down

0 comments on commit 108e419

Please sign in to comment.