Skip to content

Commit

Permalink
alex-shpak#151, move SCSS vars to CSS vars, implement dark and light …
Browse files Browse the repository at this point in the history
…modes by browser preference
  • Loading branch information
alex-shpak committed Sep 13, 2020
1 parent 6beca79 commit 4e34988
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 66 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ enableGitInfo = true
disableKinds = ['taxonomy', 'taxonomyTerm']

[params]
# (Optional, default light) Sets color theme: light, dark or auto.
# Theme 'auto' switches between dark and light modes based on browser/os preferences
BookTheme = 'light'

# (Optional, default true) Controls table of contents visibility on right side of pages.
# Start and end levels can be controlled with markup.tableOfContents setting.
# You can also specify this parameter per page in front matter.
Expand Down Expand Up @@ -252,11 +256,10 @@ There are a few features implemented as plugable `scss` styles. Usually these ar

| Plugin | Description |
| --------------------------------- | ----------------------------------------------------------- |
| `assets/plugins/_dark.scss` | Switches site to dark mode |
| `assets/plugins/_numbered.scss` | Makes headings in markdown numbered, e.g. `1.1`, `1.2` |
| `assets/plugins/_scrollbars.scss` | Overrides scrollbar styles to look similar across platforms |

To enable plugins, add `@import "plugins/{name}";` to `assets/_custom.scss` in your website root. One exception is `_dark.scss` which contains variables only and should be added to `assets/_variables.scss`.
To enable plugins, add `@import "plugins/{name}";` to `assets/_custom.scss` in your website root.

### Hugo Internal Templates

Expand Down
58 changes: 37 additions & 21 deletions assets/_defaults.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ $font-size-16: 1rem !default;

$border-radius: $padding-4 !default;

// Grayscale
$white: #ffffff !default;
$gray-100: #f8f9fa !default;
$gray-200: #e9ecef !default;
$gray-300: #dee2e6 !default;
$gray-400: #ced4da !default;
$gray-500: #adb5bd !default;
$gray-600: #868e96 !default;
$gray-700: #495057 !default;
$gray-800: #343a40 !default;
$gray-900: #212529 !default;
$black: #000 !default;

$color-link: #05b !default;
$color-visited-link: #8440f1 !default;

$body-background: white !default;
$body-font-color: $black !default;
$body-font-weight: normal !default;

$body-min-width: 20rem !default;
Expand All @@ -40,11 +22,45 @@ $toc-width: 16rem !default;

$mobile-breakpoint: $menu-width + $body-min-width * 1.2 + $toc-width !default;

// Hint colors
$hint-colors: (
info: #6bf,
warning: #fd6,
danger: #f66
danger: #f66,
) !default;

$icon-filter: none !default;
// Themes
@mixin theme-light {
--gray-100: #f8f9fa;
--gray-200: #e9ecef;
--gray-500: #adb5bd;

--color-link: #0055bb;
--color-visited-link: #8440f1;

--body-background: white;
--body-font-color: black;

--icon-filter: none;

--hint-color-info: #6bf;
--hint-color-warning: #fd6;
--hint-color-danger: #f66;
}

