UNPKG

@vuesax-alpha/nightly

Version:
114 lines (111 loc) 4.33 kB
import { defineComponent, ref, computed, openBlock, createBlock, unref, withCtx, createElementBlock, Fragment, renderList } from 'vue'; import dayjs from 'dayjs'; import customParseFormat from 'dayjs/plugin/customParseFormat.js'; import { VsSelect, VsOption } from '../../select/index.mjs'; import '../../../constants/index.mjs'; import { parseTime, formatTime, compareTime, nextTime } from './utils.mjs'; import { timeSelectProps } from './time-select.mjs'; import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs'; import { UPDATE_MODEL_EVENT } from '../../../constants/event.mjs'; const __default__ = defineComponent({ name: "VsTimeSelect" }); const _sfc_main = defineComponent({ ...__default__, props: timeSelectProps, emits: ["change", "blur", "focus", UPDATE_MODEL_EVENT], setup(__props, { expose: __expose }) { const props = __props; dayjs.extend(customParseFormat); const selectInstance = ref(); const value = computed( () => dayjs(props.modelValue || start.value, "HH:mm").format(props.format) ); const start = computed(() => { const time = parseTime(props.start); return time ? formatTime(time) : null; }); const end = computed(() => { const time = parseTime(props.end); return time ? formatTime(time) : null; }); const step = computed(() => { const time = parseTime(props.step); return time ? formatTime(time) : null; }); const minTime = computed(() => { const time = parseTime(props.minTime || ""); return time ? formatTime(time) : null; }); const maxTime = computed(() => { const time = parseTime(props.maxTime || ""); return time ? formatTime(time) : null; }); const items = computed(() => { const result = []; if (props.start && props.end && props.step) { let current = start.value; let currentTime; while (current && end.value && compareTime(current, end.value) <= 0) { currentTime = dayjs(current, "HH:mm").format(props.format); result.push({ value: currentTime, disabled: props.disabledItems.includes(current) || compareTime(current, minTime.value || "-1:-1") <= 0 || compareTime(current, maxTime.value || "100:100") >= 0 }); current = nextTime(current, step.value); } } return result; }); const focus = () => { var _a; (_a = selectInstance.value) == null ? void 0 : _a.focus(); }; const blur = () => { var _a; (_a = selectInstance.value) == null ? void 0 : _a.blur(); }; __expose({ focus, blur }); return (_ctx, _cache) => { return openBlock(), createBlock(unref(VsSelect), { ref_key: "selectInstance", ref: selectInstance, "model-value": value.value, disabled: _ctx.disabled, clearable: _ctx.clearable, "clear-icon": _ctx.clearIcon, effect: _ctx.effect, placeholder: _ctx.placeholder, "default-first-option": "", filter: _ctx.editable, "onUpdate:modelValue": _cache[0] || (_cache[0] = (event) => _ctx.$emit("update:modelValue", event)), onChange: _cache[1] || (_cache[1] = (event) => _ctx.$emit("change", event)), onBlur: _cache[2] || (_cache[2] = (event) => _ctx.$emit("blur", event)), onFocus: _cache[3] || (_cache[3] = (event) => _ctx.$emit("focus", event)) }, { default: withCtx(() => [ (openBlock(true), createElementBlock( Fragment, null, renderList(items.value, (item) => { return openBlock(), createBlock(unref(VsOption), { key: item.value, label: item.value, value: item.value, disabled: item.disabled }, null, 8, ["label", "value", "disabled"]); }), 128 )) ]), _: 1 }, 8, ["model-value", "disabled", "clearable", "clear-icon", "effect", "placeholder", "filter"]); }; } }); var TimeSelect = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/home/runner/work/vuesax-alpha/vuesax-alpha/packages/components/time-select/src/time-select.vue"]]); export { TimeSelect as default }; //# sourceMappingURL=time-select2.mjs.map