Skip to content

Commit

Permalink
fix: removed RemoveBodyClass component in favor of a customized BodyC…
Browse files Browse the repository at this point in the history
…lass component
  • Loading branch information
pnicolli committed Sep 10, 2024
1 parent 5f3de3e commit b560bf8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 41 deletions.
3 changes: 1 addition & 2 deletions src/components/ItaliaTheme/AppExtras/GenericAppExtras.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
import { BodyClass } from '@plone/volto/helpers';
import { RemoveBodyClass } from 'design-comuni-plone-theme/components/ItaliaTheme';
import ScrollToTop from 'design-comuni-plone-theme/components/ItaliaTheme/ScrollToTop/ScrollToTop';
import { SubsiteLoader } from 'volto-subsites';
import config from '@plone/volto/registry';
Expand All @@ -28,7 +27,7 @@ const GenericAppExtras = (props) => {
{isPublicUI && (
<>
<BodyClass className="public-ui" />
<RemoveBodyClass className="cms-ui" />
<BodyClass className="cms-ui" remove={true} />
</>
)}
<ScrollToTop />
Expand Down
7 changes: 2 additions & 5 deletions src/components/ItaliaTheme/LoginAgid/LoginAgid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { defineMessages, useIntl } from 'react-intl';
import { withRouter } from 'react-router-dom';
import { Login } from '@plone/volto/components';
import { Row, Col, Container } from 'design-react-kit';
import {
RemoveBodyClass,
LoginAgidButtons,
} from 'design-comuni-plone-theme/components/ItaliaTheme';
import { LoginAgidButtons } from 'design-comuni-plone-theme/components/ItaliaTheme';
import { Button } from 'design-react-kit';
import { useLocation } from 'react-router-dom';
import { getBaseUrl } from '@plone/volto/helpers';
Expand Down Expand Up @@ -72,7 +69,7 @@ const LoginAgid = (props) => {
<div id="page-login">
<Helmet title={intl.formatMessage(messages.login)} />
<BodyClass className="public-ui" />
<RemoveBodyClass className="cms-ui" />
<BodyClass className="cms-ui" remove={true} />
<Container className="view-wrapper py-5">
<Row className="view-container">
<Col xs={12} lg={{ size: 10, offset: 1 }}>
Expand Down
5 changes: 2 additions & 3 deletions src/components/ItaliaTheme/Search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { Skiplink, SkiplinkItem } from 'design-react-kit';
import { useLocation, useHistory } from 'react-router-dom';

import { Helmet, flattenToAppURL } from '@plone/volto/helpers';
import { Helmet, flattenToAppURL, BodyClass } from '@plone/volto/helpers';
import { resetSubsite } from 'volto-subsites';

import {
Expand All @@ -33,7 +33,6 @@ import {
SearchTopics,
SearchCTs,
Icon,
RemoveBodyClass,
SearchResultItem,
} from 'design-comuni-plone-theme/components/ItaliaTheme';
import {
Expand Down Expand Up @@ -727,7 +726,7 @@ const Search = () => {
</Container>
</div>
{/*force remove body class for subsite search pages*/}
<RemoveBodyClass className="cms-ui" />
<BodyClass className="cms-ui" remove={true} />
</>
);
};
Expand Down
7 changes: 2 additions & 5 deletions src/components/ItaliaTheme/Unauthorized/Unauthorized.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import { BodyClass } from '@plone/volto/helpers';
import { useLocation } from 'react-router-dom';
import { getBaseUrl } from '@plone/volto/helpers';
import config from '@plone/volto/registry';
import {
LoginAgidButtons,
RemoveBodyClass,
} from 'design-comuni-plone-theme/components/ItaliaTheme';
import { LoginAgidButtons } from 'design-comuni-plone-theme/components/ItaliaTheme';

/**
* unauthorized function.
Expand Down Expand Up @@ -58,7 +55,7 @@ const Unauthorized = (props) => {
return (
<div id="unauthorized-agid" className="view-wrapper">
<BodyClass className="public-ui" />
<RemoveBodyClass className="cms-ui" />
<BodyClass className="cms-ui" remove={true} />

<Container className="view-wrapper py-5">
{spidLoginUrl || spidLogin ? (
Expand Down
1 change: 0 additions & 1 deletion src/components/ItaliaTheme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export SectionIcon from 'design-comuni-plone-theme/components/ItaliaTheme/Icons/

/********* COMMONS ********* */
export CardCategory from 'design-comuni-plone-theme/components/ItaliaTheme/Cards/CardCategory';
export RemoveBodyClass from 'design-comuni-plone-theme/components/ItaliaTheme/RemoveBodyClass/RemoveBodyClass';
export CardPersona from 'design-comuni-plone-theme/components/ItaliaTheme/Cards/CardPersona';
export GalleryPreview from 'design-comuni-plone-theme/components/ItaliaTheme/GalleryPreview/GalleryPreview';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/**
* CUSTOMIZATIONS:
* - handle bodyclass removal
*/
import { Component, Children } from 'react';
import PropTypes from 'prop-types';
import withSideEffect from 'react-side-effect';

/**
* @export
* @class RemoveBodyClass
* @class BodyClass
* @extends {Component}
*/
class RemoveBodyClass extends Component {
class BodyClass extends Component {
/**
* Render method.
* @method render
Expand All @@ -21,14 +25,16 @@ class RemoveBodyClass extends Component {
}
}

RemoveBodyClass.propTypes = {
BodyClass.propTypes = {
children: PropTypes.element,
className: PropTypes.string,
remove: PropTypes.bool,
};

RemoveBodyClass.defaultProps = {
BodyClass.defaultProps = {
children: null,
className: null,
remove: false,
};

/**
Expand All @@ -41,7 +47,11 @@ function reducePropsToState(propsList) {
let classList = [];
propsList.forEach((props) => {
if (props.className) {
classList = classList.concat(props.className);
if (props.remove) {
classList = classList.filter((c) => c !== props.className);
} else {
classList = classList.concat(props.className.split(' '));
}
}
});
return classList;
Expand All @@ -54,31 +64,15 @@ function reducePropsToState(propsList) {
* @returns {null} null
*/
function handleStateChangeOnClient(classList) {
// document.body.className = '';
let domClassNames = [];
Object.keys(document.body.classList).forEach((k) => {
domClassNames.push(document.body.classList[k]);
});

document.body.className = '';
classList.forEach((className) => {
// This allows the component to accept more than one class at the same time
if (className.includes(' ')) {
className.split(' ').forEach((className) => {
if (document.body.classList.contains(className)) {
domClassNames.splice(domClassNames.indexOf(className), 1);
}
});
document.body.classList = domClassNames.join(' ');
} else {
if (document.body.classList.contains(className)) {
domClassNames.splice(domClassNames.indexOf(className), 1);
document.body.classList = domClassNames.join(' ');
}
if (!document.body.classList.contains(className)) {
document.body.classList.add(className);
}
});
}

export default withSideEffect(
reducePropsToState,
handleStateChangeOnClient,
)(RemoveBodyClass);
)(BodyClass);

0 comments on commit b560bf8

Please sign in to comment.