Skip to content

Commit 2678cb2

Browse files
jderochervlkcodex
andcommitted
fix(playground): improve light mode contrast and cover theme toggle flow
Improve light-mode readability for the Auto-run control and center divider styling. Add Cypress coverage for toast-driven light mode switch and switching back to dark in settings. Co-authored-by: Codex <codex@openai.com>
1 parent e3c8236 commit 2678cb2

3 files changed

Lines changed: 54 additions & 9 deletions

File tree

e2e/Playground.cy.res

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,34 @@ describe("Playground", () => {
6464
->shouldContainText("Hello ReScript!")
6565
->ignore
6666
})
67+
68+
it("should switch to light mode from toast and back to dark mode in settings", () => {
69+
// Navigate to playground and wait for initial render
70+
clickNavLink(~testId="navbar-primary-left-content", ~text="Playground")
71+
url()->shouldInclude("/try")->ignore
72+
waitForPlayground()
73+
74+
// Switch to light mode through the onboarding toast
75+
getByTestId("playground-lightmode-toast")
76+
->should("be.visible")
77+
->find("button")
78+
->containsChainable("Try it now")
79+
->click
80+
->ignore
81+
82+
// Verify playground shell is in light mode
83+
get("main")->shouldWithValue("have.class", "bg-gray-5")->ignore
84+
85+
// Switch back to dark mode from Settings
86+
contains("Settings")->click->ignore
87+
contains("Playground Theme")
88+
->closest("div")
89+
->find("button")
90+
->containsChainable("Dark")
91+
->click
92+
->ignore
93+
94+
// Verify playground shell is back to dark mode
95+
get("main")->shouldWithValue("have.class", "bg-gray-100")->ignore
96+
})
6797
})

src/Playground.res

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,7 @@ module ControlPanel = {
13111311
<div className="flex flex-row gap-x-2" dataTestId="control-panel">
13121312
<ToggleButton
13131313
checked=autoRun
1314+
isLightTheme={!isDarkTheme(theme)}
13141315
onChange={_ => {
13151316
switch state {
13161317
| Ready({autoRun: false}) => setCurrentTab(_ => Output)
@@ -2229,14 +2230,20 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
22292230
<div
22302231
ref={ReactDOM.Ref.domRef((Obj.magic(separatorRef): React.ref<Nullable.t<Dom.element>>))}
22312232
// TODO: touch-none not applied
2232-
className={"flex items-center justify-center touch-none select-none opacity-30 hover:opacity-50 rounded-lg " ++
2233-
(isDarkTheme(theme) ? "bg-gray-70" : "bg-gray-20") ++
2233+
className={"flex items-center justify-center touch-none select-none rounded-lg " ++
2234+
(isDarkTheme(theme)
2235+
? "bg-gray-70 opacity-30 hover:opacity-50"
2236+
: "bg-gray-20 border border-gray-30 opacity-100 hover:bg-gray-30") ++
22342237
" " ++ (layout == Column ? "cursor-row-resize" : "cursor-col-resize")}
22352238
onMouseDown={onMouseDown}
22362239
onTouchStart={onTouchStart}
22372240
onTouchEnd={onMouseUp}
22382241
>
2239-
<span className={`m-0.5 ${layout == Column ? "rotate-90" : ""}`}>
2242+
<span
2243+
className={"m-0.5 " ++
2244+
(isDarkTheme(theme) ? "text-gray-20" : "text-gray-60") ++
2245+
" " ++ (layout == Column ? "rotate-90" : "")}
2246+
>
22402247
{React.string("⣿")}
22412248
</span>
22422249
</div>

src/components/ToggleButton.res

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
@react.component
2-
let make = (~checked, ~onChange, ~children) => {
2+
let make = (~checked, ~onChange, ~children, ~isLightTheme=false) => {
3+
let switchThemeClass = if isLightTheme {
4+
"bg-gray-30 after:bg-white after:border-gray-40 border-gray-40 peer-checked:bg-sky"
5+
} else {
6+
"bg-gray-700 after:bg-white after:border-gray-300 border-gray-600 peer-checked:bg-sky"
7+
}
8+
9+
let labelThemeClass = isLightTheme ? "text-gray-80" : "text-gray-300"
10+
311
<label className="inline-flex items-center cursor-pointer">
412
<input type_="checkbox" value="" checked onChange className="sr-only peer" />
513
<div
6-
className={`relative w-8 h-4 bg-gray-700
14+
className={`relative w-8 h-4
715
rounded-full peer peer-checked:after:translate-x-full
816
peer-checked:rtl:after:-translate-x-full peer-checked:after:border-white
917
after:content-[''] after:absolute after:top-[2px] after:start-[4px]
10-
after:bg-white after:border-gray-300 after:border after:rounded-full
11-
after:h-3 after:w-3 after:transition-all border-gray-600
12-
peer-checked:bg-sky`}
18+
after:border after:rounded-full
19+
after:h-3 after:w-3 after:transition-all ` ++
20+
switchThemeClass}
1321
/>
14-
<span className={"ms-2 text-sm text-gray-300"}> {children} </span>
22+
<span className={"ms-2 text-sm " ++ labelThemeClass}> {children} </span>
1523
</label>
1624
}

0 commit comments

Comments
 (0)