From 42fcbc30849117490fd1491b8dab1ce05cbeb8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 26 Feb 2023 12:47:12 +0100 Subject: [PATCH] variant: make browser theme a css variable #494 --- .../content/basics/generator/_index.en.md | 16 ++++++---------- static/css/ie.css | 3 +++ static/css/theme-blue.css | 4 ---- static/css/theme-learn.css | 4 ---- static/css/theme-neon.css | 5 +---- static/css/theme-relearn-bright.css | 5 +---- static/css/theme-relearn-dark.css | 1 + static/css/theme-relearn-light.css | 5 +---- static/css/variant.css | 7 ++++++- static/js/variant.js | 1 + 10 files changed, 20 insertions(+), 31 deletions(-) diff --git a/exampleSite/content/basics/generator/_index.en.md b/exampleSite/content/basics/generator/_index.en.md index 4c516a27f8..ddd1d9f9d2 100644 --- a/exampleSite/content/basics/generator/_index.en.md +++ b/exampleSite/content/basics/generator/_index.en.md @@ -6,25 +6,21 @@ weight = 26 This interactive tool may help you to generate your own color variant stylesheet. -To get started, first select a color variant from the variant switch that fits you best as a starting point. +{{% expand "Show usage instructions" %}} +To get started, first select a color variant from the variant switch in the lower left sidebar that fits you best as a starting point. -The graph is interactive and reflect the current colors. You can click on any of the colored boxes to adjust the respective color. The graph and the page will update accordingly. +The graph is interactive and reflect the current colors. You can click on any of the colored boxes to adjust the respective color. The graph **and the page** will update accordingly. -The arrowed lines reflects how colors are inherited thru different parts of the theme if the descendent isn't overwritten. If you want to delete a color and let it inherit from its parent, just delete the value from the input field. +The arrowed lines reflect how colors are inherited thru different parts of the theme if the descendent isn't overwritten. If you want to delete a color and let it inherit from its parent, just delete the value from the input field. To better understand this select the `neon` variant and modify the different heading colors. There, colors for the heading `h2`, `h3` and `h4` are explicitly set. `h5` is not set and inherits its value from `h4`. `h6` is also not set and inherits its value from `h5`. -Once you've changed a color, the variant switch will show a "My custom variant" entry and your changes are stored in the browser. You can change pages and even close the browser without losing your changes. +Once you've changed a color, the variant switch will show a "My custom variant" entry and your changes are stored in the browser. You can **browse to other pages** and even close the browser **without losing your changes**. Once you are satisfied, you can download the new variants file and copy it into your site's `static/css` directory. Afterwards you have to adjust the `themeVariant` parameter in your `config.toml` to your chosen file name. Eg. if your new variants file is named `theme-my-custom-variant.css`, you have to set `themeVariant='my-custom-variant'` to use it. - -{{% notice note %}} -This only works in modern browsers. -{{% /notice %}} - -## Variant generator +{{% /expand %}} {{% button style="secondary" icon="download" href="javascript:window.variants&&variants.getStylesheet();this.blur();" %}}Download variant{{% /button %}} {{% button style="warning" icon="trash" href="javascript:window.variants&&variants.resetVariant();this.blur();" %}}Reset variant{{% /button %}} diff --git a/static/css/ie.css b/static/css/ie.css index 9fdf6b759a..d2517e57fa 100644 --- a/static/css/ie.css +++ b/static/css/ie.css @@ -205,6 +205,9 @@ /* ----------------------------------------------- */ /* set default colors as in variant.css for IE11 */ + html { + color-scheme: only light; + } body { background-color: #ffffff; /* var(--MAIN-BG-color) */ color: #101010; /* var(--MAIN-TEXT-color) */ diff --git a/static/css/theme-blue.css b/static/css/theme-blue.css index 61483c20f9..648cac0029 100644 --- a/static/css/theme-blue.css +++ b/static/css/theme-blue.css @@ -47,7 +47,3 @@ --BOX-BG-color: rgba( 255, 255, 255, .833 ); /* color of the content background */ --BOX-TEXT-color: rgba( 16, 16, 16, 1 ); /* fixed color of the content text */ } - -:root { - color-scheme: only light; /* set browser scrollbar color */ -} diff --git a/static/css/theme-learn.css b/static/css/theme-learn.css index b925dd56c3..5de5a55cba 100644 --- a/static/css/theme-learn.css +++ b/static/css/theme-learn.css @@ -48,10 +48,6 @@ --BOX-TEXT-color: rgba( 16, 16, 16, 1 ); /* fixed color of the content text */ } -:root { - color-scheme: only light; /* set browser scrollbar color */ -} - body a#logo, body a#logo:hover, body #logo svg, diff --git a/static/css/theme-neon.css b/static/css/theme-neon.css index b4c0c2f444..9965ec40fc 100644 --- a/static/css/theme-neon.css +++ b/static/css/theme-neon.css @@ -31,6 +31,7 @@ --CODE-INLINE-BG-color: #282a36; /* background color of inline code */ --CODE-INLINE-BORDER-color: #464646; /* border color of inline code */ + --BROWSER-theme: dark; /* name of the theme for browser scrollbars of the main section */ --MERMAID-theme: dark; /* name of the default Mermaid theme for this variant, can be overridden in config.toml */ --SWAGGER-theme: dark; /* name of the default Swagger theme for this variant, can be overridden in config.toml */ @@ -70,10 +71,6 @@ --BOX-RED-TEXT-color: var( --BOX-RED-color ); /* text color of red boxes */ } -:root { - color-scheme: only dark; /* set browser scrollbar color */ -} - body a#logo, body a#logo:hover, body #logo svg, diff --git a/static/css/theme-relearn-bright.css b/static/css/theme-relearn-bright.css index 8f60d483d2..aab3f64607 100644 --- a/static/css/theme-relearn-bright.css +++ b/static/css/theme-relearn-bright.css @@ -24,6 +24,7 @@ --CODE-INLINE-BG-color: #fffae9; /* background color of inline code */ --CODE-INLINE-BORDER-color: #f8e8c8; /* border color of inline code */ + --BROWSER-theme: light; /* name of the theme for browser scrollbars of the main section */ --MERMAID-theme: default; /* name of the default Mermaid theme for this variant, can be overridden in config.toml */ --SWAGGER-theme: light; /* name of the default Swagger theme for this variant, can be overridden in config.toml */ @@ -46,10 +47,6 @@ --BOX-TEXT-color: rgba( 16, 16, 16, 1 ); /* text color of colored box content */ } -:root { - color-scheme: only light; /* set browser scrollbar color */ -} - body a#logo, body a#logo:hover, body #logo svg, diff --git a/static/css/theme-relearn-dark.css b/static/css/theme-relearn-dark.css index f52651ceb3..e2aa4a85b7 100644 --- a/static/css/theme-relearn-dark.css +++ b/static/css/theme-relearn-dark.css @@ -23,6 +23,7 @@ --CODE-INLINE-BG-color: #2d2d2d; /* background color of inline code */ --CODE-INLINE-BORDER-color: #464646; /* border color of inline code */ + --BROWSER-theme: dark; /* name of the theme for browser scrollbars of the main section */ --MERMAID-theme: dark; /* name of the default Mermaid theme for this variant, can be overridden in config.toml */ --SWAGGER-theme: dark; /* name of the default Swagger theme for this variant, can be overridden in config.toml */ diff --git a/static/css/theme-relearn-light.css b/static/css/theme-relearn-light.css index 70b9bc46b3..13b23e4a99 100644 --- a/static/css/theme-relearn-light.css +++ b/static/css/theme-relearn-light.css @@ -24,6 +24,7 @@ --CODE-INLINE-BG-color: #fffae9; /* background color of inline code */ --CODE-INLINE-BORDER-color: #f8e8c8; /* border color of inline code */ + --BROWSER-theme: light; /* name of the theme for browser scrollbars of the main section */ --MERMAID-theme: default; /* name of the default Mermaid theme for this variant, can be overridden in config.toml */ --SWAGGER-theme: light; /* name of the default Swagger theme for this variant, can be overridden in config.toml */ @@ -45,7 +46,3 @@ --BOX-BG-color: rgba( 255, 255, 255, .833 ); /* background color of colored boxes */ --BOX-TEXT-color: rgba( 16, 16, 16, 1 ); /* text color of colored box content */ } - -:root { - color-scheme: only light; /* set browser scrollbar color */ -} diff --git a/static/css/variant.css b/static/css/variant.css index 2c6da2316b..10ea26cd46 100644 --- a/static/css/variant.css +++ b/static/css/variant.css @@ -39,6 +39,7 @@ --INTERNAL-CODE-font: var(--CODE-font, "Consolas", menlo, monospace); + --INTERNAL-BROWSER-theme: var(--BROWSER-theme, light); --INTERNAL-MERMAID-theme: var(--CONFIG-MERMAID-theme, var(--MERMAID-theme, var(--INTERNAL-PRINT-MERMAID-theme))); --INTERNAL-SWAGGER-theme: var(--CONFIG-SWAGGER-theme, var(--SWAGGER-theme, var(--INTERNAL-PRINT-SWAGGER-theme))); @@ -93,15 +94,19 @@ --INTERNAL-BOX-WARNING-TEXT-color: var(--BOX-WARNING-TEXT-color, var(--INTERNAL-BOX-RED-TEXT-color)); /* print style, values taken from relearn-light as it is used as a default print style */ - --INTERNAL-PRINT-MERMAID-theme: var(--PRINT-MERMAID-theme, default); --INTERNAL-PRINT-MAIN-BG-color: var(--PRINT-MAIN-BG-color, #ffffff); --INTERNAL-PRINT-CODE-font: var(--PRINT-CODE-font, "Consolas", menlo, monospace); --INTERNAL-PRINT-TAG-BG-color: var(--PRINT-TAG-BG-color, #7dc903); --INTERNAL-PRINT-MAIN-font: var(--PRINT-MAIN-font, "Work Sans", "Helvetica", "Tahoma", "Geneva", "Arial", sans-serif); --INTERNAL-PRINT-MAIN-TEXT-color: var(--PRINT-MAIN-TEXT-color, #101010); + --INTERNAL-PRINT-MERMAID-theme: var(--PRINT-MERMAID-theme, default); --INTERNAL-PRINT-SWAGGER-theme: var(--PRINT-SWAGGER-theme, light); } +html { + color-scheme: only var(--INTERNAL-BROWSER-theme); +} + body { background-color: var(--INTERNAL-MAIN-BG-color); color: var(--INTERNAL-MAIN-TEXT-color); diff --git a/static/js/variant.js b/static/js/variant.js index e525a6cc4a..7915f174a3 100644 --- a/static/js/variant.js +++ b/static/js/variant.js @@ -575,6 +575,7 @@ var variants = { { name: 'CODE-font', group: 'code', default: '"Consolas", menlo, monospace', tooltip: 'text font of code', }, + { name: 'BROWSER-theme', group: '3rd party', default: 'light', tooltip: 'name of the theme for browser scrollbars of the main section', }, { name: 'MERMAID-theme', group: '3rd party', default: 'default', tooltip: 'name of the default Mermaid theme for this variant, can be overridden in config.toml', }, { name: 'SWAGGER-theme', group: '3rd party', default: 'light', tooltip: 'name of the default Swagger theme for this variant, can be overridden in config.toml', },