Skip to content

Commit 3fa0e51

Browse files
author
daniel.gomez
committed
Initial Commit,
Refactored Bootstrap factories to be created by an unique Factory, now you can request which type of Bootstrap factory you want to create , i.e. edit, details, etc Added ComponentFactory as base class of each factory, this factory should be moved to a common repo to be included as dependency of each UI sub module to be created.
1 parent f8b3a58 commit 3fa0e51

38 files changed

+1522
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.idea

package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "redux-autoform-bootstrap-ui",
3+
"version": "1.0.0",
4+
"description": "Bootstrap UI implementation for redux-autoform",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/redux-autoform/redux-autoform-bootstrap-ui.git"
12+
},
13+
"keywords": [
14+
"autoform",
15+
"react",
16+
"redux",
17+
"bootstrap"
18+
],
19+
"author": "",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/redux-autoform/redux-autoform-bootstrap-ui/issues"
23+
},
24+
"homepage": "https://github.com/redux-autoform/redux-autoform-bootstrap-ui#readme"
25+
}

src/components/ArrayContainerItem.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import Glyphicon from 'react-bootstrap/lib/Glyphicon';
3+
import MenuItem from 'react-bootstrap/lib/MenuItem';
4+
import Dropdown from 'react-bootstrap/lib/Dropdown';
5+
6+
class ArrayContainerItem extends Component {
7+
static propTypes = {
8+
index: PropTypes.number.isRequired,
9+
onAction: PropTypes.func.isRequired
10+
};
11+
12+
handleAction = (eventKey) => {
13+
let { onAction, index } = this.props;
14+
15+
onAction(index, eventKey);
16+
};
17+
18+
render() {
19+
let { index, children } = this.props;
20+
21+
return <div className="array-container-item">
22+
<div className="row">
23+
<div className="col-xs-11">
24+
<div className="array-container-item-content">
25+
{ children }
26+
</div>
27+
</div>
28+
<div className="col-xs-1">
29+
<div className="array-container-item-options">
30+
<Dropdown id={`${index}-dropdown`} onSelect={this.handleAction} pullRight>
31+
<Dropdown.Toggle noCaret bsStyle="link" bsSize="small">
32+
<Glyphicon glyph="menu-hamburger"/>
33+
</Dropdown.Toggle>
34+
<Dropdown.Menu >
35+
<MenuItem eventKey="remove">
36+
<Glyphicon glyph="remove" className="text-danger"/>
37+
<span className="glyphicon-text text-danger">
38+
Remove
39+
</span>
40+
</MenuItem>
41+
<MenuItem divider/>
42+
<MenuItem eventKey="moveUp">
43+
<Glyphicon glyph="chevron-up"/>
44+
<span className="glyphicon-text">
45+
Move up
46+
</span>
47+
</MenuItem>
48+
<MenuItem eventKey="moveDown">
49+
<Glyphicon glyph="chevron-down"/>
50+
<span className="glyphicon-text">
51+
Move down
52+
</span>
53+
</MenuItem>
54+
<MenuItem divider/>
55+
<MenuItem eventKey="moveFirst">
56+
<Glyphicon glyph="chevron-up"/>
57+
<span className="glyphicon-text">
58+
Move first
59+
</span>
60+
</MenuItem>
61+
<MenuItem eventKey="moveLast">
62+
<Glyphicon glyph="chevron-down"/>
63+
<span className="glyphicon-text">
64+
Move last
65+
</span>
66+
</MenuItem>
67+
</Dropdown.Menu>
68+
</Dropdown>
69+
</div>
70+
</div>
71+
</div>
72+
</div>;
73+
}
74+
}
75+
76+
export default ArrayContainerItem;

src/components/FormControl.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import InputGroup from 'react-bootstrap/lib/InputGroup';
3+
import { FormControl as BootstrapFormControl } from 'react-bootstrap';
4+
5+
class FormControl extends Component {
6+
static propTypes = {
7+
error: PropTypes.string,
8+
touched: PropTypes.bool,
9+
displayName: PropTypes.string,
10+
name: PropTypes.string,
11+
help: PropTypes.string
12+
};
13+
14+
handleChange = (event) => {
15+
let { onChange } = this.props;
16+
17+
onChange(event.target.value);
18+
};
19+
20+
handleBlur = (event) => {
21+
let { onBlur } = this.props;
22+
23+
onBlur();
24+
};
25+
26+
getInput = () => {
27+
let { value, name, placeholder, displayName, help, componentClass, children, rows } = this.props;
28+
let label = displayName || name;
29+
30+
let formControlProps = { label, value, placeholder, help, componentClass, rows };
31+
32+
return (
33+
<BootstrapFormControl type="text" ref="input" onChange={this.handleChange} onBlur={this.handleBlur} {...formControlProps} hasFeedback>
34+
{ children }
35+
</BootstrapFormControl>
36+
)
37+
};
38+
39+
getAddonBefore = () => {
40+
let { addonBefore } = this.props;
41+
42+
if (addonBefore) {
43+
return (
44+
<InputGroup.Addon>
45+
{addonBefore}
46+
</InputGroup.Addon>
47+
);
48+
} else {
49+
return null;
50+
}
51+
};
52+
53+
getAddonAfter = () => {
54+
let { addonAfter } = this.props;
55+
56+
if (addonAfter) {
57+
return (
58+
<InputGroup.Addon>
59+
{addonAfter}
60+
</InputGroup.Addon>
61+
);
62+
} else {
63+
return null;
64+
}
65+
};
66+
67+
render() {
68+
let { addonBefore, addonAfter } = this.props;
69+
let before = this.getAddonBefore();
70+
let input = this.getInput();
71+
let after = this.getAddonAfter();
72+
73+
if (addonBefore || addonAfter) {
74+
return (
75+
<InputGroup>
76+
{ before }
77+
{ input }
78+
{ after }
79+
</InputGroup>
80+
);
81+
82+
} else {
83+
return input;
84+
}
85+
}
86+
}
87+
88+
export default FormControl;

