Skip to content

Commit

Permalink
feat(ui): support dask mode
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Oct 4, 2024
1 parent ae42d45 commit 529936e
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions packages/~/app/layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@~/app.core": "workspace:*",
"@~/app.middleware": "workspace:*",
"@~/app.ui": "workspace:*",
"@~/app.urls": "workspace:*",
"hono": "4.6.3",
"nprogress": "0.2.0"
Expand Down
2 changes: 2 additions & 0 deletions packages/~/app/layout/src/root.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//

import type { App_Context } from "@~/app.middleware/context";
import { set_prefers_color_scheme } from "@~/app.ui/scheme/scripts";
import { html } from "hono/html";
import type { PropsWithChildren } from "hono/jsx";
import { useRequestContext } from "hono/jsx-renderer";
Expand All @@ -14,6 +15,7 @@ export function Root_Layout({ children }: PropsWithChildren) {

return html`
<html
_=${set_prefers_color_scheme}
lang="fr"
data-fr-scheme="system"
hx-ext="${[
Expand Down
3 changes: 3 additions & 0 deletions packages/~/app/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"./quote": {
"default": "./src/quote/index.ts"
},
"./scheme/scripts": {
"default": "./src/scheme/scripts/index.ts"
},
"./table": {
"default": "./src/table/index.ts"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/~/app/ui/src/scheme/scripts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//

export { set_prefers_color_scheme } from "./prefers_color_scheme";
26 changes: 26 additions & 0 deletions packages/~/app/ui/src/scheme/scripts/prefers_color_scheme.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//

import { expect, test } from "bun:test";
import "htmx.org";
import _hyperscript from "hyperscript.org";
import { set_prefers_color_scheme } from "./prefers_color_scheme";

//

test("set_prefers_color_scheme", () => {
document.body.innerHTML = `
<html _="${set_prefers_color_scheme}" ></html>
`;

_hyperscript.processNode(document.body);

//

const html = document.querySelector("html")!;
expect(html.outerHTML).toEqual("My html");

Check failure on line 20 in packages/~/app/ui/src/scheme/scripts/prefers_color_scheme.test.ts

View workflow job for this annotation

GitHub Actions / build

error: expect(received).toEqual(expected)

Expected: "My html" Received: "<html><head><style> .htmx-indicator{opacity:0} .htmx-request .htmx-indicator{opacity:1; transition: opacity 200ms ease-in;} .htmx-request.htmx-indicator{opacity:1; transition: opacity 200ms ease-in;} </style></head><body>\n <html _=\"\n-- from https://github.com/sqwxl/harfang/blob/afb20cbc60c9eb44d2ce0501a7f754afc7395915/app/templates/partials/theme_toggle.html#L59C33-L84C1\ndef nextTheme()\n set currentTheme to localStorage.theme\n set prefersDark to window.matchMedia(\" prefers-color-scheme:=\"\" dark=\"\" .matches=\"\" if=\"\" prefersdark=\"\" --=\"\" auto=\"\" -=\"\"> light -&gt; dark\n if no currentTheme\n return \"light\"\n else if currentTheme is \"light\"\n return \"dark\"\n else\n return null\n end\n else\n -- auto(light) -&gt; dark -&gt; light\n if no currentTheme\n return \"dark\"\n else if currentTheme is \"dark\"\n return \"light\"\n else\n return null\n end\n end\nend\n\non load\n set theme to nextTheme()\n if no theme\n call localStorage.removeItem(\"theme\")\n else\n set localStorage.theme to theme\n end\n\" &gt;</html>\n </body></html>" at /home/runner/work/hyyypertool/hyyypertool/packages/~/app/ui/src/scheme/scripts/prefers_color_scheme.test.ts:20:26
// expect(button.getAttribute("disabled")).toBeNull();
// button.click();
// expect(button.getAttribute("disabled")).toBe("true");
// button.dispatchEvent(new Event("htmx:afterOnLoad"));
// expect(button.getAttribute("disabled")).toBeNull();
});
41 changes: 41 additions & 0 deletions packages/~/app/ui/src/scheme/scripts/prefers_color_scheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//

//
// Inspired by https://github.com/GouvernementFR/dsfr/blob/fe9d66b4ccaa7c3a3c0cb07eca69ddd6787965c4/src/scheme/script/scheme/scheme-boot.js#L14
//

export const set_prefers_color_scheme = `
-- from https://github.com/sqwxl/harfang/blob/afb20cbc60c9eb44d2ce0501a7f754afc7395915/app/templates/partials/theme_toggle.html#L59C33-L84C1
def nextTheme()
set currentTheme to localStorage.theme
set prefersDark to window.matchMedia("(prefers-color-scheme: dark)").matches
if prefersDark
-- auto(dark) -> light -> dark
if no currentTheme
return "light"
else if currentTheme is "light"
return "dark"
else
return null
end
else
-- auto(light) -> dark -> light
if no currentTheme
return "dark"
else if currentTheme is "dark"
return "light"
else
return null
end
end
end
on load
set theme to nextTheme()
if no theme
call localStorage.removeItem("theme")
else
set localStorage.theme to theme
end
`;

0 comments on commit 529936e

Please sign in to comment.