Files
pihkaal-me/app/components/Settings/BottomScreen/Menus/Clock/Date.vue

101 lines
2.2 KiB
Vue

<script setup lang="ts">
import { SettingsBottomScreenNumberInput as NumberInput } from "#components";
import { useIntervalFn } from "@vueuse/core";
import gsap from "gsap";
const store = useSettingsStore();
const now = ref(new Date());
useIntervalFn(() => {
now.value = new Date();
}, 1000);
const isAnimating = ref(true);
const bLabel = ref($t("common.goBack"));
const aLabel = ref($t("common.select"));
const monthRef = useTemplateRef<InstanceType<typeof NumberInput>>("month");
const dayRef = useTemplateRef<InstanceType<typeof NumberInput>>("day");
const yearRef = useTemplateRef<InstanceType<typeof NumberInput>>("year");
const animateIntro = async () => {
isAnimating.value = true;
await Promise.all([
monthRef.value?.animateIntro(),
dayRef.value?.animateIntro(),
yearRef.value?.animateIntro(),
gsap.timeline().call(
() => {
bLabel.value = $t("common.cancel");
aLabel.value = $t("common.confirm");
},
[],
SUBMENU_LABEL_CHANGE_DELAY,
),
]);
isAnimating.value = false;
};
const animateOutro = async () => {
isAnimating.value = true;
await Promise.all([
monthRef.value?.animateOutro(),
dayRef.value?.animateOutro(),
yearRef.value?.animateOutro(),
]);
};
onMounted(() => {
animateIntro();
});
const handleActivateB = async () => {
if (isAnimating.value) return;
await animateOutro();
store.closeSubMenu();
};
const handleActivateA = async () => {
if (isAnimating.value) return;
await animateOutro();
store.closeSubMenu();
};
defineOptions({ render: () => null });
</script>
<template>
<NumberInput
ref="month"
:model-value="now.getMonth() + 1"
:title="$t('settings.clock.date.month')"
:x="1 * 16 - 1"
:disabled="true"
/>
<NumberInput
ref="day"
:model-value="now.getDate()"
:title="$t('settings.clock.date.day')"
:x="5 * 16 - 1"
:disabled="true"
/>
<NumberInput
ref="year"
:model-value="now.getFullYear()"
:title="$t('settings.clock.date.year')"
:digits="4"
:x="9 * 16 - 1"
:disabled="true"
/>
<CommonButtons
:y-offset="store.submenuButtonsOffsetY"
:b-label="bLabel"
:a-label="aLabel"
@activate-b="handleActivateB"
@activate-a="handleActivateA"
/>
</template>