Skip to content

Commit 253129d

Browse files
committed
merge
2 parents 2d92dc4 + a4bce0c commit 253129d

File tree

10 files changed

+1405
-927
lines changed

10 files changed

+1405
-927
lines changed
11.1 MB
Loading
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Variant Theme Provider
2+
3+
This control is a super set of the Theme Provider control, which not only allows you to pass the FluentUI Theme to the child controls, but also allows you to apply "variants" or generate a theme starting from the three basic colors, primary color, text color and color background.
4+
5+
The idea comes from the possibility of "highlighting" a Web Part in the page or section where it is contained.
6+
7+
By default, the SharePoint Modern Pages allow to change the set of colors which are then applied to all controls, but this can only be done at the site level (changing the site theme) or at the page section level (applying variations from the site theme).
8+
9+
With this control we have the possibility to apply the variants to the single Web Part or to a portion of it.
10+
11+
Here is an example of the control in action inside a Web Part:
12+
13+
![Variant Theme Provider control](../assets/VariantThemeProvider.gif)
14+
15+
## How to use this control in your solutions
16+
17+
- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../../#getting-started) page for more information about installing the dependency.
18+
- In your component file, import the `VariantThemeProvider` control as follows:
19+
20+
```TypeScript
21+
import { VariantThemeProvider, VariantType, IThemeColors } from "@pnp/spfx-controls-react/lib/VariantThemeProvider";
22+
```
23+
24+
- Example on use the `VariantThemeProvider` control with the 'Neutral' variant on custom theme generated from the 'themeColors' property:
25+
26+
```TSX
27+
const customThemeColors: IThemeColors = {
28+
primaryColor: "#0078d4",
29+
textColor: "#323130",
30+
backgroundColor: "#ffffff"
31+
}
32+
<VariantThemeProvider
33+
themeColors={customThemeColors}
34+
variantType={VariantType.Neutral}>
35+
{/* Child controls */}
36+
</VariantThemeProvider>
37+
```
38+
39+
- Example on use the `VariantThemeProvider` control with the 'Strong' variant on theme passed with the from the 'theme' property:
40+
41+
```TSX
42+
<VariantThemeProvider
43+
theme={theme}
44+
variantType={VariantType.Strong}>
45+
{/* Child controls */}
46+
</VariantThemeProvider>
47+
```
48+
49+
## Implementation
50+
51+
The `VariantThemeProvider` control can be configured with the following properties (inherits all the properties present in the FluentUI ThemeProvider control):
52+
53+
| Property | Type | Required | Description |
54+
| ---- | ---- | ---- | ---- |
55+
| as | React.ElementType | no | A component that should be used as the root element of the ThemeProvider component. |
56+
| ref | React.Ref<HTMLElement> | no | Optional ref to the root element. |
57+
| theme | PartialTheme \| Theme | no | Defines the theme provided by the user. |
58+
| renderer | StyleRenderer | no | Optional interface for registering dynamic styles. Defaults to using `merge-styles`. Use this to opt into a particular rendering implementation, such as `emotion`, `styled-components`, or `jss`. Note: performance will differ between all renders. Please measure your scenarios before using an alternative implementation. |
59+
| applyTo | element \| body \| none | no | Defines where body-related theme is applied to. Setting to 'element' will apply body styles to the root element of this control. Setting to 'body' will apply body styles to document body. Setting to 'none' will not apply body styles to either element or body. |
60+
| variantType | VariantType | no | Variant type to apply to the theme. |
61+
| themeColors | IThemeColors | no | Object used to generate a new theme from colors. |
62+
63+
Interface `IThemeColors`
64+
65+
| Property | Type | Required | Description |
66+
| ---- | ---- | ---- | ---- |
67+
| primaryColor | string | yes | Primary Color of the theme. |
68+
| textColor | string | yes | Text Color of the theme. |
69+
| backgroundColor | string | yes | Background Color of the theme. |
70+
71+
Enum `VariantType`
72+
73+
| Type | Description |
74+
| ---- | ---- |
75+
| None | Apply the theme without variations. |
76+
| Neutral | Apply the 'Neutral' variation to the theme. |
77+
| Soft | Apply the 'Soft' variation to the theme. |
78+
| Strong | Apply the 'Strong' variation to the theme. |
79+
80+
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/VariantThemeProvider)

0 commit comments

Comments
 (0)