diff --git a/components/resources/index.js b/components/resources/index.js index 6163f2f..72d6547 100644 --- a/components/resources/index.js +++ b/components/resources/index.js @@ -12,22 +12,34 @@ class Resources extends React.Component { this.state = { isWordCloudModalOpen: false, - activeSlide: 1, + activeSlide: 0, }; - this.toggleWordCloudModal = this.toggleWordCloudModal.bind(this); + this.openWordCloudModal = this.openWordCloudModal.bind(this); + this.closeWordCloudModal = this.closeWordCloudModal.bind(this); } - toggleWordCloudModal(event) { - const { isWordCloudModalOpen } = this.state; - const clickedIndex = event.target.dataset.index; + openWordCloudModal(event) { + /* + /* Check if clicked element is a child and doesn't have a data-index, + /* then go get data-index from the parentNode + */ + let clic kedElement = event.target; + while (clickedElement.dataset.index === undefined) { + clickedElement = clickedElement.parentNode; + } + const clickedIndex = clickedElement.dataset.index; this.setState({ - isWordCloudModalOpen: !isWordCloudModalOpen, + isWordCloudModalOpen: true, activeSlide: clickedIndex, }); this.slider.slickGoTo(clickedIndex); } + closeWordCloudModal() { + this.setState({ isWordCloudModalOpen: false }); + } + render() { const { isWordCloudModalOpen, activeSlide } = this.state; const settings = { @@ -49,7 +61,7 @@ class Resources extends React.Component { Data.map((wordCloud, index) => ()) @@ -57,7 +69,7 @@ class Resources extends React.Component { (this.slider = slider)} {...settings}> {/* eslint-disable-line */} { diff --git a/components/wordCloud/index.js b/components/wordCloud/index.js index 735dff4..bc141cc 100644 --- a/components/wordCloud/index.js +++ b/components/wordCloud/index.js @@ -7,14 +7,17 @@ const WordCloud = props => (
-

{ props.words.title }

-
+

{ props.words.title }

+
{ props.words.cloud.map(word => ( - + { word.word } )) @@ -29,7 +32,7 @@ WordCloud.propTypes = { title: PropTypes.string, cloud: PropTypes.array, }).isRequired, - toggleWordCloudModal: PropTypes.func.isRequired, + openWordCloudModal: PropTypes.func.isRequired, }; export default WordCloud;