Fix visual bug for day name indicator

This commit is contained in:
2026-02-03 16:15:28 +13:00
parent 2fbefaa419
commit 5fff9a0359

View File

@@ -27,6 +27,7 @@
date: day.getDate(), date: day.getDate(),
month: day.getMonth(), month: day.getMonth(),
year: day.getFullYear(), year: day.getFullYear(),
dayName: headers[i],
isCurrentMonth: day.getMonth() === today.getMonth(), isCurrentMonth: day.getMonth() === today.getMonth(),
isToday: day.toDateString() === today.toDateString() isToday: day.toDateString() === today.toDateString()
}); });
@@ -49,10 +50,12 @@
// Previous month days // Previous month days
const prevMonthLastDay = new Date(year, month, 0).getDate(); const prevMonthLastDay = new Date(year, month, 0).getDate();
for (let i = startDay - 1; i >= 0; i--) { for (let i = startDay - 1; i >= 0; i--) {
const dayIndex = days.length % 7;
days.push({ days.push({
date: prevMonthLastDay - i, date: prevMonthLastDay - i,
month: month - 1, month: month - 1,
year: month === 0 ? year - 1 : year, year: month === 0 ? year - 1 : year,
dayName: headers[dayIndex],
isCurrentMonth: false, isCurrentMonth: false,
isToday: false isToday: false
}); });
@@ -64,10 +67,12 @@
const isToday = today.getDate() === i && const isToday = today.getDate() === i &&
today.getMonth() === month && today.getMonth() === month &&
today.getFullYear() === year; today.getFullYear() === year;
const dayIndex = days.length % 7;
days.push({ days.push({
date: i, date: i,
month: month, month: month,
year: year, year: year,
dayName: headers[dayIndex],
isCurrentMonth: true, isCurrentMonth: true,
isToday isToday
}); });
@@ -76,10 +81,12 @@
// Next month days to fill the grid // Next month days to fill the grid
const remaining = 42 - days.length; // 6 rows * 7 days const remaining = 42 - days.length; // 6 rows * 7 days
for (let i = 1; i <= remaining; i++) { for (let i = 1; i <= remaining; i++) {
const dayIndex = days.length % 7;
days.push({ days.push({
date: i, date: i,
month: month + 1, month: month + 1,
year: month === 11 ? year + 1 : year, year: month === 11 ? year + 1 : year,
dayName: headers[dayIndex],
isCurrentMonth: false, isCurrentMonth: false,
isToday: false isToday: false
}); });
@@ -147,13 +154,15 @@
</div> </div>
<div class="calendar"> <div class="calendar">
{#each headers as header} {#each days as day, index}
<span class="day-name">{header}</span>
{/each}
{#each days as day}
<div class="day" class:other-month={!day.isCurrentMonth} class:today={day.isToday}> <div class="day" class:other-month={!day.isCurrentMonth} class:today={day.isToday}>
<div class="day-header">
{#if index < 7}
<span class="day-name">{day.dayName}</span>
{/if}
<span class="date">{day.date}</span> <span class="date">{day.date}</span>
</div> </div>
</div>
{/each} {/each}
</div> </div>
</div> </div>
@@ -225,7 +234,6 @@
display: grid; display: grid;
width: 100%; width: 100%;
grid-template-columns: repeat(7, minmax(120px, 1fr)); grid-template-columns: repeat(7, minmax(120px, 1fr));
grid-template-rows: 50px;
grid-auto-rows: 120px; grid-auto-rows: 120px;
overflow: auto; overflow: auto;
} }
@@ -233,16 +241,33 @@
.day { .day {
border-bottom: 1px solid rgba(166, 168, 179, 0.12); border-bottom: 1px solid rgba(166, 168, 179, 0.12);
border-right: 1px solid rgba(166, 168, 179, 0.12); border-right: 1px solid rgba(166, 168, 179, 0.12);
text-align: right;
padding: 14px 20px; padding: 14px 20px;
letter-spacing: 1px;
font-size: 14px;
box-sizing: border-box; box-sizing: border-box;
color: #98a0a6; color: #98a0a6;
position: relative; position: relative;
z-index: 1; z-index: 1;
} }
.day-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.day-name {
font-size: 12px;
text-transform: uppercase;
color: #e9a1a7;
font-weight: 500;
}
.date {
font-size: 18px;
font-weight: 600;
letter-spacing: 1px;
}
.day.other-month { .day.other-month {
opacity: 0.3; opacity: 0.3;
} }
@@ -298,13 +323,4 @@
.day:nth-of-type(7n + 7) { .day:nth-of-type(7n + 7) {
grid-column: 7/7; grid-column: 7/7;
} }
.day-name {
font-size: 12px;
text-transform: uppercase;
color: #e9a1a7;
text-align: center;
border-bottom: 1px solid rgba(166, 168, 179, 0.12);
line-height: 50px;
font-weight: 500;
}
</style> </style>