index.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {Children} from 'react';
  2. import styled from '@emotion/styled';
  3. import SearchBar from 'sentry/components/searchBar';
  4. import space from 'sentry/styles/space';
  5. type Props = {
  6. onChange: (value: string) => void;
  7. placeholder: string;
  8. query: string;
  9. className?: string;
  10. /**
  11. * The filter must be the SearchBarFilter component
  12. */
  13. filter?: React.ReactElement;
  14. };
  15. function SearchBarAction({onChange, query, placeholder, filter, className}: Props) {
  16. return (
  17. <Wrapper className={className}>
  18. {filter}
  19. <StyledSearchBar
  20. onChange={onChange}
  21. query={query}
  22. placeholder={placeholder}
  23. blendWithFilter={!!filter}
  24. />
  25. </Wrapper>
  26. );
  27. }
  28. export default SearchBarAction;
  29. const Wrapper = styled('div')`
  30. display: grid;
  31. gap: ${space(2)};
  32. width: 100%;
  33. margin-top: ${space(1)};
  34. position: relative;
  35. @media (min-width: ${props => props.theme.breakpoints.small}) {
  36. margin-top: 0;
  37. gap: 0;
  38. grid-template-columns: ${p =>
  39. p.children && Children.toArray(p.children).length === 1
  40. ? '1fr'
  41. : 'max-content 1fr'};
  42. justify-content: flex-end;
  43. }
  44. @media (min-width: ${props => props.theme.breakpoints.medium}) {
  45. width: 400px;
  46. }
  47. @media (min-width: ${props => props.theme.breakpoints.xlarge}) {
  48. width: 600px;
  49. }
  50. `;
  51. // TODO(matej): remove this once we refactor SearchBar to not use css classes
  52. // - it could accept size as a prop
  53. const StyledSearchBar = styled(SearchBar)<{blendWithFilter?: boolean}>`
  54. width: 100%;
  55. position: relative;
  56. .search-input {
  57. height: 34px;
  58. }
  59. .search-clear-form,
  60. .search-input-icon {
  61. height: 32px;
  62. display: flex;
  63. align-items: center;
  64. }
  65. @media (min-width: ${props => props.theme.breakpoints.small}) {
  66. ${p =>
  67. p.blendWithFilter &&
  68. `
  69. .search-input,
  70. .search-input:focus {
  71. border-top-left-radius: 0;
  72. border-bottom-left-radius: 0;
  73. }
  74. `}
  75. }
  76. `;