-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from joyofrails/feat/add-system-mode-to-darkmod…
…e-switch Add system mode to darkmode switch
- Loading branch information
Showing
7 changed files
with
162 additions
and
73 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
<script type="text/javascript"> | ||
if (localStorage.getItem('color-theme') === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { | ||
const colorTheme = localStorage.getItem('color-theme'); | ||
if (colorTheme) { | ||
document.documentElement.classList.add(colorTheme) | ||
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
document.documentElement.classList.add('dark') | ||
} else { | ||
document.documentElement.classList.remove('dark') | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,24 @@ | ||
<div data-controller="darkmode" class="flex items-center justify-between"> | ||
<span | ||
aria-label="Toggle Dark Mode" | ||
aria-label="Change Color Scheme" | ||
data-darkmode-target="description" | ||
data-action="click->darkmode#toggle" | ||
data-action="click->darkmode#cycle" | ||
class="hidden mr-3 cursor-pointer" | ||
>Light Mode</span> | ||
<button | ||
data-action="click->darkmode#toggle" | ||
id="theme-toggle" | ||
data-action="click->darkmode#cycle" | ||
id="theme-cycle" | ||
type="button" | ||
class=" | ||
text-gray-500 dark:text-gray-400 hover:bg-theme-bg-hover focus:ring-gray-200 | ||
dark:focus:ring-gray-700 focus:ring-2 focus:outline-none rounded-lg text-sm | ||
p-2.5 | ||
" | ||
aria-label="Toggle Dark Mode" | ||
aria-label="Change Color Scheme" | ||
role="button" | ||
> | ||
<svg | ||
data-darkmode-target="darkIcon" | ||
class="hidden w-5 h-5" | ||
fill="currentColor" | ||
viewBox="0 0 20 20" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"></path> | ||
</svg> | ||
<svg | ||
data-darkmode-target="lightIcon" | ||
class="hidden w-5 h-5" | ||
fill="currentColor" | ||
viewBox="0 0 20 20" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" | ||
fill-rule="evenodd" | ||
clip-rule="evenodd" | ||
></path> | ||
</svg> | ||
<%= inline_svg_tag "darkmode/moon", data: { "darkmode-target" => "darkIcon" }, class: "hidden w-5 h-5", fill: "currentColor" %> | ||
<%= inline_svg_tag "darkmode/sun", data: { "darkmode-target" => "lightIcon" }, class: "hidden w-5 h-5", fill: "currentColor" %> | ||
<%= inline_svg_tag "darkmode/eclipse", data: { "darkmode-target" => "systemIcon" }, class: "hidden w-5 h-5", fill: "currentColor" %> | ||
</button> | ||
</div> |