index.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {useRef} from 'react';
  2. import {useHotkeys} from 'react-hotkeys-hook';
  3. import styled from '@emotion/styled';
  4. import {Search} from 'sentry/components/search';
  5. import {IconSearch} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. const MIN_SEARCH_LENGTH = 1;
  8. const MAX_RESULTS = 10;
  9. function SettingsSearch() {
  10. const searchInput = useRef<HTMLInputElement>(null);
  11. useHotkeys('/', e => {
  12. e.preventDefault();
  13. searchInput.current?.focus();
  14. });
  15. return (
  16. <Search
  17. entryPoint="settings_search"
  18. minSearch={MIN_SEARCH_LENGTH}
  19. maxResults={MAX_RESULTS}
  20. renderInput={({getInputProps}) => (
  21. <SearchInputWrapper>
  22. <SearchInputIcon size="14px" />
  23. <SearchInput
  24. {...getInputProps({type: 'text', placeholder: t('Search')})}
  25. ref={searchInput}
  26. />
  27. </SearchInputWrapper>
  28. )}
  29. />
  30. );
  31. }
  32. export default SettingsSearch;
  33. const SearchInputWrapper = styled('div')`
  34. position: relative;
  35. `;
  36. const SearchInputIcon = styled(IconSearch)`
  37. color: ${p => p.theme.gray300};
  38. position: absolute;
  39. left: 10px;
  40. top: 8px;
  41. `;
  42. const SearchInput = styled('input')`
  43. color: ${p => p.theme.formText};
  44. background-color: ${p => p.theme.background};
  45. transition: border-color 0.15s ease;
  46. font-size: 14px;
  47. width: 260px;
  48. line-height: 1;
  49. padding: 5px 8px 4px 28px;
  50. border: 1px solid ${p => p.theme.border};
  51. border-radius: 30px;
  52. height: 28px;
  53. box-shadow: inset ${p => p.theme.dropShadowLight};
  54. &:focus {
  55. outline: none;
  56. border: 1px solid ${p => p.theme.border};
  57. }
  58. &::placeholder {
  59. color: ${p => p.theme.formPlaceholder};
  60. }
  61. `;