Skip to content

Commit 8bbba3e

Browse files
committed
Add actual calendar
1 parent 56e299b commit 8bbba3e

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

config/config.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ config :logger, :console,
2323
# Use Jason for JSON parsing in Phoenix
2424
config :phoenix, :json_library, Jason
2525

26+
config :floki, :html_parser, Floki.HTMLParser.Html5ever
27+
2628
# Allow rendering markdown templates
2729
config :phoenix, :template_engines,
2830
md: ComponentsGuideWeb.TemplateEngines.MarkdownEngine,

lib/components_guide_web/components/calendar_component.ex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ defmodule ComponentsGuideWeb.CalendarComponent do
77
end_date = Date.end_of_month(today)
88
date_range = Date.range(start_date, end_date)
99

10-
day_offset = 1 - Date.day_of_week(start_date)
10+
day_inset = Date.day_of_week(start_date)
11+
day_offset = 1 - day_inset
12+
max_week = div(end_date.day + day_inset + 5, 7)
1113

1214
assigns =
1315
assigns
@@ -20,7 +22,7 @@ defmodule ComponentsGuideWeb.CalendarComponent do
2022
})
2123

2224
~H"""
23-
<h2><%= @year %> <%= @month %> <%= Gettext.dgettext(ComponentsGuideWeb.Gettext, "months", "april") %></h2>
25+
<h2><%= Calendar.strftime(@date_range.first, "%B %Y") %></h2>
2426
<table class="text-center">
2527
<thead>
2628
<tr>
@@ -34,17 +36,17 @@ defmodule ComponentsGuideWeb.CalendarComponent do
3436
</tr>
3537
</thead>
3638
<tbody>
37-
<%= for week_n <- 1..6 do %>
39+
<%= for week_n <- 1..max_week do %>
3840
<tr>
3941
<%= for day_n <- 1..7 do %>
4042
<% day = day_n + day_offset + ((week_n - 1) * 7) %>
4143
<%= if day in @date_range.first.day..@date_range.last.day do %>
4244
<% current = day == @day %>
43-
<td aria-current={if current, do: "date", else: "false"} class={if current, do: "bg-red-900", else: ""}>
45+
<td aria-current={if current, do: "date", else: "false"} class={if current, do: "bg-red-900", else: "bg-black"}>
4446
<%= day %>
4547
</td>
4648
<% else %>
47-
<td role="presentation" class="bg-black"></td>
49+
<td role="presentation" class=""></td>
4850
<% end %>
4951
<% end %>
5052
</tr>

lib/components_guide_web/controllers/calendar_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ defmodule ComponentsGuideWeb.CalendarView do
226226
"https://cdn.jsdelivr.net/npm/simple-icons@v6/icons/safari.svg"
227227

228228
<<"postgres" <> _>> ->
229-
"https://cdn.jsdelivr.net/npm/simple-icons@v6/icons/postgres.svg"
229+
"https://cdn.jsdelivr.net/npm/simple-icons@v6/icons/postgresql.svg"
230230

231231
<<"swift" <> _>> ->
232232
"https://cdn.jsdelivr.net/npm/simple-icons@v6/icons/swift.svg"

lib/components_guide_web/templates/calendar/index.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<label><input type="checkbox" name="released" checked class="rounded text-sky-500"> Released</label>
66
<label><input type="checkbox" name="lts_starts" checked class="rounded text-sky-500"> LTS</label>
77
</form>
8-
<CalendarComponent.calendar_grid date={@today} />
98
<article>
109
<%= for item <- @list do %>
1110
<%= present_item(item) %>
1211
<% end %>
1312
</article>
13+
<CalendarComponent.calendar_grid date={@today} />
1414
</div>
1515

1616
<div class="prose prose-invert max-w-2xl mx-auto pt-8 pb-16 px-3">

test/collected_live_web/components/calendar_component_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule ComponentsGuideWeb.CalendarComponentTest do
1818
assert current_date |> Enum.count() == 1
1919

2020
assert 7 == count(el, "thead th")
21-
assert 6 == count(el, "tbody tr")
21+
assert 5 == count(el, "tbody tr")
2222
assert 30 == count(el, "tbody td:not([role=presentation])")
2323
end
2424

0 commit comments

Comments
 (0)