SearchBar.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React, { useState } from "react";
  2. import Button from "./Button";
  3. import styled from "styled-components";
  4. interface Props {
  5. setSearchFilter: (x: string) => void;
  6. disabled: boolean;
  7. prompt?: string;
  8. }
  9. const SearchBar: React.FC<Props> = ({ setSearchFilter, disabled, prompt }) => {
  10. const [searchInput, setSearchInput] = useState("");
  11. return (
  12. <SearchRowWrapper>
  13. <SearchBarWrapper>
  14. <i className="material-icons">search</i>
  15. <SearchInput
  16. value={searchInput}
  17. onChange={(e: any) => {
  18. setSearchInput(e.target.value);
  19. }}
  20. onKeyPress={({ key }) => {
  21. if (key === "Enter") {
  22. setSearchFilter(searchInput);
  23. }
  24. }}
  25. placeholder={prompt}
  26. />
  27. </SearchBarWrapper>
  28. <ButtonWrapper disabled={disabled}>
  29. <Button
  30. onClick={() => setSearchFilter(searchInput)}
  31. disabled={disabled}
  32. >
  33. Search
  34. </Button>
  35. </ButtonWrapper>
  36. </SearchRowWrapper>
  37. );
  38. };
  39. export default SearchBar;
  40. const SearchRow = styled.div`
  41. display: flex;
  42. align-items: center;
  43. height: 40px;
  44. background: #ffffff11;
  45. border-bottom: 1px solid #606166;
  46. margin-bottom: 10px;
  47. `;
  48. const SearchRowWrapper = styled(SearchRow)`
  49. border-bottom: 0;
  50. border: 1px solid #ffffff55;
  51. border-radius: 3px;
  52. `;
  53. const ButtonWrapper = styled.div`
  54. background: ${(props: { disabled?: boolean }) =>
  55. props.disabled ? "#aaaabbee" : "#616FEEcc"};
  56. :hover {
  57. background: ${(props: { disabled?: boolean }) =>
  58. props.disabled ? "" : "#505edddd"};
  59. }
  60. height: 40px;
  61. display: flex;
  62. align-items: center;
  63. `;
  64. const SearchBarWrapper = styled.div`
  65. display: flex;
  66. flex: 1;
  67. > i {
  68. color: #aaaabb;
  69. padding-top: 1px;
  70. margin-left: 13px;
  71. font-size: 18px;
  72. margin-right: 8px;
  73. }
  74. `;
  75. const SearchInput = styled.input`
  76. outline: none;
  77. border: none;
  78. font-size: 13px;
  79. background: none;
  80. width: 100%;
  81. color: white;
  82. height: 20px;
  83. `;