Skip to content

Commit

Permalink
starting dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kobaltz committed Feb 9, 2024
1 parent abb791b commit 0c3819b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

.btn-default {
@apply inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover: bg-gray-50 dark:bg-gray-800 dark:text-white dark:ring-gray-600 dark:hover:bg-gray-700;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
connect() {
this.toggleDarkMode();
}

toggleDarkMode() {
if (localStorage.getItem('darkMode') === 'true') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}

toggle() {
let htmlClasses = document.documentElement.classList;
if (htmlClasses.contains('dark')) {
htmlClasses.remove('dark');
localStorage.setItem('darkMode', 'false');
} else {
htmlClasses.add('dark');
localStorage.setItem('darkMode', 'true');
}
}
}
2 changes: 2 additions & 0 deletions app/views/mission_control/servers/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<div class="mt-5 flex lg:ml-4 lg:mt-0">
<span class="hidden sm:block">
<button data-controller="dark-mode" data-action="click->dark-mode#toggle" class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50">Dark Mode</button>

<%= link_to edit_project_path(@project), class: "inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" do %>
Edit
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const defaultTheme = require('tailwindcss/defaultTheme')

module.exports = {
darkMode: 'class',
content: [
'./public/*.html',
'./app/helpers/**/*.rb',
Expand Down

0 comments on commit 0c3819b

Please sign in to comment.