Skip to content

Commit 7b320e2

Browse files
authored
Merge pull request #37 from eea/develop
Release
2 parents 6364c03 + b281e2c commit 7b320e2

File tree

8 files changed

+397
-88
lines changed

8 files changed

+397
-88
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ 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.2.0](https://github.com/eea/volto-block-toc/compare/6.1.0...6.2.0) - 11 November 2024
8+
9+
#### :hammer_and_wrench: Others
10+
11+
- Update package.json [Ichim David - [`8e4fff7`](https://github.com/eea/volto-block-toc/commit/8e4fff78d7186752f9ceac6dfb220f626ecbad9f)]
712
### [6.1.0](https://github.com/eea/volto-block-toc/compare/6.0.1...6.1.0) - 11 October 2024
813

914
#### :hammer_and_wrench: Others

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pipeline {
88
environment {
99
GIT_NAME = "volto-block-toc"
1010
NAMESPACE = "@eeacms"
11-
SONARQUBE_TAGS = "volto.eea.europa.eu,biodiversity.europa.eu,water.europa.eu-freshwater,insitu.copernicus.eu,land.copernicus.eu,climate-adapt.eea.europa.eu,demo-www.eea.europa.eu,www.eea.europa.eu-en,water.europa.eu-marine,climate-advisory-board.europa.eu"
11+
SONARQUBE_TAGS = "volto.eea.europa.eu,biodiversity.europa.eu,water.europa.eu-freshwater,insitu.copernicus.eu,land.copernicus.eu,climate-adapt.eea.europa.eu,demo-www.eea.europa.eu,www.eea.europa.eu-en,water.europa.eu-marine,climate-advisory-board.europa.eu,forest.eea.europa.eu"
1212
DEPENDENCIES = ""
1313
BACKEND_PROFILES = "eea.kitkat:testing"
1414
BACKEND_ADDONS = ""

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.1.0",
3+
"version": "6.2.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/less/side-menu.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
.eea-side-menu {
77
.icon {
8-
font-size: 1.4rem !important;
8+
font-size: 2rem !important;
99
}
1010

1111
.content {

src/hocs/less/side-nav.less

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,5 @@
1-
@media screen and (min-width: 992px) {
2-
#page-header:empty + .breadcrumbs + .content-area {
3-
padding-top: 0 !important;
4-
margin-top: 0 !important;
5-
}
6-
7-
#page-document .eea-side-menu {
8-
display: none;
9-
}
10-
11-
#page-document:has(.banner > .image) .eea-side-menu + * {
12-
margin-top: 300px;
13-
}
14-
15-
#page-document:has(.eea-side-menu) .eea.banner {
16-
position: absolute;
17-
left: 0;
18-
}
19-
20-
#page-document .eea-side-menu:not(:empty) + * {
21-
margin-top: 200px;
22-
}
23-
24-
.has-side-nav {
25-
#view {
26-
display: grid;
27-
max-width: 1300px;
28-
margin: 0 auto;
29-
gap: 5rem;
30-
grid-template-areas: 'content nav';
31-
grid-template-columns: 4fr 1fr;
32-
grid-template-rows: auto 1fr;
33-
34-
#page-document {
35-
overflow: auto;
36-
width: auto !important;
37-
min-width: 100%;
38-
max-width: 100% !important;
39-
grid-area: content;
40-
}
41-
42-
.ui.grid.column-grid {
43-
max-width: 900px;
44-
}
45-
46-
> .eea-side-menu {
47-
position: sticky;
48-
top: 0;
49-
right: 1.5rem;
50-
min-width: 315px;
51-
height: fit-content;
52-
margin-bottom: 30px;
53-
grid-area: nav;
54-
}
55-
}
56-
}
57-
}
58-
591
.eea-side-menu {
602
grid-area: nav;
61-
transition: top 0.3s cubic-bezier(0.6, -0.28, 0.735, 0.045);
623

634
&:not(.mobile, .tablet) {
645
max-width: 315px;
@@ -106,6 +47,12 @@
10647
}
10748
}
10849

