commandPalette.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {useEffect} from 'react';
  2. import {ClassNames, css, useTheme} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import {ModalRenderProps} from 'sentry/actionCreators/modal';
  5. import Input from 'sentry/components/input';
  6. import {Search} from 'sentry/components/search';
  7. import {t} from 'sentry/locale';
  8. import space from 'sentry/styles/space';
  9. import {analytics} from 'sentry/utils/analytics';
  10. function CommandPalette({Body}: ModalRenderProps) {
  11. const theme = useTheme();
  12. useEffect(() => void analytics('omnisearch.open', {}), []);
  13. return (
  14. <Body>
  15. <ClassNames>
  16. {({css: injectedCss}) => (
  17. <Search
  18. entryPoint="command_palette"
  19. minSearch={1}
  20. maxResults={10}
  21. dropdownClassName={injectedCss`
  22. width: 100%;
  23. border: transparent;
  24. border-top-left-radius: 0;
  25. border-top-right-radius: 0;
  26. position: initial;
  27. box-shadow: none;
  28. border-top: 1px solid ${theme.border};
  29. `}
  30. renderInput={({getInputProps}) => (
  31. <InputWrapper>
  32. <StyledInput
  33. autoFocus
  34. {...getInputProps({
  35. type: 'text',
  36. placeholder: t('Search for projects, teams, settings, etc...'),
  37. })}
  38. />
  39. </InputWrapper>
  40. )}
  41. />
  42. )}
  43. </ClassNames>
  44. </Body>
  45. );
  46. }
  47. export default CommandPalette;
  48. export const modalCss = css`
  49. [role='document'] {
  50. padding: 0;
  51. }
  52. `;
  53. const InputWrapper = styled('div')`
  54. padding: ${space(0.25)};
  55. `;
  56. const StyledInput = styled(Input)`
  57. width: 100%;
  58. padding: ${space(1)};
  59. border-radius: 8px;
  60. outline: none;
  61. border: none;
  62. box-shadow: none;
  63. :focus,
  64. :active,
  65. :hover {
  66. outline: none;
  67. border: none;
  68. box-shadow: none;
  69. }
  70. `;