src/components/FormGroup.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import FormGroupInline from './FormGroupInline';
3+
import FormGroupStacked from './FormGroupStacked';
4+
5+
class FormGroup extends Component {
6+
static propTypes = {
7+
error: PropTypes.string,
8+
touched: PropTypes.bool,
9+
displayName: PropTypes.string,
10+
name: PropTypes.string,
11+
help: PropTypes.string
12+
};
13+
14+
render() {
15+
let { fieldLayout } = this.props;
16+
let InnerFormGroup = fieldLayout == 'inline' ? FormGroupInline : FormGroupStacked;
17+
18+
return <InnerFormGroup {...this.props}/>;
19+
}
20+
}
21+
22+
export default FormGroup;

src/components/FormGroupInline.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import { FormGroup as BootstrapFormGroup } from 'react-bootstrap';
3+
import FormGroupInlineControlLabel from './FormGroupInlineControlLabel';
4+
import FormGroupInlineContent from './FormGroupInlineContent'
5+
import { getDisplayName } from '../../helpers/metadataHelper';
6+
7+
class FormGroupInline extends Component {
8+
static propTypes = {
9+
error: PropTypes.string,
10+
touched: PropTypes.bool,
11+
displayName: PropTypes.string,
12+
name: PropTypes.string,
13+
help: PropTypes.string
14+
};
15+
16+
render() {
17+
let { error, touched, displayName, name, children, help, className, innerSize } = this.props;
18+
displayName = getDisplayName(displayName, name);
19+
20+
let controlLabelProps = { displayName };
21+
let contentProps = { error, touched, children, help, hasControlLabel: displayName != null, innerSize };
22+
let formGroupProps = { className };
23+
24+
if (error && touched) {
25+
formGroupProps.validationState = 'error';
26+
}
27+
28+
return (
29+
<BootstrapFormGroup {...formGroupProps}>
30+
<FormGroupInlineControlLabel {...controlLabelProps}/>
31+
<FormGroupInlineContent {...contentProps}>
32+
{ children }
33+
</FormGroupInlineContent>
34+
</BootstrapFormGroup>
35+
)
36+
}
37+
}
38+
39+
export default FormGroupInline;
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import HelpBlock from 'react-bootstrap/lib/HelpBlock';
3+
import Col from 'react-bootstrap/lib/Col';
4+
5+
class FormGroupInlineContent extends Component {
6+
static propTypes = {
7+
error: PropTypes.string,
8+
touched: PropTypes.bool,
9+
displayName: PropTypes.string,
10+
name: PropTypes.string,
11+
help: PropTypes.string
12+
};
13+
14+
getHelpBlock = () => {
15+
let { error, touched, help } = this.props;
16+
let helpText = (touched ? error : '') || help;
17+
18+
if (helpText) {
19+
return (
20+
<HelpBlock>
21+
{ helpText }
22+
</HelpBlock>
23+
)
24+
} else {
25+
return null;
26+
}
27+
28+
};
29+
30+
render() {
31+
let { children, hasControlLabel, innerSize } = this.props;
32+
let className = hasControlLabel ? "col-offset-140" : null;
33+
let helpBlock = this.getHelpBlock();
34+
35+
return <Col className={className} md={12}>
36+
<Col className="no-padding-col" md={innerSize || 12}>
37+
{ children }
38+
{ helpBlock }
39+
</Col>
40+
</Col>;
41+
}
42+
}
43+
44+
export default FormGroupInlineContent;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, { Component } from 'react';
2+
import { ControlLabel } from 'react-bootstrap';
3+
4+
class FormGroupInlineControlLabel extends Component {
5+
static propTypes = {
6+
displayName: React.PropTypes.string
7+
};
8+
9+
render() {
10+
let { displayName } = this.props;
11+
12+
if (displayName == null) {
13+
return null;
14+
}
15+
16+
return (
17+
<div className="col-fixed-140">
18+
<ControlLabel>
19+
{ displayName }
20+
</ControlLabel>
21+
</div>
22+
)
23+
}
24+
}
25+
26+
export default FormGroupInlineControlLabel;

0 commit comments

Comments
 (0)