Skip to content

Commit 4125415

Browse files
authored
Merge pull request #655 from pnp/dev
v3.22
2 parents ffa69ac + 767ed9a commit 4125415

23 files changed

+1146
-4
lines changed

CHANGELOG.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
{
22
"versions": [
3+
{
4+
"version": "3.22.0",
5+
"changes": {
6+
"new": [
7+
"`PropertyFieldBrandFontPicker`: new Brand Center font picker control [#651](https://github.com/pnp/sp-dev-fx-property-controls/pull/651)"
8+
],
9+
"enhancements": [],
10+
"fixes": []
11+
},
12+
"contributions": [
13+
"[Valeras Narbutas](https://github.com/ValerasNarbutas)"
14+
]
15+
},
316
{
417
"version": "3.21.0",
518
"changes": {

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Releases
22

3+
## 3.22.0
4+
5+
### New control(s)
6+
7+
- `PropertyFieldBrandFontPicker`: new Brand Center font picker control [#651](https://github.com/pnp/sp-dev-fx-property-controls/pull/651)
8+
9+
### Contributors
10+
11+
Special thanks to our contributor: [Valeras Narbutas](https://github.com/ValerasNarbutas).
12+
313
## 3.21.0
414

515
### Enhancements

docs/documentation/docs/about/release-notes.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Releases
22

3+
## 3.22.0
4+
5+
### New control(s)
6+
7+
- `PropertyFieldBrandFontPicker`: new Brand Center font picker control [#651](https://github.com/pnp/sp-dev-fx-property-controls/pull/651)
8+
9+
### Contributors
10+
11+
Special thanks to our contributor: [Valeras Narbutas](https://github.com/ValerasNarbutas).
12+
313
## 3.21.0
414

515
### Enhancements
19.3 KB
Loading
14.1 KB
Loading
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# PropertyFieldBrandFontPicker control
2+
3+
This control generates a font picker that reads from SharePoint Brand Center and allows users to select corporate-approved fonts for their web parts. It supports both Brand Center fonts, system fonts, and custom font tokens with preview capabilities.
4+
5+
**PropertyFieldBrandFontPicker**
6+
7+
![PropertyFieldBrandFontPicker](../assets/PropertyFieldBrandFontPicker.png)
8+
9+
**PropertyFieldBrandFontPicker with font preview**
10+
11+
![Brand Font Picker with preview](../assets/brandfontpicker-preview.png)
12+
13+
## How to use this control in your solutions
14+
15+
1. Check that you installed the `@pnp/spfx-property-controls` dependency. Check out The [getting started](../../#getting-started) page for more information about installing the dependency.
16+
2. Import the following modules to your component:
17+
18+
```TypeScript
19+
import { PropertyFieldBrandFontPicker } from '@pnp/spfx-property-controls/lib/PropertyFieldBrandFontPicker';
20+
```
21+
22+
3. Create a new property for your web part, for example:
23+
24+
```TypeScript
25+
export interface IPropertyControlsTestWebPartProps {
26+
brandFont: string;
27+
}
28+
```
29+
30+
4. Add the custom property control to the `groupFields` of the web part property pane configuration:
31+
32+
```TypeScript
33+
PropertyFieldBrandFontPicker('brandFont', {
34+
label: 'Brand Font',
35+
initialValue: this.properties.brandFont,
36+
onSelectionChanged: (fontToken) => {
37+
this.properties.brandFont = fontToken.value;
38+
this.onPropertyPaneFieldChanged('brandFont', fontToken.value);
39+
},
40+
context: this.context,
41+
showPreview: true,
42+
key: 'brandFontFieldId'
43+
})
44+
```
45+
46+
## Using Custom Font Tokens
47+
48+
You can provide your own list of font tokens instead of relying on Brand Center:
49+
50+
```TypeScript
51+
import { IBrandFontToken } from '@pnp/spfx-property-controls/lib/PropertyFieldBrandFontPicker';
52+
53+
const customFontTokens: IBrandFontToken[] = [
54+
{
55+
name: 'corporateHeading',
56+
displayName: 'Corporate Heading Font',
57+
value: '"Montserrat", sans-serif',
58+
category: 'custom'
59+
},
60+
{
61+
name: 'corporateBody',
62+
displayName: 'Corporate Body Font',
63+
value: '"Open Sans", sans-serif',
64+
category: 'custom'
65+
}
66+
];
67+
68+
PropertyFieldBrandFontPicker('brandFont', {
69+
label: 'Custom Brand Font',
70+
initialValue: this.properties.brandFont,
71+
onSelectionChanged: (fontToken) => {
72+
this.properties.brandFont = fontToken.value;
73+
this.onPropertyPaneFieldChanged('brandFont', fontToken.value);
74+
},
75+
context: this.context,
76+
customFontTokens: customFontTokens,
77+
showPreview: true,
78+
key: 'brandFontFieldId'
79+
})
80+
```
81+
82+
## Implementation
83+
84+
The `PropertyFieldBrandFontPicker` control can be configured with the following properties:
85+
86+
| Property | Type | Required | Description |
87+
| ---- | ---- | ---- | ---- |
88+
| label | string | no | Property field label displayed on top. |
89+
| initialValue | string | no | Initial font value to be selected. |
90+
| onSelectionChanged | function | yes | Callback function when a font is selected. Returns the selected IBrandFontToken. |
91+
| context | BaseComponentContext | yes | The SPFx component context. |
92+
| customFontTokens | IBrandFontToken[] | no | Array of custom font tokens to display instead of Brand Center fonts. |
93+
| showPreview | boolean | no | Whether to display font preview text in the dropdown. Default is true. |
94+
| disabled | boolean | no | Whether the control is disabled. Default is false. |
95+
| onFontTokensLoaded | function | no | Callback function called when font tokens are loaded. |
96+
| loadingErrorMessage | string | no | Custom error message to display when font loading fails. |
97+
| key | string | yes | An UNIQUE key indicates the identity of this control. |
98+
99+
Interface `IBrandFontToken`:
100+
101+
| Property | Type | Required | Description |
102+
| ---- | ---- | ---- | ---- |
103+
| name | string | yes | Unique identifier for the font token. |
104+
| displayName | string | yes | Display name shown in the dropdown. |
105+
| value | string | yes | CSS font-family value (e.g., '"Lato", sans-serif'). |
106+
| preview | string | no | Optional preview text. |
107+
| category | string | no | Category for grouping (e.g., 'site', 'microsoft', 'custom'). |
108+
| fileUrl | string | no | Optional URL to font file or CSS. |
109+
110+
## Example
111+
112+
```TypeScript
113+
import * as React from 'react';
114+
import * as ReactDom from 'react-dom';
115+
import { Version } from '@microsoft/sp-core-library';
116+
import {
117+
BaseClientSideWebPart,
118+
IPropertyPaneConfiguration,
119+
PropertyPaneTextField
120+
} from '@microsoft/sp-webpart-base';
121+
122+
import { PropertyFieldBrandFontPicker } from '@pnp/spfx-property-controls/lib/PropertyFieldBrandFontPicker';
123+
124+
export interface IPropertyControlsTestWebPartProps {
125+
brandFont: string;
126+
}
127+
128+
export default class PropertyControlsTestWebPart extends BaseClientSideWebPart<IPropertyControlsTestWebPartProps> {
129+
130+
public render(): void {
131+
const element: React.ReactElement<IPropertyControlsTestWebPartProps> = React.createElement(
132+
PropertyControlsTest,
133+
{
134+
brandFont: this.properties.brandFont
135+
}
136+
);
137+
138+
ReactDom.render(element, this.domElement);
139+
}
140+
141+
protected get propertyPaneConfiguration(): IPropertyPaneConfiguration {
142+
return {
143+
pages: [
144+
{
145+
header: {
146+
description: strings.PropertyPaneDescription
147+
},
148+
groups: [
149+
{
150+
groupName: strings.BasicGroupName,
151+
groupFields: [
152+
PropertyFieldBrandFontPicker('brandFont', {
153+
label: 'Brand Font',
154+
initialValue: this.properties.brandFont,
155+
onSelectionChanged: (fontToken) => {
156+
this.properties.brandFont = fontToken.value;
157+
this.onPropertyPaneFieldChanged('brandFont', fontToken.value);
158+
},
159+
context: this.context,
160+
showPreview: true,
161+
key: 'brandFontFieldId'
162+
})
163+
]
164+
}
165+
]
166+
}
167+
]
168+
};
169+
}
170+
}
171+
```
172+
173+
![](https://telemetry.sharepointpnp.com/sp-dev-fx-property-controls/wiki/PropertyFieldBrandFontPicker)

docs/documentation/docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ telemetry.optOut();
5959

6060
The following controls are currently available:
6161

62+
- [PropertyFieldBrandFontPicker](./controls/PropertyFieldBrandFontPicker) (Property pane Brand Center font selector)
6263
- [PropertyFieldButton](./controls/PropertyFieldButton) (Property pane Button)
6364
- [PropertyFieldCodeEditor](./controls/PropertyFieldCodeEditor) (Property pane code editor)
6465
- [PropertyFieldCollectionData](./controls/PropertyFieldCollectionData) (Property pane collection data editor)

docs/documentation/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ nav:
99
- 'Submitting a PR': 'guides/submitting-pr.md'
1010
- 'Migrate v1 to v2': 'guides/migrate-from-v1.md'
1111
- Controls:
12+
- PropertyFieldBrandFontPicker: 'controls/PropertyFieldBrandFontPicker.md'
1213
- PropertyFieldButton: 'controls/PropertyFieldButton.md'
1314
- PropertyFieldCodeEditor: 'controls/PropertyFieldCodeEditor.md'
1415
- PropertyFieldCollectionData: 'controls/PropertyFieldCollectionData.md'

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pnp/spfx-property-controls",
33
"description": "Reusable property pane controls for SharePoint Framework solutions",
4-
"version": "3.21.0",
4+
"version": "3.22.0",
55
"engines": {
66
"node": ">=22.14.0 < 23.0.0"
77
},

0 commit comments

Comments
 (0)