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

Conversation

Mnickii
Copy link
Contributor

@Mnickii Mnickii commented Nov 26, 2024

Overview

Brief description of what this PR does, and why it is needed.
Closes #3439
Closes #3383

Demo

Optional. Screenshots, curl examples, etc.

Notes

Optional. Ancillary topics, caveats, alternative strategies that didn't work out, anything else.

Testing Instructions

  • How to test this PR
  • Prefer bulleted description
  • Start after checking out this branch
  • Include any setup required, such as bundling scripts, restarting services, etc.
  • Include test case, and expected output

@Mnickii Mnickii requested a review from a team as a code owner November 26, 2024 14:25
@Mnickii Mnickii requested a review from musale November 28, 2024 12:01
};
return (
<RadioGroup layout="horizontal" aria-labelledby='theme-chooser'
defaultValue={availableThemes.find(theme => theme.key === appTheme)?.displayName}
Copy link
Contributor

Choose a reason for hiding this comment

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

Fantastic work so far!

There's a console warning that draws attention to the implementation you have here
image

My understanding is that you can't use defaultValue and checked at the same time. My recomendation here is to:

  1. use the onChange listener on RadioGroup and remove the defaultValue for value.
  2. You can then create a state value which defaults to the appTheme, and use all the implementation of handleChangeTheme after setValue(data.value). Something like this:
 const [value, setValue] = useState(appTheme);
// some stuff
 <RadioGroup value={value} onChange={(_, data) =>{
        const newTheme: string = data.value
        setValue(newTheme)
        // Applies the theme to the Fluent UI components
        dispatch(changeTheme(newTheme));
        loadGETheme(newTheme); //Remove when cleaning up
        telemetry.trackEvent(eventTypes.BUTTON_CLICK_EVENT, {
          ComponentName: componentNames.SELECT_THEME_BUTTON,
          SelectedTheme: newTheme.replace('-', ' ').toSentenceCase()
        });
      }}>
// other stuff
  1. Remove checked and onClick on Radio.

Borrowed this from https://react.fluentui.dev/?path=/docs/components-radiogroup--docs#controlled-value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm currently unable to test this locally, but I'm curious if removing the Radio Checked on ln 71 in current implementation would have a similar warning. Per https://react.fluentui.dev/?path=/docs/components-radiogroup--docs#default-value, only either the default Value or the checked can be used

@ElinorW
Copy link
Contributor

ElinorW commented Nov 29, 2024

Noticed the close button is no longer there, shouldn't we still keep it? but just as a regular button?

@Mnickii
Copy link
Contributor Author

Mnickii commented Nov 29, 2024

@ElinorW since clicking outside the popover closes it, I wonder if we should keep it.

@ElinorW
Copy link
Contributor

ElinorW commented Dec 2, 2024

@ElinorW since clicking outside the popover closes it, I wonder if we should keep it.

Hmm good point, the same behaviour is there in the current version as well.
Maybe we can ask design.

import { translateMessage } from '../../../utils/translate-messages';
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

Copy link
Contributor

@musale musale left a comment

Choose a reason for hiding this comment

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

In App.tsx, we want to do two things:

  • Get the current theme or load the system theme and set it. Allows us to set the theme on app load.
  • Create a listener to the theme changes. Allows us to change our theme if a user changes the theme from their system. Something like this:
    const mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
    // Add the listener for theme changes
    mediaQueryList.addEventListener('change', handleThemeChange);

What do you think?

@Mnickii
Copy link
Contributor Author

Mnickii commented Dec 4, 2024

Yeah @musale, I noticed the theme was only picked when interacting with theme chooser, currently implementing this.

@Mnickii Mnickii requested a review from musale December 4, 2024 13:02
@Mnickii Mnickii merged commit be5a415 into feat/fluent-v9-upgrade Dec 11, 2024
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate components in theming popover Migrate GE general theming from v8 to v9
3 participants