Skip to content

Commit 3400323

Browse files
authored
Merge pull request #8755 from MicrosoftDocs/u/vilesyk/3034102_theming_doc
Fluent theming API docs
2 parents 5f3a7f9 + ad38f2a commit 3400323

File tree

10 files changed

+282
-23
lines changed

10 files changed

+282
-23
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
title: "Style components with modern theming (preview) | Microsoft Docs"
3+
description: You can style your components based on the modern theme used in the app."
4+
keywords: "Component Framework, code components, Power Apps controls"
5+
ms.author: hemantg
6+
author: HemantGaur
7+
ms.date: 11/15/2023
8+
ms.reviewer: jdaly
9+
ms.custom:
10+
- "dyn365-a11y"
11+
- "dyn365-developer"
12+
ms.topic: article
13+
ms.subservice: pcf
14+
contributors:
15+
- HemantGaur
16+
- noazarur-microsoft
17+
- JimDaly
18+
---
19+
20+
# Style components with modern theming (preview)
21+
22+
[!INCLUDE [cc-beta-prerelease-disclaimer](../../includes/cc-beta-prerelease-disclaimer.md)]
23+
24+
Developers need to be able to style their components so they look like the rest of the application they're included in. They can do this when modern theming is in effect for either a canvas app (via the [Modern controls and themes](../../maker/canvas-apps/controls/modern-controls/overview-modern-controls.md) feature) or model-driven app (through the [new refreshed look](../../user/modern-fluent-design.md)). Use modern theming, which is based on [Fluent UI React v9](https://react.fluentui.dev/), to style your component. This approach is recommended to get the best performance and theming experience for your component.
25+
26+
There are four different ways to apply modern theming to your component.
27+
28+
- [Fluent UI v9 controls](#fluent-ui-v9-controls)
29+
- [Fluent UI v8 controls](#fluent-ui-v8-controls)
30+
- [Non-Fluent UI controls](#non-fluent-ui-controls)
31+
- [Custom theme providers](#custom-theme-providers)
32+
33+
## Fluent UI v9 controls
34+
35+
Wrapping Fluent UI v9 controls as a component is the easiest way to utilize modern theming because the modern theme is automatically applied to these controls. The only prerequisite is to ensure your component adds a dependency on the [React controls & platform libraries (preview)](react-controls-platform-libraries.md) as shown below. This approach allows your component to use the same React and Fluent libraries as the platform, and therefore share the same React context that passes the theme tokens down to the component.
36+
37+
```xml
38+
<resources>
39+
<code path="index.ts" order="1"/>
40+
<!-- Dependency on React controls & platform libraries -->
41+
<platform-library name="React" version="16.8.6" />
42+
<platform-library name="Fluent" version="9.4.0" />
43+
</resources>
44+
```
45+
46+
## Fluent UI v8 controls
47+
48+
Fluent provides a migration path for applying v9 theme constructs when you use Fluent UI v8 controls in your component. Use the `createV8Theme` function included in the [Fluent's v8 to v9 migration package](https://www.npmjs.com/package/@fluentui/react-migration-v8-v9) to create a v8 theme based on v9 theme tokens, as shown in the following example:
49+
50+
```tsx
51+
const theme = createV8Theme(
52+
context.fluentDesignLanguage.brand,
53+
context.fluentDesignLanguage.theme
54+
);
55+
return <ThemeProvider theme={theme}></ThemeProvider>;
56+
```
57+
58+
## Non-Fluent UI controls
59+
60+
If your component doesn't use Fluent UI, you can take a dependency directly on the v9 theme tokens available through the `fluentDesignLanguage` context parameter. Use this parameter to get access to all [theme](reference/theming.md) tokens so it can reference any aspect of the theme to style itself.
61+
62+
```tsx
63+
<span style={{ fontSize: context.fluentDesignLanguage.theme.fontSizeBase300 }}>
64+
{"Stylizing HTML with platform provided theme."}
65+
</span>
66+
```
67+
68+
## Custom theme providers
69+
70+
When your component requires styling that is different from the current theme of the app, create your own `FluentProvider` and pass your own set of theme tokens to be used by your component.
71+
72+
```tsx
73+
<FluentProvider theme={context.fluentDesignLanguage.tokenTheme}>
74+
{/* your control */}
75+
</FluentProvider>
76+
```
77+
78+
## Sample controls
79+
80+
Examples for each of these use cases are available at [Modern Theming API control](./sample-controls/modern-theming-api-control.md).
81+
82+
## FAQ
83+
84+
This section contains frequently asked questions. If you have a question about this feature, use the **Feedback** for **This page** button at the bottom of this page to create a GitHub issue.
85+
86+
### Q: My control uses Fluent UI v9 and has a dependency on the platform libraries, but I don't want to utilize modern theming. How can I disable it for my component?
87+
88+
**A**: You can do this two different ways:
89+
90+
1. You can create your own component-level `FluentProvider`
91+
92+
```tsx
93+
<FluentProvider theme={customFluentV9Theme}>
94+
{/* your control */}
95+
</FluentProvider>
96+
```
97+
98+
1. You can wrap your control inside `IdPrefixContext.Provider` and set your own `idPrefix` value. This prevents your component from getting theme tokens from the platform.
99+
100+
```tsx
101+
<IdPrefixProvider value="custom-control-prefix">
102+
<Label weight="semibold">This label is not getting Modern Theming</Label>
103+
</IdPrefixProvider>
104+
```
105+
106+
### Q: Some of my Fluent UI v9 controls aren't getting styles
107+
108+
**A**: Fluent v9 controls that rely on the React Portal need to be rewrapped in the theme provider to ensure styling is properly applied. You can use `FluentProvider`.
109+
110+
### Q: How can I check if modern theming is enabled
111+
112+
**A**: You can check if tokens are available: `context.fluentDesignLanguage?.tokenTheme`. Or in model-driven applications you can check app settings: `context.appSettings.getIsFluentThemingEnabled()`.
113+
114+
## Related articles
115+
116+
[Theming (Power Apps component framework API reference)](../component-framework/reference/theming.md)
117+
[Modern Theming API control](./sample-controls/modern-theming-api-control.md)
118+
[Use modern themes in canvas apps (preview)](../../maker/canvas-apps/controls/modern-controls/modern-theming.md)
119+
120+
[!INCLUDE[footer-include](../../includes/footer-banner.md)]
Loading
Loading
Loading

powerapps-docs/developer/component-framework/react-controls-platform-libraries.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "React controls & platform libraries (Preview) | Microsoft Docs"
3-
description: "You can achieve significant performance gains using React and platform libraries. When you use React and platform libraries, you are using the same infrastructure used by the Power Apps platform. This means you no longer have to package React and Fluent packages individually for each control."
2+
title: "React controls & platform libraries (preview) | Microsoft Docs"
3+
description: "You can achieve significant performance gains using React and platform libraries. When you use React and platform libraries, you're using the same infrastructure used by the Power Apps platform. This means you no longer have to package React and Fluent packages individually for each control."
44
keywords: "Component Framework, code components, Power Apps controls"
55
ms.author: hemantg
66
author: HemantGaur
@@ -17,23 +17,23 @@ contributors:
1717
- JimDaly
1818
---
1919

20-
# React controls & platform libraries (Preview)
20+
# React controls & platform libraries (preview)
2121

2222
[!INCLUDE [cc-beta-prerelease-disclaimer](../../includes/cc-beta-prerelease-disclaimer.md)]
2323

24-
You can achieve significant performance gains using React and platform libraries. When you use React and platform libraries, you are using the same infrastructure used by the Power Apps platform. This means you no longer have to package React and Fluent libraries individually for each control. All controls will share a common library instance and version to provide a seamless and consistent experience.
24+
You can achieve significant performance gains using React and platform libraries. When you use React and platform libraries, you're using the same infrastructure used by the Power Apps platform. This means you no longer have to package React and Fluent libraries individually for each control. All controls share a common library instance and version to provide a seamless and consistent experience.
2525

26-
By re-using the existing platform React and Fluent libraries, you can expect the following benefits:
26+
By reusing the existing platform React and Fluent libraries, you can expect the following benefits:
2727

2828
- Reduced control bundle size
2929
- Optimized solution packaging
3030
- Faster runtime transfer, scripting and control rendering
3131

32-
With the benefits available by re-using these component resources, we expect this approach will become the preferred way all Power Apps code components will be created after this feature reaches general availability.
32+
With the benefits available by reusing these component resources, we expect this approach will become the preferred way all Power Apps code components will be created after this feature reaches general availability.
3333

3434
## Prerequisites
3535

36-
Just as with any component, you must install [Visual Studio Code](https://code.visualstudio.com/Download) and the [Microsoft Power Platform CLI](../data-platform/powerapps-cli.md#install-microsoft-power-platform-cli) as described here: [Prerequisites](implementing-controls-using-typescript.md#prerequisites)
36+
As with any component, you must install [Visual Studio Code](https://code.visualstudio.com/Download) and the [Microsoft Power Platform CLI](../data-platform/powerapps-cli.md#install-microsoft-power-platform-cli) as described here: [Prerequisites](implementing-controls-using-typescript.md#prerequisites)
3737

3838
> [!NOTE]
3939
> If you have already installed Power Platform CLI for Windows, make sure you are running the latest version by using the `pac install latest` command.
@@ -44,7 +44,7 @@ Just as with any component, you must install [Visual Studio Code](https://code.v
4444
> [!NOTE]
4545
> These instructions expect that you have created code components before. If you have not, see this tutorial: [Create your first component](implementing-controls-using-typescript.md)
4646
47-
There is a new `--framework` (`-fw`) parameter for the [pac pcf init](/power-platform/developer/cli/reference/pcf#pac-pcf-init) command. Set the value of this parameter to `react`.
47+
There's a new `--framework` (`-fw`) parameter for the [pac pcf init](/power-platform/developer/cli/reference/pcf#pac-pcf-init) command. Set the value of this parameter to `react`.
4848

4949
The following table shows the long form of the commands:
5050

@@ -56,19 +56,19 @@ The following table shows the long form of the commands:
5656
| `--framework` | `react` |
5757
| `--run-npm-install` | `true` (default) |
5858

59-
The following PowerShell command uses the parameter shortcuts and will create a React component project and run `npm-install` in the folder where you run the command:
59+
The following PowerShell command uses the parameter shortcuts and creates a React component project and run `npm-install` in the folder where you run the command:
6060

6161
```powershell
6262
pac pcf init -n ReactSample -ns SampleNamespace -t field -fw react -npm
6363
```
6464

6565
You can now build and view the control in the test harness as usual using `npm start`.
6666

67-
After you build the control you can package it inside solutions and use it for model-driven apps (including custom pages) and canvas apps like standard code components.
67+
After you build the control, you can package it inside solutions and use it for model-driven apps (including custom pages) and canvas apps like standard code components.
6868

6969
## Differences from standard components
7070

71-
These are the differences between a React component and a standard component.
71+
Thi section describes the differences between a React component and a standard component.
7272

7373
### ControlManifest.Input.xml
7474

@@ -77,7 +77,7 @@ The [control element](manifest-schema-reference/control.md) `control-type` attri
7777
> [!NOTE]
7878
> Changing this value does not convert a component from one type to another.
7979
80-
Within the [resources element](manifest-schema-reference/resources.md), you will find two new [platform-library element](manifest-schema-reference/platform-library.md) child elements like the following:
80+
Within the [resources element](manifest-schema-reference/resources.md), you'll find two new [platform-library element](manifest-schema-reference/platform-library.md) child elements like the following:
8181

8282
```xml
8383
<resources>
@@ -94,15 +94,15 @@ We recommend using Fluent platform libraries. If you don't use Fluent, you shoul
9494

9595
### Index.ts
9696

97-
The [ReactControl.init](reference/react-control/init.md) method for control initialization does not have `div` parameters because these controls do not render the DOM directly. Instead [ReactControl.updateView](reference/react-control/updateview.md) returns a ReactElement which has the details of the actual control in React format.
97+
The [ReactControl.init](reference/react-control/init.md) method for control initialization doesn't have `div` parameters because these controls don't render the DOM directly. Instead [ReactControl.updateView](reference/react-control/updateview.md) returns a ReactElement that has the details of the actual control in React format.
9898

9999
### bundle.js
100100

101-
React and Fluent libraries are not included in the package because they are shared, therfore the size of bundle.js is significantly smaller.
101+
React and Fluent libraries aren't included in the package because they're shared, therefore the size of bundle.js is smaller.
102102

103103
## Sample controls
104104

105-
You can find two new controls added to the samples as part of this preview. Functionally, they are the same as their standard version but will have much better performance.
105+
You can find two new controls added to the samples as part of this preview. Functionally, they're the same as their standard version but have better performance.
106106

107107
|Sample |Description|Link|
108108
|---------|---------|---------|
@@ -111,7 +111,7 @@ You can find two new controls added to the samples as part of this preview. Func
111111

112112
## Supported platform libraries list
113113

114-
Platform libraries are made available both at the build and runtime to the controls which are using platform libraries capability. Currently, the following versions are provided by the platform and these can also be found in the control manifest.
114+
Platform libraries are made available both at the build and runtime to the controls that are using platform libraries capability. Currently, the following versions are provided by the platform and these can also be found in the control manifest.
115115

116116
| Name | npm package name | Version |
117117
| ------ | ---------------- | ------- |
@@ -128,7 +128,7 @@ A: No. You must create a new control using the new template and then update the
128128

129129
A: No. React controls & platform libraries are currently only available for canvas and model-driven apps.
130130

131-
## Related topics
131+
## Related articles
132132

133133
[What are code components?](custom-controls-overview.md)<br/>
134134
[Code components for canvas apps](component-framework-for-canvas-apps.md)<br/>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Provides the API for platform-provided modern theming
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: Theming (Power Apps component framework API reference) | Microsoft Docs
3+
description: Provides the API for platform-provided modern theming.
4+
ms.author: vilesyk
5+
author: lesyk
6+
ms.date: 11/15/2023
7+
ms.reviewer: jdaly
8+
ms.topic: reference
9+
ms.subservice: pcf
10+
contributors:
11+
- JimDaly
12+
---
13+
14+
# Theming
15+
16+
[!INCLUDE [theming-description](includes/theming-description.md)]
17+
18+
## Available for
19+
20+
Model-driven and canvas apps
21+
22+
## Syntax
23+
24+
`context.fluentDesignLanguage`
25+
26+
## Properties
27+
28+
### tokenTheme
29+
30+
Fluent v9 theme tokens provided by the platform.
31+
32+
**Type**: [Theme](https://github.com/microsoft/fluentui/blob/master/packages/tokens/src/types.ts)
33+
34+
### typographyTokens
35+
36+
Fluent v9 typography tokens provided by the platform.
37+
38+
**Type**: [TypographyStyles](https://github.com/microsoft/fluentui/blob/master/packages/tokens/src/global/typographyStyles.ts)
39+
40+
### brand
41+
42+
Fluent v9 BrandVariants based on which Fluent v9 theme was generated.
43+
44+
**Type**: [BrandVariants](https://github.com/microsoft/fluentui/blob/master/packages/tokens/src/types.ts)
45+
46+
### isDarkTheme
47+
48+
Indicates whether the current theme is dark or not.
49+
50+
**Type**: `boolean`
51+
52+
## Example
53+
54+
```tsx
55+
const fluentDesignLanguage = props.context.fluentDesignLanguage;
56+
57+
return (
58+
<FluentProvider theme={props.theme}>
59+
<Label weight="semibold">{"Theming provided by the control."}</Label>
60+
</FluentProvider>
61+
);
62+
63+
```
64+
65+
## Sample controls
66+
67+
[Modern Theming API control](../sample-controls/modern-theming-api-control.md)
68+
69+
### Related articles
70+
71+
[Use modern themes in canvas apps (preview)](../../../maker/canvas-apps/controls/modern-controls/modern-theming.md)
72+
[Power Apps component framework API reference](../reference/index.md)
73+
[Power Apps component framework overview](../overview.md)
74+
75+
[!INCLUDE[footer-include](../../../includes/footer-banner.md)]

powerapps-docs/developer/component-framework/reference/usersettings.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ contributors:
1515

1616
[!INCLUDE [usersettings-description](includes/usersettings-description.md)]
1717

18-
## Available for
18+
## Available for
1919

2020
Model-driven and canvas apps
2121

@@ -65,7 +65,7 @@ The username of the current user. Supported only in model-driven apps.
6565

6666
## Methods
6767

68-
|Method | Description |
68+
|Method | Description |
6969
| ------|-------------|
7070
|[getTimeZoneOffsetMinutes](usersettings/gettimezoneoffsetminutes.md)|[!INCLUDE [gettimezoneoffsetminutes-description](usersettings/includes/gettimezoneoffsetminutes-description.md)]|
7171

0 commit comments

Comments
 (0)