1 | const React = require('react');
|
2 | const PropTypes = require('prop-types');
|
3 |
|
4 | const GlossaryTermsContext = require('./contexts/GlossaryTerms');
|
5 |
|
6 | function GlossaryItem({ term, terms }) {
|
7 | const foundTerm = terms.find(i => term === i.term);
|
8 |
|
9 | if (!foundTerm) return null;
|
10 |
|
11 | return (
|
12 | <span className="glossary-tooltip" v={foundTerm.term}>
|
13 | <span className="glossary-item highlight">{foundTerm.term}</span>
|
14 | <span className="tooltip-content">
|
15 | <span className="tooltip-content-body">
|
16 | - <strong className="term">{foundTerm.term}</strong> - {foundTerm.definition}
|
17 | </span>
|
18 | </span>
|
19 | </span>
|
20 | );
|
21 | }
|
22 |
|
23 | GlossaryItem.propTypes = {
|
24 | term: PropTypes.string.isRequired,
|
25 | terms: PropTypes.arrayOf(
|
26 | PropTypes.shape({
|
27 | definition: PropTypes.string.isRequired,
|
28 | term: PropTypes.string.isRequired,
|
29 | })
|
30 | ).isRequired,
|
31 | };
|
32 |
|
33 |
|
34 | module.exports = props => (
|
35 | <GlossaryTermsContext.Consumer>{terms => <GlossaryItem {...props} terms={terms} />}</GlossaryTermsContext.Consumer>
|
36 | );
|
37 |
|
38 | module.exports.GlossaryItem = GlossaryItem;
|