index.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 legacySize="14px" />
  20. <SearchInput
  21. aria-label={t('Search Settings')}
  22. {...getInputProps({type: 'text', placeholder: t('Search')})}
  23. ref={searchInput}
  24. />
  25. </SearchInputWrapper>
  26. )}
  27. />
  28. );
  29. }
  30. export default SettingsSearch;
  31. const SearchInputWrapper = styled('div')`
  32. position: relative;
  33. `;
  34. const SearchInputIcon = styled(IconSearch)`
  35. color: ${p => p.theme.gray300};
  36. position: absolute;
  37. left: 10px;
  38. top: 8px;
  39. `;
  40. const SearchInput = styled('input')`
  41. color: ${p => p.theme.formText};
  42. background-color: ${p => p.theme.background};
  43. transition: border-color 0.15s ease;
  44. font-size: 14px;
  45. width: 260px;
  46. line-height: 1;
  47. padding: 5px 8px 4px 28px;
  48. border: 1px solid ${p => p.theme.border};
  49. border-radius: 30px;
  50. height: 28px;
  51. box-shadow: inset ${p => p.theme.dropShadowMedium};
  52. &:focus {
  53. outline: none;
  54. border: 1px solid ${p => p.theme.border};
  55. }
  56. &::placeholder {
  57. color: ${p => p.theme.formPlaceholder};
  58. }
  59. `;