Skip to content

Commit ee9ed9c

Browse files
committed
fix(css): stabilize dark mode in production\n\n- Centralize RT CSS variables in src/plugin.css under :root and [data-theme='dark']\n- Use generic [data-theme='dark'] selector for robustness\n- Remove variable definitions from CSS module to avoid scoping/order issues\n\nFixes inconsistent legend/source selector backgrounds and text color in build mode.
1 parent 65ec255 commit ee9ed9c

File tree

4 files changed

+49
-36
lines changed

4 files changed

+49
-36
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "docusaurus-plugin-resistogram",
33
"version": "0.1.0",
4+
"sideEffects": [
5+
"**/*.css"
6+
],
47
"description": "A Docusaurus plugin to display resistance data tables (resistograms) from simple CSV files.",
58
"main": "dist/index.mjs",
69
"types": "dist/index.d.ts",
@@ -20,7 +23,7 @@
2023
"dist"
2124
],
2225
"scripts": {
23-
"build": "tsup src/index.ts src/remark/index.ts --format esm --dts && cp -r src/theme dist/",
26+
"build": "tsup src/index.ts src/remark/index.ts --format esm --dts && cp -r src/theme dist/ && cp src/plugin.css dist/",
2427
"dev": "tsup src/index.ts --watch",
2528
"prepare": "npm run build",
2629
"clean": "rm -rf dist",

src/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,15 @@ export default function docusaurusPluginResistogram(
4040
);
4141
ensureDirSync(pluginDataDir);
4242

43-
const isProd = process.env.NODE_ENV === 'production';
44-
4543
return {
4644
name: "docusaurus-plugin-resistogram",
4745

4846
getThemePath() {
4947
return path.resolve(__dirname, "./theme");
5048
},
5149

52-
// Explicitly add the theme's stylesheet to the client modules only for the production build.
53-
// This is a workaround for an issue where the styles are not being picked up automatically
54-
// in the production build. In development, this is disabled to allow for hot-reloading
55-
// and correct dark mode behavior.
5650
getClientModules() {
57-
return isProd ? [path.resolve(__dirname, './theme/ResistanceTable/styles.module.css')] : [];
51+
return [path.resolve(__dirname, './plugin.css')];
5852
},
5953

6054
async contentLoaded({ actions }: { actions: any }) {

src/plugin.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
:root {
2+
/* Core colors */
3+
--rt-border-color: #ddd;
4+
--rt-background-color: #fff;
5+
--rt-text-color: #333;
6+
7+
/* Component backgrounds */
8+
--rt-subtle-background: #f9f9f9;
9+
--rt-subtle-background-hover: #f0f0f0;
10+
--rt-source-info-background: #f0f0f0;
11+
--rt-source-info-text: #666;
12+
--rt-empty-cell-background: #f2f2f2;
13+
14+
/* Tooltip */
15+
--rt-tooltip-background: rgba(60, 60, 60, 0.9);
16+
--rt-tooltip-text: #fff;
17+
18+
/* Shape */
19+
--rt-tab-radius: 5px;
20+
}
21+
/*
22+
Use a generic [data-theme='dark'] selector so variables apply
23+
regardless of whether Docusaurus sets the attribute on html or body.
24+
Centralizing all variables here avoids CSS-module scoping/order issues
25+
between dev and production builds.
26+
*/
27+
[data-theme='dark'] {
28+
/* Core colors */
29+
--rt-border-color: #444;
30+
--rt-background-color: #1e1e1e;
31+
--rt-text-color: #eee;
32+
33+
/* Component backgrounds */
34+
--rt-subtle-background: #252525;
35+
--rt-subtle-background-hover: #333;
36+
--rt-source-info-background: #333;
37+
--rt-source-info-text: #bbb;
38+
--rt-empty-cell-background: #2a2a2a;
39+
40+
/* Tooltip */
41+
--rt-tooltip-background: rgba(200, 200, 200, 0.9);
42+
--rt-tooltip-text: #000;
43+
}

src/theme/ResistanceTable/styles.module.css

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,6 @@
22
General Styles
33
============================================================================ */
44

5-
:root {
6-
--rt-border-color: #ddd;
7-
--rt-background-color: #fff;
8-
--rt-text-color: #333;
9-
--rt-subtle-background: #f9f9f9;
10-
--rt-subtle-background-hover: #f0f0f0;
11-
--rt-source-info-background: #f0f0f0;
12-
--rt-source-info-text: #666;
13-
--rt-empty-cell-background: #f2f2f2;
14-
--rt-tooltip-background: rgba(60, 60, 60, 0.9);
15-
--rt-tooltip-text: #fff;
16-
--rt-tab-radius: 5px;
17-
}
18-
19-
[data-theme='dark'] {
20-
--rt-border-color: #444;
21-
--rt-background-color: #1e1e1e;
22-
--rt-text-color: #eee;
23-
--rt-subtle-background: #252525;
24-
--rt-subtle-background-hover: #333;
25-
--rt-source-info-background: #333;
26-
--rt-source-info-text: #bbb;
27-
--rt-empty-cell-background: #2a2a2a;
28-
--rt-tooltip-background: rgba(200, 200, 200, 0.9);
29-
--rt-tooltip-text: #000;
30-
}
31-
325
.error {
336
color: red;
347
border: 1px solid red;
@@ -291,4 +264,4 @@
291264
to {
292265
transform: rotate(360deg);
293266
}
294-
}
267+
}

0 commit comments

Comments
 (0)