Skip to content

Commit 05f9b99

Browse files
author
Piotr Siatka
committed
Update documentation.
1 parent 15856bd commit 05f9b99

File tree

9 files changed

+101
-12
lines changed

9 files changed

+101
-12
lines changed
166 KB
Loading
682 KB
Loading
875 KB
Loading
185 KB
Loading
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# FilePicker control
2+
3+
File picker control allows to browse and select a file from various places.
4+
Currently supported locations
5+
- Recent files - tab allows to select a file from recently modified files based on the search results.
6+
- Web search - tab uses Bing cognitive services to look for a file. (Only images)
7+
- OneDrive - tab allows to select a file from the user's One Drive.
8+
- Site document libraries - tab allows to select a file from the existing site document libraries.
9+
- Upload - tab allows to upload a file from local drive.
10+
- From a link - tab allows to paste a link to the document.
11+
12+
## Overview
13+
The control supports all types of file, however it also allows to specify list of extensions for the files that are going to be looked displayed. Currently, only single file selection is supported.
14+
![File Picker overview](../assets/FilePickerOverview.png)
15+
16+
### Contribution
17+
**File picker control has been developed based on the great SPFx project made by Hugo and presented in the [SP-Dev-Fx-WebParts Sample Repository](https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/react-comparer)**.
18+
19+
20+
## Different display types
21+
File picker support 3 types of views : List, Compact list and Tiles. In case Tiles view is selected, the control shows the thumbnail of the file.
22+
![File Picker views](../assets/FilePickerViews.gif)
23+
24+
25+
## Breadcrumb support
26+
The control displays breadcrumb navigation that allows to easily switch folders or document libraries.
27+
![File Picker breadcrumb](../assets/FilePickerBreadcrumb.gif)
28+
29+
## Paged data load
30+
File picker doesn't load all the files that exist in the folder. Instead, it allows to specify how many results are loaded in a batch, and executes paged requests when new data is required.
31+
![File Picker paged data load](../assets/FilePickerPaging.gif)
32+
33+
34+
## How to use this control
35+
36+
- 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.
37+
- Import the following module to your component:
38+
39+
```TypeScript
40+
import { FilePicker, IFilePickerResult } from '@pnp/spfx-controls-react/lib/FilePicker';
41+
```
42+
43+
- Use the `FilePicker` control in your code as follows:
44+
45+
```TypeScript
46+
<FilePicker
47+
bingAPIKey="<BING API KEY>"
48+
accepts= ".gif,.jpg,.jpeg,.bmp,.dib,.tif,.tiff,.ico,.png,.jxr,.svg"
49+
buttonIcon="FileImage"
50+
onSave={(filePickerResult: IFilePickerResult) => { this.setState({filePickerResult }) }}
51+
onChanged={(filePickerResult: IFilePickerResult) => { this.setState({filePickerResult }) }}
52+
webPartContext={this.props.context}
53+
/>
54+
```
55+
56+
## Implementation
57+
58+
The FilePicker component can be configured with the following properties:
59+
60+
| Property | Type | Required | Description |
61+
| ---- | ---- | ---- | ---- |
62+
| label | string | no | Specifies the text describing the file picker. |
63+
| buttonLabel | string | no | Specifies the label of the file picker button. |
64+
| buttonIcon | string | no | In case it is provided the file picker will be rendered as an Icon button. |
65+
| onSave | (filePickerResult: IFilePickerResult) => void | yes | Handler when the file has been selected and picker has been closed. |
66+
| onChange | (filePickerResult: IFilePickerResult) => void | yes | Handler when the file selection has been changed. |
67+
| webPartContext | WebPartContext | yes | Current context. |
68+
| accepts | string | no | Comma separated list of file extensions that going to be displayed. E.g. ".gif,.jpg,.jpeg,.bmp,.dib,.tif,.tiff,.ico,.png,.jxr,.svg" |
69+
| required | boolean | no | Sets the label to inform that the value is required. |
70+
| bingAPIKey | string | no | Used to execute WebSearch. If not provided SearchTab will not be available. |
71+
| disabled | boolean | no | Specifies if the picker button is disabled |
72+
| itemsCountQueryLimit | number | no | Number of items to obtain when executing REST queries. Default 100. |
73+
| hideRecentTab | boolean | no | Specifies if RecentTab should be hidden. |
74+
| hideWebSearchTab | boolean | no | Specifies if WebSearchTab should be hidden. |
75+
| hideOrganisationalAssetTab | boolean | no | Specifies if OrganisationalAssetTab should be hidden. |
76+
| hideOneDriveTab | boolean | no | Specifies if OneDriveTab should be hidden. |
77+
| hideSiteFilesTab | boolean | no | Specifies if SiteFilesTab should be hidden. |
78+
| hideLocalUploadTab | boolean | no | Specifies if LocalUploadTab should be hidden. |
79+
| hideLinkUploadTab | boolean | no | Specifies if LinkUploadTab should be hidden. |
80+
81+
interface `IFilePickerResult`
82+
83+
Provides options for carousel buttons location.
84+
85+
| Value | Description |
86+
| ---- | ---- |
87+
| fileName | string | yes | File namr of the result with the extension. |
88+
| fileNameWithoutExtension | string | yes | File namr of the result without the extension. |
89+
| fileAbsoluteUrl | string | yes | Absolute URL of the file. Null in case of file upload. |
90+
| file | File | yes | JS Object representing File. Will be set in case of file upload. |
91+
92+
93+
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/filePicker/FilePicker)

