Skip to content

Commit a7105ac

Browse files
committed
Merge branch 'ap-peoplepicker' of https://github.com/AsishP/sp-dev-fx-controls-react into AsishP-ap-peoplepicker
2 parents 522b7c3 + 32bfb6f commit a7105ac

File tree

10 files changed

+462
-1
lines changed

10 files changed

+462
-1
lines changed
4.02 KB
Loading
20.5 KB
Loading
7.64 KB
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# People Picker
2+
3+
This control renders a People picker field which can be used to select one or many users from a SharePoint group, or filter from all users in a SharePoint site. You could also set the control as mandatory and show a custom error message if field is empty.
4+
5+
**Empty People Picker control with error message and tooltip**
6+
7+
![People Picker](../assets/Peoplepicker-witherrorandtooltip.png)
8+
9+
**Selecting People**
10+
11+
![Selecting People](../assets/Peoplepicker-selectingchoices.png)
12+
13+
**Selected people**
14+
15+
![Selected people](../assets/Peoplepicker-multiplechoices.png)
16+
17+
18+
## How to use this control in your solutions
19+
20+
- 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.
21+
- Import the following modules to your component:
22+
23+
```TypeScript
24+
import { PeoplePicker } from "@pnp/spfx-controls-react/lib/PeoplePicker";
25+
```
26+
27+
- Use the `PeoplePicker` control in your code as follows:
28+
29+
```TypeScript
30+
<PeoplePicker
31+
context={this.props.context}
32+
titleText="People Picker"
33+
personSelectionLimit={3}
34+
groupName = {"Team Site Owners"} //leave this blank in case you want to filter from all users
35+
showtooltip = {true}
36+
isRequired = {true}
37+
selectedItems = {this._getPeoplePickerItems}
38+
/>
39+
```
40+
41+
- With the `selectedItems` property you can get the selected People in the Peoplepicker :
42+
43+
```typescript
44+
private _getPeoplePickerItems(items: any[]) {
45+
console.log('Items:', items);
46+
}
47+
```
48+
49+
## Implementation
50+
51+
The People picker control can be configured with the following properties:
52+
53+
| Property | Type | Required | Description |
54+
| ---- | ---- | ---- | ---- |
55+
| context | WebPartContext | yes | Context of the current web part. |
56+
| groupName | string | yes | group from which users are fetched. Leave it blank if need to filter all users |
57+
| titleText | string | yes | Text to be displayed on the control |
58+
| personSelectionLimit | number | no | Defines the limit of people that can be selected in the control|
59+
| isRequired | boolean | no | Set if the control is required or not |
60+
| errorMessage | string | no | Specify the error message to display |
61+
| errorMessageclassName | string | no | applies custom styling to the error message section|
62+
| showtooltip | boolean | no | Defines if need a tooltip or not |
63+
| tooltip | string | no | Specify the tooltip message to display |
64+
| tooltipDirectional | DirectionalHint | no | Direction where the tooltip would be shown |
65+
| selectedItems | function | no | get the selected users in the control|
66+
| peoplePickerWPclassName | string | no | applies custom styling to the people picker element|
67+
| peoplePickerCntrlclassName | string | no | applies custom styling to the people picker control only|
68+
69+
70+
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/PeoplePicker)

src/PeoplePicker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './controls/peoplepicker/index';
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { IPersonaProps, DirectionalHint } from "office-ui-fabric-react";
2+
import { WebPartContext } from '@microsoft/sp-webpart-base';
3+
4+
/**
5+
* Used to display a placeholder in case of no or temporary content. Button is optional.
6+
*
7+
*/
8+
export interface IPeoplePickerProps {
9+
/**
10+
* Context of the component
11+
*/
12+
context: WebPartContext;
13+
/**
14+
* Name of SharePoint Group
15+
*/
16+
groupName: string;
17+
/**
18+
* Text of the Control
19+
*/
20+
titleText: string;
21+
/**
22+
* Selection Limit of Control
23+
*/
24+
personSelectionLimit?: number;
25+
/**
26+
* Show or Hide Tooltip
27+
*/
28+
showtooltip? : boolean;
29+
/**
30+
* People Field is mandatory
31+
*/
32+
isRequired? : boolean;
33+
/**
34+
* Mandatory field error message
35+
*/
36+
errorMessage? : string;
37+
/**
38+
* Method to check value of People Picker text
39+
*/
40+
selectedItems?: (items: any[]) => void;
41+
/**
42+
* Tooltip Message
43+
*/
44+
tooltipMessage? : string;
45+
/**
46+
* Directional Hint of tool tip
47+
*/
48+
tooltipDirectional? : DirectionalHint;
49+
/**
50+
* Class Name for the whole People picker control
51+
*/
52+
peoplePickerWPclassName?:string;
53+
/**
54+
* Class Name for the People picker control
55+
*/
56+
peoplePickerCntrlclassName?: string;
57+
/**
58+
* Class Name for the Error Section
59+
*/
60+
errorMessageclassName?: string;
61+
}
62+
63+
export interface IPeoplePickerState {
64+
selectedPersons?: IPersonaProps[];
65+
mostRecentlyUsedPersons: IPersonaProps[];
66+
currentSelectedPersons: IPersonaProps[];
67+
allPersons: [{
68+
id: string,
69+
imageUrl: string,
70+
imageInitials: string,
71+
primaryText: string, //Name
72+
secondaryText: string, //Role
73+
tertiaryText: string, //status
74+
optionalText: string //stgring
75+
}];
76+
delayResults?: boolean;
77+
currentPicker?: number | string;
78+
peoplePersonaMenu?: IPersonaProps[];
79+
peoplePartTitle: string;
80+
peoplePartTooltip : string;
81+
isLoading : boolean;
82+
peopleValidatorText? : string;
83+
showmessageerror: boolean;
84+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.defaultClass {
2+
color : black;
3+
}

0 commit comments

Comments
 (0)