UNPKG

winbox-ui-next

Version:

We Design Vue 2.0: A Vue.js 3 UI Library

36 lines (35 loc) 1.21 kB
import { toRefs, computed } from "vue"; import { isFunction } from "../../_utils/is.js"; function getDefaultFormat(mode = "date", showTime = false) { switch (mode) { case "date": return showTime ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD"; case "month": return "YYYY-MM"; case "year": return "YYYY"; case "week": return "gggg-wo"; case "quarter": return "YYYY-[Q]Q"; default: return "YYYY-MM-DD"; } } function useFormat(props) { const { format: propFormat, mode, showTime, valueFormat: propValueFormat } = toRefs(props); const format = computed(() => !isFunction(propFormat == null ? void 0 : propFormat.value) && (propFormat == null ? void 0 : propFormat.value) || getDefaultFormat(mode == null ? void 0 : mode.value, showTime == null ? void 0 : showTime.value)); const valueFormat = computed(() => (propValueFormat == null ? void 0 : propValueFormat.value) || format.value); const parseValueFormat = computed(() => ["timestamp", "Date"].includes(valueFormat.value) ? format.value : valueFormat.value); return { format, valueFormat, parseValueFormat }; } export { useFormat as default, getDefaultFormat };