Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions dev/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
validateStateAndSource,
} from "../src/Activity/activityState";
import { isReportScoreByItemMessage, isReportStateMessage } from "../src/types";
import { useResolvedTheme } from "../src/utils/theme";
import type { ThemeSetting } from "../src/utils/theme";

function App() {
Expand Down Expand Up @@ -55,6 +56,35 @@ function App() {
darkMode,
} = testSettings;

// Resolve the selected dark-mode setting so the dev-harness chrome (the
// gray header box and its controls) tracks the same theme as the viewer
// below it, rather than staying light.
const resolvedTheme = useResolvedTheme(darkMode);

// Keep the whole dev page — the body backdrop and native form controls —
// in step with the selection, not just the OS preference that index.css
// keys off of. Match the backdrop to the viewer's `--canvas` color so the
// area below/around the activities doesn't read as a lighter black.
useEffect(() => {
const root = document.documentElement;
root.style.colorScheme = resolvedTheme;
root.style.backgroundColor =
resolvedTheme === "dark" ? "#121212" : "#ffffff";
return () => {
root.style.colorScheme = "";
root.style.backgroundColor = "";
};
}, [resolvedTheme]);

// Native <button>s take their background from dev/index.css, which keys off
// the OS `prefers-color-scheme` and so drifts out of sync with the selected
// theme (e.g. a white button background under a dark selection, giving
// white-on-white). Pin the dev-chrome buttons to the resolved selection.
const devButtonColors = {
backgroundColor: resolvedTheme === "dark" ? "#1a1a1a" : "#f9f9f9",
color: resolvedTheme === "dark" ? "white" : "black",
};

let controls = null;
let buttonText = "show";
if (controlsVisible) {
Expand All @@ -73,6 +103,7 @@ function App() {
setUpdateNumber((was) => was + 1);
}}
style={{
...devButtonColors,
padding: "2px",
marginLeft: "12px",
width: "80px",
Expand Down Expand Up @@ -237,8 +268,7 @@ function App() {
onChange={(e) => {
setTestSettings((was) => ({
...was,
darkMode: e.target
.value as ThemeSetting,
darkMode: e.target.value as ThemeSetting,
}));
setUpdateNumber((was) => was + 1);
}}
Expand Down Expand Up @@ -329,8 +359,10 @@ function App() {
<div style={{ marginBottom: "50vh" }}>
<div
style={{
backgroundColor: "lightGray",
color: "black",
backgroundColor:
resolvedTheme === "dark" ? "#2a2a2a" : "lightGray",
color: resolvedTheme === "dark" ? "white" : "black",
colorScheme: resolvedTheme,
width: "800px",
padding: "20px",
}}
Expand All @@ -343,6 +375,7 @@ function App() {
setControlsVisible((was) => !was);
}}
style={{
...devButtonColors,
padding: "2px",
marginLeft: "12px",
width: "160px",
Expand Down
12 changes: 6 additions & 6 deletions dev/testActivity.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"type": "singleDoc",
"isDescription": false,
"doenetML": "<problem>2+2=<answer>4</answer><selectFromSequence /></problem>",
"version": "0.7.4",
"version": "0.7.20-dev.332",
"numVariants": 10
},
{
Expand All @@ -25,7 +25,7 @@
"type": "singleDoc",
"isDescription": false,
"doenetML": "<problem>1+1=<answer>2</answer><selectFromSequence length='3' /></problem><problem>4+4=<answer>8</answer><selectFromSequence length='4' /></problem>",
"version": "0.7.4",
"version": "0.7.20-dev.332",
"numVariants": 12
}
]
Expand All @@ -41,31 +41,31 @@
"type": "singleDoc",
"isDescription": false,
"doenetML": "<question>Question 1A <graph><point name='P'/></graph><answer><award><when>$P.x > 0</when></award></answer></question>",
"version": "0.7.4",
"version": "0.7.20-dev.332",
"numVariants": 1
},
{
"id": "sel2b",
"type": "singleDoc",
"isDescription": false,
"doenetML": "<question>Question 1B <p>Enter: <select name='a'>a b c</select>. <answer>$a</answer></p></question>",
"version": "0.7.4",
"version": "0.7.20-dev.332",
"numVariants": 3
},
{
"id": "sel2c",
"type": "singleDoc",
"isDescription": false,
"doenetML": "<question>Question 1C <p>Enter: <selectFromSequence name='a' />. <answer>$a</answer></p></question>",
"version": "0.7.4",
"version": "0.7.20-dev.332",
"numVariants": 10
},
{
"id": "sel2d",
"type": "singleDoc",
"isDescription": false,
"doenetML": "<question>Question 1D <p>Enter: <selectFromSequence name='a' length=\"5\" />. <answer>$a</answer></p></question>",
"version": "0.7.4",
"version": "0.7.20-dev.332",
"numVariants": 5
}
]
Expand Down