maz-ui
Version:
A standalone components library for Vue.Js 3 & Nuxt.Js 3
95 lines (94 loc) • 4.17 kB
JavaScript
import { defineComponent, ref, computed, createElementBlock, openBlock, createElementVNode, createVNode, withModifiers, withCtx, unref, Fragment, renderList, createBlock, normalizeClass, createTextVNode, toDisplayString } from "vue";
import { MazChevronLeft, MazXMark } from "@maz-ui/icons";
import { n, i as isSameDate } from "./MazDatePicker.BkBbJH6f.js";
import dayjs from "dayjs";
import MazBtn from "../components/MazBtn.js";
import { _ as _export_sfc } from "./_plugin-vue_export-helper.B--vMWp3.js";
import '../assets/MazPickerYearSwitcher.DPD1_dfz.css';const _hoisted_1 = { class: "maz-picker-year-switcher" }, _hoisted_2 = { class: "maz-picker-year-switcher__header" }, _hoisted_3 = { class: "maz-flex maz-space-x-2" }, _hoisted_4 = { class: "maz-picker-year-switcher__main" }, _sfc_main = /* @__PURE__ */ defineComponent({
__name: "MazPickerYearSwitcher",
props: {
color: { type: String, required: !0 },
locale: { type: String, required: !0 },
calendarDate: { type: String, required: !0 }
},
emits: ["update:calendar-date", "close"],
setup(__props, { emit: __emit }) {
const props = __props, emits = __emit, currentDateTmp = ref(props.calendarDate), years = computed(() => Array.from({ length: 15 }, (_v, i) => i - 7).map((yearNumber) => {
const currentYear = dayjs(currentDateTmp.value).get("year"), dateYear = dayjs(currentDateTmp.value).set("year", currentYear + yearNumber);
return {
label: n(dateYear.format(), props.locale, {
year: "numeric"
}) ?? dateYear.format(),
date: dateYear
};
}));
function selectYear(date) {
emits("update:calendar-date", dayjs(date).format()), emits("close");
}
function previousYears() {
currentDateTmp.value = dayjs(currentDateTmp.value).subtract(7, "year").format();
}
function nextYears() {
currentDateTmp.value = dayjs(currentDateTmp.value).add(7, "year").format();
}
return (_ctx, _cache) => (openBlock(), createElementBlock("div", _hoisted_1, [
createElementVNode("div", _hoisted_2, [
createElementVNode("div", _hoisted_3, [
createVNode(MazBtn, {
size: "xs",
color: "transparent",
type: "button",
onClick: withModifiers(previousYears, ["stop"])
}, {
default: withCtx(() => [
createVNode(unref(MazChevronLeft), { class: "maz-text-lg" })
]),
_: 1
}),
createVNode(MazBtn, {
size: "xs",
color: "transparent",
type: "button",
onClick: withModifiers(nextYears, ["stop"])
}, {
default: withCtx(() => [
createVNode(unref(MazChevronLeft), { class: "maz-rotate-180 maz-text-lg" })
]),
_: 1
})
]),
createVNode(MazBtn, {
size: "xs",
color: "transparent",
type: "button",
onClick: _cache[0] || (_cache[0] = withModifiers(($event) => _ctx.$emit("close", $event), ["stop"]))
}, {
default: withCtx(() => [
createVNode(unref(MazXMark), { class: "maz-text-lg" })
]),
_: 1
})
]),
createElementVNode("div", _hoisted_4, [
(openBlock(!0), createElementBlock(Fragment, null, renderList(years.value, (year) => (openBlock(), createBlock(MazBtn, {
key: year.label,
size: "sm",
type: "button",
class: normalizeClass({
"--is-selected": unref(isSameDate)(year.date, __props.calendarDate, "year")
}),
color: unref(isSameDate)(year.date, __props.calendarDate, "year") ? __props.color : "transparent",
onClick: withModifiers(($event) => selectYear(year.date), ["stop"])
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(year.label), 1)
]),
_: 2
}, 1032, ["class", "color", "onClick"]))), 128))
])
]));
}
}), MazPickerYearSwitcher = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-0e3063eb"]]);
export {
MazPickerYearSwitcher as default
};