UNPKG

tdesign-vue

Version:
140 lines (136 loc) 5.9 kB
/** * tdesign v1.11.2 * (c) 2025 tdesign * @license MIT */ import { h as helper } from '../_chunks/dep-653f218a.js'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import Vue from 'vue'; import { omit } from '../utils/helper.js'; import { renderContent } from '../utils/render-tnode.js'; import props from './props.js'; import { emitEvent } from '../utils/event.js'; import { getClassPrefixMixins } from '../config-provider/config-receiver.js'; import mixins from '../utils/mixins.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import 'lodash-es'; import '@babel/runtime/helpers/readOnlyError'; import '@babel/runtime/helpers/typeof'; import '@vue/composition-api'; import '../config-provider/context.js'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-84fc5ae7.js'; import '../_chunks/dep-eb45b5e0.js'; import 'dayjs'; 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; } var classPrefixMixins = getClassPrefixMixins("radio"); var _Radio = mixins(Vue, classPrefixMixins).extend({ name: "TRadio", inheritAttrs: false, props: _objectSpread({}, props), inject: { radioGroup: { "default": void 0 }, radioButton: { "default": void 0 } }, data: function data() { return { formDisabled: void 0 }; }, render: function render() { var _this$radioGroup, _this$value; var h = arguments[0]; var radioGroup = this.radioGroup, radioButton = this.radioButton; var tChecked = this.getChecked(); var tDisabled = this.getDisabled(); var prefixCls = radioButton ? "".concat(this.componentName, "-button") : this.componentName; var inputClass = ["".concat(prefixCls), _defineProperty(_defineProperty({}, this.commonStatusClassName.checked, tChecked), this.commonStatusClassName.disabled, tDisabled)]; var allowUncheck = this.allowUncheck || ((_this$radioGroup = this.radioGroup) === null || _this$radioGroup === void 0 ? void 0 : _this$radioGroup.allowUncheck); return h("label", { "class": inputClass, "on": { "click": this.handleRadioClick }, "attrs": { "tabindex": tDisabled ? void 0 : "0" } }, [h("input", helper([{ "attrs": { "type": "radio", "name": this.name || (radioGroup === null || radioGroup === void 0 ? void 0 : radioGroup.name) || void 0, "disabled": tDisabled, "tabindex": "-1", "data-value": typeof this.value === "string" ? "'".concat(this.value, "'") : this.value, "data-allow-uncheck": allowUncheck || void 0 }, "class": "".concat(prefixCls, "__former"), "domProps": { "value": (_this$value = this.value) !== null && _this$value !== void 0 ? _this$value : void 0, "checked": tChecked }, "on": { "click": this.onInputClick } }, { "on": _objectSpread({}, omit(this.$listeners, ["change", "click"])) }])), h("span", { "class": "".concat(prefixCls, "__input") }), h("span", { "class": "".concat(prefixCls, "__label") }, [renderContent(this, "default", "label")])]); }, methods: { getChecked: function getChecked() { var _this$radioGroup2; return this.checked || this.value !== void 0 && ((_this$radioGroup2 = this.radioGroup) === null || _this$radioGroup2 === void 0 ? void 0 : _this$radioGroup2.value) === this.value; }, getDisabled: function getDisabled() { var _ref2, _this$radioGroup3; return Boolean((_ref2 = this.formDisabled || this.disabled) !== null && _ref2 !== void 0 ? _ref2 : (_this$radioGroup3 = this.radioGroup) === null || _this$radioGroup3 === void 0 ? void 0 : _this$radioGroup3.disabled); }, getReadonly: function getReadonly() { var _this$readonly, _this$radioGroup4; return Boolean((_this$readonly = this.readonly) !== null && _this$readonly !== void 0 ? _this$readonly : (_this$radioGroup4 = this.radioGroup) === null || _this$radioGroup4 === void 0 ? void 0 : _this$radioGroup4.readonly); }, onInputClick: function onInputClick(e) { e.stopPropagation(); }, handleRadioClick: function handleRadioClick(e) { var tDisabled = this.getDisabled(); var tReadonly = this.getReadonly(); if (tDisabled || tReadonly) return; this.$emit("click", { e: e }); this.checkRadio(e); }, checkRadio: function checkRadio(e) { var _this$radioGroup5; var tChecked = this.getChecked(); var allowUncheck = this.allowUncheck || ((_this$radioGroup5 = this.radioGroup) === null || _this$radioGroup5 === void 0 ? void 0 : _this$radioGroup5.allowUncheck); if (tChecked && !allowUncheck) return; if (this.radioGroup) { var value = tChecked && allowUncheck ? void 0 : this.value; this.radioGroup.handleRadioChange(value, { e: e, name: this.radioGroup.name }); } else { var _value = allowUncheck ? !tChecked : true; emitEvent(this, "change", _value, { e: e }); } } } }); export { _Radio as default }; //# sourceMappingURL=radio.js.map