index.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {useMemo, useRef} from 'react';
  2. import styled from '@emotion/styled';
  3. import {InputGroup} from 'sentry/components/core/input/inputGroup';
  4. import {Search} from 'sentry/components/search';
  5. import {IconSearch} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import {useHotkeys} from 'sentry/utils/useHotkeys';
  8. const MIN_SEARCH_LENGTH = 1;
  9. const MAX_RESULTS = 10;
  10. function SettingsSearch() {
  11. const searchInput = useRef<HTMLInputElement>(null);
  12. const settingsSearchHotkeys = useMemo(() => {
  13. return [{match: '/', callback: () => searchInput.current?.focus()}];
  14. }, []);
  15. useHotkeys(settingsSearchHotkeys);
  16. return (
  17. <Search
  18. entryPoint="settings_search"
  19. minSearch={MIN_SEARCH_LENGTH}
  20. maxResults={MAX_RESULTS}
  21. renderInput={({getInputProps}) => (
  22. <InputGroup>
  23. <InputGroup.LeadingItems>
  24. <IconSearch size="sm" />
  25. </InputGroup.LeadingItems>
  26. <StyledSearchInput
  27. size="sm"
  28. aria-label={t('Search Settings')}
  29. {...getInputProps({type: 'text', placeholder: t('Search')})}
  30. ref={searchInput}
  31. />
  32. </InputGroup>
  33. )}
  34. />
  35. );
  36. }
  37. export default SettingsSearch;
  38. const StyledSearchInput = styled(InputGroup.Input)`
  39. width: 260px;
  40. `;