Skip to content

Commit b9a83fc

Browse files
authored
Merge pull request #868 from pnp/site-picker-v3
Site picker v3
2 parents e1a0c84 + 73460fb commit b9a83fc

File tree

14 files changed

+569
-6
lines changed

14 files changed

+569
-6
lines changed
1.76 MB
Loading
1.71 MB
Loading
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# SitePicker control
2+
3+
This control allows you to select one or multiple available sites, site collections or hub sites.
4+
5+
Here is an example of the control.
6+
7+
`SitePicker` single selection mode:
8+
9+
![SitePicker Single Select](../assets/site-picker-single-select.gif)
10+
11+
`SitePicker` multi-selection mode
12+
13+
![SitePicker Multi Select](../assets/site-picker-multi-select.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+
- Import the control into your component:
19+
20+
```TypeScript
21+
import { SitePicker } from "@pnp/spfx-controls-react/lib/SitePicker";
22+
```
23+
24+
- Use the `SitePicker` control in your code as follows:
25+
26+
```TypeScript
27+
<SitePicker
28+
context={this.props.context}
29+
label={'Select sites'}
30+
mode={'site'}
31+
allowSearch={true}
32+
multiSelect={false}
33+
onChange={(sites) => { console.log(sites); }}
34+
placeholder={'Select sites'}
35+
searchPlaceholder={'Filter sites'} />
36+
```
37+
38+
- The `onChange` change event returns the selected site(s).
39+
40+
## Implementation
41+
42+
The `SitePicker` control can be configured with the following properties:
43+
44+
| Property | Type | Required | Description |
45+
| ---- | ---- | ---- | ---- |
46+
| allowSearch | boolean | no | Specifies if search box is displayed for the component. Default: `true`. |
47+
| context | BaseComponentContext | yes | The context object of the SPFx loaded webpart or customizer. |
48+
| deferredSearchTime | number | no | The list will be filtered after users stop typing for `deferredSearchTime` milliseconds. Default: 200. |
49+
| className | string | no | If provided, additional class name to provide on the dropdown element. |
50+
| disabled | boolean | no | Whether or not the control is disabled. |
51+
| initialSites | ISite[] | no | Intial data to load in the 'Selected sites' area (optional). |
52+
| isDesc | boolean | no | Specifies if the list is sorted in descending order. Default: `false`. |
53+
| label | string | no | Label to use for the control. |
54+
| limitToCurrentSiteCollection | boolean | no | Specifies if the options should be limited by the current site collections. Taken into consideration if selectionMode is set to `web`. |
55+
| mode | `'site' \| 'web' \| 'hub'` | no | Defines what entities are available for selection: site collections, sites, hub sites. Default: `web`. |
56+
| multiSelect | boolean | no | Optional mode indicates if multi-choice selections is allowed. Default: `true`. |
57+
| onChange | `(selectedSites: ISite[]) => void` | yes | Selection change handler. |
58+
| orderBy | `'title' \| 'url'` | no | Specifices if the list is sorted by title or url. Default: `title`. |
59+
| placeholder | string | no | Placeholder label to show in the dropdown. |
60+
| searchPlaceholder | string | no | Search input placeholder text. Displayed until search text is entered. |
61+
62+
Interface `ISite`
63+
64+
| Property | Type | Required | Description |
65+
| ---- | ---- | ---- | ---- |
66+
| id | string | no | ID of the site collection. |
67+
| title | string | no | Title of the site. |
68+
| url | string | no | URL of the site. |
69+
| webId | string | no | ID of the site. **Note: the value is not populated if the `mode` is set to `hub`. |
70+
| hubSiteId | string | no | ID of the hub site. |
71+
72+
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/SitePicker)

docs/documentation/docs/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ The following controls are currently available:
8282
- [PeoplePicker](./controls/PeoplePicker) (People Picker)
8383
- [Placeholder](./controls/Placeholder) (shows an initial placeholder if the web part has to be configured)
8484
- [Progress](./controls/Progress) (shows progress of multiple SEQUENTIALLY executed actions)
85-
- [SiteBreadcrumb](./controls/SiteBreadcrumb) (Breadcrumb control)
8685
- [SecurityTrimmedControl](./controls/SecurityTrimmedControl) (intended to be used when you want to show or hide components based on the user permissions)
86+
- [SiteBreadcrumb](./controls/SiteBreadcrumb) (Breadcrumb control)
87+
- [SitePicker](./controls/SitePicker) (Site Picker control)
8788
- [TaxonomyPicker](./controls/TaxonomyPicker) (Taxonomy Picker)
8889
- [TeamChannelPicker](./controls/TeamChannelPicker) (Team Channel Picker)
8990
- [TeamPicker](./controls/TeamPicker) (Team Picker)

