Skip to content

Commit 09e0f15

Browse files
authored
Move colors into CSS Modules (#290)
Since we can use these classes in multiple places, this moves them to a CSS Modules file that can be imported. This is natively supported with Vite.
1 parent 03248f8 commit 09e0f15

File tree

10 files changed

+78
-74
lines changed

10 files changed

+78
-74
lines changed

package-lock.json

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"globals": "^17.1.0",
6969
"jsdom": "^27.4.0",
7070
"prettier": "^3.8.1",
71-
"sass-embedded": "^1.97.3",
7271
"typescript": "^5.9.3",
7372
"typescript-eslint": "^8.53.1",
7473
"vite": "^7.3.1",
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
.fc .fc-scrollgrid-section > td,
33
.fc .fc-timegrid-axis {
44
border-color: transparent;
5-
6-
.dark & {
7-
border-color: transparent;
8-
}
95
}
106

117
.fc .fc-timegrid-slot {

src/components/Calendar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Slot } from "../lib/dates";
1414
import { Class } from "../lib/class";
1515
import { HydrantContext } from "../lib/hydrant";
1616

17-
import "./Calendar.scss";
17+
import "./Calendar.css";
1818

1919
/**
2020
* Calendar showing all the activities, including the buttons on top that
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.row {
2+
cursor: pointer;
3+
}
4+
5+
.row:hover .underline-on-hover {
6+
text-decoration: underline;
7+
}

src/components/ClassTable.scss

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/components/ClassTable.tsx

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
ExternalFilterModule,
1818
RenderApiModule,
1919
CellStyleModule,
20+
RowStyleModule,
2021
themeQuartz,
2122
type IRowNode,
2223
type ColDef,
@@ -41,9 +42,11 @@ import type { Class, Flags } from "../lib/class";
4142
import { DARK_IMAGES, getFlagImg } from "../lib/class";
4243
import { classNumberMatch, classSort, simplifyString } from "../lib/utils";
4344
import type { TSemester } from "../lib/dates";
44-
import "./ClassTable.scss";
4545
import { HydrantContext } from "../lib/hydrant";
4646
import type { State } from "../lib/state";
47+
import { ColorStyles } from "../lib/colors";
48+
49+
import styles from "./ClassTable.module.css";
4750

4851
const hydrantTheme = themeQuartz.withParams({
4952
accentColor: "var(--chakra-colors-fg)",
@@ -62,25 +65,18 @@ const GRID_MODULES: Module[] = [
6265
ExternalFilterModule,
6366
CellStyleModule,
6467
RenderApiModule,
68+
RowStyleModule,
6569
...(import.meta.env.DEV ? [ValidationModule] : []),
6670
];
6771

6872
ModuleRegistry.registerModules(GRID_MODULES);
6973

70-
enum ColorEnum {
71-
Muted = "ag-cell-muted-text",
72-
Success = "ag-cell-success-text",
73-
Warning = "ag-cell-warning-text",
74-
Error = "ag-cell-error-text",
75-
Normal = "ag-cell-normal-text",
76-
}
77-
7874
const getRatingColor = (rating?: string | null) => {
79-
if (!rating || rating === "N/A") return ColorEnum.Muted;
75+
if (!rating || rating === "N/A") return ColorStyles.Muted;
8076
const ratingNumber = Number(rating);
81-
if (ratingNumber >= 6) return ColorEnum.Success;
82-
if (ratingNumber >= 5) return ColorEnum.Warning;
83-
return ColorEnum.Error;
77+
if (ratingNumber >= 6) return ColorStyles.Success;
78+
if (ratingNumber >= 5) return ColorStyles.Warning;
79+
return ColorStyles.Error;
8480
};
8581

8682
const getHoursColor = (
@@ -89,9 +85,9 @@ const getHoursColor = (
8985
term: TSemester,
9086
half: number | undefined,
9187
) => {
92-
if (!hours || hours === "N/A") return ColorEnum.Muted;
93-
if (totalUnits === undefined) return ColorEnum.Muted;
94-
if (totalUnits === 0) return ColorEnum.Normal;
88+
if (!hours || hours === "N/A") return ColorStyles.Muted;
89+
if (totalUnits === undefined) return ColorStyles.Muted;
90+
if (totalUnits === 0) return ColorStyles.Normal;
9591

9692
const hoursNumber = Number(hours);
9793
let weeksInTerm = 0;
@@ -115,9 +111,9 @@ const getHoursColor = (
115111
const expectedHours = totalUnits * (weeksInTerm / 14) * (half ? 2 : 1);
116112
const proportion = hoursNumber / expectedHours;
117113

118-
if (proportion < 0.8) return ColorEnum.Success;
119-
if (proportion >= 0.8 && proportion <= 1.2) return ColorEnum.Warning;
120-
return ColorEnum.Error;
114+
if (proportion < 0.8) return ColorStyles.Success;
115+
if (proportion >= 0.8 && proportion <= 1.2) return ColorStyles.Warning;
116+
return ColorStyles.Error;
121117
};
122118

123119
/** A single row in the class table. */
@@ -538,6 +534,7 @@ export function ClassTable() {
538534
comparator: classSort,
539535
initialSort,
540536
maxWidth: 93,
537+
cellClass: styles["underline-on-hover"],
541538
...sortProps,
542539
},
543540
{
@@ -617,6 +614,7 @@ export function ClassTable() {
617614
<AgGridReact<ClassTableRow>
618615
theme={hydrantTheme}
619616
ref={gridRef}
617+
rowClass={styles.row}
620618
defaultColDef={defaultColDef}
621619
columnDefs={columnDefs}
622620
rowData={rowData}

src/components/PEClassTable.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ExternalFilterModule,
1919
RenderApiModule,
2020
CellStyleModule,
21+
RowStyleModule,
2122
themeQuartz,
2223
type IRowNode,
2324
type ColDef,
@@ -37,9 +38,11 @@ import { LuPlus, LuMinus, LuSearch, LuStar } from "react-icons/lu";
3738

3839
import { type PEFlags, type PEClass, getPEFlagEmoji } from "../lib/pe";
3940
import { classNumberMatch, classSort, simplifyString } from "../lib/utils";
40-
import "./ClassTable.scss";
4141
import { HydrantContext } from "../lib/hydrant";
4242
import type { State } from "../lib/state";
43+
import { ColorStyles } from "../lib/colors";
44+
45+
import styles from "./ClassTable.module.css";
4346

4447
const hydrantTheme = themeQuartz.withParams({
4548
accentColor: "var(--chakra-colors-fg)",
@@ -57,25 +60,18 @@ const GRID_MODULES: Module[] = [
5760
ClientSideRowModelModule,
5861
ExternalFilterModule,
5962
CellStyleModule,
63+
RowStyleModule,
6064
RenderApiModule,
6165
...(import.meta.env.DEV ? [ValidationModule] : []),
6266
];
6367

6468
ModuleRegistry.registerModules(GRID_MODULES);
6569

66-
enum ColorEnum {
67-
Muted = "ag-cell-muted-text",
68-
Success = "ag-cell-success-text",
69-
Warning = "ag-cell-warning-text",
70-
Error = "ag-cell-error-text",
71-
Normal = "ag-cell-normal-text",
72-
}
73-
7470
const getFeeColor = (fee: number) => {
75-
if (isNaN(fee)) return ColorEnum.Muted;
76-
if (fee == 0) return ColorEnum.Success;
77-
if (fee <= 20) return ColorEnum.Warning;
78-
return ColorEnum.Error;
71+
if (isNaN(fee)) return ColorStyles.Muted;
72+
if (fee == 0) return ColorStyles.Success;
73+
if (fee <= 20) return ColorStyles.Warning;
74+
return ColorStyles.Error;
7975
};
8076

8177
/** A single row in the class table. */
@@ -418,6 +414,7 @@ export function PEClassTable() {
418414
comparator: classSort,
419415
initialSort,
420416
maxWidth: 93,
417+
cellClass: styles["underline-on-hover"],
421418
...sortProps,
422419
},
423420
{
@@ -496,6 +493,7 @@ export function PEClassTable() {
496493
<AgGridReact<ClassTableRow>
497494
theme={hydrantTheme}
498495
ref={gridRef}
496+
rowClass={styles.row}
499497
defaultColDef={defaultColDef}
500498
columnDefs={columnDefs}
501499
rowData={rowData}

src/lib/colors.module.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.muted {
2+
color: var(--chakra-colors-fg-muted);
3+
}
4+
5+
.success {
6+
color: var(--chakra-colors-fg-success);
7+
}
8+
9+
.warning {
10+
color: var(--chakra-colors-fg-warning);
11+
}
12+
13+
.error {
14+
color: var(--chakra-colors-fg-error);
15+
}
16+
17+
.normal {
18+
color: var(--chakra-colors-fg);
19+
}

src/lib/colors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import type { ColorMode } from "../components/ui/color-mode";
22
import type { Activity } from "./activity";
33

4+
import styles from "./colors.module.css";
5+
6+
export const ColorStyles = {
7+
Muted: styles.muted,
8+
Success: styles.success,
9+
Warning: styles.warning,
10+
Error: styles.error,
11+
Normal: styles.normal,
12+
} as const;
13+
414
/** The type of color schemes. */
515
export interface ColorScheme {
616
name: string;

0 commit comments

Comments
 (0)