2019-07-09 13:35:09 +00:00
|
|
|
import { Markdown } from 'Components/utils/markdown'
|
2018-01-08 15:07:26 +00:00
|
|
|
import { path } from 'ramda'
|
2019-09-11 08:06:26 +00:00
|
|
|
import React, { useState } from 'react'
|
2017-10-13 13:47:16 +00:00
|
|
|
import './Dictionary.css'
|
2018-01-30 14:16:32 +00:00
|
|
|
import Overlay from './Overlay'
|
2017-04-28 15:47:01 +00:00
|
|
|
|
|
|
|
// On ajoute à la section la possibilité d'ouvrir un panneau d'explication des termes.
|
|
|
|
// Il suffit à la section d'appeler une fonction fournie en lui donnant du JSX
|
|
|
|
export let AttachDictionary = dictionary => Decorated =>
|
2019-09-11 08:06:26 +00:00
|
|
|
function withDictionary(props) {
|
2019-09-15 20:51:13 +00:00
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
2019-09-11 08:06:26 +00:00
|
|
|
const [{ explanation, term }, setState] = useState({
|
2017-04-28 15:47:01 +00:00
|
|
|
term: null,
|
|
|
|
explanation: null
|
2019-09-11 08:06:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const onClick = e => {
|
2018-11-13 11:23:21 +00:00
|
|
|
let term = e.target.dataset['termDefinition'],
|
|
|
|
explanation = path([term, 'description'], dictionary)
|
|
|
|
if (!term) return null
|
2019-09-11 08:06:26 +00:00
|
|
|
setState({ explanation, term })
|
2017-04-28 15:47:01 +00:00
|
|
|
}
|
2019-09-11 08:06:26 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div onClick={onClick}>
|
|
|
|
<Decorated {...props} />
|
|
|
|
{explanation && (
|
|
|
|
<Overlay onClose={() => setState({ term: null, explanation: null })}>
|
|
|
|
<div id="dictionaryPanel">
|
|
|
|
<Markdown source={`### Mécanisme : ${term}\n\n${explanation}`} />
|
|
|
|
</div>
|
|
|
|
</Overlay>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
2017-04-28 15:47:01 +00:00
|
|
|
}
|