UNPKG

1.11 kBJSXView Raw
1const React = require('react');
2const PropTypes = require('prop-types');
3
4const GlossaryTermsContext = require('./contexts/GlossaryTerms');
5
6function 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
23GlossaryItem.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// eslint-disable-next-line react/display-name
34module.exports = props => (
35 <GlossaryTermsContext.Consumer>{terms => <GlossaryItem {...props} terms={terms} />}</GlossaryTermsContext.Consumer>
36);
37
38module.exports.GlossaryItem = GlossaryItem;