element-plus
Version:
A Component Library for Vue 3
60 lines (57 loc) • 1.92 kB
JavaScript
import { inject, ref, computed, toRaw } from 'vue';
import { isEqual } from 'lodash-unified';
import '../../../form/index.mjs';
import '../../../../utils/index.mjs';
import { checkboxGroupContextKey } from '../constants.mjs';
import { isPropAbsent, isBoolean } from '../../../../utils/types.mjs';
import { isArray, isObject } from '@vue/shared';
import { useFormSize } from '../../../form/src/hooks/use-form-common-props.mjs';
const useCheckboxStatus = (props, slots, { model }) => {
const checkboxGroup = inject(checkboxGroupContextKey, void 0);
const isFocused = ref(false);
const actualValue = computed(() => {
if (!isPropAbsent(props.value)) {
return props.value;
}
return props.label;
});
const isChecked = computed(() => {
const value = model.value;
if (isBoolean(value)) {
return value;
} else if (isArray(value)) {
if (isObject(actualValue.value)) {
return value.map(toRaw).some((o) => isEqual(o, actualValue.value));
} else {
return value.map(toRaw).includes(actualValue.value);
}
} else if (value !== null && value !== void 0) {
return value === props.trueValue || value === props.trueLabel;
} else {
return !!value;
}
});
const checkboxButtonSize = useFormSize(computed(() => {
var _a;
return (_a = checkboxGroup == null ? void 0 : checkboxGroup.size) == null ? void 0 : _a.value;
}), {
prop: true
});
const checkboxSize = useFormSize(computed(() => {
var _a;
return (_a = checkboxGroup == null ? void 0 : checkboxGroup.size) == null ? void 0 : _a.value;
}));
const hasOwnLabel = computed(() => {
return !!slots.default || !isPropAbsent(actualValue.value);
});
return {
checkboxButtonSize,
isChecked,
isFocused,
checkboxSize,
hasOwnLabel,
actualValue
};
};
export { useCheckboxStatus };
//# sourceMappingURL=use-checkbox-status.mjs.map