commandPalette.tsx 2.1 KB

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