tdesign-vue-next
Version:
TDesign Component for vue-next
151 lines (147 loc) • 6.28 kB
JavaScript
/**
* tdesign v1.15.2
* (c) 2025 tdesign
* @license MIT
*/
import { defineComponent, toRefs, computed, createVNode, mergeProps } from 'vue';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _typeof from '@babel/runtime/helpers/typeof';
import { Checkbox, CheckboxGroup } from '../../checkbox/index.js';
import { intersection } from 'lodash-es';
import '../../_chunks/dep-e604a5ce.js';
import { u as usePrefixClass } from '../../_chunks/dep-79c44a11.js';
import '@babel/runtime/helpers/slicedToArray';
import '../../_chunks/dep-7324137b.js';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../_chunks/dep-1d44782f.js';
import '../../_chunks/dep-1f7ad104.js';
import '../../_chunks/dep-6c13cc0e.js';
import '../../_chunks/dep-b9ab7399.js';
import '../../config-provider/hooks/useConfig.js';
import '../../config-provider/utils/context.js';
import '../../_chunks/dep-3b49fbbe.js';
import '../../_chunks/dep-7fac49fa.js';
import 'dayjs';
import '../../_chunks/dep-5360ac56.js';
import '../../_chunks/dep-41ae8479.js';
import '../../_chunks/dep-7b209207.js';
import '../../_chunks/dep-3ba91e12.js';
import '../../_chunks/dep-34e44a4e.js';
import '../../checkbox/consts/index.js';
import '../../checkbox/hooks/useCheckboxLazyLoad.js';
import '../../_chunks/dep-6f34ddfa.js';
import '../../checkbox/hooks/useKeyboardEvent.js';
import '../../_chunks/dep-01e48141.js';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/classCallCheck';
import '../../checkbox/group.js';
import '../../checkbox/checkbox-group-props.js';
import '../../_chunks/dep-0f8c45fe.js';
import '../../_chunks/dep-37a2e7c8.js';
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 ColumnCheckboxGroup = defineComponent({
name: "ColumnCheckboxGroup",
props: {
checkboxProps: Object,
options: {
type: Array,
"default": function _default() {
return [];
}
},
label: String,
uniqueKey: String,
value: Array,
onChange: Function
},
setup: function setup(props) {
var _toRefs = toRefs(props),
checkboxProps = _toRefs.checkboxProps,
value = _toRefs.value,
options = _toRefs.options;
var classPrefix = usePrefixClass();
var allCheckedColumnKeys = computed(function () {
var allCheckedKeys = [];
options.value.forEach(function (option) {
if (_typeof(option) === "object") {
if (option.disabled) return;
if (option.value) {
allCheckedKeys.push(option.value);
} else if (typeof option.label === "string") {
allCheckedKeys.push(option.label);
}
} else {
allCheckedKeys.push(option);
}
});
return allCheckedKeys;
});
var intersectionKeys = computed(function () {
return intersection(allCheckedColumnKeys.value, value.value);
});
var isCheckedAll = computed(function () {
var len = intersectionKeys.value.length;
return Boolean(len && allCheckedColumnKeys.value.length === len);
});
var isIndeterminate = computed(function () {
var len = intersectionKeys.value.length;
return Boolean(len < allCheckedColumnKeys.value.length && len);
});
var onCheckAllColumnsChange = function onCheckAllColumnsChange(checkAll, ctx) {
var changeParams = {
e: ctx.e,
type: "check",
current: void 0,
option: void 0
};
if (checkAll) {
var _props$onChange;
var newKeys = _toConsumableArray(new Set(value.value.concat(allCheckedColumnKeys.value)));
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newKeys, changeParams);
} else {
var _props$onChange2;
var _newKeys = value.value.filter(function (val) {
return !allCheckedColumnKeys.value.includes(val);
});
(_props$onChange2 = props.onChange) === null || _props$onChange2 === void 0 || _props$onChange2.call(props, _newKeys, _objectSpread(_objectSpread({}, changeParams), {}, {
type: "uncheck"
}));
}
};
var handleCheckChange = function handleCheckChange(val, ctx) {
var _props$onChange3;
(_props$onChange3 = props.onChange) === null || _props$onChange3 === void 0 || _props$onChange3.call(props, val, ctx);
};
var classes = computed(function () {
return ["".concat(classPrefix.value, "-table__column-controller-item"), _defineProperty({}, "".concat(classPrefix.value, "-table__").concat(props.uniqueKey), props.uniqueKey)];
});
return function () {
return createVNode("div", {
"class": classes.value
}, [createVNode("div", {
"class": "".concat(classPrefix.value, "-table__column-controller-block")
}, [createVNode(Checkbox, {
"indeterminate": isIndeterminate.value,
"checked": isCheckedAll.value,
"onChange": onCheckAllColumnsChange,
"disabled": !allCheckedColumnKeys.value.length
}, {
"default": function _default() {
return [props.label];
}
})]), createVNode("div", {
"class": "".concat(classPrefix.value, "-table__column-controller-block")
}, [createVNode(CheckboxGroup, mergeProps({
"options": options.value
}, checkboxProps.value, {
"modelValue": value.value,
"onChange": handleCheckChange
}), null)])]);
};
}
});
export { ColumnCheckboxGroup as default };
//# sourceMappingURL=column-checkbox-group.js.map