@meve/ui
Version:
Argon design system components library
109 lines (100 loc) • 2.99 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import FormItem from '../form-item';
import Space from '../space';
import { createNamespace } from '../utils/create';
import { props } from './props';
import { createChildrenMixin, createParentMixin } from '../utils/mixins/relation';
var _createNamespace = createNamespace('radio-group'),
createComponent = _createNamespace.createComponent,
namespace = _createNamespace.namespace;
var directionTransformer = {
horizontal: 'row',
vertical: 'column'
};
var RadioGroupPlugin = createComponent({
props: props,
mixins: [createParentMixin('radioGroup', {
childrenKey: 'radios'
}), createChildrenMixin('form', {
parentKey: 'form',
childrenKey: 'formComponents'
})],
data: function data() {
return {
errorMessage: ''
};
},
watch: {
value: function value() {
this.syncRadios();
},
radios: function radios() {
this.syncRadios();
}
},
methods: {
// expose
reset: function reset() {
this.$emit('input', undefined);
this.resetValidation();
},
// expose
validate: function validate() {
this.$refs.formItem.validate();
},
// expose
resetValidation: function resetValidation() {
this.$refs.formItem.resetValidation();
},
nextTickValidateWithTrigger: function nextTickValidateWithTrigger(trigger) {
var _this = this;
this.$nextTick(function () {
var _this$$refs$formItem;
(_this$$refs$formItem = _this.$refs.formItem) == null ? void 0 : _this$$refs$formItem.validateWithTrigger(_this.validateTrigger, trigger, _this.rules, _this.value);
});
},
syncRadios: function syncRadios() {
var _this2 = this;
this.radios.forEach(function (_ref) {
var sync = _ref.sync;
return sync(_this2.value);
});
},
onToggle: function onToggle(changedValue) {
this.$emit('input', changedValue);
this.$emit('change', changedValue);
this.nextTickValidateWithTrigger('onChange');
},
handleErrorMessageChange: function handleErrorMessageChange(errorMessage) {
this.errorMessage = errorMessage;
}
},
render: function render() {
var h = arguments[0];
var label = this.label,
value = this.value,
rules = this.rules,
direction = this.direction,
handleErrorMessageChange = this.handleErrorMessageChange;
return h(FormItem, {
"attrs": {
"radio-group-cover": true,
"label": label,
"value": value,
"rules": rules
},
"ref": "formItem",
"on": _extends({}, {
'error-message-change': handleErrorMessageChange
})
}, [h(Space, {
"class": namespace(),
"attrs": {
"radio-group-cover": true,
"direction": directionTransformer[direction]
}
}, [this.slots()])]);
}
});
export var _RadioGroupComponent = RadioGroupPlugin;
export default RadioGroupPlugin;