react-templates/playground/playground.rt.js

78 lines
3.0 KiB
JavaScript
Raw Normal View History

2014-12-03 10:45:31 +01:00
var React = require('react/addons');
2014-11-16 16:20:04 +01:00
var _ = require('lodash');
var CodeEditor = require('./aceEditor');
2014-11-16 16:20:04 +01:00
'use strict';
2014-11-17 12:27:57 +01:00
function onChange1(evt) {
this.setState({ 'templateHTML': evt.target.value });
}
function onChange2(evt) {
this.setState({ 'templateProps': evt.target.value });
}
2014-11-27 17:53:37 +01:00
function onSubmit3(e) {
e.preventDefault();
}
2014-11-16 16:20:04 +01:00
module.exports = function () {
2014-11-27 17:53:37 +01:00
return React.DOM.div({}, React.DOM.div({
2014-12-03 17:44:57 +01:00
'id': this.props.id + '-myTab',
2014-11-27 17:53:37 +01:00
'role': 'tabpanel',
2014-12-02 13:30:06 +01:00
'className': 'code-area ' + (this.props.direction === 'horizontal' && 'horizontal' || 'vertical')
2014-11-27 17:53:37 +01:00
} /* Nav tabs */, React.DOM.ul({
'className': 'nav nav-pills',
'role': 'tablist'
}, React.DOM.li({
'role': 'presentation',
'className': 'active'
}, React.DOM.a({
2014-12-03 17:44:57 +01:00
'href': '#' + this.props.id + '-template',
2014-11-27 17:53:37 +01:00
'aria-controls': 'template',
'role': 'tab',
'data-toggle': 'tab'
2014-12-04 10:15:19 +01:00
}, 'Template')), this.props.codeVisible ? React.DOM.li({ 'role': 'presentation' }, React.DOM.a({
2014-12-03 17:44:57 +01:00
'href': '#' + this.props.id + '-classCode',
2014-11-27 17:53:37 +01:00
'aria-controls': 'classCode',
'role': 'tab',
'data-toggle': 'tab'
2014-12-03 17:44:57 +01:00
}, 'Class')) : null, React.DOM.li({ 'role': 'presentation' }, React.DOM.a({
'href': '#' + this.props.id + '-generatedCode',
2014-11-27 17:53:37 +01:00
'aria-controls': 'generatedCode',
'role': 'tab',
'data-toggle': 'tab'
}, 'Generated code'))) /* Tab panes */, React.DOM.div({ 'className': 'tab-content' }, React.DOM.div({
'role': 'tabpanel',
'className': 'tab-pane active',
2014-12-03 17:44:57 +01:00
'id': this.props.id + '-template'
2014-11-27 17:53:37 +01:00
}, CodeEditor({
2014-11-17 12:27:57 +01:00
'className': 'large-text-area',
'style': { border: this.validHTML ? '1px solid black' : '2px solid red' },
'value': this.state.templateHTML,
'mode': 'html',
2014-11-17 12:27:57 +01:00
'onChange': onChange1.bind(this)
2014-12-04 10:15:19 +01:00
})), this.props.codeVisible ? React.DOM.div({
2014-11-27 17:53:37 +01:00
'role': 'tabpanel',
'className': 'tab-pane',
2014-12-03 17:44:57 +01:00
'id': this.props.id + '-classCode'
2014-11-27 17:53:37 +01:00
}, CodeEditor({
2014-11-17 12:27:57 +01:00
'className': 'large-text-area',
'style': { border: this.validProps ? '1px solid black' : '2px solid red' },
'value': this.state.templateProps,
'mode': 'javascript',
'onChange': onChange2.bind(this)
2014-12-03 17:44:57 +01:00
})) : null, React.DOM.div({
2014-11-27 17:53:37 +01:00
'role': 'tabpanel',
'className': 'tab-pane',
2014-12-03 17:44:57 +01:00
'id': this.props.id + '-generatedCode'
2014-11-27 17:53:37 +01:00
}, CodeEditor({
2014-11-18 14:00:28 +01:00
'className': 'large-text-area',
'style': { border: '1px solid black' },
'value': this.templateSource,
'mode': 'javascript',
'readOnly': true
2014-11-27 17:53:37 +01:00
})))), React.DOM.div({
'key': 'result-area',
2014-12-02 13:30:06 +01:00
'className': 'result-area well ' + (this.props.direction === 'horizontal' && 'horizontal' || 'vertical'),
2014-11-30 16:34:43 +01:00
'style': { marginTop: '48px' }
2014-11-30 12:12:03 +01:00
}, React.DOM.h2({}, 'Preview:'), React.DOM.form({
2014-11-27 17:53:37 +01:00
'className': 'sample-view',
'onSubmit': onSubmit3.bind(this)
2014-12-02 17:59:03 +01:00
}, this.sample({ 'key': 'sample' }))), React.DOM.br({ 'style': { clear: 'both' } }));
2014-11-16 16:20:04 +01:00
};