docs/documentation/mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ nav:
4646
- Placeholder: 'controls/Placeholder.md'
4747
- Progress: 'controls/Progress.md'
4848
- RichText: 'controls/RichText.md'
49-
- SiteBreadcrumb: 'controls/SiteBreadcrumb.md'
5049
- SecurityTrimmedControl: 'controls/SecurityTrimmedControl.md'
50+
- SiteBreadcrumb: 'controls/SiteBreadcrumb.md'
51+
- SitePicker: 'controls/SitePicker.md'
5152
- TaxonomyPicker: 'controls/TaxonomyPicker.md'
5253
- TeamChannelPicker: 'controls/TeamChannelPicker.md'
5354
- TeamPicker: 'controls/TeamPicker.md'

release/manifests/45165954-80f9-44c1-9967-cd38ae92a33b.manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "45165954-80f9-44c1-9967-cd38ae92a33b",
33
"alias": "ControlsTestWebPart",
44
"componentType": "WebPart",
5-
"version": "3.0.0",
5+
"version": "3.1.0",
66
"manifestVersion": 2,
77
"requiresCustomScript": false,
88
"supportedHosts": [
@@ -34,7 +34,7 @@
3434
"scriptResources": {
3535
"controls-test-web-part": {
3636
"type": "path",
37-
"path": "controls-test-web-part_b896484b103ab8e5d0a7.js"
37+
"path": "controls-test-web-part_a9076e8a5beb0b253af9.js"
3838
},
3939
"tslib": {
4040
"type": "component",

release/manifests/57ebd944-98ed-43f9-b722-e959d6dac6ad.manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"alias": "OotbFieldsFieldCustomizer",
44
"componentType": "Extension",
55
"extensionType": "FieldCustomizer",
6-
"version": "3.0.0",
6+
"version": "3.1.0",
77
"manifestVersion": 2,
88
"requiresCustomScript": false,
99
"loaderConfig": {
@@ -14,7 +14,7 @@
1414
"scriptResources": {
1515
"ootb-fields-field-customizer": {
1616
"type": "path",
17-
"path": "ootb-fields-field-customizer_b896484b103ab8e5d0a7.js"
17+
"path": "ootb-fields-field-customizer_a9076e8a5beb0b253af9.js"
1818
},
1919
"tslib": {
2020
"type": "component",

src/SitePicker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './controls/sitePicker/index';

src/common/utilities/GeneralHelper.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,12 @@ export function urlCombine(urlStart: string, urlFinish: string, escapeFinish: bo
351351

352352
return url;
353353
}
354+
355+
export const toRelativeUrl = (absoluteUrl: string): string => {
356+
357+
if (!absoluteUrl) {
358+
return '';
359+
}
360+
361+
return absoluteUrl.replace(/^(?:\/\/|[^/]+)*\//, '/');
362+
};
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { BaseComponentContext } from '@microsoft/sp-component-base';
2+
3+
export interface ISite {
4+
/**
5+
* ID of the site
6+
*/
7+
id?: string;
8+
/**
9+
* Title
10+
*/
11+
title?: string;
12+
/**
13+
* Base URL
14+
*/
15+
url?: string;
16+
17+
/**
18+
* ID of the web
19+
*/
20+
webId?: string;
21+
22+
/**
23+
* ID of the hub site
24+
*/
25+
hubSiteId?: string;
26+
}
27+
28+
export interface ISitePickerProps {
29+
/**
30+
* Site picker label
31+
*/
32+
label?: string;
33+
/**
34+
* Specify if the control needs to be disabled
35+
*/
36+
disabled?: boolean;
37+
/**
38+
* Web Part context
39+
*/
40+
context: BaseComponentContext;
41+
/**
42+
* Intial data to load in the 'Selected sites' area (optional)
43+
*/
44+
initialSites?: ISite[];
45+
/**
46+
* Define if you want to allow multi site selection. True by default.
47+
*/
48+
multiSelect?: boolean;
49+
/**
50+
* Defines what entities are available for selection: site collections, sites, hub sites.
51+
*/
52+
mode?: 'site' | 'web' | 'hub';
53+
54+
/**
55+
* Specifies if the options should be limited by the current site collections. Taken into consideration if selectionMode is set to 'web'
56+
*/
57+
limitToCurrentSiteCollection?: boolean;
58+
59+
/**
60+
* Specifies if search box is displayed for the component. Default: true
61+
*/
62+
allowSearch?: boolean;
63+
64+
/**
65+
* Specifices if the list is sorted by title or url. Default: title
66+
*/
67+
orderBy?: 'title' | 'url';
68+
69+
/**
70+
* Specifies if the list is sorted in descending order. Default: false
71+
*/
72+
isDesc?: boolean;
73+
74+
/**
75+
* Selection change handler
76+
*/
77+
onChange: (selectedSites: ISite[]) => void;
78+
79+
/**
80+
* Input placeholder text. Displayed until option is selected.
81+
*/
82+
placeholder?: string;
83+
84+
/**
85+
* Search input placeholder text. Displayed until search text is entered.
86+
*/
87+
searchPlaceholder?: string;
88+
89+
/**
90+
* The list will be filtered after users stop typing for `deferredSearchTime` milliseconds.
91+
* Default value is 200.
92+
*/
93+
deferredSearchTime?: number;
94+
95+
/**
96+
* If provided, additional class name to provide on the dropdown element.
97+
*/
98+
className?: string;
99+
}

0 commit comments

Comments
 (0)