-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0d54d2
commit 98a8052
Showing
15 changed files
with
1,000 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import Header from './Header'; | ||
import LearningHeader from './learning-header/LearningHeader'; | ||
import StudioHeader from './studio-header'; | ||
import messages from './i18n/index'; | ||
|
||
export { LearningHeader, messages }; | ||
export { LearningHeader, messages, StudioHeader }; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const BrandNav = ({ | ||
studioBaseUrl, | ||
logo, | ||
logoAltText, | ||
}) => ( | ||
<a href={studioBaseUrl}> | ||
<img | ||
src={logo} | ||
alt={logoAltText} | ||
className="d-block logo" | ||
/> | ||
</a> | ||
); | ||
|
||
BrandNav.propTypes = { | ||
studioBaseUrl: PropTypes.string.isRequired, | ||
logo: PropTypes.string.isRequired, | ||
logoAltText: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default BrandNav; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import { | ||
OverlayTrigger, | ||
Tooltip, | ||
} from '@edx/paragon'; | ||
import messages from './messages'; | ||
|
||
const CourseLockUp = ({ | ||
outlineLink, | ||
org, | ||
number, | ||
title, | ||
// injected | ||
intl, | ||
}) => ( | ||
<OverlayTrigger | ||
placement="bottom" | ||
overlay={( | ||
<Tooltip id="course-lock-up"> | ||
{title} | ||
</Tooltip> | ||
)} | ||
> | ||
<a | ||
className="course-title-lockup w-25 mr-2" | ||
href={outlineLink} | ||
aria-label={intl.formatMessage(messages['header.label.courseOutline'])} | ||
data-testid="course-lock-up-block" | ||
> | ||
<span className="d-block small m-0 text-gray-800" data-testid="course-org-number">{org} {number}</span> | ||
<span className="d-block m-0 font-weight-bold text-gray-800" data-testid="course-title">{title}</span> | ||
</a> | ||
</OverlayTrigger> | ||
); | ||
|
||
CourseLockUp.propTypes = { | ||
number: PropTypes.string, | ||
org: PropTypes.string, | ||
title: PropTypes.string, | ||
outlineLink: PropTypes.string, | ||
// injected | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
CourseLockUp.defaultProps = { | ||
number: null, | ||
org: null, | ||
title: null, | ||
outlineLink: null, | ||
}; | ||
|
||
export default injectIntl(CourseLockUp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
ActionRow, | ||
Button, | ||
Container, | ||
Nav, | ||
Row, | ||
} from '@edx/paragon'; | ||
import { Close, MenuIcon } from '@edx/paragon/icons'; | ||
|
||
import CourseLockUp from './CourseLockUp'; | ||
import UserMenu from './UserMenu'; | ||
import BrandNav from './BrandNav'; | ||
import NavDropdownMenu from './NavDropdownMenu'; | ||
|
||
const HeaderBody = ({ | ||
logo, | ||
logoAltText, | ||
number, | ||
org, | ||
title, | ||
username, | ||
isAdmin, | ||
studioBaseUrl, | ||
logoutUrl, | ||
authenticatedUserAvatar, | ||
isMobile, | ||
setModalPopupTarget, | ||
toggleModalPopup, | ||
isModalPopupOpen, | ||
isHiddenMainMenu, | ||
mainMenuDropdowns, | ||
outlineLink, | ||
}) => { | ||
const renderBrandNav = ( | ||
<BrandNav | ||
{...{ | ||
studioBaseUrl, | ||
logo, | ||
logoAltText, | ||
}} | ||
/> | ||
); | ||
|
||
return ( | ||
<Container size="xl" className="px-4"> | ||
<ActionRow as="header"> | ||
{isHiddenMainMenu ? ( | ||
<Row className="flex-nowrap ml-4"> | ||
{renderBrandNav} | ||
</Row> | ||
) : ( | ||
<> | ||
{isMobile ? ( | ||
<Button | ||
ref={setModalPopupTarget} | ||
className="d-inline-flex align-items-center" | ||
variant="tertiary" | ||
onClick={toggleModalPopup} | ||
iconBefore={isModalPopupOpen ? Close : MenuIcon} | ||
data-testid="mobile-menu-button" | ||
> | ||
Menu | ||
</Button> | ||
) : ( | ||
<Row className="flex-nowrap m-0"> | ||
{renderBrandNav} | ||
<CourseLockUp | ||
{...{ | ||
outlineLink, | ||
number, | ||
org, | ||
title, | ||
}} | ||
/> | ||
</Row> | ||
)} | ||
{isMobile ? ( | ||
<> | ||
<ActionRow.Spacer /> | ||
{renderBrandNav} | ||
</> | ||
) : ( | ||
<Nav data-testid="desktop-menu" className="ml-4"> | ||
{mainMenuDropdowns.map(dropdown => { | ||
const { id, buttonTitle, items } = dropdown; | ||
return ( | ||
<NavDropdownMenu {...{ id, buttonTitle, items }} /> | ||
); | ||
})} | ||
</Nav> | ||
)} | ||
</> | ||
)} | ||
<ActionRow.Spacer /> | ||
<Nav> | ||
<UserMenu | ||
{...{ | ||
username, | ||
studioBaseUrl, | ||
logoutUrl, | ||
authenticatedUserAvatar, | ||
isAdmin, | ||
}} | ||
/> | ||
</Nav> | ||
</ActionRow> | ||
</Container> | ||
); | ||
}; | ||
|
||
HeaderBody.propTypes = { | ||
studioBaseUrl: PropTypes.string.isRequired, | ||
logoutUrl: PropTypes.string.isRequired, | ||
setModalPopupTarget: PropTypes.func.isRequired, | ||
toggleModalPopup: PropTypes.func.isRequired, | ||
isModalPopupOpen: PropTypes.bool.isRequired, | ||
number: PropTypes.string, | ||
org: PropTypes.string, | ||
title: PropTypes.string, | ||
logo: PropTypes.string, | ||
logoAltText: PropTypes.string, | ||
authenticatedUserAvatar: PropTypes.string, | ||
username: PropTypes.string, | ||
isAdmin: PropTypes.bool, | ||
isMobile: PropTypes.bool, | ||
isHiddenMainMenu: PropTypes.bool, | ||
mainMenuDropdowns: PropTypes.arrayOf(PropTypes.shape({ | ||
id: PropTypes.string, | ||
buttonTitle: PropTypes.string, | ||
items: PropTypes.arrayOf(PropTypes.shape({ | ||
href: PropTypes.string, | ||
title: PropTypes.string, | ||
})), | ||
})), | ||
outlineLink: PropTypes.string, | ||
}; | ||
|
||
HeaderBody.defaultProps = { | ||
logo: null, | ||
logoAltText: null, | ||
number: '', | ||
org: '', | ||
title: '', | ||
authenticatedUserAvatar: null, | ||
username: null, | ||
isAdmin: false, | ||
isMobile: false, | ||
isHiddenMainMenu: false, | ||
mainMenuDropdowns: [], | ||
outlineLink: null, | ||
}; | ||
|
||
export default HeaderBody; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useToggle, ModalPopup } from '@edx/paragon'; | ||
import HeaderBody from './HeaderBody'; | ||
import MobileMenu from './MobileMenu'; | ||
|
||
const MobileHeader = ({ | ||
mainMenuDropdowns, | ||
...props | ||
}) => { | ||
const [isOpen, , close, toggle] = useToggle(false); | ||
const [target, setTarget] = useState(null); | ||
|
||
return ( | ||
<> | ||
<HeaderBody | ||
{...props} | ||
isMobile | ||
setModalPopupTarget={setTarget} | ||
toggleModalPopup={toggle} | ||
isModalPopupOpen={isOpen} | ||
/> | ||
<ModalPopup | ||
hasArrow | ||
placement="bottom" | ||
positionRef={target} | ||
isOpen={isOpen} | ||
onClose={close} | ||
onEscapeKey={close} | ||
className="mobile-menu-container" | ||
> | ||
<MobileMenu {...{ mainMenuDropdowns }} /> | ||
</ModalPopup> | ||
</> | ||
); | ||
}; | ||
|
||
MobileHeader.propTypes = { | ||
studioBaseUrl: PropTypes.string.isRequired, | ||
logoutUrl: PropTypes.string.isRequired, | ||
setModalPopupTarget: PropTypes.func.isRequired, | ||
toggleModalPopup: PropTypes.func.isRequired, | ||
isModalPopupOpen: PropTypes.bool.isRequired, | ||
number: PropTypes.string, | ||
org: PropTypes.string, | ||
title: PropTypes.string, | ||
logo: PropTypes.string, | ||
logoAltText: PropTypes.string, | ||
authenticatedUserAvatar: PropTypes.string, | ||
username: PropTypes.string, | ||
isAdmin: PropTypes.bool, | ||
mainMenuDropdowns: PropTypes.arrayOf(PropTypes.shape({ | ||
id: PropTypes.string, | ||
buttonTitle: PropTypes.string, | ||
items: PropTypes.arrayOf(PropTypes.shape({ | ||
href: PropTypes.string, | ||
title: PropTypes.string, | ||
})), | ||
})), | ||
outlineLink: PropTypes.string, | ||
}; | ||
|
||
MobileHeader.defaultProps = { | ||
logo: null, | ||
logoAltText: null, | ||
number: null, | ||
org: null, | ||
title: null, | ||
authenticatedUserAvatar: null, | ||
username: null, | ||
isAdmin: false, | ||
mainMenuDropdowns: [], | ||
outlineLink: null, | ||
}; | ||
|
||
export default MobileHeader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Collapsible } from '@edx/paragon'; | ||
|
||
const MobileMenu = ({ | ||
mainMenuDropdowns, | ||
}) => ( | ||
<div | ||
className="ml-4 p-2 bg-light-100 border border-gray-200 small rounded" | ||
data-testid="mobile-menu" | ||
> | ||
<div> | ||
{mainMenuDropdowns.map(dropdown => { | ||
const { id, buttonTitle, items } = dropdown; | ||
return ( | ||
<Collapsible | ||
className="border-light-100" | ||
title={buttonTitle} | ||
key={id} | ||
> | ||
<ul className="p-0" style={{ listStyleType: 'none' }}> | ||
{items.map(item => ( | ||
<li className="mobile-menu-item"> | ||
<a href={item.href}> | ||
{item.title} | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
</Collapsible> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
|
||
MobileMenu.propTypes = { | ||
mainMenuDropdowns: PropTypes.arrayOf(PropTypes.shape({ | ||
id: PropTypes.string, | ||
buttonTitle: PropTypes.string, | ||
items: PropTypes.arrayOf(PropTypes.shape({ | ||
href: PropTypes.string, | ||
title: PropTypes.string, | ||
})), | ||
})), | ||
}; | ||
MobileMenu.defaultProps = { | ||
mainMenuDropdowns: [], | ||
}; | ||
|
||
export default MobileMenu; |
Oops, something went wrong.