From c77cc107caaa419d2444b88965cbf33e63687d13 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 19 Nov 2025 19:05:49 +0800 Subject: [PATCH] ui: mantine: respect color scheme setting (close #1091) --- .../ui-default/components/mantine.page.tsx | 39 +++++++++++++++++++ .../components/notification/index.ts | 33 +--------------- .../ui-default/templates/layout/html5.html | 3 +- 3 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 packages/ui-default/components/mantine.page.tsx diff --git a/packages/ui-default/components/mantine.page.tsx b/packages/ui-default/components/mantine.page.tsx new file mode 100644 index 000000000..3abc423a0 --- /dev/null +++ b/packages/ui-default/components/mantine.page.tsx @@ -0,0 +1,39 @@ +import { createTheme, Notification as MantineNotification } from '@mantine/core'; +import { AutoloadPage } from 'vj/misc/Page'; + +const colorWhite = { + color: 'var(--mantine-color-white)', +} as const; + +export const theme = createTheme({ + components: { + Notification: MantineNotification.extend({ + classNames: { + closeButton: 'mantine-notifications-close-button', + }, + styles: { + root: { + backgroundColor: 'var(--notification-color, var(--mantine-primary-color-filled))', + paddingInlineStart: 'var(--mantine-spacing-xs)', + }, + title: { + ...colorWhite, + fontSize: 'var(--mantine-font-size-md)', + }, + icon: { + fontSize: '24px', + marginInlineEnd: 'var(--mantine-spacing-xs)', + }, + description: colorWhite, + closeButton: colorWhite, + }, + }), + }, +}); + +export default new AutoloadPage('mantine', null, () => { + localStorage.setItem( + 'mantine-color-scheme-value', + document.documentElement.className.includes('theme--dark') ? 'dark' : 'light', + ); +}); diff --git a/packages/ui-default/components/notification/index.ts b/packages/ui-default/components/notification/index.ts index befd6fd4e..b7e5e52ba 100644 --- a/packages/ui-default/components/notification/index.ts +++ b/packages/ui-default/components/notification/index.ts @@ -1,39 +1,10 @@ -import { createTheme, MantineProvider, Notification as MantineNotification } from '@mantine/core'; +import { MantineProvider } from '@mantine/core'; import { Notifications, notifications } from '@mantine/notifications'; import $ from 'jquery'; import React from 'react'; +import { theme } from 'vj/components/mantine.page'; import { tpl, zIndexManager } from 'vj/utils/base'; -const colorWhite = { - color: 'var(--mantine-color-white)', -} as const; - -const theme = createTheme({ - components: { - Notification: MantineNotification.extend({ - classNames: { - closeButton: 'mantine-notifications-close-button', - }, - styles: { - root: { - backgroundColor: 'var(--notification-color, var(--mantine-primary-color-filled))', - paddingInlineStart: 'var(--mantine-spacing-xs)', - }, - title: { - ...colorWhite, - fontSize: 'var(--mantine-font-size-md)', - }, - icon: { - fontSize: '24px', - marginInlineEnd: 'var(--mantine-spacing-xs)', - }, - description: colorWhite, - closeButton: colorWhite, - }, - }), - }, -}); - document.body.append(tpl( React.createElement(MantineProvider, { theme }, React.createElement(Notifications, { position: 'bottom-left', zIndex: 99999 }), diff --git a/packages/ui-default/templates/layout/html5.html b/packages/ui-default/templates/layout/html5.html index 1ba82b5f0..dfc13d7a9 100644 --- a/packages/ui-default/templates/layout/html5.html +++ b/packages/ui-default/templates/layout/html5.html @@ -5,7 +5,8 @@ {% import "components/noscript_note.html" as noscript_note with context %} {% import "components/user.html" as user with context %} - +{% set theme = (handler.user|default({})).theme|default('default') %} +