Skip to content

Commit

Permalink
Merge pull request #64 from LuisValgoi/issue-57
Browse files Browse the repository at this point in the history
[ISSUE-57] Base Version of Shell Buttons
  • Loading branch information
lpohren committed Sep 30, 2020
2 parents 928e574 + 697a1ec commit 63d7488
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 16 deletions.
7 changes: 0 additions & 7 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import Routes from './routes/Routes';
import './App.css';
import CenteredContent from './components/Layout/CenteredContent';

const style = {
emptySpace: {
paddingTop: '44px',
},
};

function App() {
const { t } = useTranslation();

Expand All @@ -25,7 +19,6 @@ function App() {
<ReactQueryDevtools initialIsOpen={false} />
<Helmet title={t('helmet.title.app')} />
<Shell title={t('shell.title')} />
<div style={style.emptySpace} />
<ErrorBoundary>
<CenteredContent>
<Routes />
Expand Down
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>
);
}
44 changes: 35 additions & 9 deletions src/components/Shell/Shell.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,57 @@
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: {
position: 'fixed',
width: '100%',
zIndex: 100,
},
emptySpace: {
paddingTop: '44px',
},
};

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}
logo={<img alt={t('shell.logo.alt')} src="https://sap.github.io/ui5-webcomponents/assets/images/sap-logo-svg.svg" />}
{...props}
/>
<>
<ShellBar
data-testid="shell-wrapper"
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
8 changes: 8 additions & 0 deletions src/components/Shell/__snapshots__/Shell.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ exports[`Shell.js Test Suite should match snapshot 1`] = `
slot="logo"
src="https://sap.github.io/ui5-webcomponents/assets/images/sap-logo-svg.svg"
/>
<ui5-avatar
background-color="Accent6"
icon="customer"
image-fit-type="Cover"
shape="Circle"
size="S"
slot="profile"
/>
</ui5-shellbar>
`;
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 63d7488

Please sign in to comment.