src/controls/filePicker/FilePicker.module.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@
170170
flex-grow: 2;
171171
}
172172
.tabFiles {
173-
overflow-y: auto;
173+
overflow-y: hidden;
174+
overflow-x: hidden;
174175
-webkit-box-flex: 2;
175176
-ms-flex-positive: 2;
176177
flex-grow: 2;

src/controls/filePicker/FilePicker.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from 'react';
22
import { IFilePickerProps } from './IFilePickerProps';
33
import { IFilePickerState } from './IFilePickerState';
44

5-
// Office Fabric controls
65
import { PrimaryButton, IconButton } from 'office-ui-fabric-react/lib/components/Button';
76
import { Panel, PanelType } from 'office-ui-fabric-react/lib/components/Panel';
87
import { Label } from 'office-ui-fabric-react/lib/components/Label';
@@ -12,7 +11,6 @@ import { css } from "@uifabric/utilities/lib/css";
1211
// Localization
1312
import * as strings from 'ControlStrings';
1413

15-
// Custom property pane file picker tabs
1614
import LinkFilePickerTab from './LinkFilePickerTab/LinkFilePickerTab';
1715
import UploadFilePickerTab from './UploadFilePickerTab/UploadFilePickerTab';
1816
import SiteFilePickerTab from './SiteFilePickerTab/SiteFilePickerTab';
@@ -27,6 +25,8 @@ import { OrgAssetsService } from '../../services/OrgAssetsService';
2725
import { IFilePickerResult } from './FilePicker.types';
2826
import { FilesSearchService } from '../../services/FilesSearchService';
2927

28+
import * as telemetry from '../../common/telemetry';
29+
3030
export class FilePicker extends React.Component<IFilePickerProps, IFilePickerState> {
3131
private fileBrowserService: FileBrowserService;
3232
private oneDriveService: OneDriveService;
@@ -36,6 +36,8 @@ export class FilePicker extends React.Component<IFilePickerProps, IFilePickerSta
3636
constructor(props: IFilePickerProps) {
3737
super(props);
3838

39+
telemetry.track('FilePicker', {});
40+
3941
// Initialize file browser services
4042
this.fileBrowserService = new FileBrowserService(props.webPartContext, this.props.itemsCountQueryLimit);
4143
this.oneDriveService = new OneDriveService(props.webPartContext, this.props.itemsCountQueryLimit);

src/controls/filePicker/IFilePickerProps.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ export interface IFilePickerProps {
1616
*/
1717
buttonIcon?: string;
1818

19-
/**
20-
* Content of the file.
21-
*/
22-
filePickerResult: IFilePickerResult;
23-
2419
/**
2520
* Handler when the file has been selected
2621
*/

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,11 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
339339
return (
340340
<div className={styles.controlsTest}>
341341
<FilePicker
342-
bingAPIKey="D41D8CD98F00B204E9800998ECF8427E06193A4E"
343-
// buttonLabel="Choose file"
344-
// label="File picker"
342+
bingAPIKey="<BING API KEY>"
343+
accepts= ".gif,.jpg,.jpeg,.bmp,.dib,.tif,.tiff,.ico,.png,.jxr,.svg"
345344
buttonIcon="FileImage"
346345
onSave={(filePickerResult: IFilePickerResult) => { this.setState({filePickerResult }) }}
347346
onChanged={(filePickerResult: IFilePickerResult) => { this.setState({filePickerResult }) }}
348-
filePickerResult={null}
349347
webPartContext={this.props.context}
350348
/>
351349
{

0 commit comments

Comments
 (0)