Skip to content

Commit c77cc10

Browse files
committed
ui: mantine: respect color scheme setting (close #1091)
1 parent eff19f4 commit c77cc10

3 files changed

Lines changed: 43 additions & 32 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { createTheme, Notification as MantineNotification } from '@mantine/core';
2+
import { AutoloadPage } from 'vj/misc/Page';
3+
4+
const colorWhite = {
5+
color: 'var(--mantine-color-white)',
6+
} as const;
7+
8+
export const theme = createTheme({
9+
components: {
10+
Notification: MantineNotification.extend({
11+
classNames: {
12+
closeButton: 'mantine-notifications-close-button',
13+
},
14+
styles: {
15+
root: {
16+
backgroundColor: 'var(--notification-color, var(--mantine-primary-color-filled))',
17+
paddingInlineStart: 'var(--mantine-spacing-xs)',
18+
},
19+
title: {
20+
...colorWhite,
21+
fontSize: 'var(--mantine-font-size-md)',
22+
},
23+
icon: {
24+
fontSize: '24px',
25+
marginInlineEnd: 'var(--mantine-spacing-xs)',
26+
},
27+
description: colorWhite,
28+
closeButton: colorWhite,
29+
},
30+
}),
31+
},
32+
});
33+
34+
export default new AutoloadPage('mantine', null, () => {
35+
localStorage.setItem(
36+
'mantine-color-scheme-value',
37+
document.documentElement.className.includes('theme--dark') ? 'dark' : 'light',
38+
);
39+
});

packages/ui-default/components/notification/index.ts

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,10 @@
1-
import { createTheme, MantineProvider, Notification as MantineNotification } from '@mantine/core';
1+
import { MantineProvider } from '@mantine/core';
22
import { Notifications, notifications } from '@mantine/notifications';
33
import $ from 'jquery';
44
import React from 'react';
5+
import { theme } from 'vj/components/mantine.page';
56
import { tpl, zIndexManager } from 'vj/utils/base';
67

7-
const colorWhite = {
8-
color: 'var(--mantine-color-white)',
9-
} as const;
10-
11-
const theme = createTheme({
12-
components: {
13-
Notification: MantineNotification.extend({
14-
classNames: {
15-
closeButton: 'mantine-notifications-close-button',
16-
},
17-
styles: {
18-
root: {
19-
backgroundColor: 'var(--notification-color, var(--mantine-primary-color-filled))',
20-
paddingInlineStart: 'var(--mantine-spacing-xs)',
21-
},
22-
title: {
23-
...colorWhite,
24-
fontSize: 'var(--mantine-font-size-md)',
25-
},
26-
icon: {
27-
fontSize: '24px',
28-
marginInlineEnd: 'var(--mantine-spacing-xs)',
29-
},
30-
description: colorWhite,
31-
closeButton: colorWhite,
32-
},
33-
}),
34-
},
35-
});
36-
378
document.body.append(tpl(
389
React.createElement(MantineProvider, { theme },
3910
React.createElement(Notifications, { position: 'bottom-left', zIndex: 99999 }),

packages/ui-default/templates/layout/html5.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
{% import "components/noscript_note.html" as noscript_note with context %}
66
{% import "components/user.html" as user with context %}
77
<!DOCTYPE html>
8-
<html data-page="{{ page_name }}" data-layout="{{ layout_name }}" class="layout--{{ layout_name }} page--{{ page_name }} theme--{{ (handler.user|default({})).theme|default('default') }} nojs" lang="{{ UserContext.viewLang }}" data-app="Hydro">
8+
{% set theme = (handler.user|default({})).theme|default('default') %}
9+
<html data-page="{{ page_name }}" data-layout="{{ layout_name }}" class="layout--{{ layout_name }} page--{{ page_name }} theme--{{ theme }} nojs" data-mantine-color-scheme="{{ 'dark' if theme.includes('dark') else 'light' }}" lang="{{ UserContext.viewLang }}" data-app="Hydro">
910
<head>
1011
<meta charset="UTF-8">
1112
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

0 commit comments

Comments
 (0)