-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathMainNav.js
63 lines (56 loc) · 2 KB
/
MainNav.js
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
import React, { useEffect, useRef, useState } from 'react';
import { useIntl } from 'react-intl';
import { branding } from 'stripes-config';
import { Icon } from '@folio/stripes-components';
import css from './MainNav.css';
import NavButton from './NavButton';
import NavDivider from './NavDivider';
import { CurrentAppGroup } from './CurrentApp';
import ProfileDropdown from './ProfileDropdown';
import AppList from './AppList';
import { SkipLink } from './components';
import { useAppOrderContext } from './AppOrderProvider';
import { useStripes } from '../../StripesContext';
const MainNav = () => {
const {
apps,
} = useAppOrderContext();
const stripes = useStripes();
const intl = useIntl();
const [selectedApp, setSelectedApp] = useState(apps.find(entry => entry.active));
const helpUrl = useRef(stripes.config.helpUrl ?? 'https://docs.folio.org').current;
// This logic changes the visible current app at the starting side of the Main Navigation.
useEffect(() => {
setSelectedApp(apps.find(entry => entry.active));
}, [apps]);
return (
<header className={css.navRoot} style={branding?.style?.mainNav ?? {}}>
<div className={css.startSection}>
<SkipLink />
<CurrentAppGroup selectedApp={selectedApp} config={stripes.config} />
</div>
<nav aria-label={intl.formatMessage({ id: 'stripes-core.mainnav.topLevelLabel' })} className={css.endSection}>
<AppList
apps={apps}
selectedApp={selectedApp}
dropdownToggleId="app-list-dropdown-toggle"
/>
<NavDivider md="hide" />
<NavButton
aria-label={intl.formatMessage({ id: 'stripes-core.help' })}
data-test-item-help-button
href={helpUrl}
icon={<Icon
icon="question-mark"
size="large"
/>}
id="helpButton"
target="_blank"
/>
<NavDivider md="hide" />
<ProfileDropdown stripes={stripes} />
</nav>
</header>
);
};
export default MainNav;