Skip to content

Commit

Permalink
Highlight current day in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperKXT committed Aug 31, 2024
1 parent e51fcb5 commit e2364c5
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/pages/menu.astro
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const details: { name: keyof typeof titleMap; items: string[] }[] = [
<main>
<div class="day-grid">
{menuList.map((r, idx) => (
<div class="day-item">
<div id={`day-${idx}`} class="day-item">
<div class="day-no">{idx + 1}</div>
<div class="day-name">{dayNames[idx % 7]}</div>
<div class="day-menu">
Expand Down Expand Up @@ -107,6 +107,12 @@ const details: { name: keyof typeof titleMap; items: string[] }[] = [
align-items: center;
height: 50px;
}

.active > :is(.day-name, .day-no) {
background-color: #3a6070;
color: white;
}

.day-menu {
display: flex;
flex-wrap: nowrap;
Expand Down Expand Up @@ -194,3 +200,15 @@ const details: { name: keyof typeof titleMap; items: string[] }[] = [
background-color: #ffe7e3;
}
</style>

<script>
const start = new Date('2024-08-26');
const milliSecondsInDay = 1000 * 60 * 60 * 24;
const startDays = Math.floor(start.getTime() / milliSecondsInDay);
const today = new Date();
const todayDays = Math.floor(today.getTime() / milliSecondsInDay);
const daysSince = todayDays - startDays;
const currIdx = daysSince % 7;
const item = document.getElementById(`day-${currIdx}`);
item?.classList.add('active');
</script>

0 comments on commit e2364c5

Please sign in to comment.