Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate theme popover to v9 #3442

Merged
merged 9 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { lazy } from 'react';

export const popups = new Map<string, any>([
['share-query', lazy(() => import('../../../query-runner/query-input/share-query/ShareQuery'))],
['theme-chooser', lazy(() => import('../../../main-header/settings/ThemeChooser'))],
['theme-chooser', lazy(() => import('../../../main-header/settings/ThemeChooserV9'))],
['preview-collection', lazy(() => import('../../../sidebar/resource-explorer/collection/PreviewCollection'))],
['full-permissions', lazy(() => import('../../../query-runner/request/permissions/Permissions.Full'))]
]);
Expand Down
68 changes: 68 additions & 0 deletions src/app/views/main-header/settings/ThemeChooserV9.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Menu, MenuTrigger, MenuButton, MenuPopover, MenuList, MenuItem } from '@fluentui/react-components';
import { useAppDispatch, useAppSelector } from '../../../../store';
import { componentNames, eventTypes, telemetry } from '../../../../telemetry';
import { PopupsComponent } from '../../../services/context/popups-context';
import { changeTheme } from '../../../services/slices/theme.slice';
import { BrightnessHighRegular, WeatherMoonFilled, CircleHalfFillFilled } from '@fluentui/react-icons';

const availableThemes = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've added system theme support, make it an option and probably the default selected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the default selected ln70-75

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant on the popup
image

{
key: 'light',
displayName: 'Web Light',
icon: <BrightnessHighRegular />
},
{
key: 'dark',
displayName: 'Web Dark',
icon: <WeatherMoonFilled />
},
{
key: 'high-contrast',
displayName: 'Teams High Contrast',
icon: <CircleHalfFillFilled />
}
];

const ThemeChooserV9: React.FC<PopupsComponent<null>> = () => {
const dispatch = useAppDispatch();
const appTheme = useAppSelector(state=> state.theme);


const handleChangeTheme = (selectedTheme: { key: string; displayName: string; icon: JSX.Element }) => {
const newTheme: string = selectedTheme?.key ?? '';
Mnickii marked this conversation as resolved.
Show resolved Hide resolved
// Applies the theme to the Fluent UI components
switch (newTheme) {
Mnickii marked this conversation as resolved.
Show resolved Hide resolved
case 'light':
return dispatch(changeTheme('light'));
musale marked this conversation as resolved.
Show resolved Hide resolved
case 'dark':
return dispatch(changeTheme('dark'));
case 'high-contrast':
return dispatch(changeTheme('high-contrast'));
}
telemetry.trackEvent(eventTypes.BUTTON_CLICK_EVENT, {
ComponentName: componentNames.SELECT_THEME_BUTTON,
SelectedTheme: newTheme.replace('-', ' ').toSentenceCase()
});
};
return (
<Menu>
Mnickii marked this conversation as resolved.
Show resolved Hide resolved
<MenuTrigger>
<MenuButton icon={availableThemes.find(theme => theme.key === appTheme)?.icon}>
{availableThemes.find(theme => theme.key === appTheme)?.displayName}
</MenuButton>
</MenuTrigger>

<MenuPopover>
<MenuList>
{availableThemes.map(theme => (
<MenuItem icon={theme.icon} key={theme.key} onClick={() => handleChangeTheme(theme)}>
{theme.displayName}
</MenuItem>
))}
</MenuList>
</MenuPopover>
</Menu>
);
}

export default ThemeChooserV9
Loading