UNPKG

ivue-material-plus

Version:

A high quality UI components Library with Vue.js

48 lines (45 loc) 1.5 kB
import { ref, computed } from 'vue'; import { ensureArray } from '../../utils/arrays.mjs'; import { debugWarn } from '../../utils/error.mjs'; const filterFields = (fields, props) => { const normalized = ensureArray(props); return normalized.length > 0 ? fields.filter((field) => field.prop && normalized.includes(field.prop)) : fields; }; function useFormLabelWidth() { const potentialLabelWidthArr = ref([]); const autoLabelWidth = computed(() => { if (!potentialLabelWidthArr.value.length) { return "0"; } const max = Math.max(...potentialLabelWidthArr.value); return max ? `${max}px` : ""; }); const getLabelWidthIndex = (width) => { const index = potentialLabelWidthArr.value.indexOf(width); if (index === -1 && autoLabelWidth.value === "0") { debugWarn("ivue-form", `unexpected width ${width}`); } return index; }; const registerLabelWidth = (value, oldValue) => { if (value && oldValue) { const index = getLabelWidthIndex(oldValue); potentialLabelWidthArr.value.splice(index, 1, value); } else if (value) { potentialLabelWidthArr.value.push(value); } }; const deregisterLabelWidth = (value) => { const index = getLabelWidthIndex(value); if (index > -1) { potentialLabelWidthArr.value.splice(index, 1); } }; return { autoLabelWidth, registerLabelWidth, deregisterLabelWidth }; } export { filterFields, useFormLabelWidth }; //# sourceMappingURL=utils.mjs.map