Skip to content

Commit 85701dc

Browse files
authored
move theme button to top level menu again and make it available at all times, without the need to register (#104)
Signed-off-by: Kai Wagner <kai.wagner@percona.com>
1 parent 5c6de3e commit 85701dc

5 files changed

Lines changed: 28 additions & 31 deletions

File tree

app/assets/stylesheets/components/navigation.css

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,11 @@
184184
}
185185

186186
.theme-toggle {
187-
border-color: var(--color-border);
188-
background: var(--color-bg-card);
189-
color: var(--color-text-secondary);
190187
cursor: pointer;
191-
box-shadow: var(--shadow-sm);
192-
border-radius: 999px;
193-
194-
&:hover {
195-
background: var(--color-bg-hover);
196-
}
188+
appearance: none;
189+
font: inherit;
190+
line-height: inherit;
191+
margin: 0;
197192
}
198193

199194
.nav-overflow-dropdown {
@@ -367,15 +362,20 @@
367362
display: none;
368363
}
369364

370-
.mobile-nav-menu .nav-link {
371-
width: 100%;
372-
justify-content: space-between;
373-
}
365+
.mobile-nav-menu .nav-link {
366+
width: 100%;
367+
justify-content: space-between;
368+
}
374369

375-
.mobile-nav-menu .nav-user {
376-
display: block;
377-
padding: 0 var(--spacing-2);
378-
}
370+
.mobile-nav-theme-control {
371+
width: 100%;
372+
justify-content: space-between;
373+
}
374+
375+
.mobile-nav-menu .nav-user {
376+
display: block;
377+
padding: 0 var(--spacing-2);
378+
}
379379

380380
.mobile-nav-menu {
381381
position: fixed;

app/javascript/controllers/theme_controller.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ export default class extends Controller {
4949
}
5050

5151
if (this.hasIconTarget) {
52-
this.iconTarget.classList.remove("fa-moon", "fa-sun")
52+
this.iconTarget.classList.remove("fa-regular", "fa-solid", "fa-moon", "fa-sun")
53+
this.iconTarget.classList.add("fa-solid")
5354
this.iconTarget.classList.add(theme === "dark" ? "fa-sun" : "fa-moon")
5455
}
5556

5657
this.element.setAttribute("aria-pressed", theme === "dark")
58+
this.element.setAttribute("aria-label", `Switch to ${theme === "dark" ? "light" : "dark"} mode`)
5759
this.element.setAttribute("title", `Switch to ${theme === "dark" ? "light" : "dark"} mode`)
5860

5961
if (this.hasButtonTarget) {

app/views/layouts/application.html.slim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ html data-theme="light"
5656
span.mobile-nav-label Menu
5757
i.fa-solid.fa-caret-down
5858
.mobile-nav-menu data-action="click->sidebar#closeMenuOnNavigate"
59+
= render "shared/theme_control", extra_class: "mobile-nav-theme-control", show_label: true
5960
= link_to "Topics", topics_path, class: "nav-link"
6061
- if user_signed_in?
6162
- icon_class = starred_active ? "fa-solid fa-star" : "fa-regular fa-star"
@@ -101,6 +102,7 @@ html data-theme="light"
101102
- if user_signed_in?
102103
- if current_user&.person&.default_alias
103104
= link_to current_user.person.default_alias.name, person_path(current_user.person.default_alias.email), class: "nav-link nav-user"
105+
= render "shared/theme_control", extra_class: "nav-theme-control", show_label: false
104106
- unread = activity_unread_count
105107
= link_to activities_path, class: "nav-link nav-link-activity", title: "Activity" do
106108
i.fa-regular.fa-bell
@@ -109,6 +111,7 @@ html data-theme="light"
109111
- else
110112
= link_to "Sign in", new_session_path, class: "nav-link"
111113
= link_to "Register", new_registration_path, class: "nav-link"
114+
= render "shared/theme_control", extra_class: "nav-theme-control", show_label: false
112115
details.nav-overflow-dropdown data-controller="nav-dropdown"
113116
summary.nav-link.nav-overflow-toggle aria-label="Menu" data-action="click->sidebar#closeMenuOnNavigate"
114117
i.fa-solid.fa-bars

app/views/settings/profiles/show.html.slim

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@
1111
= f.text_field :username, placeholder: "your_name", value: current_user.username
1212
= f.submit "Save username", class: "button-primary"
1313

14-
.settings-section
15-
h2 Appearance
16-
p.settings-hint Choose your preferred theme.
17-
.theme-choice data-controller="theme"
18-
span.theme-choice-label Theme
19-
.theme-choice-buttons
20-
button.theme-choice-button type="button" data-theme-value="light" data-theme-target="button" data-action="click->theme#select"
21-
i.fa-solid.fa-sun aria-hidden="true"
22-
span Light
23-
button.theme-choice-button type="button" data-theme-value="dark" data-theme-target="button" data-action="click->theme#select"
24-
i.fa-regular.fa-moon aria-hidden="true"
25-
span Dark
26-
2714
.settings-section
2815
h2 Mention Settings
2916
p.settings-hint Control who can @mention you in notes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- classes = ["nav-link", "theme-toggle", local_assigns[:extra_class]].compact.join(" ")
2+
button class=classes type="button" data-controller="theme" data-action="click->theme#toggle" aria-label="Toggle theme"
3+
i.fa-regular.fa-moon data-theme-target="icon" aria-hidden="true"
4+
- if local_assigns.fetch(:show_label, true)
5+
span Theme

0 commit comments

Comments
 (0)