Skip to content

Commit 1d75e32

Browse files
committed
Adding the demo #5
1 parent 41f5a97 commit 1d75e32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1694
-2
lines changed

demo/Client.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import {Router} from 'react-router'
3+
import routes from './Routes';
4+
import configureStore from './store/configureStore';
5+
import {Provider} from 'react-redux';
6+
import {syncHistoryWithStore} from 'react-router-redux';
7+
import {browserHistory} from 'react-router'
8+
import {render} from 'react-dom';
9+
import './less/styles.less';
10+
11+
const store = configureStore();
12+
const history = syncHistoryWithStore(browserHistory, store);
13+
14+
render(
15+
<Provider store={store}>
16+
<Router history={history} routes={routes}/>
17+
</Provider>,
18+
document.getElementById('#app_container')
19+
);

demo/Routes.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import App from './containers/App';
3+
import Demo from './pages/Demo.js';
4+
5+
import { Route, Redirect } from 'react-router';
6+
7+
export default (
8+
<Route component={App}>
9+
<Route path="/redux-autoform-bootstrap-ui/demo.html" component={Demo}/>
10+
<Redirect from="*" to="/redux-autoform-bootstrap-ui/demo.html" />
11+
</Route>
12+
);

demo/Server.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import fs from 'fs';
2+
import React from 'react';
3+
import express from 'express';
4+
import path from 'path';
5+
import webpackConfig from '../webpack/webpack.config.demo.dev';
6+
import colors from 'colors';
7+
import webpackMiddleware from 'webpack-dev-middleware';
8+
import webpackHotMiddleware from 'webpack-hot-middleware';
9+
import webpack from 'webpack';
10+
11+
const webpackCompiler = webpack(webpackConfig);
12+
13+
require.extensions['.html'] = function (module, filename) {
14+
module.exports = fs.readFileSync(filename, 'utf8');
15+
};
16+
17+
const development = process.env.NODE_ENV !== 'production';
18+
let app = express();
19+
20+
if (development) {
21+
app.use(webpackMiddleware(webpackCompiler));
22+
app.use(webpackHotMiddleware(webpackCompiler));
23+
app.use(function renderApp(req, res) {
24+
let wrap = require('./pages/BasePage.html')
25+
.replace(/\$\{cssBundlePath\}/g, '')
26+
.replace(/\$\{jsBundlePath\}/g, '/bundle.js');
27+
28+
res.status(200).send(wrap);
29+
});
30+
} else {
31+
app.use(express.static(path.join(__dirname, '../demo-built')));
32+
}
33+
34+
app.listen(4000, '0.0.0.0', function () {
35+
console.log(colors.green(`React-metaform started at http://localhost:4000/. NODE_ENV: ${process.env.NODE_ENV}`));
36+
});

demo/actions/formOptions.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const UPDATE_FORM = 'UPDATE_FORM';
2+
const SET_STACKED_FIELD_LAYOUT = 'SET_STACKED_FIELD_LAYOUT';
3+
const SET_INLINE_FIELD_LAYOUT = 'SET_INLINE_FIELD_LAYOUT';
4+
const SET_EDIT_COMPONENT_FACTORY = 'SET_EDIT_COMPONENT_FACTORY';
5+
const SET_DETAILS_COMPONENT_FACTORY = 'SET_DETAILS_COMPONENT_FACTORY';
6+
7+
/**
8+
* Updates the form
9+
*/
10+
export const updateForm = (schema) => ({
11+
type: UPDATE_FORM,
12+
schema: schema
13+
});
14+
15+
/**
16+
* Sets the field layout as stacked
17+
* @returns {{type: string}}
18+
*/
19+
export const setStackedFieldLayout = () => ({
20+
type: SET_STACKED_FIELD_LAYOUT
21+
});
22+
23+
/**
24+
* Sets the field layout as inline
25+
* @returns {{type: string}}
26+
*/
27+
export const setInlineFieldLayout = () => ({
28+
type: SET_INLINE_FIELD_LAYOUT
29+
});
30+
31+
export const setEditComponentFactory = () => ({
32+
type: SET_EDIT_COMPONENT_FACTORY
33+
});
34+
35+
export const setDetailsComponentFactory = () => ({
36+
type: SET_DETAILS_COMPONENT_FACTORY
37+
});
38+
39+
export default {
40+
UPDATE_FORM,
41+
SET_STACKED_FIELD_LAYOUT,
42+
SET_INLINE_FIELD_LAYOUT,
43+
SET_EDIT_COMPONENT_FACTORY,
44+
SET_DETAILS_COMPONENT_FACTORY
45+
}

