All files / menu option-profile.js

100% Statements 11/11
100% Branches 12/12
50% Functions 1/2
100% Lines 11/11

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                                                                      3x   3x       3x       3x       3x       3x       3x       3x         3x 3x   3x                                                                      
/*
Copyright (c) 2018-2019 Uber Technologies, Inc.
 
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
 
// @flow
import * as React from 'react';
// Components
import MaybeChildMenu from './maybe-child-menu.js';
import {
  StyledListItemProfile,
  StyledProfileImgContainer,
  StyledProfileImg,
  StyledProfileLabelsContainer,
  StyledProfileTitle,
  StyledProfileSubtitle,
  StyledProfileBody,
} from './styled-components.js';
import {getOverrides} from '../helpers/overrides.js';
// Types
import type {OptionProfilePropsT} from './types.js';
 
export default function OptionProfile(props: OptionProfilePropsT) {
  const {
    item,
    getChildMenu,
    getProfileItemLabels,
    getProfileItemImg,
    getProfileItemImgText,
    overrides = {},
    resetMenu = () => {},
    $isHighlighted,
    ...restProps
  } = props;
 
  const [ListItemProfile, listItemProfileProps] = getOverrides(
    overrides.ListItemProfile,
    StyledListItemProfile,
  );
  const [ProfileImgContainer, profileImgContainerProps] = getOverrides(
    overrides.ProfileImgContainer,
    StyledProfileImgContainer,
  );
  const [ProfileImg, profileImgProps] = getOverrides(
    overrides.ProfileImg,
    StyledProfileImg,
  );
  const [ProfileLabelsContainer, profileLabelsContainerProps] = getOverrides(
    overrides.ProfileLabelsContainer,
    StyledProfileLabelsContainer,
  );
  const [ProfileTitle, profileTitleProps] = getOverrides(
    overrides.ProfileTitle,
    StyledProfileTitle,
  );
  const [ProfileSubtitle, profileSubtitleProps] = getOverrides(
    overrides.ProfileSubtitle,
    StyledProfileSubtitle,
  );
  const [ProfileBody, profileBodyProps] = getOverrides(
    overrides.ProfileBody,
    StyledProfileBody,
  );
 
  const ItemImg = getProfileItemImg(item);
  const {title, subtitle, body} = getProfileItemLabels(item);
 
  return (
    <MaybeChildMenu
      getChildMenu={getChildMenu}
      isOpen={!!$isHighlighted}
      item={item}
      resetParentMenu={resetMenu}
    >
      <ListItemProfile {...restProps} {...listItemProfileProps}>
        <ProfileImgContainer {...profileImgContainerProps}>
          {ItemImg &&
            (typeof ItemImg === 'string' ? (
              // Render img src string wrapped with image component
              <ProfileImg
                src={ItemImg}
                alt={getProfileItemImgText(item)}
                {...profileImgProps}
              />
            ) : (
              // Or just render the entire component user specified
              <ItemImg {...profileImgProps} />
            ))}
        </ProfileImgContainer>
        <ProfileLabelsContainer {...profileLabelsContainerProps}>
          {title && <ProfileTitle {...profileTitleProps}>{title}</ProfileTitle>}
          {subtitle && (
            <ProfileSubtitle {...profileSubtitleProps}>
              {subtitle}
            </ProfileSubtitle>
          )}
          {body && <ProfileBody {...profileBodyProps}>{body}</ProfileBody>}
        </ProfileLabelsContainer>
      </ListItemProfile>
    </MaybeChildMenu>
  );
}