UNPKG

@nextcloud/vue

Version:
66 lines (65 loc) 3.73 kB
import "../assets/index25.css"; import { n as h } from "../chunks/_plugin-vue2_normalizer-5b4c43a4.mjs"; import { S as p } from "../chunks/ScopeComponent-dbcd0e07.mjs"; const y = ["date", "datetime-local", "month", "time", "week"], $ = { name: "NcDateTimePickerNative", inheritAttrs: !1, props: { value: { type: Date, required: !0 }, id: { type: String, required: !0 }, type: { type: String, default: "date", validate: (t) => y.includes(t) }, label: { type: String, default: "Please choose a date" }, min: { type: [Date, Boolean], default: null }, max: { type: [Date, Boolean], default: null }, hideLabel: { type: Boolean, default: !1 }, inputClass: { type: [Object, String], default: "" } }, emits: ["input"], computed: { formattedValue() { return this.formatValue(this.value); }, formattedMin() { return this.min ? this.formatValue(this.min) : !1; }, formattedMax() { return this.max ? this.formatValue(this.max) : !1; }, listeners() { return { ...this.$listeners, input: (t) => { if (isNaN(t.target.valueAsNumber)) return this.$emit("input", ""); if (this.type === "time") { const a = t.target.value; if (this.value === "") { const { yyyy: l, MM: u, dd: o } = this.getReadableDate(/* @__PURE__ */ new Date()); return this.$emit("input", /* @__PURE__ */ new Date(`${l}-${u}-${o}T${a}`)); } const { yyyy: i, MM: n, dd: s } = this.getReadableDate(this.value); return this.$emit("input", /* @__PURE__ */ new Date(`${i}-${n}-${s}T${a}`)); } else if (this.type === "month") { const a = (new Date(t.target.value).getMonth() + 1).toString().padStart(2, "0"); if (this.value === "") { const { yyyy: u, dd: o, hh: d, mm: m } = this.getReadableDate(/* @__PURE__ */ new Date()); return this.$emit("input", /* @__PURE__ */ new Date(`${u}-${a}-${o}T${d}:${m}`)); } const { yyyy: i, dd: n, hh: s, mm: l } = this.getReadableDate(this.value); return this.$emit("input", /* @__PURE__ */ new Date(`${i}-${a}-${n}T${s}:${l}`)); } const e = new Date(t.target.valueAsNumber).getTimezoneOffset() * 1e3 * 60, r = t.target.valueAsNumber + e; return this.$emit("input", new Date(r)); } }; } }, methods: { getReadableDate(t) { if (t instanceof Date) { const e = t.getFullYear().toString().padStart(4, "0"), r = (t.getMonth() + 1).toString().padStart(2, "0"), a = t.getDate().toString().padStart(2, "0"), i = t.getHours().toString().padStart(2, "0"), n = t.getMinutes().toString().padStart(2, "0"); return { yyyy: e, MM: r, dd: a, hh: i, mm: n }; } }, formatValue(t) { if (t instanceof Date) { const { yyyy: e, MM: r, dd: a, hh: i, mm: n } = this.getReadableDate(t); if (this.type === "datetime-local") return `${e}-${r}-${a}T${i}:${n}`; if (this.type === "date") return `${e}-${r}-${a}`; if (this.type === "month") return `${e}-${r}`; if (this.type === "time") return `${i}:${n}`; if (this.type === "week") { const s = new Date(e, 0, 1), l = Math.floor((t - s) / (24 * 60 * 60 * 1e3)), u = Math.ceil(l / 7); return `${e}-W${u}`; } } else return ""; } } }; var f = function() { var t = this, e = t._self._c; return e("div", { staticClass: "native-datetime-picker" }, [e("label", { class: { "hidden-visually": t.hideLabel }, attrs: { for: t.id } }, [t._v(t._s(t.label))]), e("input", t._g(t._b({ staticClass: "native-datetime-picker--input", class: t.inputClass, attrs: { id: t.id, type: t.type, min: t.formattedMin, max: t.formattedMax }, domProps: { value: t.formattedValue } }, "input", t.$attrs, !1), t.listeners))]); }, c = [], g = h($, f, c, !1, null, "a99b9317", null, null); const D = g.exports; p(D); export { D as default };