-
Notifications
You must be signed in to change notification settings - Fork 93
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
Changes from 4 commits
7abdbfd
4c81805
7f546a9
7dfd148
f4aa8d5
0becb35
21ba3c9
4d8f773
08411d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { makeStyles, RadioGroup, Radio} 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 { loadGETheme } from '../../../../themes'; | ||
import { translateMessage } from '../../../utils/translate-messages'; | ||
import { BrightnessHighRegular, WeatherMoonFilled, CircleHalfFillFilled } from '@fluentui/react-icons'; | ||
|
||
const availableThemes = [ | ||
{ | ||
key: 'light', | ||
displayName: 'Web Light', | ||
icon: <BrightnessHighRegular /> | ||
}, | ||
{ | ||
key: 'dark', | ||
displayName: 'Web Dark', | ||
icon: <WeatherMoonFilled /> | ||
}, | ||
{ | ||
key: 'high-contrast', | ||
displayName: 'Teams High Contrast', | ||
icon: <CircleHalfFillFilled /> | ||
} | ||
]; | ||
|
||
const useIconOptionStyles = makeStyles({ | ||
root: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: '5px' | ||
}, | ||
icon: { | ||
fontSize: '30px' | ||
} | ||
}); | ||
|
||
const useLabelStyles = makeStyles({ | ||
root: { | ||
display: 'flex', | ||
gap: '5px' | ||
} | ||
}); | ||
|
||
const ThemeChooserV9: React.FC<PopupsComponent<null>> = () => { | ||
const dispatch = useAppDispatch(); | ||
const appTheme = useAppSelector(state=> state.theme); | ||
const iconOptionStyles = useIconOptionStyles(); | ||
const labelStyles = useLabelStyles(); | ||
|
||
|
||
const handleChangeTheme = (selectedTheme: { key: string; displayName: string; icon: JSX.Element }) => { | ||
const newTheme: string = selectedTheme.key; | ||
// 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() | ||
}); | ||
}; | ||
return ( | ||
<RadioGroup layout="horizontal" aria-labelledby='theme-chooser' | ||
defaultValue={availableThemes.find(theme => theme.key === appTheme)?.displayName} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 My understanding is that you can't use
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
Borrowed this from https://react.fluentui.dev/?path=/docs/components-radiogroup--docs#controlled-value There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
> | ||
{availableThemes.map((theme) => ( | ||
<div key={theme.key} className={iconOptionStyles.root}> | ||
<Radio | ||
value={theme.key} | ||
checked={appTheme === theme.key} | ||
label={{ | ||
className: labelStyles.root, | ||
children: ( | ||
<> | ||
<span className={iconOptionStyles.icon}>{theme.icon}</span> {translateMessage(theme.displayName)} | ||
</> | ||
) | ||
}} | ||
onClick={() => handleChangeTheme(theme)}> | ||
</Radio> | ||
</div> | ||
))} | ||
</RadioGroup> | ||
); | ||
} | ||
|
||
export default ThemeChooserV9 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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