50+
// hide summary marker from eea-side-menu as we use our own summary icon
51+
.eea-side-menu summary::-webkit-details-marker,
52+
.eea-side-menu summary::marker {
53+
display: none;
54+
}
55+
10956
@media screen and (min-width: 768px) and (max-width: 991px) {
11057
.has-side-nav #view {
11158
grid-template-areas:
@@ -119,8 +66,54 @@
11966
}
12067
}
12168

122-
// hide summary marker from eea-side-menu as we use our own summary icon
123-
.eea-side-menu summary::-webkit-details-marker,
124-
.eea-side-menu summary::marker {
125-
display: none;
69+
@media screen and (min-width: 992px) {
70+
#page-document .eea-side-menu {
71+
display: none;
72+
}
73+
74+
#page-document:has(.banner > .image) .eea-side-menu + * {
75+
margin-top: 300px;
76+
}
77+
78+
#page-document:has(.eea-side-menu) .eea.banner {
79+
position: absolute;
80+
left: 0;
81+
}
82+
83+
#page-document .eea-side-menu:not(:empty) + * {
84+
margin-top: 200px;
85+
}
86+
87+
.has-side-nav {
88+
#view {
89+
display: grid;
90+
max-width: 1300px;
91+
margin: 0 auto;
92+
gap: 5rem;
93+
grid-template-areas: 'content nav';
94+
grid-template-columns: 4fr 1fr;
95+
grid-template-rows: auto 1fr;
96+
97+
#page-document {
98+
width: auto !important;
99+
min-width: 100%;
100+
max-width: 100% !important;
101+
grid-area: content;
102+
}
103+
104+
.ui.grid {
105+
max-width: 900px;
106+
}
107+
108+
> .eea-side-menu {
109+
position: sticky;
110+
top: 0;
111+
right: 1.5rem;
112+
min-width: 315px;
113+
height: fit-content;
114+
margin-bottom: 30px;
115+
grid-area: nav;
116+
}
117+
}
118+
}
126119
}

