Skip to content

Commit fb9e647

Browse files
lpohrenMarcusNotheis
authored andcommitted
Merge pull request #64 from LuisValgoi/issue-57
[ISSUE-57] Base Version of Shell Buttons
1 parent b648391 commit fb9e647

File tree

6 files changed

+85
-16
lines changed

6 files changed

+85
-16
lines changed

packages/ui5-webcomponents-react-seed/src/App.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import Routes from './routes/Routes';
1111
import './App.css';
1212
import CenteredContent from './components/Layout/CenteredContent';
1313

14-
const style = {
15-
emptySpace: {
16-
paddingTop: '44px',
17-
},
18-
};
19-
2014
function App() {
2115
const { t } = useTranslation();
2216

@@ -25,7 +19,6 @@ function App() {
2519
<ReactQueryDevtools initialIsOpen={false} />
2620
<Helmet title={t('helmet.title.app')} />
2721
<Shell title={t('shell.title')} />
28-
<div style={style.emptySpace} />
2922
<ErrorBoundary>
3023
<CenteredContent>
3124
<Routes />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
3+
import { Popover } from '@ui5/webcomponents-react/lib/Popover';
4+
import { PlacementType } from '@ui5/webcomponents-react/lib/PlacementType';
5+
import { FlexBoxDirection, Title } from '@ui5/webcomponents-react';
6+
import { FlexBox } from '@ui5/webcomponents-react/lib/FlexBox';
7+
import { spacing } from '@ui5/webcomponents-react-base';
8+
9+
export default function PopoverInfo({ popoverRef, placementType, title, children }) {
10+
return (
11+
<Popover ref={popoverRef} placementType={placementType && PlacementType.Bottom}>
12+
<FlexBox direction={FlexBoxDirection.Column}>
13+
<div className="popover-header">
14+
<Title style={spacing.sapUiContentPadding}>{title}</Title>
15+
</div>
16+
<div className="popover-content">{children}</div>
17+
</FlexBox>
18+
</Popover>
19+
);
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { List, StandardListItem } from '@ui5/webcomponents-react';
2+
import React from 'react';
3+
import PopoverInfo from '../Info/PopoverInfo';
4+
5+
export default function PopoverListItems({ popoverRef, title, items }) {
6+
return (
7+
<PopoverInfo popoverRef={popoverRef} title={title}>
8+
<List>
9+
{items.map((item, index) => {
10+
return (
11+
<StandardListItem key={index} selected={item.selected} info={item.info} icon={item.icon} description={item.description} onClick={item.onClick}>
12+
{item.children}
13+
</StandardListItem>
14+
);
15+
})}
16+
</List>
17+
</PopoverInfo>
18+
);
19+
}

packages/ui5-webcomponents-react-seed/src/components/Shell/Shell.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,57 @@
1-
import React from 'react';
1+
import React, { useRef } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { useHistory } from 'react-router-dom';
44

55
import { ShellBar } from '@ui5/webcomponents-react/lib/ShellBar';
6+
import { Avatar } from '@ui5/webcomponents-react/lib/Avatar';
7+
import { AvatarShape } from '@ui5/webcomponents-react/lib/AvatarShape';
8+
import { AvatarSize } from '@ui5/webcomponents-react/lib/AvatarSize';
69
import BrowserProvider from '../../util/URL/BrowserProvider';
10+
import PopoverListItems from '../Popover/List/PopoverListItems';
711

812
const style = {
913
shell: {
1014
position: 'fixed',
1115
width: '100%',
1216
zIndex: 100,
1317
},
18+
emptySpace: {
19+
paddingTop: '44px',
20+
},
1421
};
1522

1623
const Shell = ({ title, ...props }) => {
1724
const { t } = useTranslation();
1825
const history = useHistory();
26+
const popoverConfigItemsRef = useRef(null);
27+
const popoverItemsInterface = [
28+
{
29+
children: t('shell.button.user.settings.item.languageSwitch'),
30+
icon: 'user-settings',
31+
onClick: () => alert('activate language switch dialog'),
32+
},
33+
{
34+
children: t('shell.button.user.settings.item.themeSwitch'),
35+
icon: 'customize',
36+
onClick: () => alert('activate theme switch dialog'),
37+
},
38+
];
1939

2040
return (
21-
<ShellBar
22-
data-testid="shell-wrapper"
23-
style={style.shell}
24-
onLogoClick={() => history.push(BrowserProvider.HOME)}
25-
primaryTitle={title}
26-
logo={<img alt={t('shell.logo.alt')} src="https://sap.github.io/ui5-webcomponents/assets/images/sap-logo-svg.svg" />}
27-
{...props}
28-
/>
41+
<>
42+
<ShellBar
43+
data-testid="shell-wrapper"
44+
primaryTitle={title}
45+
style={style.shell}
46+
logo={<img alt={t('shell.logo.alt')} src="https://sap.github.io/ui5-webcomponents/assets/images/sap-logo-svg.svg" />}
47+
onLogoClick={() => history.push(BrowserProvider.HOME)}
48+
profile={<Avatar icon="customer" shape={AvatarShape.Circle} size={AvatarSize.S} />}
49+
onProfileClick={(e) => popoverConfigItemsRef.current.openBy(e.detail.targetRef)}
50+
{...props}
51+
/>
52+
<div style={style.emptySpace} />
53+
<PopoverListItems popoverRef={popoverConfigItemsRef} title={t('shell.button.user.settings')} items={popoverItemsInterface} />
54+
</>
2955
);
3056
};
3157

packages/ui5-webcomponents-react-seed/src/components/Shell/__snapshots__/Shell.test.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,13 @@ exports[`Shell.js Test Suite should match snapshot 1`] = `
1010
slot="logo"
1111
src="https://sap.github.io/ui5-webcomponents/assets/images/sap-logo-svg.svg"
1212
/>
13+
<ui5-avatar
14+
background-color="Accent6"
15+
icon="customer"
16+
image-fit-type="Cover"
17+
shape="Circle"
18+
size="S"
19+
slot="profile"
20+
/>
1321
</ui5-shellbar>
1422
`;

packages/ui5-webcomponents-react-seed/src/locales/en/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"helmet.title.notfound": "NotFound - TodoList App",
55
"shell.title": "TodoList Application",
66
"shell.logo.alt": "SAP Logo",
7+
"shell.button.user.settings": "User Settings",
8+
"shell.button.user.settings.item.languageSwitch": "Language Switch",
9+
"shell.button.user.settings.item.themeSwitch": "Theme Switch",
710
"page.error.text": "Ops! There was an error in loading this page",
811
"page.error.alt": "Error",
912
"page.notfound.text": "Hmmm, we could find this URL",

0 commit comments

Comments
 (0)