Skip to content

Commit 4875334

Browse files
committed
Add theme toggle and fix header styles
Signed-off-by: Joe Adams <github@joeadams.io>
1 parent 7aa1b9f commit 4875334

5 files changed

Lines changed: 69 additions & 0 deletions

File tree

ui/mantine-ui/package-lock.json

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

ui/mantine-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@mantine/core": "^8.3.13",
2222
"@mantine/hooks": "^8.3.13",
2323
"@tanstack/react-query": "^5.90.21",
24+
"@tabler/icons-react": "^3.36.1",
2425
"highlight.js": "^11.11.1",
2526
"react": "^19.1.0",
2627
"react-dom": "^19.2.4",

ui/mantine-ui/src/components/Header.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
.header {
2+
background-color: rgb(65, 73, 81);
3+
color: #fff;
4+
border-bottom: 1px solid var(--mantine-color-gray-6);
5+
}
6+
17
.navMain {
28
flex: 1;
39
}

ui/mantine-ui/src/components/Header.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Link, NavLink, Route, Routes } from 'react-router-dom';
22
import { AppShell, Button, Group, Menu, Text } from '@mantine/core';
3+
import { ThemeSelector } from '@/components/ThemeSelector';
34
import { AlertsPage } from '@/pages/Alerts.page';
45
import { SilencesPage } from '@/pages/Silences.page';
56
import classes from './Header.module.css';
@@ -117,6 +118,9 @@ export const Header = () => {
117118
{navLinks}
118119
</Group>
119120
</Group>
121+
<Group visibleFrom="xs" wrap="nowrap" gap="xs">
122+
<ThemeSelector />
123+
</Group>
120124
</Group>
121125
</Group>
122126
</AppShell.Header>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { FC } from 'react';
2+
import { IconBrightnessFilled, IconMoonFilled, IconSunFilled } from '@tabler/icons-react';
3+
import { ActionIcon, rem, useMantineColorScheme } from '@mantine/core';
4+
5+
export const ThemeSelector: FC = () => {
6+
const { colorScheme, setColorScheme } = useMantineColorScheme();
7+
const iconProps = {
8+
style: { width: rem(20), height: rem(20), display: 'block' },
9+
stroke: 1.5,
10+
};
11+
12+
return (
13+
<ActionIcon
14+
color="gray"
15+
title={`Switch to ${colorScheme === 'light' ? 'dark' : colorScheme === 'dark' ? 'browser-preferred' : 'light'} theme`}
16+
aria-label={`Switch to ${colorScheme === 'light' ? 'dark' : colorScheme === 'dark' ? 'browser-preferred' : 'light'} theme`}
17+
size={32}
18+
onClick={() =>
19+
setColorScheme(colorScheme === 'light' ? 'dark' : colorScheme === 'dark' ? 'auto' : 'light')
20+
}
21+
>
22+
{colorScheme === 'light' ? (
23+
<IconSunFilled {...iconProps} />
24+
) : colorScheme === 'dark' ? (
25+
<IconMoonFilled {...iconProps} />
26+
) : (
27+
<IconBrightnessFilled {...iconProps} />
28+
)}
29+
</ActionIcon>
30+
);
31+
};

0 commit comments

Comments
 (0)