]> git.immae.eu Git - github/bastienwirtz/homer.git/commitdiff
Implementing dark mode 2/head
authorBastien Wirtz <bastien.wirtz@gmail.com>
Wed, 2 Oct 2019 04:35:51 +0000 (21:35 -0700)
committerBastien Wirtz <bastien.wirtz@gmail.com>
Wed, 2 Oct 2019 04:40:45 +0000 (21:40 -0700)
app.css
app.js
app.scss
index.html

diff --git a/app.css b/app.css
index 846b54b274022be76d4490be336cda7d0dccabec..8a9774249f35426439b2886eb9136288fdc6d1e2 100644 (file)
--- a/app.css
+++ b/app.css
@@ -3,8 +3,86 @@ html {
 
 body {
   font-family: 'Raleway', sans-serif;
-  background-color: #F5F5F5;
-  min-height: 100%; }
+  height: 100%; }
+  body #app {
+    min-height: 100%;
+    transition: background-color cubic-bezier(0.165, 0.84, 0.44, 1) 300ms;
+    background-color: #f5f5f5;
+    color: #363636; }
+    body #app .title {
+      color: #303030; }
+    body #app .subtitle {
+      color: #424242; }
+    body #app .card {
+      background-color: #ffffff;
+      box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.1); }
+      body #app .card:hover {
+        background-color: #ffffff; }
+    body #app .footer {
+      background-color: #ffffff;
+      box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.1); }
+    @media (prefers-color-scheme: light), (prefers-color-scheme: no-preference) {
+      body #app {
+        background-color: #f5f5f5;
+        color: #363636; }
+        body #app .title {
+          color: #303030; }
+        body #app .subtitle {
+          color: #424242; }
+        body #app .card {
+          background-color: #ffffff;
+          box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.1); }
+          body #app .card:hover {
+            background-color: #ffffff; }
+        body #app .footer {
+          background-color: #ffffff;
+          box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.1); } }
+    @media (prefers-color-scheme: dark) {
+      body #app {
+        background-color: #131313;
+        color: #eaeaea; }
+        body #app .title {
+          color: #fafafa; }
+        body #app .subtitle {
+          color: #f5f5f5; }
+        body #app .card {
+          background-color: #2b2b2b;
+          box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.4); }
+          body #app .card:hover {
+            background-color: #2b2b2b; }
+        body #app .footer {
+          background-color: #2b2b2b;
+          box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.4); } }
+    body #app.is-light {
+      background-color: #f5f5f5;
+      color: #363636; }
+      body #app.is-light .title {
+        color: #303030; }
+      body #app.is-light .subtitle {
+        color: #424242; }
+      body #app.is-light .card {
+        background-color: #ffffff;
+        box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.1); }
+        body #app.is-light .card:hover {
+          background-color: #ffffff; }
+      body #app.is-light .footer {
+        background-color: #ffffff;
+        box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.1); }
+    body #app.is-dark {
+      background-color: #131313;
+      color: #eaeaea; }
+      body #app.is-dark .title {
+        color: #fafafa; }
+      body #app.is-dark .subtitle {
+        color: #f5f5f5; }
+      body #app.is-dark .card {
+        background-color: #2b2b2b;
+        box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.4); }
+        body #app.is-dark .card:hover {
+          background-color: #2b2b2b; }
+      body #app.is-dark .footer {
+        background-color: #2b2b2b;
+        box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.4); }
   body h1, body h2, body h3, body h4, body h5, body h6 {
     font-family: 'Lato', sans-serif; }
   body h1 {
@@ -54,7 +132,7 @@ body {
         body #bighead .navbar a:hover {
           background-color: #5a95f5; }
   body #main-section {
-    margin-bottom: 3rem;
+    margin-bottom: 2rem;
     padding: 0; }
     body #main-section h2 {
       border-bottom: 1px dashed #ccc;
@@ -95,7 +173,6 @@ body {
     body .card a {
       outline: none; }
   body .card:hover {
-    background-color: #FFFFFF;
     transform: translate(0, -3px); }
     body .card:hover .tag {
       width: auto;
@@ -117,10 +194,9 @@ body {
     bottom: 0;
     padding: 0.5rem;
     text-align: left;
-    background-color: #fafafa;
-    border-top: 1px solid #F5F5F5;
     color: #676767;
-    font-size: 0.85rem; }
+    font-size: 0.85rem;
+    transition: background-color cubic-bezier(0.165, 0.84, 0.44, 1) 300ms; }
   body .search-bar {
     position: relative;
     display: inline-block; }
diff --git a/app.js b/app.js
index dc8b6cc65ff9fe055f74cfefccc2e4b4fbcd7525..a404314df8f8911597fb9dd72c1d7e1056f04fd7 100644 (file)
--- a/app.js
+++ b/app.js
@@ -4,7 +4,8 @@ const app = new Vue({
         config: null,
         offline: false,
         filter: '',
-        vlayout: true
+        vlayout: true,
+        overrideDark: null
     },
     created: function () {
         let that = this;
@@ -22,6 +23,13 @@ const app = new Vue({
             }
         }, false);
     },
+    computed: {
+        isDark: function() {
+            return this.overrideDark !== null
+                ? this.overrideDark
+                : matchMedia("(prefers-color-scheme: dark)").matches;
+        }
+      },
     methods: {
         checkOffline: function () {
             let that = this;
@@ -44,6 +52,9 @@ const app = new Vue({
                 });
             });
         },
+        toggleTheme: function() {
+            this.overrideDark = !this.isDark;
+        }
     }
 });
 
