Skip to content

Commit

Permalink
Expose a compiled-down version of the jsx source.
Browse files Browse the repository at this point in the history
  • Loading branch information
twisty committed May 11, 2015
1 parent 46f4e29 commit b8fbdfc
Show file tree
Hide file tree
Showing 10 changed files with 520 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"description": "A set of React JS components for use in a formsy-react form. Markup adheres to Bootstrap structure.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "NODE_ENV=production gulp production",
"lint": "eslint src"
"lint": "eslint src",
"release": "jsx --no-cache-dir src release"
},
"main": "./src/main.js",
"main": "./release/main.js",
"repository": {
"type": "git",
"url": "https://github.com/twisty/formsy-react-components.git"
Expand Down
44 changes: 44 additions & 0 deletions release/checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*jshint node:true */

'use strict';

var React = require('react');
var Formsy = require('formsy-react');

var Checkbox = React.createClass({displayName: "Checkbox",

mixins: [Formsy.Mixin],

getDefaultProps: function() {
return {
label: '',
value: false,
onChange: function() {},
disabled: false
};
},

changeValue: function(event) {
var target = event.currentTarget;
this.setValue(target.checked);
this.props.onChange(this.props.name, target.checked);
},

render: function() {
return (
React.createElement("div", {className: "checkbox"},
React.createElement("label", null,
React.createElement("input", {
checked: this.getValue() === true,
type: "checkbox",
value: this.props.value,
onChange: this.changeValue,
disabled: this.isFormDisabled() || this.props.disabled}
), " ", this.props.label
)
)
);
}
});

module.exports = Checkbox;
25 changes: 25 additions & 0 deletions release/icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

var React = require('react');

var Icon = React.createClass({displayName: "Icon",

requiredProps: {
symbol: React.PropTypes.string.isRequired,
className: React.PropTypes.string
},

defaultProps: {
className: ''
},

render: function() {
var className = 'glyphicon glyphicon-' + this.props.symbol + ' ' + this.props.className;
return (
React.createElement("span", {className: className, "aria-hidden": "true"})
);
}

});

module.exports = Icon;
73 changes: 73 additions & 0 deletions release/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*jshint node:true */

'use strict';

var React = require('react');
var Formsy = require('formsy-react');
var FRCMixin = require('./mixin');
var Row = require('./row');
var Icon = require('./icon.js');

var Input = React.createClass({displayName: "Input",

mixins: [Formsy.Mixin, FRCMixin],

propTypes: {
type: React.PropTypes.oneOf(['text', 'date', 'email', 'password', 'hidden'])
},

changeValue: function(event) {
this.setValue(event.currentTarget.value);
},

getDefaultProps: function() {
return {
type: 'text'
};
},

render: function() {

var warningIcon = '';

if (this.showErrors()) {
warningIcon = (
React.createElement(Icon, {symbol: "remove", className: "form-control-feedback"})
);
}

if (this.props.layout === 'elementOnly' || this.props.type === 'hidden') {
return this.renderElement();
}

return (
React.createElement(Row, {
label: this.props.label,
required: this.isRequired(),
hasErrors: this.showErrors(),
layout: this.props.layout
},
this.renderElement(),
warningIcon,
this.renderHelp(),
this.renderErrorMessage()
)
);
},

renderElement: function() {
return (
React.createElement("input", React.__spread({
className: "form-control"},
this.props,
{label: null,
value: this.getValue(),
onChange: this.changeValue,
disabled: this.isFormDisabled() || this.props.disabled})
)
);
}

});

module.exports = Input;
8 changes: 8 additions & 0 deletions release/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
Input: require('./input'),
Textarea: require('./textarea'),
Select: require('./select'),
RadioGroup: require('./radio-group')
};
47 changes: 47 additions & 0 deletions release/mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

var React = require('react');

module.exports = {
getDefaultProps: function() {
return {
disabled: false,
validatePristine: false,
layout: 'horizontal',
onChange: function() {},
onFocus: function() {},
onBlur: function() {}
};
},

renderHelp: function() {
if (!this.props.help) {
return '';
}
return (
React.createElement("span", {className: "help-block"}, this.props.help)
);
},

renderErrorMessage: function() {
if (!this.showErrors()) {
return '';
}
var errorMessage = this.getErrorMessage();
if (!errorMessage) {
return '';
}
return (
React.createElement("span", {className: "help-block"}, errorMessage)
);
},

showErrors: function() {
if (this.isPristine() === true) {
if (this.props.validatePristine === false) {
return false;
}
}
return (this.isValid() === false);
}
};
94 changes: 94 additions & 0 deletions release/radio-group.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*jshint node:true */

'use strict';

var React = require('react');
var Formsy = require('formsy-react');
var FRCMixin = require('./mixin');
var Row = require('./row');

var RadioGroup = React.createClass({displayName: "RadioGroup",

mixins: [Formsy.Mixin, FRCMixin],

propTypes: {
name: React.PropTypes.string.isRequired,
type: React.PropTypes.oneOf(['inline', 'stacked']),
options: React.PropTypes.array.isRequired
},

getDefaultProps: function() {
return {
type: 'stacked',
label: '',
help: null
};
},

changeRadio: function(event) {
var value = event.currentTarget.value;
this.setValue(value);
this.props.onChange(this.props.name, value);
},

renderElement: function() {
var _this = this;
var controls = this.props.options.map(function(radio, key) {
var checked = (_this.getValue() === radio.value);
var disabled = _this.isFormDisabled() || radio.disabled || _this.props.disabled;
var className = 'radio' + (disabled ? ' disabled' : '');
if (_this.props.type === 'inline') {
return (
React.createElement("label", {className: "radio-inline", key: key},
React.createElement("input", {
checked: checked,
type: "radio",
value: radio.value,
onChange: _this.changeRadio,
disabled: disabled}
), " ", radio.label
)
);
}
return (
React.createElement("div", {className: className, key: key},
React.createElement("label", null,
React.createElement("input", {
checked: checked,
type: "radio",
value: radio.value,
onChange: _this.changeRadio,
disabled: disabled}
), " ", radio.label
)
)
);
});
return controls;
},

render: function() {

if (this.props.layout === 'elementOnly') {
return (
React.createElement("div", null, this.renderElement())
);
}

return (
React.createElement(Row, {
label: this.props.label,
required: this.isRequired(),
hasErrors: this.showErrors(),
layout: this.props.layout,
fakeLabel: true
},
this.renderElement(),
this.renderHelp(),
this.renderErrorMessage()
)
);
}
});

module.exports = RadioGroup;
Loading

0 comments on commit b8fbdfc

Please sign in to comment.