diff --git a/telemetry/ui/src/App.tsx b/telemetry/ui/src/App.tsx index 121337ae3..d49900c49 100644 --- a/telemetry/ui/src/App.tsx +++ b/telemetry/ui/src/App.tsx @@ -31,6 +31,7 @@ import { StreamingChatbotWithTelemetry } from './examples/StreamingChatbot'; import { AdminView } from './components/routes/AdminView'; import { AnnotationsViewContainer } from './components/routes/app/AnnotationsView'; import { DeepResearcherWithTelemetry } from './examples/DeepResearcher'; +import { useTheme } from './hooks/useTheme'; /** * Basic application. We have an AppContainer -- this has a breadcrumb and a sidebar. @@ -48,6 +49,9 @@ import { DeepResearcherWithTelemetry } from './examples/DeepResearcher'; * @returns A rendered application object */ const App = () => { + // Initialize theme at the app root so the `dark` class is applied on load + // (respects system preference, falls back to stored manual override). + useTheme(); return ( diff --git a/telemetry/ui/src/components/common/ThemeToggle.tsx b/telemetry/ui/src/components/common/ThemeToggle.tsx new file mode 100644 index 000000000..569ce9061 --- /dev/null +++ b/telemetry/ui/src/components/common/ThemeToggle.tsx @@ -0,0 +1,47 @@ +/* + * 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 { MoonIcon, SunIcon } from '@heroicons/react/24/outline'; +import { classNames } from '../../utils/tailwind'; +import { useTheme } from '../../hooks/useTheme'; + +/** + * A simple sun/moon button that toggles between light and dark mode. + * Replaces the previously broken radio toggle referenced in issue #209. + */ +export const ThemeToggle = (props: { showLabel?: boolean }) => { + const { isDark, toggle } = useTheme(); + const Icon = isDark ? SunIcon : MoonIcon; + const label = isDark ? 'Switch to light mode' : 'Switch to dark mode'; + return ( + + ); +}; diff --git a/telemetry/ui/src/components/nav/appcontainer.tsx b/telemetry/ui/src/components/nav/appcontainer.tsx index 35c217e5f..5e4969b7d 100644 --- a/telemetry/ui/src/components/nav/appcontainer.tsx +++ b/telemetry/ui/src/components/nav/appcontainer.tsx @@ -37,6 +37,7 @@ import { classNames } from '../../utils/tailwind'; import React from 'react'; import { DefaultService } from '../../api'; import { useQuery } from 'react-query'; +import { ThemeToggle } from '../common/ThemeToggle'; // Define your GitHub logo SVG as a React component const GithubLogo = () => ( @@ -64,8 +65,8 @@ const ToggleOpenButton = (props: { open: boolean; toggleSidebar: () => void }) = return (