Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/hexdocs/view/components.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import hexdocs/data/model.{type Model}
import hexdocs/data/msg
import lustre/attribute.{class}
import lustre/element
import lustre/element/html
import lustre/event

pub fn input_classes() {
[
Expand All @@ -12,3 +17,18 @@ pub fn input_classes() {
),
]
}

pub fn dark_mode_toggle(model: Model) -> element.Element(msg.Msg) {
html.button([class("p-2"), event.on_click(msg.UserToggledDarkMode)], [
html.i(
[
class("theme-icon text-xl text-slate-700 dark:text-slate-300"),
class(case model.dark_mode.mode {
msg.Dark -> "ri-sun-line"
msg.Light -> "ri-moon-line"
}),
],
[],
),
])
}
30 changes: 13 additions & 17 deletions src/hexdocs/view/home.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import lustre/element/html
import lustre/event

pub fn home(model: Model) {
let toggle_mode = event.on_click(msg.UserToggledDarkMode)
html.div([class("bg-white dark:bg-gray-900")], [
html.div(
[
Expand All @@ -28,22 +27,19 @@ pub fn home(model: Model) {
[
html.main([class("grow")], [
html.section([], [
html.div([id("nav"), class("flex justify-between items-center")], [
html.a(
[
attribute.href("https://hex.pm/"),
class("text-sm text-gray-600 dark:text-gray-100"),
],
[html.text("← Go back to Hex")],
),
html.button(
[
toggle_mode,
class("p-3 text-gray-700 dark:text-gray-100 mt-10"),
],
[html.i([class("theme-icon text-xl")], [])],
),
]),
html.div(
[id("nav"), class("flex justify-between items-center mt-2")],
[
html.a(
[
attribute.href("https://hex.pm/"),
class("text-sm text-gray-600 dark:text-gray-100"),
],
[html.text("← Go back to Hex")],
),
html.div([], [components.dark_mode_toggle(model)]),
],
),
html.div(
[class("flex flex-col justify-around mt-14 md:mt-26 lg:mt-40")],
[
Expand Down
18 changes: 1 addition & 17 deletions src/hexdocs/view/search.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -298,23 +298,7 @@ pub fn search(model: Model) {
[],
),
]),
html.button(
[class("p-2"), event.on_click(msg.UserToggledDarkMode)],
[
html.i(
[
class(
"theme-icon text-xl text-slate-700 dark:text-slate-300",
),
class(case model.dark_mode.mode {
msg.Dark -> "ri-sun-line"
msg.Light -> "ri-moon-line"
}),
],
[],
),
],
),
components.dark_mode_toggle(model),
]),
]),
html.div([class("flex flex-col mx-auto max-w-[800px]")], {
Expand Down