Skip to content

Commit 6364c03

Browse files
authored
Merge pull request #35 from eea/develop
feat(side-menu): enhance side menu styling and allow it to close when clicking around it #270999
2 parents 318a7f9 + 299f861 commit 6364c03

File tree

7 files changed

+174
-79
lines changed

7 files changed

+174
-79
lines changed

CHANGELOG.md

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

7-
### [6.0.1](https://github.com/eea/volto-block-toc/compare/6.0.0...6.0.1) - 16 September 2024
7+
### [6.1.0](https://github.com/eea/volto-block-toc/compare/6.0.1...6.1.0) - 11 October 2024
88

9-
#### :bug: Bug Fixes
9+
#### :hammer_and_wrench: Others
1010

11-
- fix(header): by removing header and banner styling #274418 [ichim-david - [`08563b9`](https://github.com/eea/volto-block-toc/commit/08563b976e70511865ccd7dc21341e1b81670f04)]
11+
- Release 6.1.0 [alin - [`71b3fb4`](https://github.com/eea/volto-block-toc/commit/71b3fb4ea7fef34033aab229f89609f90ab2282d)]
12+
### [6.0.1](https://github.com/eea/volto-block-toc/compare/6.0.0...6.0.1) - 16 September 2024
1213

1314
#### :house: Internal changes
1415

@@ -27,19 +28,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
2728

2829
#### :hammer_and_wrench: Others
2930

30-
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`e421222`](https://github.com/eea/volto-block-toc/commit/e42122215c6ff6e1502632ffa990add919ddc1f7)]
31-
- Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`29640f2`](https://github.com/eea/volto-block-toc/commit/29640f237937e12974f289c944ce51a3900db0df)]
3231
### [5.0.1](https://github.com/eea/volto-block-toc/compare/5.0.0...5.0.1) - 22 April 2024
3332

3433
#### :hammer_and_wrench: Others
3534

36-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`fa93184`](https://github.com/eea/volto-block-toc/commit/fa93184e49a35af45223aca195d568ba09fdff54)]
37-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`12ce383`](https://github.com/eea/volto-block-toc/commit/12ce38371021797c3a13135da6680f9222bc4b04)]
38-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`a79ed2d`](https://github.com/eea/volto-block-toc/commit/a79ed2d321c8e1551c4fd6ad6d5a07eb15d2223a)]
39-
- Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`cd4e095`](https://github.com/eea/volto-block-toc/commit/cd4e0954417c86348567edffaa7a7cc647291612)]
40-
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`e9ad6fd`](https://github.com/eea/volto-block-toc/commit/e9ad6fd4a78c3ecd23c8ba5486d4d1a2e69ba880)]
4135
- package.json [alin - [`30a7dbe`](https://github.com/eea/volto-block-toc/commit/30a7dbec2682f17c01d9cefd5f76e7e456fc91f3)]
42-
- Add Sonarqube tag using insitu-frontend addons list [EEA Jenkins - [`0fde850`](https://github.com/eea/volto-block-toc/commit/0fde8502587b7a8a632ae2cd98c4ce9b61206ab3)]
4336
## [5.0.0](https://github.com/eea/volto-block-toc/compare/4.0.0...5.0.0) - 17 April 2024
4437

4538
#### :rocket: New Features
@@ -65,7 +58,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6558
- include volto-anchors as dependency and update import of github-slugger [Teodor - [`b2cc084`](https://github.com/eea/volto-block-toc/commit/b2cc084e515882852e5702e670aa045f4ef429c4)]
6659
- fix horizontal menu variation [Teodor - [`9d339f8`](https://github.com/eea/volto-block-toc/commit/9d339f88f7061c62274a022b6ff063fdda07e6f5)]
6760
- fix table of contents default renderer as per volto 17 fix [Teodor - [`be8de3b`](https://github.com/eea/volto-block-toc/commit/be8de3bdbc20889d20f64fa0a839513df7d70bcb)]
68-
- Add Sonarqube tag using freshwater-frontend addons list [EEA Jenkins - [`561d863`](https://github.com/eea/volto-block-toc/commit/561d863557380f92832f9f38dfeaf18dedad78f1)]
6961
### [3.0.8](https://github.com/eea/volto-block-toc/compare/3.0.7...3.0.8) - 19 February 2024
7062

7163
#### :house: Internal changes
@@ -95,7 +87,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
9587
- test: Update Makefile and docker-compose to align it with Jenkinsfile [valentinab25 - [`ede85d4`](https://github.com/eea/volto-block-toc/commit/ede85d4ba7888001add18888d24f8c712af68bef)]
9688
- test: jest should look for addons in node_modules Refs #253277 [valentinab25 - [`8e48d6f`](https://github.com/eea/volto-block-toc/commit/8e48d6fd45f0ea2e91b64494cbc029152632bcee)]
9789
- test: Fix test config, coverage Refs #253277 [valentinab25 - [`4f80fe5`](https://github.com/eea/volto-block-toc/commit/4f80fe53f3fc31ef7f7c15955d6df412cfb139d7)]
98-
- Add Sonarqube tag using bise-frontend addons list [EEA Jenkins - [`d10a982`](https://github.com/eea/volto-block-toc/commit/d10a982c3173080bfcfc29e7a7367b223fa10258)]
9990
### [3.0.5](https://github.com/eea/volto-block-toc/compare/3.0.4...3.0.5) - 22 May 2023
10091

10192
#### :hammer_and_wrench: Others
@@ -121,14 +112,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
121112
#### :hammer_and_wrench: Others
122113

123114
- Update Jenkinsfile [Claudia Ifrim - [`96e0797`](https://github.com/eea/volto-block-toc/commit/96e079736684c7b0fa8e7abaa0486f8b50b31b7c)]
124-
- Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`66e274d`](https://github.com/eea/volto-block-toc/commit/66e274da2d5945e78c00c0e1b7a42b8a08966cbc)]
125-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`91a49d2`](https://github.com/eea/volto-block-toc/commit/91a49d2712097854d7ba75ffc361f757c5fd2175)]
126115
- update(jest): add @plone/volto-slate resolver refs- #153447 [nileshgulia1 - [`c98050d`](https://github.com/eea/volto-block-toc/commit/c98050d7aa3cc48f658a5d498e5232bd7b4b0ae7)]
127116
### [3.0.1](https://github.com/eea/volto-block-toc/compare/3.0.0...3.0.1) - 30 June 2022
128117

129118
#### :hammer_and_wrench: Others
130119

131-
- Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`b3c16c6`](https://github.com/eea/volto-block-toc/commit/b3c16c6a31c38a44451b009af271f17244edbc1f)]
132120
## [3.0.0](https://github.com/eea/volto-block-toc/compare/2.3.0...3.0.0) - 17 May 2022
133121

134122
#### :hammer_and_wrench: Others
@@ -142,27 +130,17 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
142130

143131
- Release 2.3.0 [Alin Voinea - [`693f4bb`](https://github.com/eea/volto-block-toc/commit/693f4bbb13068e0b7c22353de5a451414e4d91a0)]
144132
- remove uneeded code [Miu Razvan - [`b554883`](https://github.com/eea/volto-block-toc/commit/b554883f393936e7a1e8e28ec2fcdc954982a4e7)]
145-
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`9961973`](https://github.com/eea/volto-block-toc/commit/996197359b91c0769f1fd8a1891b55063dd6c1e5)]
146-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`a3f1404`](https://github.com/eea/volto-block-toc/commit/a3f1404ec40f9bde18495e0e02eb23609deca78a)]
147133
### [2.2.5](https://github.com/eea/volto-block-toc/compare/2.2.4...2.2.5) - 3 January 2022
148134

149135
### [2.2.4](https://github.com/eea/volto-block-toc/compare/2.2.3...2.2.4) - 18 December 2021
150136

151137
#### :hammer_and_wrench: Others
152138

153-
- Add Sonarqube tag using freshwater-frontend addons list [EEA Jenkins - [`1f07faa`](https://github.com/eea/volto-block-toc/commit/1f07faa181ece91cc97fc4087fc0a5bdd83292dc)]
154139
### [2.2.3](https://github.com/eea/volto-block-toc/compare/2.2.2...2.2.3) - 10 December 2021
155140

156141
#### :hammer_and_wrench: Others
157142

158143
- Refs #142010 - Optimize Volto-addons gitflow pipelines [valentinab25 - [`6973d84`](https://github.com/eea/volto-block-toc/commit/6973d84e3fe20548be2cb7903d6cb23e93610c0d)]
159-
- Add Sonarqube tag using industry-frontend addons list [EEA Jenkins - [`bf8be2e`](https://github.com/eea/volto-block-toc/commit/bf8be2e0027002150a52b187e08f56b2f0905e54)]
160-
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`c47d850`](https://github.com/eea/volto-block-toc/commit/c47d850e4feccb6c42ccb0e5463f32af62fed95b)]
161-
- Add Sonarqube tag using forests-frontend addons list [EEA Jenkins - [`5565395`](https://github.com/eea/volto-block-toc/commit/5565395a8b90cd5fd8650a24d0931b84306c0704)]
162-
- Add Sonarqube tag using sustainability-frontend addons list [EEA Jenkins - [`96d69df`](https://github.com/eea/volto-block-toc/commit/96d69dfc20e738c0f9af809a684dcb5b6c33cdf7)]
163-
- Add Sonarqube tag using climate-energy-frontend addons list [EEA Jenkins - [`9509446`](https://github.com/eea/volto-block-toc/commit/950944640e317ac2e375311663a150d0e0166dd8)]
164-
- Add Sonarqube tag using ims-frontend addons list [EEA Jenkins - [`1c96364`](https://github.com/eea/volto-block-toc/commit/1c963640148edbb6978ab518dfa2743044234c91)]
165-
- Add Sonarqube tag using frontend addons list [EEA Jenkins - [`421c23c`](https://github.com/eea/volto-block-toc/commit/421c23cb1ad5add8dc74796d8e93b8c5f88524d1)]
166144
### [2.2.2](https://github.com/eea/volto-block-toc/compare/2.2.1...2.2.2) - 27 May 2021
167145

168146
### [2.2.1](https://github.com/eea/volto-block-toc/compare/2.2.0...2.2.1) - 14 May 2021
@@ -191,7 +169,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
191169

192170
- Release 1.0.0 [Alin Voinea - [`5501bf6`](https://github.com/eea/volto-block-toc/commit/5501bf6e97cd6dae5af9735bea0ab28dee10dd30)]
193171
- Release 1.0.0 [Alin Voinea - [`528b2e6`](https://github.com/eea/volto-block-toc/commit/528b2e69303482bdefd240b3d6d95e1690e43a5d)]
194-
- yarn prettier [Alin Voinea - [`18f812b`](https://github.com/eea/volto-block-toc/commit/18f812b776964062054bf6f77710c6a8ece1cc8f)]
195172
### 0.1.0 - 21 October 2020
196173

197174
#### :hammer_and_wrench: Others

cypress/e2e/01-toc-basics.cy.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ describe('Block Tests: Toc', () => {
6060
cy.contains('Volto Toc');
6161
cy.contains('Title 1');
6262
cy.contains('Title 2');
63-
cy.get('a[href="#title-1"]').click();
64-
cy.get('a[href="#title-2"]').click();
63+
// cy.get('a[href="#title-1"]').click();
64+
// cy.get('a[href="#title-2"]').click();
6565
cy.get('h2[id="title-1"]').contains('Title 1');
6666
cy.get('h2[id="title-2"]').contains('Title 2');
6767
});
@@ -236,8 +236,8 @@ describe('Block Tests: Toc', () => {
236236
cy.contains('Volto Toc');
237237
cy.contains('Title 1');
238238
cy.contains('Title 2');
239-
cy.get('a[href="#title-1"]').click();
240-
cy.get('a[href="#title-2"]').click();
239+
// cy.get('a[href="#title-1"]').click();
240+
// cy.get('a[href="#title-2"]').click();
241241
cy.get('h2[id="title-1"]').contains('Title 1');
242242
cy.get('h2[id="title-2"]').contains('Title 2');
243243
cy.get('.eea-side-menu').get('summary').click();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eeacms/volto-block-toc",
3-
"version": "6.0.1",
3+
"version": "6.1.0",
44
"description": "volto-block-toc: Volto add-on",
55
"main": "src/index.js",
66
"author": "European Environment Agency: IDM2 A-Team",

src/Block/variations/SideMenu.jsx

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
1+
import { Icon, MaybeWrap, UniversalLink } from '@plone/volto/components';
32
import Slugger from 'github-slugger';
4-
import AnchorLink from 'react-anchor-link-smooth-scroll';
5-
import { Icon } from '@plone/volto/components';
3+
import PropTypes from 'prop-types';
4+
import React from 'react';
65

76
import downIcon from '@plone/volto/icons/down-key.svg';
87
import upIcon from '@plone/volto/icons/up-key.svg';
@@ -11,22 +10,32 @@ import withEEASideMenu from '@eeacms/volto-block-toc/hocs/withEEASideMenu';
1110
import { normalizeString } from './helpers';
1211
import './less/side-menu.less';
1312

14-
const RenderMenuItems = ({ items }) => (
13+
const RenderMenuItems = ({ items, defaultOpen, setIsNavOpen }) => (
1514
<>
1615
{items.map((item, index) => {
1716
const { title, override_toc, plaintext, items: subItems } = item;
1817
const slug = override_toc
1918
? Slugger.slug(normalizeString(plaintext))
2019
: Slugger.slug(normalizeString(title));
20+
const href = `#${slug}`;
21+
const isActive = __CLIENT__ && window.location.hash === href;
2122
return (
2223
<React.Fragment key={index}>
2324
<li className="toc-menu-list-item">
24-
<AnchorLink href={`#${slug}`} className="toc-menu-list-title">
25+
<UniversalLink
26+
href={href}
27+
className={`toc-menu-list-title ${isActive ? 'active' : ''}`}
28+
onClick={() => defaultOpen && setIsNavOpen(false)}
29+
>
2530
{title}
26-
</AnchorLink>
31+
</UniversalLink>
2732
</li>
2833
{subItems && subItems.length > 0 && (
29-
<RenderMenuItems items={subItems} />
34+
<RenderMenuItems
35+
items={subItems}
36+
defaultOpen={defaultOpen}
37+
setIsNavOpen={setIsNavOpen}
38+
/>
3039
)}
3140
</React.Fragment>
3241
);
@@ -41,15 +50,38 @@ const RenderTocEntries = ({
4150
isMenuOpenOnOutsideClick,
4251
}) => {
4352
const [isNavOpen, setIsNavOpen] = React.useState(!defaultOpen);
53+
const summaryRef = React.useRef(null);
54+
const contentRef = React.useRef(null);
4455

4556
React.useEffect(() => {
4657
if (isMenuOpenOnOutsideClick === false) setIsNavOpen(false);
4758
}, [isMenuOpenOnOutsideClick]);
4859

60+
React.useEffect(() => {
61+
if (defaultOpen) {
62+
const handleOutsideClick = (event) => {
63+
if (
64+
summaryRef.current &&
65+
contentRef.current &&
66+
!summaryRef.current.contains(event.target) &&
67+
!contentRef.current.contains(event.target)
68+
) {
69+
setIsNavOpen(false);
70+
}
71+
};
72+
73+
document.addEventListener('click', handleOutsideClick);
74+
return () => {
75+
document.removeEventListener('click', handleOutsideClick);
76+
};
77+
}
78+
}, [summaryRef, defaultOpen]);
79+
4980
return (
5081
<details open={isNavOpen}>
5182
{/* eslint-disable-next-line */}
5283
<summary
84+
ref={summaryRef}
5385
onClick={(e) => {
5486
e.preventDefault();
5587
setIsNavOpen(!isNavOpen);
@@ -62,13 +94,30 @@ const RenderTocEntries = ({
6294
}}
6395
className="context-navigation-header accordion-header"
6496
>
65-
<span className="menuTitle">{title || ''}</span>
66-
<Icon name={isNavOpen ? upIcon : downIcon} size="40px" />
97+
<MaybeWrap
98+
condition={defaultOpen}
99+
className="ui container d-flex flex-items-center"
100+
>
101+
<span className="menuTitle">{title || ''}</span>
102+
<Icon name={isNavOpen ? upIcon : downIcon} size="40px" />
103+
</MaybeWrap>
67104
</summary>
68105
<nav className="toc-menu">
69-
<ol className="toc-menu-list">
70-
<RenderMenuItems items={tocEntries} />
71-
</ol>
106+
<MaybeWrap
107+
condition={defaultOpen}
108+
className="ui container d-flex flex-items-center"
109+
>
110+
<ol
111+
className="toc-menu-list context-navigation-list"
112+
ref={contentRef}
113+
>
114+
<RenderMenuItems
115+
items={tocEntries}
116+
defaultOpen={defaultOpen}
117+
setIsNavOpen={setIsNavOpen}
118+
/>
119+
</ol>
120+
</MaybeWrap>
72121
</nav>
73122
</details>
74123
);

src/Block/variations/less/side-menu.less

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
font-weight: bold;
2525
}
2626

27-
.toc-menu {
28-
background-color: white;
29-
}
30-
3127
.toc-menu-list {
3228
padding-left: 0;
3329
margin: 0;
@@ -39,13 +35,17 @@
3935
padding: 0.75rem 1rem;
4036
border-bottom: 2px solid @darkTextColor;
4137
color: @darkTextColor;
42-
font-weight: bold;
38+
font-weight: 500;
39+
40+
&.active {
41+
color: @secondaryColor;
42+
}
4343
}
4444

4545
.toc-menu-list-item:hover {
4646
.toc-menu-list-title {
4747
color: @secondaryColor;
48-
font-weight: bold;
48+
font-weight: 500;
4949
}
5050

5151
.menuTitle {

0 commit comments

Comments
 (0)