typescriptmicrosoft-teamsspfxfluent-uifluentui-react

Loading Fluentui 9.19.1 React components' style on Microsoft SharePoint WebPart


I'm currently developing a Microsoft WebPart. I'm using "yo @microsoft/sharepoint" to generate the project with React framework and I'd like to use the new "@fluentui/react-components" to design the WebPart.

But, when I deploy the application, the components appear without any style...

On App view

Extract from the code I use (.tsx file)

import { LargeTitle, Divider, Button } from '@fluentui/react-components';
import { DocumentRegular } from '@fluentui/react-icons'

<LargeTitle>Title:</LargeTitle>
<Button appearance="primary" icon={<DocumentRegular />}>
            Primary
</Button>
<Divider />

Expected Result : Expected Button

Any help is appreciated! Thank you

I have already tried: -to change browser -to clear the cache -to uninstall the package and then reinstall it -to install the package with npm install @fluentui/react-components or yarn add @fluentui/react-components.


Solution

  • Finally, I've found a way to load my FluentUI's style on my WebPart. First, I have to include my components in a Fluent Provider and add a theme :

    import {
      FluentProvider,
      teamsLightTheme,
      Button
    } from '@fluentui/react-components';
    
    ...
    
        <FluentProvider theme={teamsLightTheme}>
           <Button appearance=primary>
              Button
           </Button>
        </FluentProvider>