Skip to content

Commit 1fd7786

Browse files
committed
Color schema toggle (not stored yet)
1 parent 49cfefe commit 1fd7786

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

src/app/global.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:root {
2-
--bs-body-color-rgb: 33, 37, 41;
3-
--bs-body-bg-rgb: 255, 255, 255;
2+
/*--bs-body-color-rgb: 33, 37, 41;
3+
--bs-body-bg-rgb: 255, 255, 255;*/
44
--bs-font-sans-serif: "IBM Plex Sans", "Helvetica Neue", sans-serif;
55
--bs-font-serif: "IBM Plex Serif", serif;
66
--bs-font-monospace: "IBM Plex Mono", monospace;
@@ -9,6 +9,6 @@
99
--bs-body-font-size: 1.25em;
1010
--bs-body-font-weight: 400;
1111
--bs-body-line-height: 1.5;
12-
--bs-body-color: #212121;
13-
--bs-body-bg: #fff;
12+
/*--bs-body-color: #212121;
13+
--bs-body-bg: #fff;*/
1414
}

src/app/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function Home() {
6262
<div className="card m-3 d-inline-block" style={{ "width": "18rem" }}>
6363
<h5 className="card-header xborder-bottom p-3 bg-body-tertiary">Regex Zone</h5>
6464
<div className="card-body pt-1">
65-
The <a href="https://www.regex.zone/">Regex Zone</a> is a place to share regular expressions, and learn from others. It is a community of regex enthusiasts.
65+
The <a href="https://www.regex.zone/">Regex Zone</a> is the place to share regular expressions and find common regex patterns.
6666
<div className="pt-2 d-flex justify-content-center">
6767
<a className="btn btn-primary" href="https://www.regex.zone/" rel="nofollow">Visit the Regex Zone</a>
6868
</div>
@@ -74,14 +74,14 @@ export default function Home() {
7474
<hr />
7575

7676
<h2 className="mt-3">One last thing</h2>
77-
<div className="card my-3 bg-light">
77+
<div className="card my-3 bg-body-tertiary">
7878
<div className="card-body">
7979
Some people, when confronted with a problem, think &ldquo;I know, I’ll use regular expressions.&rdquo; Now they have two problems.<br />
8080
&nbsp;&nbsp;-- <a href="http://www.jwz.org/">Jamie Zawinski</a> in comp.lang.emacs (or <a href="http://regex.info/blog/2006-09-15/247">somewhere else</a>).
8181
</div>
8282
</div>
8383

84-
<div className="card my-3 bg-light">
84+
<div className="card my-3 bg-body-tertiary">
8585
<div className="card-body">
8686
I define UNIX as &ldquo;30 definitions of regular expressions living under one roof&rdquo;.<br />
8787
&nbsp;&nbsp;-- <a href="https://www-cs-faculty.stanford.edu/~knuth/">Donald Knuth</a> in <a href="http://amzn.to/GXRTbS">Digital Typography</a>, ch. 33, p. 649 (1999) via <a href="http://code.google.com/p/re2/wiki/Syntax">re2</a>.

src/components/ColorSchemeToggle.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use client'
2+
import React from "react";
3+
4+
function getColorScheme() {
5+
6+
if (typeof window === 'undefined') {
7+
return 'light';
8+
}
9+
10+
if (document.documentElement.hasAttribute('data-bs-theme')) {
11+
return document.documentElement.getAttribute('data-bs-theme');
12+
}
13+
14+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
15+
return 'dark';
16+
} else {
17+
return 'light';
18+
}
19+
}
20+
21+
export function ColorSchemeToggle() {
22+
const [currentScheme, setColorScheme] = React.useState(getColorScheme());
23+
24+
const onClick = (scheme: 'light' | 'dark' | 'auto') => {
25+
if (scheme == 'auto') {
26+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
27+
scheme = 'dark';
28+
} else {
29+
scheme = 'light';
30+
}
31+
}
32+
document.documentElement.setAttribute('data-bs-theme', scheme);
33+
setColorScheme(scheme);
34+
}
35+
36+
return (
37+
<div className="btn-group" role="group" aria-label="Color scheme selector">
38+
<button className={`btn btn-sm ${currentScheme == 'light' ? 'btn-primary' : 'btn-outline-primary'}`} onClick={() => onClick('light')}>Light</button>
39+
<button className={`btn btn-sm ${currentScheme == 'dark' ? 'btn-primary' : 'btn-outline-primary'}`} onClick={() => onClick('dark')}>Dark</button>
40+
</div>
41+
);
42+
}

src/components/Footer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Link from 'next/link';
22

3+
import { ColorSchemeToggle } from './ColorSchemeToggle';
4+
35
const links = [
46
{ link: 'https://github.com/regexplanet/regexplanet-next?tab=readme-ov-file#credits', label: 'Credits' },
57
{ link: 'https://github.com/regexplanet/regexplanet-next', label: 'Source' },
@@ -24,9 +26,9 @@ export function Footer() {
2426
return (
2527
<div className="container-lg py-3">
2628
<hr />
27-
<footer className="d-flex justify-content-center text-body-tertiary"><small>
29+
<footer className="d-flex justify-content-center text-body-tertiary"><small className="me-3">
2830
{initial}
29-
</small></footer>
31+
</small> <ColorSchemeToggle /></footer>
3032
</div>
3133
)
3234
}

0 commit comments

Comments
 (0)