index ab9a394155353c46ad225797118892a4fbd6c184..d4d2099529f6487739c0ff7cde14fe6b5c14661a 100644 (file)
--- a/app.scss
+++ b/app.scss
@@ -1,12 +1,83 @@
 $primary-color: #3367d6;
 $secondary-color: #4285f4;
 
-html { height: 100%; }
+
+// /!\ Keep background colors sync with `theme-color` meta info
+$theme-light: (
+  background: #f5f5f5,
+  card-background: #ffffff,
+  text: #363636,
+  text-title: #303030,
+  text-subtitle: #424242,
+  card-shadow: rgba(0, 0, 0, 0.1)
+);
+$theme-dark: (
+  background: #131313,
+  card-background: #2b2b2b,
+  text: #eaeaea,
+  text-title: #fafafa,
+  text-subtitle: #f5f5f5,
+  card-shadow: rgba(0, 0, 0, 0.4)
+);
+
+  
+
+@mixin theme($theme) {
+  background-color: map-get($theme, "background");
+  color: map-get($theme, "text");
+
+  .title {
+    color: map-get($theme, "text-title");
+  }
+  .subtitle {
+    color: map-get($theme, "text-subtitle");
+  }
+
+  .card {
+    background-color: map-get($theme, "card-background");
+    box-shadow: 0 2px 15px 0 map-get($theme, "card-shadow");
+    &:hover {
+      background-color: map-get($theme, "card-background");
+    }
+  }
+
+  .footer {
+    background-color:  map-get($theme, "card-background");
+    box-shadow: 0 2px 15px 0 map-get($theme, "card-shadow");
+  }
+}
+
+html { 
+  height: 100%; 
+}
 
 body {
   font-family: 'Raleway', sans-serif;
-  background-color: #F5F5F5;
-  min-height: 100%;
+  height: 100%;
+
+  #app {
+    min-height: 100%;
+    transition: background-color cubic-bezier(0.165, 0.84, 0.44, 1) 300ms;
+
+    // Default theme
+    @include theme($theme-light);
+
+    // System pref theme
+    @media (prefers-color-scheme: light), (prefers-color-scheme: no-preference) {
+      @include theme($theme-light);
+    }
+    @media (prefers-color-scheme: dark) {
+      @include theme($theme-dark);
+    }
+
+    // User override theme
+    &.is-light {
+      @include theme($theme-light);
+    }
+    &.is-dark {
+      @include theme($theme-dark);
+    }
+  }
 
   h1, h2, h3, h4, h5, h6 {
     font-family: 'Lato', sans-serif;
@@ -90,7 +161,7 @@ body {
   }
 
   #main-section {
-    margin-bottom: 3rem;
+    margin-bottom: 2rem;
     padding: 0;
 
     h2 {
@@ -155,7 +226,6 @@ body {
   }
 
   .card:hover {
-    background-color: #FFFFFF;
     transform: translate(0, -3px);
 
     .tag {
@@ -191,10 +261,9 @@ body {
     bottom: 0;
     padding: 0.5rem;
     text-align: left;
-    background-color: #fafafa;
-    border-top: 1px solid #F5F5F5;
     color: #676767;
     font-size: 0.85rem;
+    transition: background-color cubic-bezier(0.165, 0.84, 0.44, 1) 300ms;
   }
 
   .search-bar {
index 6b75e497b197b09cd846e592cb5e52e51d0044f4..d5aebd30e64dbb05cfbcc1bd54fcf0d70062a260 100644 (file)
 </head>
 
 <body>
-  <div id="app" v-if="config">
+  <div id="app" v-if="config" :class="{
+    'is-dark': overrideDark === true,
+    'is-light': overrideDark === false
+  }">
     <div id="bighead">
       <section class="first-line">
         <div v-cloak class="container">
                 </a>
               </div>
               <div class="end">
+                  <a
+                    v-on:click="toggleTheme()"
+                    aria-label="Toggle dark mode"
+                    ><i class="fas fa-adjust"></i>
+                </a>
                 <a v-on:click="vlayout = !vlayout" class="icon-button navbar-item"><i
                     :class="['fas', vlayout ? 'fa-list' : 'fa-columns']"></i></a>
                 <div class="search-bar">
         </div>
       </div>
     </section>
+    <footer class="footer">
+        <div class="container">
+          <div class="content has-text-centered">
+            <p>Created with <span class="has-text-danger">❤️</span> with <a href="https://bulma.io/">bulma</a>, <a
+                href="https://vuejs.org/">vuejs</a>
+              & <a href="https://fontawesome.com/">font awesome</a> // Fork me on <a href="https://github.com/bastienwirtz/homer"><i
+                  class="fab fa-github-alt"></i></a></p>
+          </div>
+        </div>
+      </footer>
   </div>
 
-  <footer class="footer">
-    <div class="container">
-      <div class="content has-text-centered">
-        <p>Created with <span class="has-text-danger">❤️</span> with <a href="https://bulma.io/">bulma</a>, <a
-            href="https://vuejs.org/">vuejs</a>
-          & <a href="#">font awesome</a> // Fork me on <a href="https://github.com/bastienwirtz/homer"><i
-              class="fab fa-github-alt"></i></a></p>
-      </div>
-    </div>
-  </footer>
-
   <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js"></script>
   <script src="vendors/js-yaml.min.js"></script>
   <script src="app.js"></script>