@meve/ui
Version:
Argon design system components library
73 lines (67 loc) • 2.15 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { createNamespace } from '../utils/create';
import { props } from './props';
import { createParentMixin } from '../utils/mixins/relation';
var _createNamespace = createNamespace('form'),
createComponent = _createNamespace.createComponent,
namespace = _createNamespace.namespace;
var FormPlugin = createComponent({
mixins: [createParentMixin('form', {
childrenKey: 'formItems'
}), createParentMixin('form', {
childrenKey: 'formComponents'
})],
props: props,
methods: {
// expose
validate: function validate() {
var _this = this;
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var res;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return Promise.all(_this.formItems.map(function (_ref) {
var validate = _ref.validate;
return validate();
}));
case 2:
res = _context.sent;
return _context.abrupt("return", res.every(function (r) {
return r === true;
}));
case 4:
case "end":
return _context.stop();
}
}
}, _callee);
}))();
},
// expose
reset: function reset() {
this.formComponents.forEach(function (_ref2) {
var reset = _ref2.reset;
return reset();
});
},
// expose
resetValidation: function resetValidation() {
this.formItems.forEach(function (_ref3) {
var resetValidation = _ref3.resetValidation;
return resetValidation();
});
}
},
render: function render() {
var h = arguments[0];
return h("div", {
"class": namespace()
}, [this.slots()]);
}
});
export var _FormComponent = FormPlugin;
export default FormPlugin;