Skip to content

Commit

Permalink
feat: added first version of popover dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Valgoi committed Sep 30, 2020
1 parent 686e8bb commit aca17f1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/components/Popover/Info/PopoverInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';

import { Popover } from '@ui5/webcomponents-react/lib/Popover';
import { PlacementType } from '@ui5/webcomponents-react/lib/PlacementType';
import { FlexBoxDirection, Title } from '@ui5/webcomponents-react';
import { FlexBox } from '@ui5/webcomponents-react/lib/FlexBox';
import { spacing } from '@ui5/webcomponents-react-base';

export default function PopoverInfo({ popoverRef, placementType, title, children }) {
return (
<Popover ref={popoverRef} placementType={placementType && PlacementType.Bottom}>
<FlexBox direction={FlexBoxDirection.Column}>
<div className="popover-header">
<Title style={spacing.sapUiContentPadding}>{title}</Title>
</div>
<div className="popover-content">{children}</div>
</FlexBox>
</Popover>
);
}
19 changes: 19 additions & 0 deletions src/components/Popover/List/PopoverListItems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { List, StandardListItem } from '@ui5/webcomponents-react';
import React from 'react';
import PopoverInfo from '../Info/PopoverInfo';

export default function PopoverListItems({ popoverRef, title, items }) {
return (
<PopoverInfo popoverRef={popoverRef} title={title}>
<List>
{items.map((item, index) => {
return (
<StandardListItem key={index} selected={item.selected} info={item.info} icon={item.icon} description={item.description} onClick={item.onClick}>
{item.children}
</StandardListItem>
);
})}
</List>
</PopoverInfo>
);
}
26 changes: 23 additions & 3 deletions src/components/Shell/Shell.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from 'react';
import React, { useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';

import { ShellBar } from '@ui5/webcomponents-react/lib/ShellBar';
import { Avatar } from '@ui5/webcomponents-react/lib/Avatar';
import { AvatarShape } from '@ui5/webcomponents-react/lib/AvatarShape';
import { AvatarSize } from '@ui5/webcomponents-react/lib/AvatarSize';
import BrowserProvider from '../../util/URL/BrowserProvider';
import PopoverListItems from '../Popover/List/PopoverListItems';

const style = {
shell: {
Expand All @@ -19,18 +23,34 @@ const style = {
const Shell = ({ title, ...props }) => {
const { t } = useTranslation();
const history = useHistory();
const popoverConfigItemsRef = useRef(null);
const popoverItemsInterface = [
{
children: t('shell.button.user.settings.item.languageSwitch'),
icon: 'user-settings',
onClick: () => alert('activate language switch dialog'),
},
{
children: t('shell.button.user.settings.item.themeSwitch'),
icon: 'customize',
onClick: () => alert('activate theme switch dialog'),
},
];

return (
<>
<ShellBar
data-testid="shell-wrapper"
style={style.shell}
onLogoClick={() => history.push(BrowserProvider.HOME)}
primaryTitle={title}
style={style.shell}
logo={<img alt={t('shell.logo.alt')} src="https://sap.github.io/ui5-webcomponents/assets/images/sap-logo-svg.svg" />}
onLogoClick={() => history.push(BrowserProvider.HOME)}
profile={<Avatar icon="customer" shape={AvatarShape.Circle} size={AvatarSize.S} />}
onProfileClick={(e) => popoverConfigItemsRef.current.openBy(e.detail.targetRef)}
{...props}
/>
<div style={style.emptySpace} />
<PopoverListItems popoverRef={popoverConfigItemsRef} title={t('shell.button.user.settings')} items={popoverItemsInterface} />
</>
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"helmet.title.notfound": "NotFound - TodoList App",
"shell.title": "TodoList Application",
"shell.logo.alt": "SAP Logo",
"shell.button.user.settings": "User Settings",
"shell.button.user.settings.item.languageSwitch": "Language Switch",
"shell.button.user.settings.item.themeSwitch": "Theme Switch",
"page.error.text": "Ops! There was an error in loading this page",
"page.error.alt": "Error",
"page.notfound.text": "Hmmm, we could find this URL",
Expand Down

0 comments on commit aca17f1

Please sign in to comment.