Copilot commented on code in PR #3310:
URL: https://github.com/apache/apisix-dashboard/pull/3310#discussion_r2872326701


##########
src/components/Header/DarkModeToggleBtn.tsx:
##########
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { ActionIcon, useComputedColorScheme, useMantineColorScheme } from 
'@mantine/core';
+
+import IconDarkMode from '~icons/material-symbols/dark-mode';
+import IconLightMode from '~icons/material-symbols/light-mode';
+
+export const DarkModeToggleBtn = () => {
+    const { toggleColorScheme } = useMantineColorScheme();
+    const computedColorScheme = useComputedColorScheme('light', { 
getInitialValueInEffect: true });
+    const isDark = computedColorScheme === 'dark';
+
+    return (
+        <ActionIcon
+            onClick={() => toggleColorScheme()}
+            variant="light"
+            size="sm"
+        >
+            {isDark ? <IconLightMode /> : <IconDarkMode />}
+        </ActionIcon>
+    );

Review Comment:
   This new component’s indentation/formatting is inconsistent with the 
surrounding header components (e.g., `SettingModalBtn.tsx` uses 2-space 
indentation). Please run the repo formatter / align indentation here to match 
the established style so future diffs stay clean.
   ```suggestion
     const { toggleColorScheme } = useMantineColorScheme();
     const computedColorScheme = useComputedColorScheme('light', { 
getInitialValueInEffect: true });
     const isDark = computedColorScheme === 'dark';
   
     return (
       <ActionIcon
         onClick={() => toggleColorScheme()}
         variant="light"
         size="sm"
       >
         {isDark ? <IconLightMode /> : <IconDarkMode />}
       </ActionIcon>
     );
   ```



##########
src/components/Header/DarkModeToggleBtn.tsx:
##########
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { ActionIcon, useComputedColorScheme, useMantineColorScheme } from 
'@mantine/core';
+
+import IconDarkMode from '~icons/material-symbols/dark-mode';
+import IconLightMode from '~icons/material-symbols/light-mode';
+
+export const DarkModeToggleBtn = () => {
+    const { toggleColorScheme } = useMantineColorScheme();
+    const computedColorScheme = useComputedColorScheme('light', { 
getInitialValueInEffect: true });
+    const isDark = computedColorScheme === 'dark';

Review Comment:
   `useComputedColorScheme('light', { getInitialValueInEffect: true })` forces 
the initial render to assume light mode and then update in an effect. In this 
app (client-rendered via `document.getElementById` in `main.tsx`), that can 
cause a visible flash and briefly show the wrong icon/theme. Prefer deriving 
`isDark` from `useMantineColorScheme().colorScheme` (or set 
`getInitialValueInEffect: false`) so the initial paint matches the 
stored/current scheme.



##########
src/config/antdConfigProvider.tsx:
##########
@@ -16,23 +16,47 @@
  */
 import '@ant-design/v5-patch-for-react-19';
 
-import { ConfigProvider } from 'antd';
+import { useComputedColorScheme, useMantineTheme } from '@mantine/core';
+import { ConfigProvider, theme } from 'antd';
 import enUS from 'antd/locale/en_US';
 import type { PropsWithChildren } from 'react';
 import { useTranslation } from 'react-i18next';
 
 export const AntdConfigProvider = (props: PropsWithChildren) => {
   const { children } = props;
   const { t } = useTranslation();
+  const colorScheme = useComputedColorScheme('light', {
+    getInitialValueInEffect: true,
+  });
+  const isDark = colorScheme === 'dark';
+  const mantineTheme = useMantineTheme();

Review Comment:
   As in the header toggle, `useComputedColorScheme('light', { 
getInitialValueInEffect: true })` can render Ant Design in light mode first and 
then switch to dark in an effect (causing a flash / temporary Mantine↔AntD 
mismatch). Since this is a client-rendered app, consider using 
`useMantineColorScheme().colorScheme` (or `getInitialValueInEffect: false`) so 
AntD theme is correct on the first paint.



##########
src/components/Header/DarkModeToggleBtn.tsx:
##########
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { ActionIcon, useComputedColorScheme, useMantineColorScheme } from 
'@mantine/core';
+
+import IconDarkMode from '~icons/material-symbols/dark-mode';
+import IconLightMode from '~icons/material-symbols/light-mode';
+
+export const DarkModeToggleBtn = () => {
+    const { toggleColorScheme } = useMantineColorScheme();
+    const computedColorScheme = useComputedColorScheme('light', { 
getInitialValueInEffect: true });
+    const isDark = computedColorScheme === 'dark';
+
+    return (
+        <ActionIcon
+            onClick={() => toggleColorScheme()}
+            variant="light"
+            size="sm"

Review Comment:
   `ActionIcon` renders an icon-only control but has no accessible name. Please 
add an `aria-label` (and ideally localize it) or wrap it with a labeled 
`Tooltip` so screen readers can announce what this button does.
   ```suggestion
       const isDark = computedColorScheme === 'dark';
       const label = isDark ? 'Switch to light mode' : 'Switch to dark mode';
   
       return (
           <ActionIcon
               onClick={() => toggleColorScheme()}
               variant="light"
               size="sm"
               aria-label={label}
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to