-
Notifications
You must be signed in to change notification settings - Fork 11
/
preview.js
42 lines (37 loc) · 1.05 KB
/
preview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import element from 'virtual-element';
import { deku, render } from 'deku';
import { Menu, Code } from './lib';
import examples from './examples' ;
/**
* App.
*/
let App = {
render({ props, state }, updateState) {
let { examples } = props;
let example = state.example || examples.Code;
let items = Object.keys(examples);
return (
<div class='App'>
<div class='App-menu'>
<Menu items={ items } onChange={ changeExample } defaultActive={ Object.keys(examples)[0] }/>
</div>
<div class='App-example'>
<div class='App-example-component'>
{ example.component }
</div>
<div class='App-example-code'>
<Code language='html'>
{ example.code }
</Code>
</div>
</div>
</div>
);
function changeExample(expl) {
analytics.track('Viewed Example', expl);
updateState({ example: examples[expl] });
}
}
};
let app = deku(<App examples={ examples }/>);
render(app, document.querySelector('main'));