Skip to content

Commit 7a89e5b

Browse files
authored
Added details to sample and switched to bodyBackground
1 parent 517ef8e commit 7a89e5b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

docs/spfx/web-parts/guidance/supporting-section-backgrounds.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ You will have to add a `supportsThemeVariants` property to the manifest of your
5656
In order to make the web part aware of any theme changes you have to implement support for the ThemeProvider service which will raise an event in case a theme change has taken place.
5757

5858
```typescript
59+
import { ThemeProvider, ThemeChangedEventArgs, IReadonlyTheme, ISemanticColors } from '@microsoft/sp-component-base';
60+
61+
...
62+
63+
private _themeProvider: ThemeProvider;
64+
private _themeVariant: IReadonlyTheme | undefined;
65+
5966
protected onInit(): Promise<void> {
6067
// Consume the new ThemeProvider service
6168
this._themeProvider = this.context.serviceScope.consume(ThemeProvider.serviceKey);
@@ -97,6 +104,13 @@ public render(): void {
97104
For a React based web part you will have to implement code to consume the ThemeProvider, just like with a basic web part:
98105

99106
```typescript
107+
import { ThemeProvider, ThemeChangedEventArgs, IReadonlyTheme } from '@microsoft/sp-component-base';
108+
109+
...
110+
111+
private _themeProvider: ThemeProvider;
112+
private _themeVariant: IReadonlyTheme | undefined;
113+
100114
protected onInit(): Promise<void> {
101115
// Consume the new ThemeProvider service
102116
this._themeProvider = this.context.serviceScope.consume(ThemeProvider.serviceKey);
@@ -139,6 +153,8 @@ public render(): void {
139153
In order to use that property in your component you will have to add it to your properties interface definition, which in this case is called IBasicSectionBackgroundExampleProps:
140154

141155
```typescript
156+
import { IReadonlyTheme } from '@microsoft/sp-component-base';
157+
142158
export interface IBasicSectionBackgroundExampleProps {
143159
themeVariant: IReadonlyTheme | undefined;
144160
}
@@ -152,7 +168,7 @@ public render(): React.ReactElement<IBasicSectionBackgroundExampleProps> {
152168
const { semanticColors }: IReadonlyTheme = this.props.themeVariant;
153169

154170
return (
155-
<div style={{color: semanticColors.bodyText}}>
171+
<div style={{backgroundColor: semanticColors.bodyBackground}}>
156172
<p>This React web part has support for section backgrounds and will inherit its background from the section</p>
157173
</div>
158174
);
@@ -162,4 +178,5 @@ public render(): React.ReactElement<IBasicSectionBackgroundExampleProps> {
162178
## See also
163179

164180
- [Designing for section backgrounds using semantic slots](../../../design/semantic_slots.md)
165-
- [SharePoint Framework Overview](../../sharepoint-framework-overview.md)
181+
- [SharePoint Framework Overview](../../sharepoint-framework-overview.md)
182+
- [SPFx Section Background Samples](https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/section-backgrounds)

0 commit comments

Comments
 (0)