commandPalette.tsx 2.0 KB

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