Skip to content

Commit

Permalink
feat(changelog): Changelog with conventional-commits (#26)
Browse files Browse the repository at this point in the history
* Adding Changelog
  • Loading branch information
apuntovanini authored and rkuykendall committed Nov 22, 2017
1 parent f8dc5f5 commit d6ce00c
Show file tree
Hide file tree
Showing 6 changed files with 467 additions and 133 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<a name="1.1.0"></a>
# [1.1.0](https://github.com/formsy/formsy-react/compare/v1.0.2...v1.1.0) (2017-11-21)


### Features

* **react16:** add support for react16 by loosening dev and peer dependencies ([16b9065](https://github.com/formsy/formsy-react/commit/16b9065))




201 changes: 84 additions & 117 deletions lib/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,90 @@ exports.default = function (Component) {

var _this = _possibleConstructorReturn(this, (WrappedComponent.__proto__ || Object.getPrototypeOf(WrappedComponent)).call(this, props));

_this.getErrorMessage = function () {
var messages = _this.getErrorMessages();
return messages.length ? messages[0] : null;
};

_this.getErrorMessages = function () {
if (!_this.isValid() || _this.showRequired()) {
return _this.state.externalError || _this.state.validationError || [];
}
return [];
};

_this.getValue = function () {
return _this.state.value;
};

_this.setValidations = function (validations, required) {
// Add validations to the store itself as the props object can not be modified
_this.validations = convertValidationsToObject(validations) || {};
_this.requiredValidations = required === true ? { isDefaultRequiredValue: true } : convertValidationsToObject(required);
};

_this.setValue = function (value) {
var validate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;

if (!validate) {
_this.setState({
value: value
});
} else {
_this.setState({
value: value,
isPristine: false
}, function () {
_this.context.formsy.validate(_this);
});
}
};

_this.hasValue = function () {
return _this.state.value !== '';
};

_this.isFormDisabled = function () {
return _this.context.formsy.isFormDisabled();
};

_this.isFormSubmitted = function () {
return _this.state.formSubmitted;
};

_this.isPristine = function () {
return _this.state.isPristine;
};

_this.isRequired = function () {
return !!_this.props.required;
};

_this.isValid = function () {
return _this.state.isValid;
};

_this.isValidValue = function (value) {
return _this.context.formsy.isValidValue.call(null, _this, value);
};

_this.resetValue = function () {
_this.setState({
value: _this.state.pristineValue,
isPristine: true
}, function () {
_this.context.formsy.validate(_this);
});
};

_this.showError = function () {
return !_this.showRequired() && !_this.isValid();
};

_this.showRequired = function () {
return _this.state.isRequired;
};

_this.state = {
value: props.value,
isRequired: false,
Expand All @@ -86,22 +170,6 @@ exports.default = function (Component) {
externalError: null,
formSubmitted: false
};

_this.getErrorMessage = _this.getErrorMessage.bind(_this);
_this.getErrorMessages = _this.getErrorMessages.bind(_this);
_this.getValue = _this.getValue.bind(_this);
_this.hasValue = _this.hasValue.bind(_this);
_this.isFormDisabled = _this.isFormDisabled.bind(_this);
_this.isPristine = _this.isPristine.bind(_this);
_this.isFormSubmitted = _this.isFormSubmitted.bind(_this);
_this.isRequired = _this.isRequired.bind(_this);
_this.isValidValue = _this.isValidValue.bind(_this);
_this.isValid = _this.isValid.bind(_this);
_this.resetValue = _this.resetValue.bind(_this);
_this.setValidations = _this.setValidations.bind(_this);
_this.setValue = _this.setValue.bind(_this);
_this.showRequired = _this.showRequired.bind(_this);
_this.showError = _this.showError.bind(_this);
return _this;
}

Expand Down Expand Up @@ -153,111 +221,10 @@ exports.default = function (Component) {
value: function componentWillUnmount() {
this.context.formsy.detachFromForm(this);
}
}, {
key: 'getErrorMessage',
value: function getErrorMessage() {
var messages = this.getErrorMessages();
return messages.length ? messages[0] : null;
}
}, {
key: 'getErrorMessages',
value: function getErrorMessages() {
return !this.isValid() || this.showRequired() ? this.state.externalError || this.state.validationError || [] : [];
}
}, {
key: 'getValue',
value: function getValue() {
return this.state.value;
}
}, {
key: 'setValidations',
value: function setValidations(validations, required) {
// Add validations to the store itself as the props object can not be modified
this.validations = convertValidationsToObject(validations) || {};
this.requiredValidations = required === true ? { isDefaultRequiredValue: true } : convertValidationsToObject(required);
}

// By default, we validate after the value has been set.
// A user can override this and pass a second parameter of `false` to skip validation.

}, {
key: 'setValue',
value: function setValue(value) {
var _this3 = this;

var validate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;

if (!validate) {
this.setState({
value: value
});
} else {
this.setState({
value: value,
isPristine: false
}, function () {
_this3.context.formsy.validate(_this3);
});
}
}
}, {
key: 'hasValue',
value: function hasValue() {
return this.state.value !== '';
}
}, {
key: 'isFormDisabled',
value: function isFormDisabled() {
return this.context.formsy.isFormDisabled();
}
}, {
key: 'isFormSubmitted',
value: function isFormSubmitted() {
return this.state.formSubmitted;
}
}, {
key: 'isPristine',
value: function isPristine() {
return this.state.isPristine;
}
}, {
key: 'isRequired',
value: function isRequired() {
return !!this.props.required;
}
}, {
key: 'isValid',
value: function isValid() {
return this.state.isValid;
}
}, {
key: 'isValidValue',
value: function isValidValue(value) {
return this.context.formsy.isValidValue.call(null, this, value);
// return this.props.isValidValue.call(null, this, value);
}
}, {
key: 'resetValue',
value: function resetValue() {
var _this4 = this;

this.setState({
value: this.state.pristineValue,
isPristine: true
}, function () {
_this4.context.formsy.validate(_this4);
});
}
}, {
key: 'showError',
value: function showError() {
return !this.showRequired() && !this.isValid();
}
}, {
key: 'showRequired',
value: function showRequired() {
return this.state.isRequired;
}
}, {
key: 'render',
value: function render() {
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ var addValidationRule = function addValidationRule(name, func) {
var withFormsy = _Wrapper2.default;

var deprecatedWrapper = function deprecatedWrapper(Component) {
// eslint-disable-next-line no-console
console.warn('Wrapper has been renamed to withFormsy. Importing Wrapper from formsy-react is depreacted and will be removed in the future. Please rename your Wrapper imports to withFormsy.');

return withFormsy(Component);
Expand Down
3 changes: 2 additions & 1 deletion lib/validationRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ var validations = {
return isEmpty(value);
},
isEmail: function isEmail(values, value) {
return validations.matchRegexp(values, value, /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i);
// Regex from http://emailregex.com/
return validations.matchRegexp(values, value, /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i);
},
isUrl: function isUrl(values, value) {
return validations.matchRegexp(values, value, /^(?:\w+:)?\/\/([^\s.]+\.\S{2}|localhost[:?\d]*)\S*$/i);
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"react-component",
"validation"
],
"standard-version": {
"skip": {
"tag": true
}
},
"license": "MIT",
"homepage": "https://github.com/formsy/formsy-react",
"bugs": "https://github.com/formsy/formsy-react/issues",
Expand All @@ -27,6 +32,7 @@
"examples": "webpack-dev-server --config examples/webpack.config.js --content-base examples",
"lint": "eslint src/**/*.js",
"prepublish": "rm -Rf ./lib && babel ./src/ -d ./lib/",
"changelog": "standard-changelog",
"test": "babel-node testrunner"
},
"dependencies": {
Expand All @@ -52,6 +58,8 @@
"react-addons-test-utils": "^15.6.0",
"react-dom": "^15.6.1 || ^16.0.0",
"sinon": "^3.2.0",
"standard-changelog": "^1.0.5",
"standard-version": "^4.2.0",
"webpack": "^3.5.4",
"webpack-dev-server": "^2.7.1"
},
Expand Down
Loading

0 comments on commit d6ce00c

Please sign in to comment.