8000 Dark mode for documentation by jdeniau · Pull Request #2091 · immutable-js/immutable-js · GitHub
[go: up one dir, main page]

Skip to content

Dark mode for documentation #2091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 7, 2025
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
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"globals": "^15.15.0",
"jest": "^29.0.0",
"jest-environment-jsdom": "^29.6.4",
"jsonml-html": "^1.1.0",
"jsonml-html": "^1.2.0",
"make-synchronous": "0.1.1",
"marked": "^11.2.0",
"marked-highlight": "^2.1.0",
Expand Down
1 change: 1 addition & 0 deletions website/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Metadata } from 'next';
import React from 'react';
import '../../styles/globals.css';
import '../../styles/prism-theme.css';

export const metadata: Metadata = {
title: 'Immutable.js',
Expand Down
31 changes: 27 additions & 4 deletions website/src/app/play/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,35 @@ export default function OverviewDocPage() {
<DocSearch />
<h1>Playgroud ({version})</h1>

{/*
Debug with:

List([
'apple',
'banana',
'coconut',
123,
null,
undefined,
new Date()
])
.push('dragonfruit')
.map((fruit) => upperFirst(fruit))

*/}

<ReplNoSSR
defaultValue={`const upperFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1);
defaultValue={`const upperFirst = (str) => typeof str === 'string'
? str.charAt(0).toUpperCase() + str.slice(1)
: str;

List(['apple', 'banana', 'coconut'])
.push('dragonfruit')
.map((fruit) => upperFirst(fruit))
List([
'apple',
'banana',
'coconut',
])
.push('dragonfruit')
.map((fruit) => upperFirst(fruit))
`}
/>
</div>
Expand Down
16 changes: 10 additions & 6 deletions website/src/repl/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { useEffect, useRef } from 'react';
import { basicSetup } from 'codemirror';
import { EditorView, keymap } from '@codemirror/view';
import { defaultKeymap, indentWithTab } from '@codemirror/commands';
import { EditorState } from '@codemirror/state';
import { EditorState, Extension } from '@codemirror/state';
import { javascript } from '@codemirror/lang-javascript';
// TODO activate this when we have a dark mode
// import { oneDark } from '@codemirror/theme-one-dark';
import { oneDark } from '@codemirror/theme-one-dark';
import useDarkMode from '../useDarkMode';

type Props = {
value: string;
Expand All @@ -14,6 +15,7 @@ type Props = {

export function Editor({ value, onChange }: Props): JSX.Element {
const editor = useRef<HTMLDivElement>(null);
const darkMode = useDarkMode();

const onUpdate = EditorView.updateListener.of((v) => {
onChange(v.state.doc.toString());
Expand All @@ -29,11 +31,13 @@ export function Editor({ value, onChange }: Props): JSX.Element {
basicSetup,
keymap.of([...defaultKeymap, indentWithTab]),
javascript(),
// TODO activate this when we have a dark mode
// oneDark,
darkMode ? oneDark : undefined,

onUpdate,
],
].filter(
(value: Extension | undefined): value is Extension =>
typeof value !== 'undefined'
),
});

const view = new EditorView({
Expand All @@ -44,7 +48,7 @@ export function Editor({ value, onChange }: Props): JSX.Element {
return () => {
view.destroy();
};
}, []);
}, [darkMode]);

return <div className="repl-editor" ref={editor}></div>;
}
2 changes: 1 addition & 1 deletion website/src/repl/Repl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Repl({ defaultValue }: Props): JSX.Element {

useEffect(() => {
const workerScript = `
importScripts('https://cdn.jsdelivr.net/npm/immutable@5.1.1', 'https://cdn.jsdelivr.net/npm/immutable-devtools@0.1.5');
importScripts('https://cdn.jsdelivr.net/npm/immutable@5.1.1', 'https://cdn.jsdelivr.net/npm/@jdeniau/immutable-devtools@0.2.0');

// extract all Immutable exports to have them available in the worker automatically
const {
Expand Down
18 changes: 18 additions & 0 deletions website/src/useDarkMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useEffect, useState } from 'react';

export default function useDarkMode(): boolean {
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
const [darkMode, setDarkMode] = useState(darkModeMediaQuery.matches);

useEffect(() => {
const handleChange = (e: MediaQueryListEvent) => {
setDarkMode(e.matches);
};
darkModeMediaQuery.addEventListener('change', handleChange);
return () => {
darkModeMediaQuery.removeEventListener('change', handleChange);
};
}, [darkModeMediaQuery]);

return darkMode;
}
102 changes: 37 additions & 65 deletions website/styles/globals.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@import url('//code.cdn.mozilla.net/fonts/fira.css');

:root {
color-scheme: light dark;
}

html,
body {
--link-color: #4183c4;
Expand All @@ -8,6 +12,10 @@ body {
--header-bg-color: #6dbcdb;
--body-color: #626466;
--code-block-bg-color: #f4f4f4;
--code-block-color: #484a4c;

background-color: #ffffff;
color: var(--body-color);

-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-text-size-adjust: 100%;
Expand All @@ -17,6 +25,21 @@ body {
-webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: dark) {
html,
body {
--link-color: #79a6f6;
--link-hover-color: #5683d4;
--header-color: #e0e0e0;
--header-bg-color: #2b3a42;
--body-color: #c0c0c0;
--code-block-bg-color: #2e2e2e;
--code-block-color: #d1d5da;

background-color: #121212;
}
}

body,
input {
color: var(--body-color);
Expand Down Expand Up @@ -65,8 +88,8 @@ a:hover {
pre,
code {
font-family: 'Fira Mono', Menlo, monospace;
background: #f9f8f7;
color: #484a4c;
background: var(--code-block-bg-color);
color: var(--code-block-color);
font-size: 0.9375em;
letter-spacing: -0.015em;
}
Expand Down Expand Up @@ -112,67 +135,6 @@ blockquote > :last-child {
padding-left: 2ch;
}

/* TODO: not random colors */

.token.punctuation,
.token.ignore,
.t.interfaceDef,
.t.member,
.t.callSig {
color: #808890;
}

.token.function,
.token.class-name,
.token.qualifier,
.t.fnQualifier,
.t.fnName {
color: #32308e;
}

.token.primitive,
.t.primitive {
color: #922;
}

.token.number,
.t.typeParam {
color: #905;
}

.t.typeQualifier,
.t.typeName {
color: #013679;
}

.t.param {
color: #945277;
}

.t.memberName {
color: teal;
}

.token.block-keyword,
.token.keyword,
.t.keyword {
color: #a51;
}

.token.string,
.token.regex {
color: #df5050;
}

.token.operator {
color: #a67f59;
CF34 }

.token.comment {
color: #998;
font-style: italic;
}

a.try-it {
position: absolute;
cursor: pointer;
Expand Down Expand Up @@ -458,6 +420,16 @@ img {
color: #141420;
}

@media (prefers-color-scheme: dark) {
.toolBar {
color: #bbb;
}

.toolBar .selected {
color: #fff;
}
}

@media only screen and (max-width: 680px) {
.toolBar {
display: none;
Expand Down Expand Up @@ -547,7 +519,7 @@ img {
}

.typeHeader {
color: #555;
color: light-dark(#555, #fff);
font-size: 1.5em;
font-weight: normal;
margin: 1rem 0;
Expand All @@ -560,7 +532,7 @@ img {
}

.infoHeader {
color: #555;
color: light-dark(#555, #fff);
font-size: 10px;
letter-spacing: 0.25ch;
line-height: 16px;
Expand Down
Loading
0