1 | import React from 'react'
|
2 | import ReactDOM from 'react-dom'
|
3 |
|
4 | import { EmailArticleData, EmailArticleView } from '..'
|
5 |
|
6 | import DemosConfig from './demos-config'
|
7 |
|
8 | const randomContent = (
|
9 | <div>
|
10 | <p><em>Hint: Click on the email icon above</em></p>
|
11 | <p>Lorem ipsum dolor sit amet, ea nonumy lucilius nam, pri ei tale soluta. Et nibh minimum duo, mea ad omnis feugait argumentum, doming deseruisse est at. Duo volumus detracto ne. Nam consul albucius sapientem id, decore prodesset consequuntur est ne. Ex dicit eirmod vituperata vel.</p>
|
12 | </div>
|
13 | )
|
14 |
|
15 | export default class extends React.Component {
|
16 |
|
17 | onDemosConfigChange (mode, apiResponses, customMessage) {
|
18 |
|
19 | Array.from(document.querySelectorAll('[data-n-article-email-container]')).forEach(view => view.innerHTML = null)
|
20 |
|
21 |
|
22 | this.views = {}
|
23 | this.data = new EmailArticleData(mode)
|
24 |
|
25 |
|
26 | Object.keys(apiResponses).map(api => this.data.api[api] = apiResponses[api])
|
27 |
|
28 |
|
29 | this.data.customMessage = customMessage
|
30 | }
|
31 |
|
32 | onToggleOpen (id) {
|
33 |
|
34 | const isTop = id === 'top'
|
35 |
|
36 | if (!this.views[id]) {
|
37 | const props = {
|
38 | mode: this.mode,
|
39 | isTop: isTop,
|
40 | store: this.data.store,
|
41 | actions: this.data.actions,
|
42 | dispatch: this.data.dispatch,
|
43 | customMessage: this.data.customMessage
|
44 | }
|
45 | this.views[id] = React.createElement(EmailArticleView, props)
|
46 | const container = document.querySelector(`[data-n-article-email-${id}-container]`)
|
47 | ReactDOM.render(this.views[id], container)
|
48 | }
|
49 |
|
50 | if (isTop) this.data.dispatch(this.data.actions.toggleOpenTop())
|
51 | else this.data.dispatch(this.data.actions.toggleOpenBottom())
|
52 | }
|
53 |
|
54 | render () {
|
55 |
|
56 |
|
57 | return (
|
58 | <div className="article" data-content-id="737195aa-1347-11e6-839f-292294709880">
|
59 | <div className="demos__config">
|
60 | <DemosConfig
|
61 | onConfigChange={(mode, apiResponses, customMessage) => {
|
62 | return this.onDemosConfigChange(mode, apiResponses, customMessage)}
|
63 | }
|
64 | />
|
65 | </div>
|
66 | <div className="demos__article">
|
67 | <h1 className="demos__article-title">Article title</h1>
|
68 | <h2>Top toolbar</h2>
|
69 | <button onClick={() => this.onToggleOpen('top')} type="button"
|
70 | className="o-buttons o-buttons--medium demos__email">Email</button>
|
71 | <div data-n-article-email-container data-n-article-email-top-container></div>
|
72 | {randomContent}
|
73 | <h2>Bottom toolbar</h2>
|
74 | <button onClick={() => this.onToggleOpen('bottom')} type="button"
|
75 | className="o-buttons o-buttons--medium demos__email">Email</button>
|
76 | <div data-n-article-email-container data-n-article-email-bottom-container></div>
|
77 | {randomContent}
|
78 | </div>
|
79 | </div>
|
80 | )
|
81 | }
|
82 |
|
83 | }
|