index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React from 'react';
  2. import keydown from 'react-keydown';
  3. import styled from '@emotion/styled';
  4. import Search from 'app/components/search';
  5. import {IconSearch} from 'app/icons';
  6. import {t} from 'app/locale';
  7. const MIN_SEARCH_LENGTH = 1;
  8. const MAX_RESULTS = 10;
  9. type Props = {};
  10. class SettingsSearch extends React.Component<Props> {
  11. searchInput = React.createRef<HTMLInputElement>();
  12. @keydown('/')
  13. handleFocusSearch(e: React.FormEvent<HTMLInputElement>) {
  14. if (!this.searchInput.current) {
  15. return;
  16. }
  17. if (e.target === this.searchInput.current) {
  18. return;
  19. }
  20. e.preventDefault();
  21. this.searchInput.current.focus();
  22. }
  23. render() {
  24. return (
  25. <Search
  26. entryPoint="settings_search"
  27. minSearch={MIN_SEARCH_LENGTH}
  28. maxResults={MAX_RESULTS}
  29. renderInput={({getInputProps}) => (
  30. <SearchInputWrapper>
  31. <SearchInputIcon size="14px" />
  32. <SearchInput
  33. {...getInputProps({
  34. type: 'text',
  35. placeholder: t('Search'),
  36. })}
  37. ref={this.searchInput}
  38. />
  39. </SearchInputWrapper>
  40. )}
  41. />
  42. );
  43. }
  44. }
  45. // This is so we can use this as a selector for emotion
  46. const StyledSettingsSearch = styled(SettingsSearch)``;
  47. export default StyledSettingsSearch;
  48. // We use named export for StyledSettingsSearch to prevent circular import in `app/components/search/searchResult`
  49. export {SettingsSearch, StyledSettingsSearch};
  50. const SearchInputWrapper = styled('div')`
  51. position: relative;
  52. `;
  53. const SearchInputIcon = styled(IconSearch)`
  54. color: ${p => p.theme.gray300};
  55. position: absolute;
  56. left: 10px;
  57. top: 8px;
  58. `;
  59. const SearchInput = styled('input')`
  60. color: ${p => p.theme.formText};
  61. background-color: ${p => p.theme.background};
  62. transition: border-color 0.15s ease;
  63. font-size: 14px;
  64. width: 260px;
  65. line-height: 1;
  66. padding: 5px 8px 4px 28px;
  67. border: 1px solid ${p => p.theme.border};
  68. border-radius: 30px;
  69. height: 28px;
  70. box-shadow: inset ${p => p.theme.dropShadowLight};
  71. &:focus {
  72. outline: none;
  73. border: 1px solid ${p => p.theme.border};
  74. }
  75. &::placeholder {
  76. color: ${p => p.theme.formPlaceholder};
  77. }
  78. `;