Skip to content

Commit bad92a9

Browse files
authored
Chore/remove usage of mantine color scheme (Stirling-Tools#6108)
Remove instances of `colorScheme === "dark" ?` in the app and rely on the theme.css' light and dark variables instead.
1 parent a7a5bb2 commit bad92a9

18 files changed

Lines changed: 218 additions & 176 deletions

File tree

frontend/.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
dist/
2+
# Tauri/Cargo build output (binary assets named *.js etc. confuse Prettier)
3+
src-tauri/target/
24
node_modules/
35
public/vendor/
46
public/pdfjs*/

frontend/src/core/components/fileEditor/AddFileCard.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useRef, useState } from "react";
2-
import { Button, Group, useMantineColorScheme } from "@mantine/core";
2+
import { Button, Group } from "@mantine/core";
33
import { useTranslation } from "react-i18next";
44
import AddIcon from "@mui/icons-material/Add";
55
import { useFilesModalContext } from "@app/contexts/FilesModalContext";
66
import LocalIcon from "@app/components/shared/LocalIcon";
7-
import { useLogoAssets } from "@app/hooks/useLogoAssets";
7+
import { Wordmark } from "@app/components/shared/Wordmark";
88
import styles from "@app/components/fileEditor/FileEditor.module.css";
99
import { useFileActionTerminology } from "@app/hooks/useFileActionTerminology";
1010
import { useFileActionIcons } from "@app/hooks/useFileActionIcons";
@@ -24,9 +24,7 @@ const AddFileCard = ({
2424
const { t } = useTranslation();
2525
const fileInputRef = useRef<HTMLInputElement>(null);
2626
const { openFilesModal } = useFilesModalContext();
27-
const { colorScheme } = useMantineColorScheme();
2827
const [isUploadHover, setIsUploadHover] = useState(false);
29-
const { wordmark } = useLogoAssets();
3028
const terminology = useFileActionTerminology();
3129
const icons = useFileActionIcons();
3230

@@ -98,9 +96,9 @@ const AddFileCard = ({
9896
<div className={styles.addFileContent}>
9997
{/* Stirling PDF Branding */}
10098
<Group gap="xs" align="center">
101-
<img
102-
src={colorScheme === "dark" ? wordmark.white : wordmark.grey}
99+
<Wordmark
103100
alt="Stirling PDF"
101+
muted
104102
style={{ height: "2.2rem", width: "auto" }}
105103
/>
106104
</Group>

frontend/src/core/components/fileManager/EmptyFilesState.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
import React, { useState } from "react";
2-
import {
3-
Button,
4-
Group,
5-
Text,
6-
Stack,
7-
useMantineColorScheme,
8-
} from "@mantine/core";
2+
import { Button, Group, Text, Stack } from "@mantine/core";
93
import HistoryIcon from "@mui/icons-material/History";
104
import { useTranslation } from "react-i18next";
115
import { useFileManagerContext } from "@app/contexts/FileManagerContext";
126
import LocalIcon from "@app/components/shared/LocalIcon";
13-
import { useLogoAssets } from "@app/hooks/useLogoAssets";
7+
import { Wordmark } from "@app/components/shared/Wordmark";
148
import { useFileActionTerminology } from "@app/hooks/useFileActionTerminology";
159
import { useFileActionIcons } from "@app/hooks/useFileActionIcons";
1610

1711
const EmptyFilesState: React.FC = () => {
1812
const { t } = useTranslation();
19-
const { colorScheme } = useMantineColorScheme();
2013
const { onLocalFileClick } = useFileManagerContext();
2114
const [isUploadHover, setIsUploadHover] = useState(false);
22-
const { wordmark } = useLogoAssets();
2315
const terminology = useFileActionTerminology();
2416
const icons = useFileActionIcons();
2517

@@ -65,9 +57,9 @@ const EmptyFilesState: React.FC = () => {
6557

6658
{/* Stirling PDF Logo */}
6759
<Group gap="xs" align="center">
68-
<img
69-
src={colorScheme === "dark" ? wordmark.white : wordmark.grey}
60+
<Wordmark
7061
alt="Stirling PDF"
62+
muted
7163
style={{ height: "2.2rem", width: "auto" }}
7264
/>
7365
</Group>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "react";
2+
import { useMantineColorScheme } from "@mantine/core";
3+
import { useLogoPath } from "@app/hooks/useLogoPath";
4+
5+
interface LogoIconProps extends React.ImgHTMLAttributes<HTMLImageElement> {
6+
alt?: string;
7+
}
8+
9+
export function LogoIcon({ alt = "", ...props }: LogoIconProps) {
10+
const { colorScheme } = useMantineColorScheme();
11+
const logoPaths = useLogoPath();
12+
const src = colorScheme === "dark" ? logoPaths.dark : logoPaths.light;
13+
return <img src={src} alt={alt} {...props} />;
14+
}

frontend/src/core/components/shared/TextInput.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { forwardRef } from "react";
2-
import { useMantineColorScheme } from "@mantine/core";
32
import LocalIcon from "@app/components/shared/LocalIcon";
43
import styles from "@app/components/shared/textInput/TextInput.module.css";
54

@@ -61,8 +60,6 @@ export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
6160
},
6261
ref,
6362
) => {
64-
const { colorScheme } = useMantineColorScheme();
65-
6663
const handleClear = () => {
6764
if (onClear) {
6865
onClear();
@@ -79,7 +76,7 @@ export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
7976
{icon && (
8077
<span
8178
className={styles.icon}
82-
style={{ color: colorScheme === "dark" ? "#FFFFFF" : "#6B7382" }}
79+
style={{ color: "var(--search-text-and-icon-color)" }}
8380
>
8481
{icon}
8582
</span>
@@ -99,8 +96,8 @@ export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
9996
aria-label={ariaLabel}
10097
onFocus={onFocus}
10198
style={{
102-
backgroundColor: colorScheme === "dark" ? "#4B525A" : "#FFFFFF",
103-
color: colorScheme === "dark" ? "#FFFFFF" : "#6B7382",
99+
backgroundColor: "var(--input-bg)",
100+
color: "var(--search-text-and-icon-color)",
104101
paddingRight: shouldShowClearButton ? "40px" : "12px",
105102
paddingLeft: icon ? "40px" : "12px",
106103
}}
@@ -111,7 +108,7 @@ export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
111108
type="button"
112109
className={styles.clearButton}
113110
onClick={handleClear}
114-
style={{ color: colorScheme === "dark" ? "#FFFFFF" : "#6B7382" }}
111+
style={{ color: "var(--search-text-and-icon-color)" }}
115112
aria-label="Clear input"
116113
>
117114
<LocalIcon icon="close-rounded" width="1.25rem" height="1.25rem" />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { useMantineColorScheme } from "@mantine/core";
3+
import { useLogoAssets } from "@app/hooks/useLogoAssets";
4+
5+
interface WordmarkProps extends React.ImgHTMLAttributes<HTMLImageElement> {
6+
alt?: string;
7+
muted?: boolean;
8+
}
9+
10+
export function Wordmark({ alt = "", muted = false, ...props }: WordmarkProps) {
11+
const { colorScheme } = useMantineColorScheme();
12+
const isDark = colorScheme === "dark";
13+
const { wordmark } = useLogoAssets();
14+
15+
// light: black text (standard) or grey text (muted)
16+
// dark: white text for both variants
17+
const src = isDark ? wordmark.white : muted ? wordmark.grey : wordmark.black;
18+
19+
return <img src={src} alt={alt} {...props} />;
20+
}

frontend/src/core/components/tools/FullscreenToolSurface.tsx

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import { useState, useRef } from "react";
2-
import {
3-
ActionIcon,
4-
ScrollArea,
5-
Switch,
6-
useMantineColorScheme,
7-
} from "@mantine/core";
2+
import { ActionIcon, ScrollArea, Switch } from "@mantine/core";
83
import DoubleArrowIcon from "@mui/icons-material/DoubleArrow";
94
import { useTranslation } from "react-i18next";
105
import ToolSearch from "@app/components/tools/toolPicker/ToolSearch";
116
import FullscreenToolList from "@app/components/tools/FullscreenToolList";
127
import { ToolRegistryEntry } from "@app/data/toolsTaxonomy";
138
import { ToolId } from "@app/types/toolId";
149
import { useFocusTrap } from "@app/hooks/useFocusTrap";
15-
import { useLogoPath } from "@app/hooks/useLogoPath";
16-
import { useLogoAssets } from "@app/hooks/useLogoAssets";
10+
import { LogoIcon } from "@app/components/shared/LogoIcon";
11+
import { Wordmark } from "@app/components/shared/Wordmark";
1712
import { Tooltip } from "@app/components/shared/Tooltip";
1813
import "@app/components/tools/ToolPanel.css";
1914
import { ToolPanelGeometry } from "@app/hooks/tools/useToolPanelGeometry";
@@ -52,7 +47,6 @@ const FullscreenToolSurface = ({
5247
geometry,
5348
}: FullscreenToolSurfaceProps) => {
5449
const { t } = useTranslation();
55-
const { colorScheme } = useMantineColorScheme();
5650
const [isExiting, setIsExiting] = useState(false);
5751
const surfaceRef = useRef<HTMLDivElement>(null);
5852
const isRTL =
@@ -62,9 +56,6 @@ const FullscreenToolSurface = ({
6256
useFocusTrap(surfaceRef, !isExiting);
6357

6458
const brandAltText = t("home.mobile.brandAlt", "Stirling PDF logo");
65-
const brandIconSrc = useLogoPath();
66-
const { wordmark } = useLogoAssets();
67-
const brandTextSrc = colorScheme === "dark" ? wordmark.white : wordmark.black;
6859

6960
const handleExit = () => {
7061
const prefersReducedMotion = window.matchMedia(
@@ -118,13 +109,8 @@ const FullscreenToolSurface = ({
118109
>
119110
<header className="tool-panel__fullscreen-header">
120111
<div className="tool-panel__fullscreen-brand">
121-
<img
122-
src={brandIconSrc}
123-
alt=""
124-
className="tool-panel__fullscreen-brand-icon"
125-
/>
126-
<img
127-
src={brandTextSrc}
112+
<LogoIcon className="tool-panel__fullscreen-brand-icon" />
113+
<Wordmark
128114
alt={brandAltText}
129115
className="tool-panel__fullscreen-brand-text"
130116
/>

frontend/src/core/components/tools/convert/ConvertSettings.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Divider,
77
UnstyledButton,
88
useMantineTheme,
9-
useMantineColorScheme,
109
} from "@mantine/core";
1110
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
1211
import { useTranslation } from "react-i18next";
@@ -64,7 +63,6 @@ const ConvertSettings = ({
6463
}: ConvertSettingsProps) => {
6564
const { t } = useTranslation();
6665
const theme = useMantineTheme();
67-
const { colorScheme } = useMantineColorScheme();
6866
const { setSelectedFiles } = useFileSelection();
6967
const { state, selectors } = useFileState();
7068
const activeFiles = state.files.ids;
@@ -339,14 +337,8 @@ const ConvertSettings = ({
339337
padding: "0.5rem 0.75rem",
340338
border: `0.0625rem solid ${theme.colors.gray[4]}`,
341339
borderRadius: theme.radius.sm,
342-
backgroundColor:
343-
colorScheme === "dark"
344-
? theme.colors.dark[5]
345-
: theme.colors.gray[1],
346-
color:
347-
colorScheme === "dark"
348-
? theme.colors.dark[2]
349-
: theme.colors.gray[6],
340+
backgroundColor: "var(--select-placeholder-bg)",
341+
color: "var(--select-placeholder-text)",
350342
cursor: "not-allowed",
351343
}}
352344
>
@@ -360,10 +352,7 @@ const ConvertSettings = ({
360352
<KeyboardArrowDownIcon
361353
style={{
362354
fontSize: "1rem",
363-
color:
364-
colorScheme === "dark"
365-
? theme.colors.dark[2]
366-
: theme.colors.gray[6],
355+
color: "var(--select-placeholder-text)",
367356
}}
368357
/>
369358
</Group>

frontend/src/core/components/tools/convert/GroupedFormatDropdown.tsx

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
Popover,
99
UnstyledButton,
1010
useMantineTheme,
11-
useMantineColorScheme,
1211
} from "@mantine/core";
1312
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
1413
import CloudOutlinedIcon from "@mui/icons-material/CloudOutlined";
@@ -47,7 +46,6 @@ const GroupedFormatDropdown = ({
4746
}: GroupedFormatDropdownProps) => {
4847
const [dropdownOpened, setDropdownOpened] = useState(false);
4948
const theme = useMantineTheme();
50-
const { colorScheme } = useMantineColorScheme();
5149

5250
const groupedOptions = useMemo(() => {
5351
const groups: Record<string, FormatOption[]> = {};
@@ -100,18 +98,12 @@ const GroupedFormatDropdown = ({
10098
borderRadius: theme.radius.sm,
10199
backgroundColor: disabled
102100
? theme.colors.gray[1]
103-
: colorScheme === "dark"
104-
? theme.colors.dark[6]
105-
: theme.white,
101+
: "var(--dropdown-trigger-bg)",
106102
cursor: disabled ? "not-allowed" : "pointer",
107103
width: "100%",
108104
color: disabled
109-
? colorScheme === "dark"
110-
? theme.colors.dark[1]
111-
: theme.colors.dark[7]
112-
: colorScheme === "dark"
113-
? theme.colors.dark[0]
114-
: theme.colors.dark[9],
105+
? "var(--dropdown-trigger-text-disabled)"
106+
: "var(--dropdown-trigger-text)",
115107
}}
116108
>
117109
<Group justify="space-between">
@@ -123,10 +115,7 @@ const GroupedFormatDropdown = ({
123115
fontSize: "1rem",
124116
transform: dropdownOpened ? "rotate(180deg)" : "rotate(0deg)",
125117
transition: "transform 0.2s ease",
126-
color:
127-
colorScheme === "dark"
128-
? theme.colors.dark[2]
129-
: theme.colors.gray[6],
118+
color: "var(--dropdown-trigger-icon)",
130119
}}
131120
/>
132121
</Group>
@@ -138,9 +127,8 @@ const GroupedFormatDropdown = ({
138127
maxWidth: "90vw",
139128
maxHeight: "40vh",
140129
overflow: "auto",
141-
backgroundColor:
142-
colorScheme === "dark" ? theme.colors.dark[7] : theme.white,
143-
border: `0.0625rem solid ${colorScheme === "dark" ? theme.colors.dark[4] : theme.colors.gray[4]}`,
130+
backgroundColor: "var(--dropdown-panel-bg)",
131+
border: `0.0625rem solid var(--dropdown-panel-border)`,
144132
}}
145133
>
146134
<Stack gap="md">
@@ -149,8 +137,8 @@ const GroupedFormatDropdown = ({
149137
<Text
150138
size="sm"
151139
fw={600}
152-
c={colorScheme === "dark" ? "dark.2" : "gray.6"}
153140
mb="xs"
141+
style={{ color: "var(--dropdown-group-label)" }}
154142
>
155143
{groupName}
156144
</Text>

frontend/src/core/hooks/useLogoAssets.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ export function useLogoAssets() {
1515
folder,
1616
folderPath,
1717
getAssetPath: (name: string) => `${folderPath}/${name}`,
18+
wordmark: {
19+
black: `${folderPath}/StirlingPDFLogoBlackText.svg`,
20+
grey: `${folderPath}/StirlingPDFLogoGreyText.svg`,
21+
white: `${folderPath}/StirlingPDFLogoWhiteText.svg`,
22+
},
1823
tooltipLogo: `${folderPath}/logo-tooltip.svg`,
1924
firstPage: `${folderPath}/Firstpage.png`,
2025
favicon: `${folderPath}/favicon.ico`,
2126
logo192: `${folderPath}/logo192.png`,
2227
logo512: `${folderPath}/logo512.png`,
23-
wordmark: {
24-
white: `${folderPath}/StirlingPDFLogoWhiteText.svg`,
25-
black: `${folderPath}/StirlingPDFLogoBlackText.svg`,
26-
grey: `${folderPath}/StirlingPDFLogoGreyText.svg`,
27-
},
2828
manifestHref:
2929
logoVariant === "classic"
3030
? `${BASE_PATH}/manifest-classic.json`

0 commit comments

Comments
 (0)