dropdownMenuSectionV2.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import styled from '@emotion/styled';
  2. import {useMenuSection} from '@react-aria/menu';
  3. import {Node} from '@react-types/shared';
  4. import {MenuItemProps} from 'sentry/components/dropdownMenuItemV2';
  5. import space from 'sentry/styles/space';
  6. type Props = {
  7. children: React.ReactNode;
  8. node: Node<MenuItemProps>;
  9. };
  10. /**
  11. * A wrapper component for menu sections. See:
  12. * https://react-spectrum.adobe.com/react-aria/useMenu.html
  13. */
  14. function MenuSection({node, children}: Props) {
  15. const {itemProps, headingProps, groupProps} = useMenuSection({
  16. heading: node.rendered,
  17. 'aria-label': node['aria-label'],
  18. });
  19. return (
  20. <MenuSectionWrap {...itemProps}>
  21. {node.rendered && <Heading {...headingProps}>{node.rendered}</Heading>}
  22. <Group {...groupProps}>{children}</Group>
  23. </MenuSectionWrap>
  24. );
  25. }
  26. export default MenuSection;
  27. const MenuSectionWrap = styled('li')`
  28. list-style-type: none;
  29. `;
  30. const Heading = styled('span')`
  31. display: inline-block;
  32. font-weight: 600;
  33. font-size: ${p => p.theme.fontSizeSmall};
  34. color: ${p => p.theme.subText};
  35. text-transform: uppercase;
  36. white-space: nowrap;
  37. margin: ${space(1)} ${space(1.5)} ${space(0.5)};
  38. padding-right: ${space(1)};
  39. ${/* sc-selector */ MenuSectionWrap}:first-of-type & {
  40. margin-top: ${space(0.5)};
  41. }
  42. `;
  43. const Group = styled('ul')`
  44. list-style-type: none;
  45. padding: 0;
  46. margin: 0;
  47. `;