Skip to content

Commit e176dff

Browse files
authored
Merge pull request #867 from pnp/site-picker
Site picker
2 parents e59fb52 + 2a70957 commit e176dff

File tree

12 files changed

+564
-2
lines changed

12 files changed

+564
-2
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
@@ -77,8 +77,9 @@ The following controls are currently available:
7777
- [PeoplePicker](./controls/PeoplePicker) (People Picker)
7878
- [Placeholder](./controls/Placeholder) (shows an initial placeholder if the web part has to be configured)
7979
- [Progress](./controls/Progress) (shows progress of multiple SEQUENTIALLY executed actions)
80-
- [SiteBreadcrumb](./controls/SiteBreadcrumb) (Breadcrumb control)
8180
- [SecurityTrimmedControl](./controls/SecurityTrimmedControl) (intended to be used when you want to show or hide components based on the user permissions)
81+
- [SiteBreadcrumb](./controls/SiteBreadcrumb) (Breadcrumb control)
82+
- [SitePicker](./controls/SitePicker) (Site Picker control)
8283
- [TaxonomyPicker](./controls/TaxonomyPicker) (Taxonomy Picker)
8384
- [Toolbar](./controls/Toolbar) (Control to render Toolbar in Microsoft Teams)
8485
- [TreeView](./controls/TreeView) (Tree View)

docs/documentation/mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ nav:
4747
- Placeholder: 'controls/Placeholder.md'
4848
- Progress: 'controls/Progress.md'
4949
- RichText: 'controls/RichText.md'
50-
- SiteBreadcrumb: 'controls/SiteBreadcrumb.md'
5150
- SecurityTrimmedControl: 'controls/SecurityTrimmedControl.md'
51+
- SiteBreadcrumb: 'controls/SiteBreadcrumb.md'
52+
- SitePicker: 'controls/SitePicker.md'
5253
- TaxonomyPicker: 'controls/TaxonomyPicker.md'
5354
- Toolbar: 'controls/Toolbar.md'
5455
- TreeView: 'controls/TreeView.md'

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)