Skip to content

Commit 0d5a41c

Browse files
authored
Include the dark mode toggle on the home page (#15)
It looks like this was intended to be there, but missing an icon. The button has been extracted out into the components module.
1 parent aabfb37 commit 0d5a41c

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

src/hexdocs/view/components.gleam

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import hexdocs/data/model.{type Model}
2+
import hexdocs/data/msg
13
import lustre/attribute.{class}
4+
import lustre/element
5+
import lustre/element/html
6+
import lustre/event
27

38
pub fn input_classes() {
49
[
@@ -12,3 +17,18 @@ pub fn input_classes() {
1217
),
1318
]
1419
}
20+
21+
pub fn dark_mode_toggle(model: Model) -> element.Element(msg.Msg) {
22+
html.button([class("p-2"), event.on_click(msg.UserToggledDarkMode)], [
23+
html.i(
24+
[
25+
class("theme-icon text-xl text-slate-700 dark:text-slate-300"),
26+
class(case model.dark_mode.mode {
27+
msg.Dark -> "ri-sun-line"
28+
msg.Light -> "ri-moon-line"
29+
}),
30+
],
31+
[],
32+
),
33+
])
34+
}

src/hexdocs/view/home.gleam

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import lustre/element/html
1414
import lustre/event
1515

1616
pub fn home(model: Model) {
17-
let toggle_mode = event.on_click(msg.UserToggledDarkMode)
1817
html.div([class("bg-white dark:bg-gray-900")], [
1918
html.div(
2019
[
@@ -28,22 +27,19 @@ pub fn home(model: Model) {
2827
[
2928
html.main([class("grow")], [
3029
html.section([], [
31-
html.div([id("nav"), class("flex justify-between items-center")], [
32-
html.a(
33-
[
34-
attribute.href("https://hex.pm/"),
35-
class("text-sm text-gray-600 dark:text-gray-100"),
36-
],
37-
[html.text("← Go back to Hex")],
38-
),
39-
html.button(
40-
[
41-
toggle_mode,
42-
class("p-3 text-gray-700 dark:text-gray-100 mt-10"),
43-
],
44-
[html.i([class("theme-icon text-xl")], [])],
45-
),
46-
]),
30+
html.div(
31+
[id("nav"), class("flex justify-between items-center mt-2")],
32+
[
33+
html.a(
34+
[
35+
attribute.href("https://hex.pm/"),
36+
class("text-sm text-gray-600 dark:text-gray-100"),
37+
],
38+
[html.text("← Go back to Hex")],
39+
),
40+
html.div([], [components.dark_mode_toggle(model)]),
41+
],
42+
),
4743
html.div(
4844
[class("flex flex-col justify-around mt-14 md:mt-26 lg:mt-40")],
4945
[

src/hexdocs/view/search.gleam

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -298,23 +298,7 @@ pub fn search(model: Model) {
298298
[],
299299
),
300300
]),
301-
html.button(
302-
[class("p-2"), event.on_click(msg.UserToggledDarkMode)],
303-
[
304-
html.i(
305-
[
306-
class(
307-
"theme-icon text-xl text-slate-700 dark:text-slate-300",
308-
),
309-
class(case model.dark_mode.mode {
310-
msg.Dark -> "ri-sun-line"
311-
msg.Light -> "ri-moon-line"
312-
}),
313-
],
314-
[],
315-
),
316-
],
317-
),
301+
components.dark_mode_toggle(model),
318302
]),
319303
]),
320304
html.div([class("flex flex-col mx-auto max-w-[800px]")], {

0 commit comments

Comments
 (0)