All files / src/DropdownMenu DropdownMenuPopover.tsx

100% Statements 9/9
100% Branches 0/0
100% Functions 2/2
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112                      1x                                                                 68x 68x                                                                   68x   68x               68x         1x   68x 68x                            
import { Box as ReakitBox, useMenu as useReakitMenu, MenuProps as ReakitMenuProps } from 'reakit';
 
import { useClassName, createComponent, createElement, createHook } from '../utils';
import { Box, BoxProps } from '../Box';
 
import * as styles from './styles';
import { Popover as popoverStyles } from '../Popover/styles';
 
export type LocalDropdownMenuPopoverProps = {};
export type DropdownMenuPopoverProps = BoxProps & ReakitMenuProps & LocalDropdownMenuPopoverProps;
 
const useProps = createHook<DropdownMenuPopoverProps>(
  (props, { themeKey, themeKeyOverride }) => {
    const {
      baseId,
      first,
      hide,
      hideOnClickOutside,
      last,
      modal,
      move,
      next,
      orientation,
      placement,
      preventBodyScroll,
      previous,
      setModal,
      stops,
      unstable_initialFocusRef,
      unstable_finalFocusRef,
      unstable_popoverRef,
      unstable_popoverStyles,
      unstable_modal,
      unstable_orphan,
      unstable_autoFocusOnShow,
      unstable_autoFocusOnHide,
      unstable_animating,
      unstable_animated,
      unstable_setIsMounted,
      unstable_setBaseId,
      unstable_idCountRef,
      unstable_stopAnimation,
      visible,
      ...restProps
    } = props;
    const dropdownMenuPopoverProps = useReakitMenu(
      {
        baseId,
        first,
        hide,
        hideOnClickOutside,
        last,
        modal,
        move,
        next,
        orientation,
        placement,
        preventBodyScroll,
        previous,
        setModal,
        stops,
        unstable_initialFocusRef,
        unstable_finalFocusRef,
        unstable_popoverRef,
        unstable_popoverStyles,
        unstable_modal,
        unstable_orphan,
        unstable_autoFocusOnShow,
        unstable_autoFocusOnHide,
        unstable_animating,
        unstable_animated,
        unstable_setIsMounted,
        unstable_setBaseId,
        unstable_idCountRef,
        unstable_stopAnimation,
        visible
      },
      restProps
    );
    const boxProps = Box.useProps({ ...restProps, ...dropdownMenuPopoverProps });
 
    const className = useClassName({
      style: [styles.DropdownMenuPopover, popoverStyles],
      styleProps: props,
      themeKey,
      themeKeyOverride,
      prevClassName: boxProps.className
    });
 
    return { ...boxProps, className };
  },
  { defaultProps: { altitude: '200' }, themeKey: 'DropdownMenu.Popover' }
);
 
export const DropdownMenuPopover = createComponent<DropdownMenuPopoverProps>(
  props => {
    const dropdownMenuPopoverProps = useProps(props);
    return createElement({
      children: props.children,
      component: ReakitBox,
      use: props.use,
      htmlProps: dropdownMenuPopoverProps
    });
  },
  {
    attach: {
      useProps
    },
    themeKey: 'DropdownMenu.Popover'
  }
);