Skip to content

Commit 42497ab

Browse files
committed
Make calendar layout better on mobile
1 parent dea689d commit 42497ab

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/components_guide_web/components/calendar_component.ex

+10-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defmodule ComponentsGuideWeb.CalendarComponent do
3434
<% date = Date.add(@current_row_start_date, week_offset * 7 + (weekday - 1)) %>
3535
<% current_day? = week_offset == 0 && @current_day_of_week == weekday %>
3636
<td aria-current={if current_day?, do: "date", else: "false"} class={td_class(%{current_day?: current_day?, weekday: weekday, week_offset: week_offset})}>
37-
<div class={td_text_class(week_offset)}><%= Calendar.strftime(date, "%d %b") %></div>
37+
<div class={td_text_class(week_offset, weekday, current_day?)}><%= Calendar.strftime(date, "%d %b") %></div>
3838
<%= @extra.(date) %>
3939
</td>
4040
<% end %>
@@ -50,8 +50,13 @@ defmodule ComponentsGuideWeb.CalendarComponent do
5050
defp td_class(%{week_offset: 0}), do: "bg-green-900/25"
5151
defp td_class(_), do: "bg-black"
5252

53-
defp td_text_class(0), do: "text-sm opacity-100"
54-
defp td_text_class(week_offset) when week_offset in [-1, 1], do: "text-sm opacity-75"
55-
defp td_text_class(week_offset) when week_offset in [-2, 2], do: "text-sm opacity-60"
56-
defp td_text_class(_), do: "text-sm opacity-50"
53+
defp td_text_class(0, weekday, current_day?), do: "text-sm opacity-100 #{td_text_class_weekday(weekday, current_day?)}"
54+
defp td_text_class(week_offset, weekday, current_day?) when week_offset in [-1, 1], do: "text-sm opacity-90 #{td_text_class_weekday(weekday, current_day?)}"
55+
defp td_text_class(week_offset, weekday, current_day?) when week_offset in [-2, 2], do: "text-sm opacity-80 #{td_text_class_weekday(weekday, current_day?)}"
56+
defp td_text_class(_, weekday, current_day?), do: "text-sm opacity-75 #{td_text_class_weekday(weekday, current_day?)}"
57+
58+
defp td_text_class_weekday(1, _current_day?), do: ""
59+
defp td_text_class_weekday(5, _current_day?), do: ""
60+
defp td_text_class_weekday(_, true), do: ""
61+
defp td_text_class_weekday(_weekday, _current_day?), do: "hidden"
5762
end

lib/components_guide_web/controllers/calendar_controller.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ defmodule ComponentsGuideWeb.CalendarView do
302302
}
303303

304304
~H"""
305-
<a href={@href}>
305+
<a href={@href} class="flex flex-col md:block">
306306
<span class="text-3xl not-prose"><%= @icon %></span>
307307
<%= @what %>
308308
</a>
@@ -313,10 +313,10 @@ defmodule ComponentsGuideWeb.CalendarView do
313313
assigns = %{ids: ids}
314314

315315
~H"""
316-
<div>
316+
<div class="flex flex-col gap-2">
317317
<%= for id <- @ids do %>
318318
<div>
319-
<%= ComponentsGuideWeb.CalendarView.icon_link(id, Map.get(links, id)) %>
319+
<%= icon_link(id, Map.get(links, id)) %>
320320
</div>
321321
<% end %>
322322
</div>

0 commit comments

Comments
 (0)