breadcrumbDropdown.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {useState} from 'react';
  2. import DropdownAutoCompleteMenu from 'sentry/components/dropdownAutoComplete/menu';
  3. import type {Item} from 'sentry/components/dropdownAutoComplete/types';
  4. import Crumb from 'sentry/views/settings/components/settingsBreadcrumb/crumb';
  5. import Divider from 'sentry/views/settings/components/settingsBreadcrumb/divider';
  6. import type {RouteWithName} from './types';
  7. interface AdditionalDropdownProps
  8. extends Pick<
  9. React.ComponentProps<typeof DropdownAutoCompleteMenu>,
  10. 'onChange' | 'busyItemsStillVisible'
  11. > {}
  12. export interface BreadcrumbDropdownProps extends AdditionalDropdownProps {
  13. items: Item[];
  14. name: React.ReactNode;
  15. onSelect: (item: Item) => void;
  16. route: RouteWithName;
  17. hasMenu?: boolean;
  18. isLast?: boolean;
  19. }
  20. function BreadcrumbDropdown({
  21. hasMenu,
  22. route,
  23. isLast,
  24. name,
  25. onSelect,
  26. ...dropdownProps
  27. }: BreadcrumbDropdownProps) {
  28. const [isActive, setIsActive] = useState(false);
  29. return (
  30. <DropdownAutoCompleteMenu
  31. blendCorner={false}
  32. isOpen={isActive}
  33. virtualizedHeight={41}
  34. onSelect={item => {
  35. setIsActive(false);
  36. onSelect(item);
  37. }}
  38. menuProps={{
  39. onMouseEnter: () => setIsActive(true),
  40. onMouseLeave: () => setIsActive(false),
  41. }}
  42. {...dropdownProps}
  43. >
  44. {({getActorProps, isOpen}) => (
  45. <Crumb
  46. {...getActorProps({
  47. onClick: () => setIsActive(false),
  48. onMouseEnter: () => setIsActive(true),
  49. onMouseLeave: () => setIsActive(false),
  50. })}
  51. >
  52. <span>{name || route.name} </span>
  53. <Divider isHover={hasMenu && isOpen} isLast={isLast} />
  54. </Crumb>
  55. )}
  56. </DropdownAutoCompleteMenu>
  57. );
  58. }
  59. export default BreadcrumbDropdown;