Redesign month grid

This commit is contained in:
iamdoubz committed 2026-11-05 17:41:35 -06:00
1 parent 65ac86cc06
commit 569f125f7d
1 file changed
+26 -21
+26 -21
View File
@@ -5,13 +5,15 @@
let {
month,
events,
colorFor = () => 'var(--accent)',
colorFor = () => 'var(--primary)',
onday = null,
showTitle = true,
}: {
month: string;
events: CalEvent[];
colorFor?: (e: CalEvent) => string;
onday?: ((date: string) => void) | null;
showTitle?: boolean;
} = $props();
const weeks = $derived(monthWeeks(month));
@@ -30,30 +32,29 @@
return m;
});
// Weekday names in the device's language, Sunday first (2026-01-04 was a Sunday).
const names = Array.from({ length: 7 }, (_, i) =>
new Date(2026, 0, 4 + i).toLocaleDateString(undefined, { weekday: 'short' }),
);
const names = Array.from({ length: 7 }, (_, i) => new Date(2026, 0, 4 + i).toLocaleDateString(undefined, { weekday: 'short' }));
const today = iso(new Date());
const longDay = (d: string) => parse(d).toLocaleDateString(undefined, { weekday: 'long', month: 'long', day: 'numeric' });
</script>
<section class="grid-wrap" aria-label={monthLabel(month)}>
<h3>{monthLabel(month)}</h3>
<section class="month card" aria-label={monthLabel(month)}>
{#if showTitle}<h3>{monthLabel(month)}</h3>{/if}
<div class="grid">
{#each names as n}<div class="head">{n}</div>{/each}
{#each names as n}<div class="head" aria-hidden="true">{n}</div>{/each}
{#each weeks as week}
{#each week as day}
{@const list = byDay.get(day) ?? []}
{@const outside = day.slice(0, 7) !== month}
{#snippet cell()}
<span class="num">{parse(day).getDate()}</span>
<span class="num tabular">{parse(day).getDate()}</span>
{#each list.slice(0, 3) as e (e.id)}
<span class="chip" style:--c={colorFor(e)} title={e.title}>{e.title}</span>
{/each}
{#if list.length > 3}<span class="more">+{list.length - 3}</span>{/if}
{#if list.length > 3}<span class="more">+{list.length - 3} more</span>{/if}
{/snippet}
{#if onday}
<button type="button" class="day" class:outside class:today={day === today} onclick={() => onday(day)}
aria-label={`${parse(day).toLocaleDateString(undefined, { month: 'long', day: 'numeric' })}: ${list.length} events. Add an event`}>
aria-label={`${longDay(day)}: ${list.length} ${list.length === 1 ? 'event' : 'events'}. Add an event`}>
{@render cell()}
</button>
{:else}
@@ -65,20 +66,24 @@
</section>
<style>
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.head { font-size: 0.75rem; color: var(--muted); text-align: center; padding: 4px 0; }
.month { padding: var(--s3); }
h3 { margin: 0 0 var(--s3) var(--s1); }
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.head { font-size: var(--fs-xs); font-weight: 650; color: var(--text-2); text-align: center; padding: var(--s1) 0; text-transform: uppercase; letter-spacing: 0.04em; }
.day {
min-height: 72px; padding: 3px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border);
display: flex; flex-direction: column; align-items: stretch; gap: 2px; text-align: left; font-size: 0.7rem;
overflow: hidden; min-width: 0; justify-content: flex-start;
min-height: 76px; padding: 4px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid transparent;
display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 2px;
text-align: left; font-size: var(--fs-xs); font-weight: 500; overflow: hidden; min-width: 0; white-space: normal;
}
button.day { cursor: pointer; }
.outside { opacity: 0.45; }
.today .num { color: var(--accent); font-weight: 700; }
.num { font-size: 0.75rem; }
button.day:hover:not(:disabled) { border-color: var(--primary); background: var(--surface-2); }
.outside { opacity: 0.4; }
.num { font-size: var(--fs-xs); font-weight: 700; color: var(--text-2); width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.today .num { background: var(--primary); color: var(--on-primary); }
.chip {
display: block; background: color-mix(in srgb, var(--c) 22%, transparent); border-left: 3px solid var(--c);
border-radius: 3px; padding: 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
display: block; padding: 1px 4px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
background: color-mix(in srgb, var(--c) 20%, var(--surface)); border-left: 3px solid var(--c); color: var(--text);
}
.more { color: var(--muted); }
.more { color: var(--text-2); font-weight: 600; }
@media (min-width: 768px) { .day { min-height: 96px; } }
</style>