Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Light Mode + Follow System Theme #346

Open
amadeusp opened this issue Nov 9, 2024 · 7 comments
Open

Add Light Mode + Follow System Theme #346

amadeusp opened this issue Nov 9, 2024 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@amadeusp
Copy link

amadeusp commented Nov 9, 2024

I'd like both the Keila app and the actual user-facing newsletter front-end to support light and dark modes (in the case of the front-end, with customizable themes for both modes), and for the app and front-end to follow the system theme of the host computer when viewing/using either.

@wmnnd
Copy link
Contributor

wmnnd commented Dec 4, 2024

Hey @amadeusp, sorry for the late response! A light theme is definitely something I want to add. I’ll add it to the roadmap on GitHub 😊
The first step will be to add a light mode to the UI, the second step will be dark/light mode customization for the form pages.

@wmnnd wmnnd changed the title Follow system theme Add Light Mode + Follow System Theme Dec 4, 2024
@github-project-automation github-project-automation bot moved this to Inbox & Ideas in Roadmap to 1.0 Dec 4, 2024
@wmnnd wmnnd added enhancement New feature or request help wanted Extra attention is needed labels Dec 4, 2024
@marc-bouvier
Copy link

Here is a quick prototype based on tailwindcss "selector" mode.

https://github.com/pentacent/keila/compare/main...marc-bouvier:keila:feature/346-theme-light-systeme?expand=1

Basically, we'll have to

  • prefix current color related tailwind classes with :dark
  • add light theme classes along them
  • theme switch can be triggered by toggle class="dark" on <html>
  • this switch might be changed with a simple select list in vanilla HTML/Js or using liveview Hook.

A small example in styles.scss

.bg-onboarding {
-  @apply bg-gradient-to-r from-red-900 via-indigo-900 to-emerald-900;
+  @apply bg-gradient-to-r from-red-200 via-indigo-200 to-emerald-200 dark:from-red-900 dark:via-indigo-900 dark:to-emerald-900;
}

In templates

- <body class="bg-black grid grid-cols-1 sm:grid-cols-[16em,1fr]">
+ <body class="bg-white dark:bg-black grid grid-cols-1 sm:grid-cols-[16em,1fr]">

Theme switcher function could look like this :

    <script type="text/javascript">
          // this function must stay inline in head to avoid FOUC 
          function apply_theme(){
              document.documentElement.classList.toggle(
              'dark',
              localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)
            )
          }
          apply_theme()

      /**
      * Switches theme.
      * @see https://tailwindcss.com/docs/dark-mode#supporting-system-preference-and-manual-selection
      * @param {"dark"|"light"|"system"} mode 
      */
      function switch_theme (mode){
        if(mode==='dark') {
            localStorage.theme = 'dark'
        }
        if(mode==='light') {
            localStorage.theme = 'light' 
        }
        if(mode==='system') {
            localStorage.removeItem('theme')
        }
        // relies on function apply_theme() defined inline in head in HTML root (explained there)
        window.apply_theme()
      } 

        
    </script>

A very basic select list to showcase the switch.

  <select name="theme" onchange="window.switch_theme(event.target.value)">
    <option value="dark">Dark</option>
    <option value="light">Light</option>
    <option value="system">System</option>
  </select>
Screen.Recording.2025-01-18.at.02.07.38.mov

@marc-bouvier
Copy link

I've not yet looked at how to manage with the form pages.

@marc-bouvier
Copy link

Tailwind "inline" styles has a lot of duplication. It might be hell to maintain.

We could factorize color-related styles to css classes to make maintainance easier ?

@wmnnd
Copy link
Contributor

wmnnd commented Jan 19, 2025

It would even make sense to factor out some bits that are used regularly into components. I've been thinking about refreshing some parts of the UI anyways … starting next week I'll have more time to work on Keila again. Then I want to create a roadmap for the next couple of months. Is the styling something you're interested in helping with, @marc-bouvier?

@marc-bouvier
Copy link

marc-bouvier commented Jan 19, 2025

It would even make sense to factor out some bits that are used regularly into components.

I share the same feeling after digging a bit into it.

I've been thinking about refreshing some parts of the UI anyways … starting next week I'll have more time to work on Keila again. Then I want to create a roadmap for the next couple of months. Is the styling something you're interested in helping with, @marc-bouvier?

Indeed, I'd like helping with styling @wmnnd .

@marc-bouvier
Copy link

Based on what I've seen so far,

Image Image Image Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: Inbox & Ideas
Development

No branches or pull requests

3 participants