src/hocs/withDeviceSize.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ export default function withDeviceSize(WrappedComponent) {
66

77
const updateScreenSize = () => {
88
if (__CLIENT__) {
9-
const screenWidth =
10-
document.documentElement.clientWidth ||
11-
document.body.clientWidth ||
12-
window.innerWidth ||
13-
0;
9+
const screenWidth = window.innerWidth || 0;
1410

1511
setDevice(getDeviceConfig(screenWidth));
1612
}

src/hocs/withEEASideMenu.jsx

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,47 @@
1-
import React, { useEffect } from 'react';
2-
import { Portal } from 'react-portal';
1+
import React, { useEffect, useState, useRef, useCallback } from 'react';
2+
import ReactDOM from 'react-dom';
33

44
import { useFirstVisited } from '@eeacms/volto-block-toc/hooks';
55
import withDeviceSize from '@eeacms/volto-block-toc/hocs/withDeviceSize';
66
import { BodyClass, useDetectClickOutside } from '@plone/volto/helpers';
77
import './less/side-nav.less';
88

9-
function IsomorphicPortal({ children, target }) {
10-
const [isClient, setIsClient] = React.useState();
11-
useEffect(() => setIsClient(true), []);
9+
function IsomorphicPortal({ children, target, insertBeforeOnMobile }) {
10+
const [isClient, setIsClient] = useState(false);
11+
const containerRef = useRef(null);
1212

13-
return isClient ? (
14-
<Portal node={document.querySelector(target)}>{children}</Portal>
15-
) : (
16-
children
17-
);
13+
useEffect(() => {
14+
setIsClient(true);
15+
16+
if (insertBeforeOnMobile) {
17+
const targetNode = document.querySelector(target);
18+
const beforeNode = targetNode?.querySelector(insertBeforeOnMobile);
19+
20+
if (targetNode && beforeNode && !containerRef.current) {
21+
const div = document.createElement('div');
22+
div.classList.add('eea-side-menu-mobile-wrapper');
23+
targetNode.insertBefore(div, beforeNode);
24+
containerRef.current = div;
25+
}
26+
}
27+
28+
return () => {
29+
if (containerRef.current) {
30+
containerRef.current.remove();
31+
containerRef.current = null;
32+
}
33+
};
34+
}, [target, insertBeforeOnMobile]);
35+
36+
if (!isClient) {
37+
return children;
38+
}
39+
40+
if (insertBeforeOnMobile && containerRef.current) {
41+
return ReactDOM.createPortal(children, containerRef.current);
42+
}
43+
44+
return ReactDOM.createPortal(children, document.querySelector(target));
1845
}
1946

2047
const withEEASideMenu = (WrappedComponent) =>
@@ -23,17 +50,23 @@ const withEEASideMenu = (WrappedComponent) =>
2350
mode,
2451
device,
2552
targetParent = '.eea.header',
53+
fixedVisibilitySwitchTarget = targetParent,
54+
insertBeforeOnMobile = null,
2655
shouldRender = true,
2756
targetParentThreshold = '0px',
57+
fixedVisibilitySwitchTargetThreshold = targetParentThreshold,
2858
} = props;
29-
const visible = useFirstVisited(targetParent, targetParentThreshold);
59+
const visible = useFirstVisited(
60+
fixedVisibilitySwitchTarget,
61+
fixedVisibilitySwitchTargetThreshold,
62+
);
3063
const [isMenuOpen, setIsMenuOpen] = React.useState(true);
3164
const isSmallScreen = device === 'mobile' || device === 'tablet';
3265

33-
const ClickOutsideListener = () => {
66+
const ClickOutsideListener = useCallback(() => {
3467
setIsMenuOpen(false);
3568
setTimeout(() => setIsMenuOpen(true), 0);
36-
};
69+
}, []);
3770

3871
const ref = useDetectClickOutside({
3972
onTriggered: ClickOutsideListener,
@@ -57,7 +90,10 @@ const withEEASideMenu = (WrappedComponent) =>
5790
{mode === 'edit' ? (
5891
<WrappedComponent {...props} />
5992
) : (
60-
<IsomorphicPortal target={isSmallScreen ? targetParent : '#view'}>
93+
<IsomorphicPortal
94+
target={isSmallScreen ? targetParent : '#view'}
95+
insertBeforeOnMobile={isSmallScreen ? insertBeforeOnMobile : null}
96+
>
6197
<div
6298
className={`eea-side-menu ${props.device}`}
6399
ref={isSmallScreen ? ref : null}
@@ -74,10 +110,17 @@ const withEEASideMenu = (WrappedComponent) =>
74110
);
75111
});
76112

77-
/* can be used to override the default targetParent
113+
/* can be used to override the default targetParent
78114
export default compose(
79-
(WrappedComponent) => (props) =>
80-
withEEASideMenu(WrappedComponent)({ ...props, targetParent: '.your-custom-target', targetParentThreshold: '100px' })
115+
(WrappedComponent) => (props) =>
116+
withEEASideMenu(WrappedComponent)({ ...props,
117+
targetParent: '.your-custom-target',
118+
targetParentThreshold: '100px', // the threshold at which the menu will be visible when targetParent is not visible
119+
insertBeforeOnMobile: '.banner', // add if you need the WrappedContent to be added before a certain
120+
element inside the targetParent
121+
fixedVisibilitySwitchTarget: '.main.bar', // add if you need the menu to be fixed on certain element
122+
going out of view
123+
fixedVisibilitySwitchTargetThreshold: '100px' // overrides targetParentThreshold })
81124
)(Component);
82125
*/
83126

0 commit comments

Comments
 (0)