index.tsx 1.6 KB

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