UNPKG

@ohu-mobile/core

Version:
109 lines (108 loc) 7.31 kB
"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 _defineComponent = require("../_utils/defineComponent"); var _SwitchBase = _interopRequireWildcard(require("../_internal/SwitchBase")); var _fieldMixin = require("../Form/fieldMixin"); var _excluded = ["checked", "disabled", "name", "color", "unCheckedColor", "checkedIcon", "unCheckedIcon"]; function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } 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 _default = exports.default = (0, _defineComponent.defineDescendantComponent)('checkbox-group', 'checkbox').mixin((0, _fieldMixin.fieldMixin)('checkedValue', 'checked', true)).create({ model: { prop: 'checked', event: 'change' }, props: _SwitchBase.switchBaseProps, 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: { toggle: function toggle() { this.handleChange(!this.getChecked()); }, getChecked: function getChecked() { return this.ancestor ? this.ancestor.isChildChecked(this.value) : this.checkedValue; }, handleChange: function handleChange(checked, e) { if (this.internalDisabled) return; if (this.ancestor) { var success = this.ancestor.childrenChange(this.value, checked, this.attach, e); if (success) { this.checkedValue = checked; } } else { this.checkedValue = checked; } this.$emit('change', checked, this.attach); } }, render: function render(h) { var _this = this; 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, checkboxProps = _objectWithoutProperties(_this$$props, _excluded); var props = _objectSpread({ baseName: 'checkbox', role: 'checkbox', 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 }, checkboxProps); var switchBaseProps = { props: props, class: ancestor && 'is-group-item', on: _objectSpread(_objectSpread({}, this.$listeners), {}, { change: this.handleChange, blur: function blur(e) { _this.$emit('blur', e); } }) }; return h(_SwitchBase.default, (0, _babelHelperVueJsxMergeProps.default)([{}, switchBaseProps, { "scopedSlots": $scopedSlots }]), [this.$slots.default]); } });