@mixin theme-dark {
--gray-100: rgba(255, 255, 255, 0.1);
--gray-200: rgba(255, 255, 255, 0.2);
--gray-500: rgba(255, 255, 255, 0.5);

--color-link: #84b2ff;
--color-visited-link: #b88dff;

--body-background: #343a40;
--body-font-color: #e9ecef;

--icon-filter: brightness(0) invert(1);

--hint-color-info: #6bf;
--hint-color-warning: #fd6;
--hint-color-danger: #f66;
}
20 changes: 10 additions & 10 deletions assets/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ html {

body {
min-width: $body-min-width;
color: $body-font-color;
background: $body-background;
color: var(--body-font-color);
background: var(--body-background);

letter-spacing: 0.33px;
font-weight: $body-font-weight;
Expand All @@ -31,7 +31,7 @@ h5 {

a {
text-decoration: none;
color: $color-link;
color: var(--color-link);
}

img {
Expand Down Expand Up @@ -81,7 +81,7 @@ ul.pagination {
}

.book-icon {
filter: $icon-filter;
filter: var(--icon-filter);
}

.book-brand {
Expand All @@ -102,7 +102,7 @@ ul.pagination {
nav {
width: $menu-width;
padding: $padding-16;
background: $body-background;
background: var(--body-background);

@include fixed;
}
Expand All @@ -113,7 +113,7 @@ ul.pagination {
}

a.active {
color: $color-link;
color: var(--color-link);
}

a.collapsed {
Expand Down Expand Up @@ -174,8 +174,8 @@ ul.pagination {
border: 0;
border-radius: $border-radius;

background: $gray-100;
color: $body-font-color;
background: var(--gray-100);
color: var(--body-font-color);

&:required + .book-search-spinner {
display: block;
Expand All @@ -192,7 +192,7 @@ ul.pagination {
height: $padding-16;

border: $padding-1 solid transparent;
border-top-color: $body-font-color;
border-top-color: var(--body-font-color);
border-radius: 50%;

@include spin(1s);
Expand Down Expand Up @@ -271,7 +271,7 @@ ul.pagination {
left: 0;
padding: $padding-8 0;

background: $body-background;
background: var(--body-background);
box-shadow: 0 0 $padding-4 rgba(0, 0, 0, 0.1);

li img {
Expand Down
21 changes: 11 additions & 10 deletions assets/_markdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

a.anchor {
opacity: 0;
font-size: .75em;
font-size: 0.75em;
vertical-align: middle;
text-decoration: none;
}

&:hover a.anchor, a.anchor:focus {
&:hover a.anchor,
a.anchor:focus {
opacity: initial;
}
}
Expand Down Expand Up @@ -58,7 +59,7 @@
text-decoration: underline;
}
&:visited {
color: $color-visited-link;
color: var(--color-visited-link);
}
}

Expand All @@ -68,14 +69,14 @@

code {
padding: 0 $padding-4;
background: $gray-200;
background: var(--gray-200);
border-radius: $border-radius;
font-size: 0.875em;
}

pre {
padding: $padding-16;
background: $gray-100;
background: var(--gray-100);
border-radius: $border-radius;
overflow-x: auto;

Expand All @@ -89,7 +90,7 @@
margin: $padding-16 0;
padding: $padding-8 $padding-16 $padding-8 ($padding-16 - $padding-4); //to keep total left space 16dp

border-inline-start: $padding-4 solid $gray-200;
border-inline-start: $padding-4 solid var(--gray-200);
border-radius: $border-radius;

:first-child {
Expand All @@ -111,18 +112,18 @@
tr th,
tr td {
padding: $padding-8 $padding-16;
border: $padding-1 solid $gray-200;
border: $padding-1 solid var(--gray-200);
}

tr:nth-child(2n) {
background: $gray-100;
background: var(--gray-100);
}
}

hr {
height: $padding-1;
border: none;
background: $gray-200;
background: var(--gray-200);
}

ul,
Expand Down Expand Up @@ -156,7 +157,7 @@

details {
padding: $padding-16;
border: $padding-1 solid $gray-200;
border: $padding-1 solid var(--gray-200);
border-radius: $border-radius;

summary {
Expand Down
16 changes: 8 additions & 8 deletions assets/_shortcodes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
margin-top: $padding-16;
margin-bottom: $padding-16;

border: $padding-1 solid $gray-200;
border: $padding-1 solid var(--gray-200);
border-radius: $border-radius;

overflow: hidden;

.book-expand-head {
background: $gray-100;
background: var(--gray-100);
padding: $padding-8 $padding-16;
cursor: pointer;
}
Expand All @@ -30,7 +30,7 @@
margin-top: $padding-16;
margin-bottom: $padding-16;

border: $padding-1 solid $gray-200;
border: $padding-1 solid var(--gray-200);
border-radius: $border-radius;

overflow: hidden;
Expand All @@ -48,19 +48,19 @@
.book-tabs-content {
order: 999; //Move content blocks to the end
width: 100%;
border-top: $padding-1 solid $gray-100;
border-top: $padding-1 solid var(--gray-100);
padding: $padding-16;
display: none;
}

input[type="radio"]:checked + label {
border-bottom: $padding-1 solid $color-link;
border-bottom: $padding-1 solid var(--color-link);
}
input[type="radio"]:checked + label + .book-tabs-content {
display: block;
}
input[type="radio"]:focus + label {
@include outline
@include outline;
}
}

Expand All @@ -80,10 +80,10 @@
a.book-btn {
display: inline-block;
font-size: $font-size-14;
color: $color-link;
color: var(--color-link);
line-height: $padding-16 * 2;
padding: 0 $padding-16;
border: $padding-1 solid $color-link;
border: $padding-1 solid var(--color-link);
border-radius: $border-radius;
cursor: pointer;

Expand Down
1 change: 1 addition & 0 deletions assets/book.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "defaults";
@import "variables";
@import "themes/{{ default "auto" .Site.Params.BookTheme }}";

@import "normalize";
@import "utils";
Expand Down
10 changes: 0 additions & 10 deletions assets/plugins/_dark.scss

This file was deleted.

6 changes: 3 additions & 3 deletions assets/plugins/_scrollbars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
}

:hover::-webkit-scrollbar-thumb {
background: $gray-500;
background: var(--gray-500);
}

// MS
body {
-ms-overflow-style: -ms-autohiding-scrollbar
-ms-overflow-style: -ms-autohiding-scrollbar;
}

// Future
.book-menu nav {
scrollbar-color: transparent $gray-500;
scrollbar-color: transparent var(--gray-500);
}
9 changes: 9 additions & 0 deletions assets/themes/_auto.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:root {
@include theme-light;
}

@media (prefers-color-scheme: dark) {
:root {
@include theme-dark;
}
}
3 changes: 3 additions & 0 deletions assets/themes/_dark.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:root {
@include theme-dark;
}
3 changes: 3 additions & 0 deletions assets/themes/_light.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:root {
@include theme-light;
}
4 changes: 4 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ enableGitInfo = true
weight = 20

[params]
# (Optional, default light) Sets color theme: light, dark or auto.
# Theme 'auto' switches between dark and light modes based on browser/os preferences
BookTheme = 'light'

# (Optional, default true) Controls table of contents visibility on right side of pages.
# Start and end levels can be controlled with markup.tableOfContents setting.
# You can also specify this parameter per page in front matter.
Expand Down
4 changes: 4 additions & 0 deletions exampleSite/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ menu:
weight: 20

params:
# (Optional, default light) Sets color theme: light, dark or auto.
# Theme 'auto' switches between dark and light modes based on browser/os preferences
BookTheme: "light"

# (Optional, default true) Controls table of contents visibility on right side of pages.
# Start and end levels can be controlled with markup.tableOfContents setting.
# You can also specify this parameter per page in front matter.
Expand Down
Loading

0 comments on commit 4e34988

Please sign in to comment.