@ohu-mobile/core
Version:
128 lines (127 loc) • 7.58 kB
JavaScript
"use strict";
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _babelHelperVueJsxMergeProps = _interopRequireDefault(require("@vue/babel-helper-vue-jsx-merge-props"));
var _CheckboxBlankCircleOutlined2 = _interopRequireDefault(require("@ohu-mobile/icons/lib/CheckboxBlankCircleOutlined"));
var _CheckboxCircleFilled2 = _interopRequireDefault(require("@ohu-mobile/icons/lib/CheckboxCircleFilled"));
var _defineComponent = require("../_utils/defineComponent");
var _SwitchBase = _interopRequireDefault(require("../_internal/SwitchBase"));
var _variables = require("../_config/variables");
var _fieldMixin = require("../Form/fieldMixin");
var _excluded = ["checked", "disabled", "name", "color", "unCheckedColor", "checkedIcon", "unCheckedIcon"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
var createRadio = (0, _defineComponent.defineDsc)('radio-group', 'radio').mixin((0, _fieldMixin.fieldMixin)('checkedValue', 'checked', true));
var _default = exports.default = createRadio.create({
model: {
prop: 'checked',
event: 'change'
},
props: {
name: String,
value: _defineComponent.props.ofType().optional,
defaultChecked: (0, _defineComponent.props)(Boolean).default(false),
checked: (0, _defineComponent.props)(Boolean).optional,
disabled: (0, _defineComponent.props)(Boolean).optional,
labelClickable: (0, _defineComponent.props)(Boolean).default(true),
color: (0, _defineComponent.props)(String).default(_variables.$radioActiveColor),
unCheckedColor: (0, _defineComponent.props)(String).default(_variables.$radioColor),
checkedIcon: _defineComponent.props.ofType().default(function () {
return _CheckboxCircleFilled2.default;
}),
unCheckedIcon: _defineComponent.props.ofType().default(function () {
return _CheckboxBlankCircleOutlined2.default;
}),
attach: _defineComponent.props.ofAny().optional
},
watch: {
checked: function checked(cur) {
if (!this.ancestor) {
this.checkedValue = cur;
}
}
},
data: function data() {
return {
checkedValue: this.ancestor ? this.ancestor.isChildChecked(this.value) : this.initFieldValue(this.checked)
};
},
computed: {
internalDisabled: function internalDisabled() {
if (this.disabled === true) return true;
if (this.ancestor && this.ancestor.disabled !== undefined) {
return this.ancestor.disabled;
}
return this.disabled;
}
},
methods: {
check: function check() {
this.handleChange(true);
},
uncheck: function uncheck() {
this.handleChange(false);
},
getChecked: function getChecked() {
return this.ancestor ? this.ancestor.isChildChecked(this.value) : this.checkedValue;
},
handleChange: function handleChange(checked) {
if (this.internalDisabled) return;
if (this.ancestor) {
var success = this.ancestor.childrenChange(this.value, checked, this.attach);
if (success) {
this.checkedValue = checked;
}
} else {
this.checkedValue = checked;
}
this.$emit('change', checked, this.attach);
}
},
render: function render() {
var _this = this;
var h = arguments[0];
var internalDisabled = this.internalDisabled,
ancestor = this.ancestor,
$scopedSlots = this.$scopedSlots;
var _this$$props = this.$props,
checked = _this$$props.checked,
disabled = _this$$props.disabled,
name = _this$$props.name,
color = _this$$props.color,
unCheckedColor = _this$$props.unCheckedColor,
checkedIcon = _this$$props.checkedIcon,
unCheckedIcon = _this$$props.unCheckedIcon,
radioProps = _objectWithoutProperties(_this$$props, _excluded);
var switchBaseProps = {
props: _objectSpread({
baseName: 'radio',
role: 'radio',
checked: this.getChecked(),
disabled: internalDisabled,
name: (ancestor === null || ancestor === void 0 ? void 0 : ancestor.name) || name,
color: (ancestor === null || ancestor === void 0 ? void 0 : ancestor.color) || color,
unCheckedColor: (ancestor === null || ancestor === void 0 ? void 0 : ancestor.unCheckedColor) || unCheckedColor,
checkedIcon: (ancestor === null || ancestor === void 0 ? void 0 : ancestor.checkedIcon) !== undefined ? ancestor === null || ancestor === void 0 ? void 0 : ancestor.checkedIcon : checkedIcon,
unCheckedIcon: (ancestor === null || ancestor === void 0 ? void 0 : ancestor.unCheckedIcon) !== undefined ? ancestor === null || ancestor === void 0 ? void 0 : ancestor.unCheckedIcon : unCheckedIcon
}, radioProps),
on: _objectSpread(_objectSpread({}, this.$listeners), {}, {
change: this.handleChange,
blur: function blur(e) {
_this.$emit('blur', e);
}
}),
scopedSlots: $scopedSlots
};
return h(_SwitchBase.default, (0, _babelHelperVueJsxMergeProps.default)([{}, switchBaseProps]), [this.$slots.default]);
}
});