Toggle colorscheme on Demo body
This commit is contained in:
parent
863246eed0
commit
4b42e4b0de
3 changed files with 28 additions and 1 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
<div class="hero-body">
|
<div class="hero-body">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="title is-size-1 is-spaced">Demo<a href="#help">
|
<h1 class="title is-size-1 is-spaced">Demo<a href="#help">
|
||||||
<svg height="32" class="octicon octicon-unverified" viewBox="0 0 16 16" version="1.1" width="64"
|
<svg fill="currentColor" height="32" class="octicon octicon-unverified" viewBox="0 0 16 16" version="1.1" width="64"
|
||||||
aria-hidden="true">
|
aria-hidden="true">
|
||||||
<path
|
<path
|
||||||
d="M15.67 7.06l-1.08-1.34c-.17-.22-.28-.48-.31-.77l-.19-1.7a1.51 1.51 0 0 0-1.33-1.33l-1.7-.19c-.3-.03-.56-.16-.78-.33L8.94.32c-.55-.44-1.33-.44-1.88 0L5.72 1.4c-.22.17-.48.28-.77.31l-1.7.19c-.7.08-1.25.63-1.33 1.33l-.19 1.7c-.03.3-.16.56-.33.78L.32 7.05c-.44.55-.44 1.33 0 1.88l1.08 1.34c.17.22.28.48.31.77l.19 1.7c.08.7.63 1.25 1.33 1.33l1.7.19c.3.03.56.16.78.33l1.34 1.08c.55.44 1.33.44 1.88 0l1.34-1.08c.22-.17.48-.28.77-.31l1.7-.19c.7-.08 1.25-.63 1.33-1.33l.19-1.7c.03-.3.16-.56.33-.78l1.08-1.34c.44-.55.44-1.33 0-1.88zM9 11.5c0 .28-.22.5-.5.5h-1c-.27 0-.5-.22-.5-.5v-1c0-.28.23-.5.5-.5h1c.28 0 .5.22.5.5v1zm1.56-4.89c-.06.17-.17.33-.3.47-.13.16-.14.19-.33.38-.16.17-.31.3-.52.45-.11.09-.2.19-.28.27-.08.08-.14.17-.19.27-.05.1-.08.19-.11.3-.03.11-.03.13-.03.25H7.13c0-.22 0-.31.03-.48.03-.19.08-.36.14-.52.06-.14.14-.28.25-.42.11-.13.23-.25.41-.38.27-.19.36-.3.48-.52.12-.22.2-.38.2-.59 0-.27-.06-.45-.2-.58-.13-.13-.31-.19-.58-.19-.09 0-.19.02-.3.05-.11.03-.17.09-.25.16-.08.07-.14.11-.2.2a.41.41 0 0 0-.09.28h-2c0-.38.13-.56.27-.83.16-.27.36-.5.61-.67.25-.17.55-.3.88-.38.33-.08.7-.13 1.09-.13.44 0 .83.05 1.17.13.34.09.63.22.88.39.23.17.41.38.55.63.13.25.19.55.19.88 0 .22 0 .42-.08.59l-.02-.01z">
|
d="M15.67 7.06l-1.08-1.34c-.17-.22-.28-.48-.31-.77l-.19-1.7a1.51 1.51 0 0 0-1.33-1.33l-1.7-.19c-.3-.03-.56-.16-.78-.33L8.94.32c-.55-.44-1.33-.44-1.88 0L5.72 1.4c-.22.17-.48.28-.77.31l-1.7.19c-.7.08-1.25.63-1.33 1.33l-.19 1.7c-.03.3-.16.56-.33.78L.32 7.05c-.44.55-.44 1.33 0 1.88l1.08 1.34c.17.22.28.48.31.77l.19 1.7c.08.7.63 1.25 1.33 1.33l1.7.19c.3.03.56.16.78.33l1.34 1.08c.55.44 1.33.44 1.88 0l1.34-1.08c.22-.17.48-.28.77-.31l1.7-.19c.7-.08 1.25-.63 1.33-1.33l.19-1.7c.03-.3.16-.56.33-.78l1.08-1.34c.44-.55.44-1.33 0-1.88zM9 11.5c0 .28-.22.5-.5.5h-1c-.27 0-.5-.22-.5-.5v-1c0-.28.23-.5.5-.5h1c.28 0 .5.22.5.5v1zm1.56-4.89c-.06.17-.17.33-.3.47-.13.16-.14.19-.33.38-.16.17-.31.3-.52.45-.11.09-.2.19-.28.27-.08.08-.14.17-.19.27-.05.1-.08.19-.11.3-.03.11-.03.13-.03.25H7.13c0-.22 0-.31.03-.48.03-.19.08-.36.14-.52.06-.14.14-.28.25-.42.11-.13.23-.25.41-.38.27-.19.36-.3.48-.52.12-.22.2-.38.2-.59 0-.27-.06-.45-.2-.58-.13-.13-.31-.19-.58-.19-.09 0-.19.02-.3.05-.11.03-.17.09-.25.16-.08.07-.14.11-.2.2a.41.41 0 0 0-.09.28h-2c0-.38.13-.56.27-.83.16-.27.36-.5.61-.67.25-.17.55-.3.88-.38.33-.08.7-.13 1.09-.13.44 0 .83.05 1.17.13.34.09.63.22.88.39.23.17.41.38.55.63.13.25.19.55.19.88 0 .22 0 .42-.08.59l-.02-.01z">
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,21 @@
|
||||||
.diff-url-btn.is-small {
|
.diff-url-btn.is-small {
|
||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.d2h-dark-color-scheme .title {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.d2h-dark-color-scheme .footer {
|
||||||
|
background-color: #2d2d2d;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
.d2h-auto-color-scheme .title {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.d2h-auto-color-scheme .footer {
|
||||||
|
background-color: #2d2d2d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import '../../../main.css';
|
||||||
import 'highlight.js/styles/github.css';
|
import 'highlight.js/styles/github.css';
|
||||||
import '../../../../src/ui/css/diff2html.css';
|
import '../../../../src/ui/css/diff2html.css';
|
||||||
import './demo.css';
|
import './demo.css';
|
||||||
|
import { colorSchemeToCss } from '../../../../src/render-utils';
|
||||||
|
import { ColorSchemeType } from '../../../../src/types';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Example URLs:
|
* Example URLs:
|
||||||
|
|
@ -155,9 +157,16 @@ async function getDiff(request: Request): Promise<string> {
|
||||||
|
|
||||||
function draw(diffString: string, config: Diff2HtmlUIConfig, elements: Elements): void {
|
function draw(diffString: string, config: Diff2HtmlUIConfig, elements: Elements): void {
|
||||||
const diff2htmlUi = new Diff2HtmlUI(elements.structure.diffTarget, diffString, config);
|
const diff2htmlUi = new Diff2HtmlUI(elements.structure.diffTarget, diffString, config);
|
||||||
|
|
||||||
|
setBodyColorScheme(diff2htmlUi.config.colorScheme);
|
||||||
|
|
||||||
diff2htmlUi.draw();
|
diff2htmlUi.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setBodyColorScheme(colorScheme: ColorSchemeType): void {
|
||||||
|
document.body.className = colorSchemeToCss(colorScheme);
|
||||||
|
}
|
||||||
|
|
||||||
async function prepareInitialState(elements: Elements): Promise<[Diff2HtmlUIConfig, string]> {
|
async function prepareInitialState(elements: Elements): Promise<[Diff2HtmlUIConfig, string]> {
|
||||||
const urlParams = getParamsFromSearch(window.location.search);
|
const urlParams = getParamsFromSearch(window.location.search);
|
||||||
const currentUrl = (urlParams && urlParams[searchParam]) || 'https://github.com/rtfpessoa/diff2html/pull/106';
|
const currentUrl = (urlParams && urlParams[searchParam]) || 'https://github.com/rtfpessoa/diff2html/pull/106';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue