-
-
Notifications
You must be signed in to change notification settings - Fork 571
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 #246 from plone/improved-helmet-body-classname-app…
…endable Add helper BodyClass for appending classes to the body tag from View …
- Loading branch information
Showing
12 changed files
with
98 additions
and
35 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
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,66 @@ | ||
import { Component, Children } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import withSideEffect from 'react-side-effect'; | ||
|
||
/** | ||
* @export | ||
* @class BodyClass | ||
* @extends {Component} | ||
*/ | ||
class BodyClass extends Component { | ||
/** | ||
* Render method. | ||
* @method render | ||
* @returns {string} Markup for the component. | ||
*/ | ||
render() { | ||
if (this.props.children) { | ||
return Children.only(this.props.children); | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
BodyClass.propTypes = { | ||
children: PropTypes.element, | ||
className: PropTypes.string, | ||
}; | ||
|
||
BodyClass.defaultProps = { | ||
children: null, | ||
className: null, | ||
}; | ||
|
||
/** | ||
* reducePropsToState | ||
* @function reducePropsToState | ||
* @param {*} propsList propsList | ||
* @returns {List} classList | ||
*/ | ||
function reducePropsToState(propsList) { | ||
let classList = []; | ||
propsList.map(props => { | ||
if (props.className) { | ||
classList = classList.concat(props.className); | ||
} | ||
}); | ||
return classList; | ||
} | ||
|
||
/** | ||
* handleStateChangeOnClient | ||
* @function handleStateChangeOnClient | ||
* @param {*} classList classList | ||
* @returns {null} null | ||
*/ | ||
function handleStateChangeOnClient(classList) { | ||
classList.map(className => { | ||
if (!document.body.classList.contains(className)) { | ||
document.body.classList.add(className); | ||
} | ||
}); | ||
} | ||
|
||
export default withSideEffect(reducePropsToState, handleStateChangeOnClient)( | ||
BodyClass, | ||
); |
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