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

Added 'EnhancedThemeProvider' control #1206

Merged
merged 4 commits into from
May 8, 2022

Conversation

fabiofranzini
Copy link
Collaborator

Q A
Bug fix? [ ]
New feature? [X]
New sample? [ ]
Related issues? fixes #1202

What's in this Pull Request?

I added the new 'EnhancedThemeProvider' Control used to improve support for themes and fonts when creating Tab or Personal App in SPFx for Teams or creating Isolated Web Parts.

The reasons behind this control are many and concern the use of Fluent UI controls currently officially supported by SPFx, that is:

  • Problems with Teams theme support, when hosting a Web Part like Tab or Personal App and specifically the lack of support by this version of Fluent UI React of the high contrast theme.
  • Lack of basic style, such as fonts, for basic HTML elements when creating Web Parts hosted in Teams as Tabs or personal App.
  • Lack of basic style, such as fonts, for basic HTML elements when creating Web Parts in "isDomainIsolated" mode, aka the Isolated Web Parts.

Therefore, the control is to be considered as a sort of wrapper for all react and non-react controls that you want to add to the WebPart.

The control extends the functionality of the Fluent UI ThemeProvider control (currently in version 7) by adding some logic thanks to the information contained in the 'context' property, that is:

  • If the Web Part is hosted inside SharePoint, the theme passed through the 'Theme' property will be used or the default one of the current site will be taken.
  • If the web part is hosted within Teams, the "Theme" property will be ignored and using the "Context" property checks which theme is currently applied and adds a handler to notify when the theme is changed. This allows you to manage the change of theme in Teams in real-time, without having to reload the Tab or the Personal App.

As for Teams, given the inconsistency of the theme system of Fluent UI NorthStar (used in Teams) and Fluent UI React (used by SPFx), the themes are "emulated".

The control contains the refining of Teams' Default, Dark and Hight Contrast themes.

This is just an example on Teams with Hight Contrast theme applied:
Teams Hight Contrast

@fabiofranzini
Copy link
Collaborator Author

Hi @AJIXuMuK and @joelfmrodrigues with the last commit I finalized the default, dark and high contrast theme for Teams.

As mentioned in the Twitter thread with @AJIXuMuK, I created a repo to individually test the various Fluent controls (not all but most) with the default themes and the ones I created instead.

Specifically, you can see the themes applied using this branch: https://github.com/fabiofranzini/spfx-test-fluent-ui-theme/tree/custom-teams-themes

For this component, as you can see, I have placed the themes in the "common" folder, to share these themes with other components as well (for example the AdaptiveCardHost control).

Thanks in advance 🙂

@joelfmrodrigues
Copy link
Collaborator

@fabiofranzini Many thanks for another great contribution!
I'm just reviewing this now and while testing the solution that you linked above I got one error as it's missing the package @fluentui/react-theme-provider from package.json. Was going to submit a PR, but a bit busy so letting you know here instead as it's a quick fix for you

@fabiofranzini
Copy link
Collaborator Author

@fabiofranzini Many thanks for another great contribution! I'm just reviewing this now and while testing the solution that you linked above I got one error as it's missing the package @fluentui/react-theme-provider from package.json. Was going to submit a PR, but a bit busy so letting you know here instead as it's a quick fix for you

Hi @joelfmrodrigues I just fixed the package.json! Thanks 🙂

Copy link
Collaborator

@joelfmrodrigues joelfmrodrigues left a comment

Choose a reason for hiding this comment

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

@fabiofranzini Great stuff! I just added 2 minor comments as I think you are using the same function in different locations

@joelfmrodrigues
Copy link
Collaborator

@fabiofranzini sorry just another note. As you are adding a new control, can you also update the documentation links so it get's displayed on the site?
image
No problem if not, I can always do it after. Just thought you were probably not aware of this

@fabiofranzini
Copy link
Collaborator Author

@fabiofranzini sorry just another note. As you are adding a new control, can you also update the documentation links so it get's displayed on the site? image No problem if not, I can always do it after. Just thought you were probably not aware of this

Great, sorry for that but I've completely missed this step! Thanks again

@joelfmrodrigues joelfmrodrigues merged commit 81219ed into pnp:dev May 8, 2022
@joelfmrodrigues joelfmrodrigues added this to the 3.9.0 milestone May 8, 2022
@joelfmrodrigues
Copy link
Collaborator

@fabiofranzini Merged! 👏👏👏

@fabiofranzini
Copy link
Collaborator Author

@fabiofranzini Merged! 👏👏👏

Great, thanks for your feedback! ♥️

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.

None yet

3 participants