Skip to content

Commit e0f409e

Browse files
authored
Merge pull request #32 from eea/develop
Release
2 parents 0ae9f86 + 563cc43 commit e0f409e

File tree

11 files changed

+459
-27
lines changed

11 files changed

+459
-27
lines changed

CHANGELOG.md

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ 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.0](https://github.com/eea/volto-block-toc/compare/5.0.2...6.0.0) - 26 August 2024
8+
9+
#### :rocket: New Features
10+
11+
- feat: Add side menu variation - refs #272384 [dobri1408 - [`595a210`](https://github.com/eea/volto-block-toc/commit/595a21030a74ffa8a8dd833b6c3d1b83e4d35b33)]
12+
13+
#### :hammer_and_wrench: Others
14+
15+
- Release 6.0.0 [Alin Voinea - [`2dbf58c`](https://github.com/eea/volto-block-toc/commit/2dbf58c3a8f4aa02a114d6e2cfb1b25dcedc081f)]
716
### [5.0.2](https://github.com/eea/volto-block-toc/compare/5.0.1...5.0.2) - 13 May 2024
817

918
#### :hammer_and_wrench: Others
1019

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

1522
#### :hammer_and_wrench: Others
1623

17-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`fa93184`](https://github.com/eea/volto-block-toc/commit/fa93184e49a35af45223aca195d568ba09fdff54)]
18-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`12ce383`](https://github.com/eea/volto-block-toc/commit/12ce38371021797c3a13135da6680f9222bc4b04)]
19-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`a79ed2d`](https://github.com/eea/volto-block-toc/commit/a79ed2d321c8e1551c4fd6ad6d5a07eb15d2223a)]
20-
- Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`cd4e095`](https://github.com/eea/volto-block-toc/commit/cd4e0954417c86348567edffaa7a7cc647291612)]
21-
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`e9ad6fd`](https://github.com/eea/volto-block-toc/commit/e9ad6fd4a78c3ecd23c8ba5486d4d1a2e69ba880)]
2224
- package.json [alin - [`30a7dbe`](https://github.com/eea/volto-block-toc/commit/30a7dbec2682f17c01d9cefd5f76e7e456fc91f3)]
23-
- Add Sonarqube tag using insitu-frontend addons list [EEA Jenkins - [`0fde850`](https://github.com/eea/volto-block-toc/commit/0fde8502587b7a8a632ae2cd98c4ce9b61206ab3)]
2425
## [5.0.0](https://github.com/eea/volto-block-toc/compare/4.0.0...5.0.0) - 17 April 2024
2526

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

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

8281
#### :hammer_and_wrench: Others
@@ -102,14 +101,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
102101
#### :hammer_and_wrench: Others
103102

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

110107
#### :hammer_and_wrench: Others
111108

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

115111
#### :hammer_and_wrench: Others
@@ -123,27 +119,17 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
123119

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

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

132126
#### :hammer_and_wrench: Others
133127

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

137130
#### :hammer_and_wrench: Others
138131

139132
- Refs #142010 - Optimize Volto-addons gitflow pipelines [valentinab25 - [`6973d84`](https://github.com/eea/volto-block-toc/commit/6973d84e3fe20548be2cb7903d6cb23e93610c0d)]
140-
- Add Sonarqube tag using industry-frontend addons list [EEA Jenkins - [`bf8be2e`](https://github.com/eea/volto-block-toc/commit/bf8be2e0027002150a52b187e08f56b2f0905e54)]
141-
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`c47d850`](https://github.com/eea/volto-block-toc/commit/c47d850e4feccb6c42ccb0e5463f32af62fed95b)]
142-
- Add Sonarqube tag using forests-frontend addons list [EEA Jenkins - [`5565395`](https://github.com/eea/volto-block-toc/commit/5565395a8b90cd5fd8650a24d0931b84306c0704)]
143-
- Add Sonarqube tag using sustainability-frontend addons list [EEA Jenkins - [`96d69df`](https://github.com/eea/volto-block-toc/commit/96d69dfc20e738c0f9af809a684dcb5b6c33cdf7)]
144-
- Add Sonarqube tag using climate-energy-frontend addons list [EEA Jenkins - [`9509446`](https://github.com/eea/volto-block-toc/commit/950944640e317ac2e375311663a150d0e0166dd8)]
145-
- Add Sonarqube tag using ims-frontend addons list [EEA Jenkins - [`1c96364`](https://github.com/eea/volto-block-toc/commit/1c963640148edbb6978ab518dfa2743044234c91)]
146-
- Add Sonarqube tag using frontend addons list [EEA Jenkins - [`421c23c`](https://github.com/eea/volto-block-toc/commit/421c23cb1ad5add8dc74796d8e93b8c5f88524d1)]
147133
### [2.2.2](https://github.com/eea/volto-block-toc/compare/2.2.1...2.2.2) - 27 May 2021
148134

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

173159
- Release 1.0.0 [Alin Voinea - [`5501bf6`](https://github.com/eea/volto-block-toc/commit/5501bf6e97cd6dae5af9735bea0ab28dee10dd30)]
174160
- Release 1.0.0 [Alin Voinea - [`528b2e6`](https://github.com/eea/volto-block-toc/commit/528b2e69303482bdefd240b3d6d95e1690e43a5d)]
175-
- yarn prettier [Alin Voinea - [`18f812b`](https://github.com/eea/volto-block-toc/commit/18f812b776964062054bf6f77710c6a8ece1cc8f)]
176161
### 0.1.0 - 21 October 2020
177162

178163
#### :hammer_and_wrench: Others

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,54 @@ describe('Block Tests: Toc', () => {
194194
cy.contains('Volto Toc');
195195
cy.get('.table-of-contents .dropdown').contains('More').click();
196196
});
197+
198+
it('Add Block: add side menu TOC', () => {
199+
// Change page title
200+
cy.clearSlateTitle();
201+
cy.getSlateTitle().type('Volto Toc');
202+
cy.getSlate().click();
203+
204+
// Add TOC block
205+
cy.get('.ui.basic.icon.button.block-add-button').first().click();
206+
cy.get(".blocks-chooser .ui.form .field.searchbox input[type='text']").type(
207+
'table of contents',
208+
);
209+
cy.get('.button.toc').click();
210+
211+
cy.get('#sidebar-properties .form .react-select-container').first().click();
212+
cy.contains('Side Menu').click();
213+
214+
// Add headings
215+
cy.get('.ui.drag.block.inner.slate').click().type('Title 1').click();
216+
cy.get('.ui.drag.block.inner.slate span span span').setSelection('Title 1');
217+
cy.get('.slate-inline-toolbar .button-wrapper a[title="Title"]').click({
218+
force: true,
219+
});
220+
cy.get('.ui.drag.block.inner.slate').click().type('{enter}');
221+
222+
cy.get('.ui.drag.block.inner.slate').eq(1).click().type('Title 2').click();
223+
cy.get('.ui.drag.block.inner.slate span span span')
224+
.eq(1)
225+
.setSelection('Title 2');
226+
cy.get('.slate-inline-toolbar .button-wrapper a[title="Title"]').click({
227+
force: true,
228+
});
229+
cy.get('.ui.drag.block.inner.slate').eq(1).click().type('{enter}');
230+
231+
// Save page
232+
cy.get('#toolbar-save').click();
233+
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');
234+
235+
// Check if the page contains the TOC and the headings
236+
cy.contains('Volto Toc');
237+
cy.contains('Title 1');
238+
cy.contains('Title 2');
239+
cy.get('a[href="#title-1"]').click();
240+
cy.get('a[href="#title-2"]').click();
241+
cy.get('h2[id="title-1"]').contains('Title 1');
242+
cy.get('h2[id="title-2"]').contains('Title 2');
243+
cy.get('.eea-side-menu').get('summary').click();
244+
cy.get('.eea-side-menu');
245+
cy.get('.eea-side-menu details').should('not.have.attr', 'open');
246+
});
197247
});

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": "5.0.2",
3+
"version": "6.0.0",
44
"description": "volto-block-toc: Volto add-on",
55
"main": "src/index.js",
66
"author": "European Environment Agency: IDM2 A-Team",

src/Block/TocView.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
getBlocksFieldname,
1515
getBlocksLayoutFieldname,
1616
} from '@plone/volto/helpers';
17+
import withDeviceSize from '@eeacms/volto-block-toc/hocs/withDeviceSize';
1718

1819
export const getBlocksTocEntries = (properties, tocData) => {
1920
const blocksFieldName = getBlocksFieldname(properties);
@@ -132,7 +133,7 @@ const View = (props) => {
132133
const Renderer = variation?.view;
133134

134135
return (
135-
<div className={cx('table-of-contents', variation?.id)}>
136+
<div className={cx('table-of-contents', variation?.id, props.device)}>
136137
{props.mode === 'edit' && !data.title && !tocEntries.length && (
137138
<Message>Table of content</Message>
138139
)}
@@ -155,4 +156,4 @@ View.propTypes = {
155156
properties: PropTypes.objectOf(PropTypes.any).isRequired,
156157
};
157158

158-
export default injectIntl(withBlockExtensions(View));
159+
export default injectIntl(withBlockExtensions(withDeviceSize(View)));

src/Block/variations/SideMenu.jsx

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import Slugger from 'github-slugger';
4+
import AnchorLink from 'react-anchor-link-smooth-scroll';
5+
import { Icon } from '@plone/volto/components';
6+
7+
import downIcon from '@plone/volto/icons/down-key.svg';
8+
import upIcon from '@plone/volto/icons/up-key.svg';
9+
10+
import withEEASideMenu from '@eeacms/volto-block-toc/hocs/withEEASideMenu';
11+
import { normalizeString } from './helpers';
12+
import './less/side-menu.less';
13+
14+
const RenderMenuItems = ({ items }) => (
15+
<>
16+
{items.map((item, index) => {
17+
const { title, override_toc, plaintext, items: subItems } = item;
18+
const slug = override_toc
19+
? Slugger.slug(normalizeString(plaintext))
20+
: Slugger.slug(normalizeString(title));
21+
return (
22+
<React.Fragment key={index}>
23+
<li className="toc-menu-list-item">
24+
<AnchorLink href={`#${slug}`} className="toc-menu-list-title">
25+
{title}
26+
</AnchorLink>
27+
</li>
28+
{subItems && subItems.length > 0 && (
29+
<RenderMenuItems items={subItems} />
30+
)}
31+
</React.Fragment>
32+
);
33+
})}
34+
</>
35+
);
36+
37+
const RenderTocEntries = ({
38+
tocEntries,
39+
title,
40+
defaultOpen,
41+
isMenuOpenOnOutsideClick,
42+
}) => {
43+
const [isNavOpen, setIsNavOpen] = React.useState(!defaultOpen);
44+
45+
React.useEffect(() => {
46+
if (isMenuOpenOnOutsideClick === false) setIsNavOpen(false);
47+
}, [isMenuOpenOnOutsideClick]);
48+
49+
return (
50+
<details open={isNavOpen}>
51+
{/* eslint-disable-next-line */}
52+
<summary
53+
onClick={(e) => {
54+
e.preventDefault();
55+
setIsNavOpen(!isNavOpen);
56+
}}
57+
onKeyDown={(e) => {
58+
if (e.keyCode === 13 || e.keyCode === 32) {
59+
e.preventDefault();
60+
setIsNavOpen(!isNavOpen);
61+
}
62+
}}
63+
className="context-navigation-header accordion-header"
64+
>
65+
<span className="menuTitle">{title || ''}</span>
66+
<Icon name={isNavOpen ? upIcon : downIcon} size="40px" />
67+
</summary>
68+
<nav className="toc-menu">
69+
<ol className="toc-menu-list">
70+
<RenderMenuItems items={tocEntries} />
71+
</ol>
72+
</nav>
73+
</details>
74+
);
75+
};
76+
77+
const View = (props) => {
78+
const { data, tocEntries, device, isMenuOpenOnOutsideClick } = props;
79+
return (
80+
<RenderTocEntries
81+
defaultOpen={device === 'mobile' || device === 'tablet'}
82+
tocEntries={tocEntries}
83+
isMenuOpenOnOutsideClick={isMenuOpenOnOutsideClick}
84+
title={data?.title}
85+
/>
86+
);
87+
};
88+
89+
View.propTypes = {
90+
data: PropTypes.object.isRequired,
91+
tocEntries: PropTypes.array,
92+
mode: PropTypes.string,
93+
};
94+
95+
export default withEEASideMenu(View);

src/Block/variations/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import AccordionMenu from './AccordionMenu';
22
import DefaultTocRenderer from './DefaultTocRenderer';
33
import HorizontalMenu from './HorizontalMenu';
4+
import SideMenu from './SideMenu';
45

56
const ToCVariations = [
67
{
@@ -19,6 +20,11 @@ const ToCVariations = [
1920
title: 'Accordion Menu',
2021
view: AccordionMenu,
2122
},
23+
{
24+
id: 'eea-side-menu',
25+
title: 'Side Menu',
26+
view: SideMenu,
27+
},
2228
];
2329

2430
export default ToCVariations;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@import (multiple, reference, optional) '../../../../theme.config';
2+
3+
@secondaryColor: #007b6c;
4+
@darkTextColor: #3d5265;
5+
6+
.eea-side-menu {
7+
.icon {
8+
font-size: 1.4rem !important;
9+
}
10+
11+
.content {
12+
--bg-color: transparent;
13+
padding: 0 !important;
14+
}
15+
16+
.accordion.ui.fluid {
17+
padding-top: 0;
18+
margin-top: 0;
19+
background-color: white;
20+
}
21+
22+
.menuTitle {
23+
font-size: 1.2rem;
24+
font-weight: bold;
25+
}
26+
27+
.toc-menu {
28+
background-color: white;
29+
}
30+
31+
.toc-menu-list {
32+
padding-left: 0;
33+
margin: 0;
34+
list-style: none;
35+
}
36+
37+
.toc-menu-list-title {
38+
display: block;
39+
padding: 0.75rem 1rem;
40+
border-bottom: 2px solid @darkTextColor;
41+
color: @darkTextColor;
42+
font-weight: bold;
43+
}
44+
45+
.toc-menu-list-item:hover {
46+
.toc-menu-list-title {
47+
color: @secondaryColor;
48+
font-weight: bold;
49+
}
50+
51+
.menuTitle {
52+
color: @darkTextColor;
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)