2018-05-24 12:38:21 +00:00
|
|
|
import marked from 'Engine/marked'
|
2018-01-08 15:07:26 +00:00
|
|
|
import { path } from 'ramda'
|
2018-10-17 15:23:48 +00:00
|
|
|
import React, { Component } 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 =>
|
2018-05-09 16:41:57 +00:00
|
|
|
class withDictionary extends Component {
|
2017-04-28 15:47:01 +00:00
|
|
|
state = {
|
|
|
|
term: null,
|
|
|
|
explanation: null
|
|
|
|
}
|
2018-11-13 11:23:21 +00:00
|
|
|
onClick = e => {
|
|
|
|
let term = e.target.dataset['termDefinition'],
|
|
|
|
explanation = path([term, 'description'], dictionary)
|
|
|
|
if (!term) return null
|
|
|
|
this.setState({ explanation, term })
|
2017-04-28 15:47:01 +00:00
|
|
|
}
|
|
|
|
renderExplanationMarkdown(explanation, term) {
|
2018-10-17 15:23:48 +00:00
|
|
|
return marked(`### Mécanisme : ${term}\n\n${explanation}`)
|
2017-04-28 15:47:01 +00:00
|
|
|
}
|
2018-01-03 15:54:19 +00:00
|
|
|
render() {
|
|
|
|
let { explanation, term } = this.state
|
2017-04-28 15:47:01 +00:00
|
|
|
return (
|
2018-11-13 11:23:21 +00:00
|
|
|
<div onClick={this.onClick}>
|
|
|
|
<Decorated {...this.props} />
|
2018-01-03 15:54:19 +00:00
|
|
|
{explanation && (
|
2018-01-30 14:16:32 +00:00
|
|
|
<Overlay
|
2018-05-24 12:38:21 +00:00
|
|
|
onClose={() => this.setState({ term: null, explanation: null })}>
|
2018-01-03 15:54:19 +00:00
|
|
|
<div
|
|
|
|
id="dictionaryPanel"
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
__html: this.renderExplanationMarkdown(explanation, term)
|
|
|
|
}}
|
|
|
|
/>
|
2018-01-30 14:16:32 +00:00
|
|
|
</Overlay>
|
2018-01-03 15:54:19 +00:00
|
|
|
)}
|
2017-04-28 15:47:01 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|