-
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7abdbfd
migrate theme popover to v9
Mnickii 4c81805
revert loadGETheme removal for v8 components
Mnickii 7f546a9
use customized radio Group
Mnickii 7dfd148
adjusst icon size
Mnickii f4aa8d5
remove checked
Mnickii 0becb35
detect system theme in theme-chooser and set as default
Mnickii 21ba3c9
include system theme appwise
Mnickii 4d8f773
Merge branch 'feat/fluent-v9-upgrade' into feat/theme-popover
Mnickii 08411d8
add system to options
Mnickii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import React, { useEffect } from 'react'; | ||
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' | ||
}, | ||
icon: { | ||
fontSize: '30px' | ||
}, | ||
radio: { | ||
'&:checked ~ .fui-Radio__indicator::after': { | ||
borderRadius: '50%' | ||
} | ||
} | ||
|
||
}); | ||
|
||
const useLabelStyles = makeStyles({ | ||
root: { | ||
display: 'flex', | ||
textAlign: 'center' | ||
}, | ||
container: { | ||
display: 'block', | ||
alignItems: 'center', | ||
justifyContent: 'center' | ||
} | ||
}); | ||
|
||
const getSystemTheme = (): string => { | ||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
return 'dark'; | ||
} | ||
return 'light'; | ||
}; | ||
|
||
const ThemeChooserV9: React.FC<PopupsComponent<null>> = () => { | ||
const dispatch = useAppDispatch(); | ||
const appTheme = useAppSelector(state=> state.theme); | ||
const iconOptionStyles = useIconOptionStyles(); | ||
const labelStyles = useLabelStyles(); | ||
|
||
useEffect(() => { | ||
// Load the theme from local storage or use the system theme as the default | ||
const savedTheme = localStorage.getItem('appTheme') ?? getSystemTheme(); | ||
dispatch(changeTheme(savedTheme)); | ||
loadGETheme(savedTheme); // Remove when cleaning up | ||
}, [dispatch]); | ||
|
||
|
||
const handleChangeTheme = (selectedTheme: { key: string; displayName: string; icon: JSX.Element }) => { | ||
const newTheme: string = selectedTheme.key; | ||
// Save the selected theme to local storage | ||
localStorage.setItem('appTheme', 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() | ||
}); | ||
}; | ||
return ( | ||
<RadioGroup layout="horizontal" aria-labelledby='theme-chooser' | ||
value={availableThemes.find(theme => theme.key === appTheme)?.displayName} | ||
> | ||
{availableThemes.map((theme) => ( | ||
<div key={theme.key} className={iconOptionStyles.root}> | ||
<Radio | ||
value={theme.key} | ||
checked={appTheme === theme.key} | ||
className={iconOptionStyles.radio} | ||
label={{ | ||
className: labelStyles.root, | ||
children: ( | ||
<div className={labelStyles.container}> | ||
<span className={iconOptionStyles.icon}>{theme.icon}</span> {translateMessage(theme.displayName)} | ||
</div> | ||
) | ||
}} | ||
onClick={() => handleChangeTheme(theme)}> | ||
</Radio> | ||
</div> | ||
))} | ||
</RadioGroup> | ||
); | ||
} | ||
|
||
export default ThemeChooserV9 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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