SearchBar.tsx 2.1 KB

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