LogSearchBar.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React, { useState } from "react";
  2. import Button from "./Button";
  3. import styled from "styled-components";
  4. import dayjs from "dayjs";
  5. interface Props {
  6. searchText: string;
  7. setSearchText: (x: string) => void;
  8. setEnteredSearchText: (x: string) => void;
  9. setSelectedDate: () => void;
  10. }
  11. const escapeRegExp = (str: string) => {
  12. return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
  13. };
  14. const LogSearchBar: React.FC<Props> = ({
  15. searchText,
  16. setSearchText,
  17. setEnteredSearchText,
  18. setSelectedDate,
  19. }) => {
  20. return (
  21. <SearchRowWrapper>
  22. <SearchBarWrapper>
  23. <i className="material-icons">search</i>
  24. <SearchInput
  25. value={searchText}
  26. onChange={(e: any) => {
  27. setSearchText(e.target.value);
  28. }}
  29. onKeyPress={(event) => {
  30. if (event.key === "Enter") {
  31. setEnteredSearchText(escapeRegExp(searchText));
  32. setSelectedDate();
  33. }
  34. }}
  35. placeholder="Search logs..."
  36. />
  37. </SearchBarWrapper>
  38. </SearchRowWrapper>
  39. );
  40. };
  41. export default LogSearchBar;
  42. const SearchBarWrapper = styled.div`
  43. display: flex;
  44. flex: 1;
  45. > i {
  46. color: #aaaabb;
  47. padding-top: 1px;
  48. margin-left: 8px;
  49. font-size: 16px;
  50. margin-right: 8px;
  51. }
  52. `;
  53. const SearchInput = styled.input`
  54. outline: none;
  55. border: none;
  56. font-size: 13px;
  57. background: none;
  58. width: 100%;
  59. color: white;
  60. height: 100%;
  61. `;
  62. const SearchRow = styled.div`
  63. display: flex;
  64. align-items: center;
  65. height: 30px;
  66. margin-right: 10px;
  67. background: #26292e;
  68. border-radius: 5px;
  69. border: 1px solid #aaaabb33;
  70. `;
  71. const SearchRowWrapper = styled(SearchRow)`
  72. border-radius: 5px;
  73. width: 250px;
  74. `;