hongluan-ui
Version:
Hongluan Component Library for Vue 3
34 lines (31 loc) • 1.41 kB
JavaScript
import { inject, computed } from 'vue';
import '../../../../hooks/index.mjs';
import '../../../../utils/index.mjs';
import '../../../../tokens/index.mjs';
import { checkboxGroupContextKey } from '../../../../tokens/checkbox.mjs';
import { isUndefined } from '../../../../utils/types.mjs';
import { useConsistentProp } from '../../../../hooks/use-consistent-prop/index.mjs';
const useCheckboxDisabled = ({
model,
isChecked
}) => {
const checkboxGroup = inject(checkboxGroupContextKey, void 0);
const isGroup = computed(() => isUndefined(checkboxGroup) === false);
const isLimitDisabled = computed(() => {
var _a, _b;
const max = (_a = checkboxGroup == null ? void 0 : checkboxGroup.max) == null ? void 0 : _a.value;
const min = (_b = checkboxGroup == null ? void 0 : checkboxGroup.min) == null ? void 0 : _b.value;
return !isUndefined(max) && model.value.length >= max && !isChecked.value || !isUndefined(min) && model.value.length <= min && isChecked.value;
});
const isDisabled = computed(() => {
var _a;
const { disabled } = useConsistentProp();
return (_a = isGroup.value ? (checkboxGroup == null ? void 0 : checkboxGroup.disabled.value) || disabled.value || isLimitDisabled.value : disabled.value) != null ? _a : false;
});
return {
isDisabled,
isLimitDisabled
};
};
export { useCheckboxDisabled };
//# sourceMappingURL=use-checkbox-disabled.mjs.map