Skip to content

Commit 581e7fe

Browse files
committed
fix(dark-mode): ensure dark theme works in production
- Add inline color palette based on useColorMode - Style SourceSwitcher, Legend, Tooltip, table headers and row labels inline - Inline fallback for empty-cell background - Add Root theme wrapper to import plugin.css - Expose CSS variables globally in styles.module.css via :global selectors This fixes missing text/background colors for Source selector, Legend, and headers in production builds.
1 parent 1e73db4 commit 581e7fe

File tree

22 files changed

+347
-46
lines changed

22 files changed

+347
-46
lines changed

dist/index.mjs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,18 +2165,13 @@ function docusaurusPluginResistogram(ctx, opts = {}) {
21652165
pluginId
21662166
);
21672167
(0, import_fs_extra.ensureDirSync)(pluginDataDir);
2168-
const isProd = process.env.NODE_ENV === "production";
21692168
return {
21702169
name: "docusaurus-plugin-resistogram",
21712170
getThemePath() {
21722171
return path.resolve(__dirname, "./theme");
21732172
},
2174-
// Explicitly add the theme's stylesheet to the client modules only for the production build.
2175-
// This is a workaround for an issue where the styles are not being picked up automatically
2176-
// in the production build. In development, this is disabled to allow for hot-reloading
2177-
// and correct dark mode behavior.
21782173
getClientModules() {
2179-
return isProd ? [path.resolve(__dirname, "./theme/ResistanceTable/styles.module.css")] : [];
2174+
return [path.resolve(__dirname, "./plugin.css")];
21802175
},
21812176
async contentLoaded({ actions }) {
21822177
const { abx, org, sources, hierarchicalSources, allAbxIds, allOrgIds, orgClasses, orgIdToRank, abxSyn2Id, orgSyn2Id } = await getSharedData(dataPath, files);

dist/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+
}

dist/theme/ResistanceTable/components/Legend.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ import React from 'react';
44
// Helper function to remove type annotations for JS conversion
55
const identity = (props) => props;
66

7-
export const Legend = ({ cols, displayMode, styles }) => {
7+
export const Legend = ({ cols, displayMode, styles, palette }) => {
88
if (displayMode === 'full') return null;
99

1010
return (
11-
<div className={styles.legend}>
11+
<div
12+
className={styles.legend}
13+
style={{
14+
backgroundColor: palette?.subtleBg,
15+
borderTop: `1px solid ${palette?.border}`,
16+
color: palette?.text,
17+
}}
18+
>
1219
{cols.map((c, i) => (
1320
<span key={c.id}>
1421
<b>{displayMode === 'superCompact' ? `[${i + 1}]` : c.short}:</b>{' '}

dist/theme/ResistanceTable/components/TableBody.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const TableBody = ({
1515
styles,
1616
colorMode,
1717
sourceId2ShortName,
18+
palette,
1819
t,
1920
}) => {
2021
return (
@@ -35,6 +36,7 @@ export const TableBody = ({
3536
onHideTooltip={onHideTooltip}
3637
styles={styles}
3738
colorMode={colorMode}
39+
palette={palette}
3840
sourceId2ShortName={sourceId2ShortName}
3941
t={t}
4042
/>

dist/theme/ResistanceTable/components/TableHeader.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const TableHeader = ({
1010
onShowTooltip,
1111
onHideTooltip,
1212
styles,
13+
palette,
1314
}) => {
1415
const abxCol = { whiteSpace: 'nowrap', width: '1%' };
1516

@@ -29,6 +30,7 @@ export const TableHeader = ({
2930
onShowTooltip={onShowTooltip}
3031
onHideTooltip={onHideTooltip}
3132
styles={styles}
33+
palette={palette}
3234
/>
3335
))}
3436
</tr>

dist/theme/ResistanceTable/components/TableHeaderCell.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const TableHeaderCell = React.memo(
1212
onShowTooltip,
1313
onHideTooltip,
1414
styles,
15+
palette,
1516
}) => {
1617
const highlight = hoveredCol === colIndex;
1718

@@ -42,6 +43,7 @@ export const TableHeaderCell = React.memo(
4243
<th
4344
style={{
4445
cursor: displayMode !== 'full' ? 'help' : 'default',
46+
color: palette?.text,
4547
...(highlight ? hl : {}),
4648
}}
4749
onMouseEnter={handleMouseEnter}

dist/theme/ResistanceTable/components/TableRow.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const TableRow = React.memo(
1616
onShowTooltip,
1717
onHideTooltip,
1818
styles,
19+
palette,
1920
colorMode,
2021
sourceId2ShortName,
2122
t,
@@ -45,6 +46,7 @@ export const TableRow = React.memo(
4546
<td
4647
style={{
4748
...abxCol,
49+
color: palette?.text,
4850
...(highlight ? hl : {}),
4951
cursor: displayMode !== 'full' ? 'help' : 'default',
5052
}}

dist/theme/ResistanceTable/index.jsx

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,37 @@ export default function ResistanceTable(props) {
108108

109109
const { colorMode } = useColorMode();
110110

111+
const palette = useMemo(() => {
112+
if (colorMode === 'dark') {
113+
return {
114+
border: '#444',
115+
background: '#1e1e1e',
116+
text: '#eee',
117+
subtleBg: '#252525',
118+
subtleBgHover: '#333',
119+
sourceInfoBg: '#333',
120+
sourceInfoText: '#bbb',
121+
emptyCellBg: '#2a2a2a',
122+
tooltipBg: 'rgba(200, 200, 200, 0.9)',
123+
tooltipText: '#000',
124+
overlay: 'rgba(30, 30, 30, 0.7)',
125+
};
126+
}
127+
return {
128+
border: '#ddd',
129+
background: '#fff',
130+
text: '#333',
131+
subtleBg: '#f9f9f9',
132+
subtleBgHover: '#f0f0f0',
133+
sourceInfoBg: '#f0f0f0',
134+
sourceInfoText: '#666',
135+
emptyCellBg: '#f2f2f2',
136+
tooltipBg: 'rgba(60, 60, 60, 0.9)',
137+
tooltipText: '#fff',
138+
overlay: 'rgba(255, 255, 255, 0.7)',
139+
};
140+
}, [colorMode]);
141+
111142
const [showEmpty, setShowEmpty] = useState(showEmptyProp === 'true');
112143
const [display, setDisplay] = useState('full');
113144
const [hover, setHover] = useState({ row: null, col: null });
@@ -383,13 +414,18 @@ export default function ResistanceTable(props) {
383414
const isStale = isLoading && data && data.length > 0;
384415
const isInitialLoad = isLoading && (!data || data.length === 0);
385416

386-
if (isInitialLoad) return <div className={styles.placeholder}><div className={styles.spinner} />{t('loading')}</div>;
417+
if (isInitialLoad) return (
418+
<div className={styles.placeholder} style={{ color: palette.sourceInfoText }}>
419+
<div className={styles.spinner} style={{ border: `3px solid ${palette.subtleBgHover}`, borderTopColor: palette.text }} />
420+
{t('loading')}
421+
</div>
422+
);
387423
if (error) return <div className={styles.error}>{t('generationFailed')}: {error.message}</div>;
388424

389425
const unresolvedIds = [...unresolvedAbx, ...unresolvedOrg];
390426
if (unresolvedIds.length > 0) {
391427
return (
392-
<div className={styles.noDataContainer}>
428+
<div className={styles.noDataContainer} style={{ backgroundColor: palette.subtleBg, color: palette.text }}>
393429
<p><strong>{t('resistanceTable')}</strong></p>
394430
<p>{t('unrecognizedIdentifiers')}:</p>
395431
<ul className={styles.noDataList}>
@@ -406,7 +442,7 @@ export default function ResistanceTable(props) {
406442
const orgNames = organismIds.map(idToName);
407443

408444
return (
409-
<div className={styles.noDataContainer}>
445+
<div className={styles.noDataContainer} style={{ backgroundColor: palette.subtleBg, color: palette.text }}>
410446
<p><strong>{t('resistanceTable')}</strong></p>
411447
<p>{t('noDataForCombination')}:</p>
412448
{abxNames.length > 0 && (
@@ -424,13 +460,17 @@ export default function ResistanceTable(props) {
424460

425461
return (
426462
<>
427-
{isStale && <div className={styles.tableOverlay}><div className={styles.spinner} /></div>}
428-
<table ref={tableRef} className={styles.resistanceTable} style={{ borderCollapse: 'separate', borderSpacing: 0 }}>
429-
<TableHeader {...{ cols, displayMode: display, hoveredCol: hover.col, onSetHover: handleSetHover, onClearHover: handleClearHover, onShowTooltip: showTooltip, onHideTooltip: hideTooltip, styles }} />
430-
<TableBody {...{ data, cols, displayMode: display, rowsAreAbx, hoveredRow: hover.row, hoveredCol: hover.col, onSetHover: handleSetHover, onClearHover: handleClearHover, onShowTooltip: showTooltip, onHideTooltip: hideTooltip, styles, colorMode, sourceId2ShortName, t }} />
463+
{isStale && (
464+
<div className={styles.tableOverlay} style={{ backgroundColor: palette.overlay }}>
465+
<div className={styles.spinner} style={{ border: `3px solid ${palette.subtleBgHover}`, borderTopColor: palette.text }} />
466+
</div>
467+
)}
468+
<table ref={tableRef} className={styles.resistanceTable} style={{ borderCollapse: 'separate', borderSpacing: 0, color: palette.text }}>
469+
<TableHeader {...{ cols, displayMode: display, hoveredCol: hover.col, onSetHover: handleSetHover, onClearHover: handleClearHover, onShowTooltip: showTooltip, onHideTooltip: hideTooltip, styles, palette }} />
470+
<TableBody {...{ data, cols, displayMode: display, rowsAreAbx, hoveredRow: hover.row, hoveredCol: hover.col, onSetHover: handleSetHover, onClearHover: handleClearHover, onShowTooltip: showTooltip, onHideTooltip: hideTooltip, styles, colorMode, sourceId2ShortName, palette, t }} />
431471
</table>
432-
<Legend {...{ cols, displayMode: display, styles }} />
433-
<div className={styles.sourceInfo}>
472+
<Legend {...{ cols, displayMode: display, styles, palette }} />
473+
<div className={styles.sourceInfo} style={{ backgroundColor: palette.sourceInfoBg, borderTop: `1px solid ${palette.border}`, color: palette.sourceInfoText }}>
434474
{renderHiddenInfo()}
435475
{sourceChain.length > 0 && (
436476
<>
@@ -464,7 +504,7 @@ export default function ResistanceTable(props) {
464504
<div ref={containerRef} style={{ minHeight: '150px' }}>
465505
<div className={styles.rootContainer}>
466506
{hierarchicalSources.length > 0 && (
467-
<SourceSwitcher {...{ sources: hierarchicalSources, selected: selectedSource, onSelect: setSelectedSource, styles, locale }} />
507+
<SourceSwitcher {...{ sources: hierarchicalSources, selected: selectedSource, onSelect: setSelectedSource, styles, locale, palette }} />
468508
)}
469509
<div className={styles.tableContainer}>
470510
{renderContent()}
@@ -475,9 +515,15 @@ export default function ResistanceTable(props) {
475515
<RadixTooltip.Root open={tooltipOpen} onOpenChange={setTooltipOpen}>
476516
<RadixTooltip.Trigger asChild><VirtualTrigger ref={virtualTriggerRef} /></RadixTooltip.Trigger>
477517
<RadixTooltip.Portal>
478-
<RadixTooltip.Content side="top" align="center" sideOffset={5} className={styles.tooltipContent}>
518+
<RadixTooltip.Content
519+
side="top"
520+
align="center"
521+
sideOffset={5}
522+
className={styles.tooltipContent}
523+
style={{ backgroundColor: palette.tooltipBg, color: palette.tooltipText }}
524+
>
479525
{tooltipContent}
480-
<RadixTooltip.Arrow width={8} height={4} className={styles.tooltipArrow} />
526+
<RadixTooltip.Arrow width={8} height={4} className={styles.tooltipArrow} style={{ fill: palette.tooltipBg }} />
481527
</RadixTooltip.Content>
482528
</RadixTooltip.Portal>
483529
</RadixTooltip.Root>

dist/theme/ResistanceTable/styles.module.css

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,55 @@
11
/* ============================================================================
2-
General Styles
2+
CSS Variables (Global)
33
============================================================================ */
44

5-
:root {
5+
:global(:root) {
6+
/* Core colors */
67
--rt-border-color: #ddd;
78
--rt-background-color: #fff;
89
--rt-text-color: #333;
10+
11+
/* Component backgrounds */
912
--rt-subtle-background: #f9f9f9;
1013
--rt-subtle-background-hover: #f0f0f0;
1114
--rt-source-info-background: #f0f0f0;
1215
--rt-source-info-text: #666;
1316
--rt-empty-cell-background: #f2f2f2;
17+
18+
/* Tooltip */
1419
--rt-tooltip-background: rgba(60, 60, 60, 0.9);
1520
--rt-tooltip-text: #fff;
21+
22+
/* Shape */
1623
--rt-tab-radius: 5px;
1724
}
1825

19-
[data-theme='dark'] {
26+
/*
27+
Use a generic [data-theme='dark'] selector so variables apply
28+
regardless of whether Docusaurus sets the attribute on html or body.
29+
Wrap in :global so CSS-module scoping doesn't interfere in prod builds.
30+
*/
31+
:global([data-theme='dark']) {
32+
/* Core colors */
2033
--rt-border-color: #444;
2134
--rt-background-color: #1e1e1e;
2235
--rt-text-color: #eee;
36+
37+
/* Component backgrounds */
2338
--rt-subtle-background: #252525;
2439
--rt-subtle-background-hover: #333;
2540
--rt-source-info-background: #333;
2641
--rt-source-info-text: #bbb;
2742
--rt-empty-cell-background: #2a2a2a;
43+
44+
/* Tooltip */
2845
--rt-tooltip-background: rgba(200, 200, 200, 0.9);
2946
--rt-tooltip-text: #000;
3047
}
3148

49+
/* ============================================================================
50+
General Styles
51+
============================================================================ */
52+
3253
.error {
3354
color: red;
3455
border: 1px solid red;
@@ -291,4 +312,4 @@
291312
to {
292313
transform: rotate(360deg);
293314
}
294-
}
315+
}

0 commit comments

Comments
 (0)