hongluan-ui
Version:
Hongluan Component Library for Vue 3
80 lines (75 loc) • 2.94 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
require('../../../../utils/index.js');
require('../../../../tokens/index.js');
var lodashUnified = require('lodash-unified');
require('../../../../hooks/index.js');
var checkbox = require('../../../../tokens/checkbox.js');
var types = require('../../../../utils/types.js');
var shared = require('@vue/shared');
var index = require('../../../../hooks/use-consistent-prop/index.js');
const useCheckboxStatus = (props, slots, { model }) => {
const checkboxGroup = vue.inject(checkbox.checkboxGroupContextKey, void 0);
const isFocused = vue.ref(false);
const actualValue = vue.computed(() => {
if (!types.isPropAbsent(props.value)) {
return props.value;
}
return props.label;
});
const isGroup = vue.computed(() => types.isUndefined(checkboxGroup) === false);
const isChecked = vue.computed(() => {
const value = model.value;
if (types.isBoolean(value)) {
return value;
} else if (shared.isArray(value)) {
if (shared.isObject(actualValue.value)) {
return value.map(vue.toRaw).some((o) => lodashUnified.isEqual(o, actualValue.value));
} else {
return value.map(vue.toRaw).includes(actualValue.value);
}
} else if (value !== null && value !== void 0) {
return value === props.trueValue || value === props.trueLabel;
} else {
return !!value;
}
});
const isCustom = vue.computed(() => {
var _a;
return isGroup.value ? ((_a = checkboxGroup == null ? void 0 : checkboxGroup.custom) == null ? void 0 : _a.value) || props.custom : props.custom;
});
const isRound = vue.computed(() => {
var _a;
return isGroup.value ? ((_a = checkboxGroup == null ? void 0 : checkboxGroup.round) == null ? void 0 : _a.value) || props.round : props.round;
});
const isFill = vue.computed(() => {
var _a;
return isGroup.value ? ((_a = checkboxGroup == null ? void 0 : checkboxGroup.fill) == null ? void 0 : _a.value) || props.fill : props.fill;
});
const checkboxType = vue.computed(() => {
var _a;
return isGroup.value ? ((_a = checkboxGroup == null ? void 0 : checkboxGroup.type) == null ? void 0 : _a.value) || props.type : props.type;
});
const checkboxSize = vue.computed(() => {
var _a;
const { size: temCheckboxSize } = index.useConsistentProp();
return isGroup.value ? ((_a = checkboxGroup == null ? void 0 : checkboxGroup.size) == null ? void 0 : _a.value) || temCheckboxSize.value : temCheckboxSize.value;
});
const hasOwnLabel = vue.computed(() => {
return !!slots.default || !types.isPropAbsent(actualValue.value);
});
return {
isChecked,
isFocused,
isCustom,
isRound,
isFill,
checkboxType,
checkboxSize,
hasOwnLabel,
actualValue
};
};
exports.useCheckboxStatus = useCheckboxStatus;
//# sourceMappingURL=use-checkbox-status.js.map