Skip to content

Commit 6799fc0

Browse files
feature calendar refutes claims
1 parent a237a13 commit 6799fc0

27 files changed

+3404
-11
lines changed

components.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
},
99
"aliases": {
1010
"components": "$lib/components",
11-
"utils": "$lib/utils"
11+
"utils": "$lib/utils",
12+
"ui": "$lib/components/ui",
13+
"hooks": "$lib/hooks"
1214
},
13-
"typescript": true
14-
}
15+
"typescript": true,
16+
"registry": "https://next.shadcn-svelte.com/registry"
17+
}

package-lock.json

Lines changed: 137 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
"d3": "^7.9.0",
3838
"hast-util-to-string": "^3.0.1",
3939
"hastscript": "^9.0.0",
40+
"highlight.js": "^11.9.0",
4041
"html-escaper": "^3.0.3",
42+
"marked": "^15.0.7",
4143
"mdast-util-to-string": "^4.0.0",
4244
"reading-time": "^1.5.0",
4345
"rehype-autolink-headings": "^7.1.0",
@@ -49,8 +51,11 @@
4951
"tailwind-variants": "^0.3.0",
5052
"tailwindcss": "^3.4.17",
5153
"unist-util-remove": "^4.0.0",
52-
"unist-util-visit": "^5.0.0",
53-
"marked": "^15.0.7",
54-
"highlight.js": "^11.9.0"
54+
"unist-util-visit": "^5.0.0"
55+
},
56+
"devDependencies": {
57+
"@internationalized/date": "^3.7.0",
58+
"bits-ui": "^1.1.0",
59+
"lucide-svelte": "^0.475.0"
5560
}
5661
}

src/components/HolidayCalendar.svelte

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<script lang="ts">
2+
import { getLocalTimeZone, today, parseDate } from "@internationalized/date";
3+
import type { DateValue } from "@internationalized/date";
4+
import { Calendar } from "$lib/components/ui/calendar";
5+
import { Badge } from "$lib/components/ui/badge";
6+
import holidays from "../utils/holidays.ts";
7+
import { onMount } from "svelte";
8+
import type { Holiday } from "../utils/holidays.ts";
9+
10+
// default selected date is today
11+
let value: DateValue | undefined = today(getLocalTimeZone());
12+
// let selectedDate: Date = new Date();
13+
let selectedHolidays: Holiday[];
14+
15+
$: {
16+
console.log("selectedDate changed:", value);
17+
selectedHolidays = value
18+
? holidays.filter((h) => h.date === value.toString())
19+
: [];
20+
console.log("selectedHolidays:", selectedHolidays);
21+
}
22+
23+
function modifierClass(date: DateValue): string {
24+
const isoDateStr = date.toString();
25+
const hasHoliday = holidays.some((h) => h.date === isoDateStr);
26+
if (hasHoliday) {
27+
console.log("Date has holiday:", isoDateStr);
28+
}
29+
return hasHoliday ? "holiday-date" : "";
30+
}
31+
32+
let maxValue = parseDate("2025-12-31");
33+
let minValue = parseDate("2025-01-01");
34+
35+
function isDateUnavailable(date: DateValue) {
36+
// if a date is not in the list of holidays, return false
37+
return !holidays.some((h) => h.date === date.toString());
38+
}
39+
40+
onMount(() => {
41+
console.log("Total holidays in dataset:", holidays.length);
42+
console.log("Sample holidays:", holidays.slice(0, 100));
43+
});
44+
</script>
45+
46+
<div class="calendar-container space-y-4">
47+
<Calendar
48+
type="single"
49+
bind:value
50+
{maxValue}
51+
{minValue}
52+
numberOfMonths={1}
53+
class="rounded-md border shadow calendar-container"
54+
{isDateUnavailable}
55+
/>
56+
<button
57+
class="px-2 my-2 border-slate-800 dark:border-slate-200 border-2 rounded hover:bg-purple-500 disabled:opacity-50 disabled:cursor-not-allowed"
58+
disabled={value?.toString() === today(getLocalTimeZone()).toString()}
59+
on:click={() => (value = today(getLocalTimeZone()))}>Return to today</button
60+
>
61+
62+
{#if selectedHolidays.length > 0}
63+
<div class="p-4 border rounded-md space-y-2">
64+
<h3 class="font-semibold text-lg">
65+
Holidays on {value?.toString()}
66+
</h3>
67+
<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
68+
{#each selectedHolidays as holiday}
69+
<Badge variant="secondary" class="flex items-center gap-1">
70+
{holiday.holiday}
71+
{#if holiday.note}
72+
<span class="text-xs text-muted-foreground">({holiday.note})</span
73+
>
74+
{/if}
75+
</Badge>
76+
{/each}
77+
</div>
78+
</div>
79+
{:else}
80+
<div class="p-4 border rounded-md space-y-2">
81+
<h3 class="font-semibold text-lg">
82+
No holidays on {value?.toString()}
83+
</h3>
84+
</div>
85+
{/if}
86+
</div>
87+
88+
<style lang="postcss">
89+
:global(.calendar-container) {
90+
--destructive-foreground: rgb(239 68 68);
91+
}
92+
93+
:global(
94+
.data-\[unavailable\]\:text-destructive-foreground[data-unavailable]
95+
) {
96+
color: var(--destructive-foreground) !important;
97+
}
98+
99+
:global(.calendar-container div div) {
100+
justify-content: center;
101+
}
102+
103+
:global(.calendar-container div div table) {
104+
width: initial !important;
105+
}
106+
</style>

src/components/HolidayList.astro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
import holidays from "../utils/holidays.ts";
3+
4+
const holidaysToShow = holidays;
5+
---
6+
7+
<ul class="list-none p-0">
8+
{holidaysToShow.map((holiday) => (
9+
<li class="py-2 px-2 border-b border-gray-200">
10+
<span class="text-gray-500 mr-4">{holiday.date}</span>
11+
<span class="text-gray-900">{holiday.holiday}</span>
12+
{holiday.note && (
13+
<span class="text-gray-500 ml-4">{holiday.note}</span>
14+
)}
15+
</li>
16+
))}
17+
</ul>

src/components/MarkdownPreview.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
</script>
9797

9898
<div class="markdown-preview">
99-
<div class="grid grid-cols-2 gap-4">
99+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
100100
<div class="editor">
101101
<textarea
102102
class="w-full h-[500px] p-4 border rounded"

0 commit comments

Comments
 (0)