hongluan-ui
Version:
Hongluan Component Library for Vue 3
140 lines (137 loc) • 5.36 kB
JavaScript
import { defineComponent, ref, computed, resolveComponent, openBlock, createBlock, withCtx, renderSlot, createVNode, createElementBlock, Fragment, renderList } from 'vue';
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat.js';
import '../../../hooks/index.mjs';
import { HlSelect } from '../../select/index.mjs';
import { HlOption } from '../../option/index.mjs';
import { HlIcon } from '../../icon/index.mjs';
import '../../system-icon/index.mjs';
import { timeSelectProps } from './time-select.mjs';
import { parseTime, formatTime, compareTime, nextTime } from './utils.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import SystemClock from '../../system-icon/src/clock.mjs';
import { useLocale } from '../../../hooks/use-locale/index.mjs';
import { useConsistentProp } from '../../../hooks/use-consistent-prop/index.mjs';
dayjs.extend(customParseFormat);
const _sfc_main = defineComponent({
name: "TimeSelect",
components: { HlSelect, HlOption, HlIcon, SystemClock },
props: timeSelectProps,
emits: ["change", "blur", "focus", "clear", "update:modelValue"],
setup(props) {
const { lang } = useLocale();
const select = ref();
const value = computed(() => props.modelValue);
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").locale(lang.value).format(props.format);
result.push({
value: currentTime,
disabled: compareTime(current, minTime.value || "-1:-1") <= 0 || compareTime(current, maxTime.value || "100:100") >= 0
});
current = nextTime(current, step.value);
}
}
return result;
});
const popperPaneRef = computed(() => {
var _a;
return (_a = select.value) == null ? void 0 : _a.popperPaneRef;
});
const blur = () => {
var _a, _b;
(_b = (_a = select.value) == null ? void 0 : _a.blur) == null ? void 0 : _b.call(_a);
};
const focus = () => {
var _a, _b;
(_b = (_a = select.value) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a);
};
const { size: timeSize, disabled: timeDisabled, fill: timeFill } = useConsistentProp();
return {
select,
popperPaneRef,
value,
items,
blur,
focus,
timeSize,
timeDisabled,
timeFill
};
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_hl_option = resolveComponent("hl-option");
const _component_system_clock = resolveComponent("system-clock");
const _component_hl_icon = resolveComponent("hl-icon");
const _component_hl_select = resolveComponent("hl-select");
return openBlock(), createBlock(_component_hl_select, {
ref: "select",
"model-value": _ctx.value,
disabled: _ctx.timeDisabled,
clearable: _ctx.clearable,
size: _ctx.timeSize,
effect: _ctx.effect,
fill: _ctx.timeFill,
placeholder: _ctx.placeholder,
"default-first-option": "",
filterable: _ctx.editable,
teleported: _ctx.teleported,
"empty-values": _ctx.emptyValues,
"value-on-clear": _ctx.valueOnClear,
"onUpdate:modelValue": (event) => _ctx.$emit("update:modelValue", event),
onChange: (event) => _ctx.$emit("change", event),
onBlur: (event) => _ctx.$emit("blur", event),
onFocus: (event) => _ctx.$emit("focus", event),
onClear: () => _ctx.$emit("clear")
}, {
prefix: withCtx(() => [
renderSlot(_ctx.$slots, "prefix", {}, () => [
createVNode(_component_hl_icon, null, {
default: withCtx(() => [
createVNode(_component_system_clock)
]),
_: 1
})
])
]),
default: withCtx(() => [
(openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.items, (item) => {
return openBlock(), createBlock(_component_hl_option, {
key: item.value,
label: item.value,
value: item.value,
disabled: item.disabled
}, null, 8, ["label", "value", "disabled"]);
}), 128))
]),
_: 3
}, 8, ["model-value", "disabled", "clearable", "size", "effect", "fill", "placeholder", "filterable", "teleported", "empty-values", "value-on-clear", "onUpdate:modelValue", "onChange", "onBlur", "onFocus", "onClear"]);
}
var TimeSelect = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export { TimeSelect as default };
//# sourceMappingURL=time-select2.mjs.map