demo/components/ButtonToolbar.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { Component } from 'react';
2+
import { ButtonToolbar, Button }from 'react-bootstrap'
3+
4+
class Layout extends Component {
5+
render() {
6+
7+
let { submitting } = this.props;
8+
9+
return (
10+
<ButtonToolbar className="button-toolbar">
11+
<Button className="pull-right" bsStyle="success" bsSize="large" type="submit" disabled={submitting}>
12+
Submit
13+
</Button>
14+
</ButtonToolbar>
15+
);
16+
}
17+
}
18+
19+
export default Layout;

demo/components/CodeEditor.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { Component } from 'react';
2+
import AceEditor from 'react-ace';
3+
4+
import 'brace/mode/jsx';
5+
import 'brace/theme/github.js';
6+
7+
class CodeEditor extends Component {
8+
render() {
9+
let { value, name, readOnly, onChange, mode, width, height } = this.props;
10+
mode = mode || 'jsx';
11+
width = width || '100%';
12+
13+
// metadata
14+
let props = { value, name, ref: 'input', readOnly, onChange, mode, width, theme: 'github', height, fontSize: 14, editorProps: {$blockScrolling: true} };
15+
16+
return <AceEditor className="code-editor" {...props}/>;
17+
}
18+
}
19+
20+
export default CodeEditor;

demo/components/DevTools.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import { createDevTools } from 'redux-devtools';
3+
import LogMonitor from 'redux-devtools-log-monitor';
4+
import DockMonitor from 'redux-devtools-dock-monitor';
5+
6+
export default createDevTools(
7+
<DockMonitor
8+
toggleVisibilityKey="ctrl-h"
9+
changePositionKey="ctrl-q"
10+
defaultIsVisible={false}
11+
>
12+
<LogMonitor />
13+
</DockMonitor>
14+
);

demo/components/FormOptions.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import { ButtonGroup, Button, ButtonToolbar } from 'react-bootstrap'
3+
4+
class FormOptions extends Component {
5+
static propTypes = {
6+
fieldLayout: PropTypes.string.isRequired,
7+
setStackedFieldLayout: PropTypes.func.isRequired,
8+
setInlineFieldLayout: PropTypes.func.isRequired
9+
};
10+
11+
render() {
12+
let { fieldLayout, componentFactory, setStackedFieldLayout, setInlineFieldLayout, setEditComponentFactory, setDetailsComponentFactory, updateForm, editorSchema, schema} = this.props;
13+
14+
return (
15+
<ButtonToolbar className="form-options">
16+
<ButtonGroup>
17+
<Button bsStyle="success" onClick={ () => updateForm(editorSchema) }>
18+
<i className="fa fa-refresh" aria-hidden="true"/>
19+
Update
20+
</Button>
21+
</ButtonGroup>
22+
<ButtonGroup>
23+
<Button active={fieldLayout == 'stacked'} onClick={ () => setStackedFieldLayout() }>
24+
<i className="fa fa-ellipsis-v" aria-hidden="true"/>
25+
Stacked
26+
</Button>
27+
<Button active={fieldLayout == 'inline'} onClick={ () => setInlineFieldLayout() }>
28+
<i className="fa fa-ellipsis-h" aria-hidden="true"/>
29+
Inline
30+
</Button>
31+
</ButtonGroup>
32+
<ButtonGroup>
33+
<Button active={componentFactory == 'edit'} onClick={ () => setEditComponentFactory() }>
34+
<i className="fa fa-pencil" aria-hidden="true"/>
35+
Edit
36+
</Button>
37+
<Button active={componentFactory == 'details'} onClick={ () => setDetailsComponentFactory() }>
38+
<i className="fa fa-eye" aria-hidden="true"/>
39+
Details
40+
</Button>
41+
</ButtonGroup>
42+
</ButtonToolbar>
43+
);
44+
}
45+
}
46+
47+
export default FormOptions;

demo/components/Layout.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { Component } from 'react';
2+
import DevTools from './DevTools';
3+
4+
class Layout extends Component {
5+
render() {
6+
let { children } = this.props;
7+
8+
return (
9+
<div>
10+
<div className="container-fluid">
11+
{ children }
12+
</div>
13+
<DevTools />;
14+
</div>
15+
);
16+
}
17+
}
18+
19+
export default Layout;

0 commit comments

Comments
 (0)