generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from eea/develop
Release
- Loading branch information
Showing
11 changed files
with
459 additions
and
27 deletions.
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
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
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,95 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Slugger from 'github-slugger'; | ||
import AnchorLink from 'react-anchor-link-smooth-scroll'; | ||
import { Icon } from '@plone/volto/components'; | ||
|
||
import downIcon from '@plone/volto/icons/down-key.svg'; | ||
import upIcon from '@plone/volto/icons/up-key.svg'; | ||
|
||
import withEEASideMenu from '@eeacms/volto-block-toc/hocs/withEEASideMenu'; | ||
import { normalizeString } from './helpers'; | ||
import './less/side-menu.less'; | ||
|
||
const RenderMenuItems = ({ items }) => ( | ||
<> | ||
{items.map((item, index) => { | ||
const { title, override_toc, plaintext, items: subItems } = item; | ||
const slug = override_toc | ||
? Slugger.slug(normalizeString(plaintext)) | ||
: Slugger.slug(normalizeString(title)); | ||
return ( | ||
<React.Fragment key={index}> | ||
<li className="toc-menu-list-item"> | ||
<AnchorLink href={`#${slug}`} className="toc-menu-list-title"> | ||
{title} | ||
</AnchorLink> | ||
</li> | ||
{subItems && subItems.length > 0 && ( | ||
<RenderMenuItems items={subItems} /> | ||
)} | ||
</React.Fragment> | ||
); | ||
})} | ||
</> | ||
); | ||
|
||
const RenderTocEntries = ({ | ||
tocEntries, | ||
title, | ||
defaultOpen, | ||
isMenuOpenOnOutsideClick, | ||
}) => { | ||
const [isNavOpen, setIsNavOpen] = React.useState(!defaultOpen); | ||
|
||
React.useEffect(() => { | ||
if (isMenuOpenOnOutsideClick === false) setIsNavOpen(false); | ||
}, [isMenuOpenOnOutsideClick]); | ||
|
||
return ( | ||
<details open={isNavOpen}> | ||
{/* eslint-disable-next-line */} | ||
<summary | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
setIsNavOpen(!isNavOpen); | ||
}} | ||
onKeyDown={(e) => { | ||
if (e.keyCode === 13 || e.keyCode === 32) { | ||
e.preventDefault(); | ||
setIsNavOpen(!isNavOpen); | ||
} | ||
}} | ||
className="context-navigation-header accordion-header" | ||
> | ||
<span className="menuTitle">{title || ''}</span> | ||
<Icon name={isNavOpen ? upIcon : downIcon} size="40px" /> | ||
</summary> | ||
<nav className="toc-menu"> | ||
<ol className="toc-menu-list"> | ||
<RenderMenuItems items={tocEntries} /> | ||
</ol> | ||
</nav> | ||
</details> | ||
); | ||
}; | ||
|
||
const View = (props) => { | ||
const { data, tocEntries, device, isMenuOpenOnOutsideClick } = props; | ||
return ( | ||
<RenderTocEntries | ||
defaultOpen={device === 'mobile' || device === 'tablet'} | ||
tocEntries={tocEntries} | ||
isMenuOpenOnOutsideClick={isMenuOpenOnOutsideClick} | ||
title={data?.title} | ||
/> | ||
); | ||
}; | ||
|
||
View.propTypes = { | ||
data: PropTypes.object.isRequired, | ||
tocEntries: PropTypes.array, | ||
mode: PropTypes.string, | ||
}; | ||
|
||
export default withEEASideMenu(View); |
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,55 @@ | ||
@import (multiple, reference, optional) '../../../../theme.config'; | ||
|
||
@secondaryColor: #007b6c; | ||
@darkTextColor: #3d5265; | ||
|
||
.eea-side-menu { | ||
.icon { | ||
font-size: 1.4rem !important; | ||
} | ||
|
||
.content { | ||
--bg-color: transparent; | ||
padding: 0 !important; | ||
} | ||
|
||
.accordion.ui.fluid { | ||
padding-top: 0; | ||
margin-top: 0; | ||
background-color: white; | ||
} | ||
|
||
.menuTitle { | ||
font-size: 1.2rem; | ||
font-weight: bold; | ||
} | ||
|
||
.toc-menu { | ||
background-color: white; | ||
} | ||
|
||
.toc-menu-list { | ||
padding-left: 0; | ||
margin: 0; | ||
list-style: none; | ||
} | ||
|
||
.toc-menu-list-title { | ||
display: block; | ||
padding: 0.75rem 1rem; | ||
border-bottom: 2px solid @darkTextColor; | ||
color: @darkTextColor; | ||
font-weight: bold; | ||
} | ||
|
||
.toc-menu-list-item:hover { | ||
.toc-menu-list-title { | ||
color: @secondaryColor; | ||
font-weight: bold; | ||
} | ||
|
||
.menuTitle { | ||
color: @darkTextColor; | ||
} | ||
} | ||
} |
Oops, something went wrong.