adding sample to spfx repo (#643)
This commit is contained in:
parent
c9cb5ae48d
commit
e3d097576b
|
@ -0,0 +1,25 @@
|
|||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
|
||||
[*]
|
||||
|
||||
# change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# we recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{package,bower}.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
|
@ -0,0 +1,32 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
|
||||
# Build generated files
|
||||
dist
|
||||
lib
|
||||
solution
|
||||
temp
|
||||
*.sppkg
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# OSX
|
||||
.DS_Store
|
||||
|
||||
# Visual Studio files
|
||||
.ntvs_analysis.dat
|
||||
.vs
|
||||
bin
|
||||
obj
|
||||
|
||||
# Resx Generated Code
|
||||
*.resx.ts
|
||||
|
||||
# Styles Generated Code
|
||||
*.scss.ts
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"version": "1.6.0",
|
||||
"libraryName": "sp-fx-code-splitting",
|
||||
"libraryId": "e71d24c8-d252-4a08-a8b4-6616ac46775e",
|
||||
"environment": "spo",
|
||||
"packageManager": "npm",
|
||||
"isCreatingSolution": false,
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
# Code Splitting in SharePoint Framework
|
||||
|
||||
## Summary
|
||||
Load React components and third party packages on demand in SPFx
|
||||
|
||||
![Dynamic Loading of React components](./assets/cs3.gif)
|
||||
|
||||
## Used SharePoint Framework Version
|
||||
![SPFx v1.6.0](https://img.shields.io/badge/SPFx-1.6-green.svg)
|
||||
|
||||
## Applies to
|
||||
|
||||
* [SharePoint Framework](https:/dev.office.com/sharepoint)
|
||||
* [Office 365 tenant](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment)
|
||||
|
||||
## Solution
|
||||
|
||||
Solution|Author(s)
|
||||
--------|---------
|
||||
react-components-dynamicloading | Vardhaman Deshpande ([@vrdmn](https://twitter.com/vrdmn) , [vrdmn.com](http://vrdmn.com))
|
||||
|
||||
## Version history
|
||||
|
||||
Version|Date|Comments
|
||||
-------|----|--------
|
||||
1.0|October 09, 2018|Initial release
|
||||
|
||||
## Disclaimer
|
||||
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
|
||||
|
||||
---
|
||||
|
||||
## Minimal Path to Awesome
|
||||
|
||||
- Clone this repository
|
||||
- in the command line run:
|
||||
- `npm install`
|
||||
- `gulp serve`
|
||||
|
||||
## Features
|
||||
More details included in this blog post: https://www.vrdmn.com/2018/10/code-splitting-in-sharepoint-framework.html
|
||||
|
||||
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-components-dynamicloading" />
|
Binary file not shown.
After Width: | Height: | Size: 478 KiB |
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"loader-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/loader/LoaderWebPart.js",
|
||||
"manifest": "./src/webparts/loader/LoaderWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"LoaderWebPartStrings": "lib/webparts/loader/loc/{locale}.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
|
||||
"deployCdnPath": "temp/deploy"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||
"workingDir": "./temp/deploy/",
|
||||
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||
"container": "sp-fx-code-splitting",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "sp-fx-code-splitting-client-side-solution",
|
||||
"id": "e71d24c8-d252-4a08-a8b4-6616ac46775e",
|
||||
"version": "1.0.0.0",
|
||||
"includeClientSideAssets": true,
|
||||
"skipFeatureDeployment": true
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/sp-fx-code-splitting.sppkg"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||
"port": 4321,
|
||||
"https": true,
|
||||
"initialPage": "https://localhost:5432/workbench",
|
||||
"api": {
|
||||
"port": 5432,
|
||||
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const gulp = require('gulp');
|
||||
const build = require('@microsoft/sp-build-web');
|
||||
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||
|
||||
build.initialize(gulp);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"name": "sp-fx-code-splitting",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test",
|
||||
"prod": "gulp clean && gulp build --ship && gulp bundle -ship && gulp package-solution --ship"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/sp-core-library": "1.6.0",
|
||||
"@microsoft/sp-lodash-subset": "1.6.0",
|
||||
"@microsoft/sp-webpart-base": "1.6.0",
|
||||
"@types/es6-promise": "0.0.33",
|
||||
"@types/react": "15.6.6",
|
||||
"@types/react-dom": "15.5.6",
|
||||
"@types/webpack-env": "1.13.1",
|
||||
"moment": "^2.22.2",
|
||||
"office-ui-fabric-react": "^5.125.0",
|
||||
"react": "15.6.2",
|
||||
"react-dom": "15.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/sp-build-web": "1.6.0",
|
||||
"@microsoft/sp-module-interfaces": "1.6.0",
|
||||
"@microsoft/sp-webpart-workbench": "1.6.0",
|
||||
"tslint-microsoft-contrib": "~5.0.0",
|
||||
"gulp": "~3.9.1",
|
||||
"@types/chai": "3.4.34",
|
||||
"@types/mocha": "2.2.38",
|
||||
"ajv": "~5.2.2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "71039ada-32dc-4509-944c-91d3f1b3ae33",
|
||||
"alias": "LoaderWebPart",
|
||||
"componentType": "WebPart",
|
||||
|
||||
// The "*" signifies that the version should be taken from the package.json
|
||||
"version": "*",
|
||||
"manifestVersion": 2,
|
||||
|
||||
// If true, the component can only be installed on sites where Custom Script is allowed.
|
||||
// Components that allow authors to embed arbitrary script code should set this to true.
|
||||
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
|
||||
"requiresCustomScript": false,
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||
"group": { "default": "Other" },
|
||||
"title": { "default": "Code Splitting Demo - Loader" },
|
||||
"description": { "default": "Loader description" },
|
||||
"officeFabricIconFontName": "Code",
|
||||
"properties": {
|
||||
"description": "Loader"
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
import * as React from 'react';
|
||||
import * as ReactDom from 'react-dom';
|
||||
import { Version } from '@microsoft/sp-core-library';
|
||||
import {
|
||||
BaseClientSideWebPart
|
||||
} from '@microsoft/sp-webpart-base';
|
||||
|
||||
import Loader from './components/Loader';
|
||||
import { ILoaderProps } from './components/ILoaderProps';
|
||||
|
||||
export interface ILoaderWebPartProps {
|
||||
}
|
||||
|
||||
export default class LoaderWebPart extends BaseClientSideWebPart<ILoaderWebPartProps> {
|
||||
|
||||
public render(): void {
|
||||
const element: React.ReactElement<ILoaderProps > = React.createElement(
|
||||
Loader
|
||||
);
|
||||
|
||||
ReactDom.render(element, this.domElement);
|
||||
}
|
||||
|
||||
protected onDispose(): void {
|
||||
ReactDom.unmountComponentAtNode(this.domElement);
|
||||
}
|
||||
|
||||
protected get dataVersion(): Version {
|
||||
return Version.parse('1.0');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,337 @@
|
|||
import * as React from 'react';
|
||||
import { TextField } from 'office-ui-fabric-react/lib/TextField';
|
||||
import { Toggle } from 'office-ui-fabric-react/lib/Toggle';
|
||||
import {
|
||||
DetailsList,
|
||||
DetailsListLayoutMode,
|
||||
Selection,
|
||||
SelectionMode,
|
||||
IColumn
|
||||
} from 'office-ui-fabric-react/lib/DetailsList';
|
||||
import { MarqueeSelection } from 'office-ui-fabric-react/lib/MarqueeSelection';
|
||||
|
||||
let _items: IDocument[] = [];
|
||||
|
||||
const fileIcons: { name: string }[] = [
|
||||
{ name: 'accdb' },
|
||||
{ name: 'csv' },
|
||||
{ name: 'docx' },
|
||||
{ name: 'dotx' },
|
||||
{ name: 'mpp' },
|
||||
{ name: 'mpt' },
|
||||
{ name: 'odp' },
|
||||
{ name: 'ods' },
|
||||
{ name: 'odt' },
|
||||
{ name: 'one' },
|
||||
{ name: 'onepkg' },
|
||||
{ name: 'onetoc' },
|
||||
{ name: 'potx' },
|
||||
{ name: 'ppsx' },
|
||||
{ name: 'pptx' },
|
||||
{ name: 'pub' },
|
||||
{ name: 'vsdx' },
|
||||
{ name: 'vssx' },
|
||||
{ name: 'vstx' },
|
||||
{ name: 'xls' },
|
||||
{ name: 'xlsx' },
|
||||
{ name: 'xltx' },
|
||||
{ name: 'xsn' }
|
||||
];
|
||||
|
||||
export interface IDetailsListDocumentsExampleState {
|
||||
columns: IColumn[];
|
||||
items: IDocument[];
|
||||
selectionDetails: string;
|
||||
isModalSelection: boolean;
|
||||
isCompactMode: boolean;
|
||||
}
|
||||
|
||||
export interface IDocument {
|
||||
[key: string]: any;
|
||||
name: string;
|
||||
value: string;
|
||||
iconName: string;
|
||||
modifiedBy: string;
|
||||
dateModified: string;
|
||||
dateModifiedValue: number;
|
||||
fileSize: string;
|
||||
fileSizeRaw: number;
|
||||
}
|
||||
|
||||
export class DetailsListDocumentsComponent extends React.Component<any, IDetailsListDocumentsExampleState> {
|
||||
private _selection: Selection;
|
||||
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
|
||||
// Populate with items for demos.
|
||||
if (_items.length === 0) {
|
||||
for (let i = 0; i < 500; i++) {
|
||||
const randomDate = this._randomDate(new Date(2012, 0, 1), new Date());
|
||||
const randomFileSize = this._randomFileSize();
|
||||
const randomFileType = this._randomFileIcon();
|
||||
let fileName: string = Math.random().toString(36).substring(7);
|
||||
let userName: string = "Joe Contoso";
|
||||
fileName = fileName.charAt(0).toUpperCase() + fileName.slice(1).concat(`.${randomFileType.docType}`);
|
||||
userName = userName
|
||||
.split(' ')
|
||||
.map((name: string) => name.charAt(0).toUpperCase() + name.slice(1))
|
||||
.join(' ');
|
||||
_items.push({
|
||||
name: fileName,
|
||||
value: fileName,
|
||||
iconName: randomFileType.url,
|
||||
modifiedBy: userName,
|
||||
dateModified: randomDate.dateFormatted,
|
||||
dateModifiedValue: randomDate.value,
|
||||
fileSize: randomFileSize.value,
|
||||
fileSizeRaw: randomFileSize.rawSize
|
||||
});
|
||||
}
|
||||
_items = this._sortItems(_items, 'name');
|
||||
}
|
||||
|
||||
const _columns: IColumn[] = [
|
||||
{
|
||||
key: 'column1',
|
||||
name: 'File Type',
|
||||
headerClassName: 'DetailsListExample-header--FileIcon',
|
||||
className: 'DetailsListExample-cell--FileIcon',
|
||||
iconClassName: 'DetailsListExample-Header-FileTypeIcon',
|
||||
ariaLabel: 'Column operations for File type',
|
||||
iconName: 'Page',
|
||||
isIconOnly: true,
|
||||
fieldName: 'name',
|
||||
minWidth: 16,
|
||||
maxWidth: 16,
|
||||
onColumnClick: this._onColumnClick,
|
||||
onRender: (item: IDocument) => {
|
||||
return <img src={item.iconName} className={'DetailsListExample-documentIconImage'} />;
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'column2',
|
||||
name: 'Name',
|
||||
fieldName: 'name',
|
||||
minWidth: 210,
|
||||
maxWidth: 350,
|
||||
isRowHeader: true,
|
||||
isResizable: true,
|
||||
isSorted: true,
|
||||
isSortedDescending: false,
|
||||
sortAscendingAriaLabel: 'Sorted A to Z',
|
||||
sortDescendingAriaLabel: 'Sorted Z to A',
|
||||
onColumnClick: this._onColumnClick,
|
||||
data: 'string',
|
||||
isPadded: true
|
||||
},
|
||||
{
|
||||
key: 'column3',
|
||||
name: 'Date Modified',
|
||||
fieldName: 'dateModifiedValue',
|
||||
minWidth: 70,
|
||||
maxWidth: 90,
|
||||
isResizable: true,
|
||||
onColumnClick: this._onColumnClick,
|
||||
data: 'number',
|
||||
onRender: (item: IDocument) => {
|
||||
return <span>{item.dateModified}</span>;
|
||||
},
|
||||
isPadded: true
|
||||
},
|
||||
{
|
||||
key: 'column4',
|
||||
name: 'Modified By',
|
||||
fieldName: 'modifiedBy',
|
||||
minWidth: 70,
|
||||
maxWidth: 90,
|
||||
isResizable: true,
|
||||
isCollapsable: true,
|
||||
data: 'string',
|
||||
onColumnClick: this._onColumnClick,
|
||||
onRender: (item: IDocument) => {
|
||||
return <span>{item.modifiedBy}</span>;
|
||||
},
|
||||
isPadded: true
|
||||
},
|
||||
{
|
||||
key: 'column5',
|
||||
name: 'File Size',
|
||||
fieldName: 'fileSizeRaw',
|
||||
minWidth: 70,
|
||||
maxWidth: 90,
|
||||
isResizable: true,
|
||||
isCollapsable: true,
|
||||
data: 'number',
|
||||
onColumnClick: this._onColumnClick,
|
||||
onRender: (item: IDocument) => {
|
||||
return <span>{item.fileSize}</span>;
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
this._selection = new Selection({
|
||||
onSelectionChanged: () => {
|
||||
this.setState({
|
||||
selectionDetails: this._getSelectionDetails(),
|
||||
isModalSelection: this._selection.isModal()
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.state = {
|
||||
items: _items,
|
||||
columns: _columns,
|
||||
selectionDetails: this._getSelectionDetails(),
|
||||
isModalSelection: this._selection.isModal(),
|
||||
isCompactMode: false
|
||||
};
|
||||
}
|
||||
|
||||
public render() {
|
||||
const { columns, isCompactMode, items, selectionDetails } = this.state;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Toggle
|
||||
label="Enable Compact Mode"
|
||||
checked={isCompactMode}
|
||||
onChanged={this._onChangeCompactMode}
|
||||
onText="Compact"
|
||||
offText="Normal"
|
||||
/>
|
||||
<Toggle
|
||||
label="Enable Modal Selection"
|
||||
checked={this.state.isModalSelection}
|
||||
onChanged={this._onChangeModalSelection}
|
||||
onText="Modal"
|
||||
offText="Normal"
|
||||
/>
|
||||
<div>{selectionDetails}</div>
|
||||
<TextField label="Filter by name:" onChanged={this._onChangeText} />
|
||||
<MarqueeSelection selection={this._selection}>
|
||||
<DetailsList
|
||||
items={items}
|
||||
compact={isCompactMode}
|
||||
columns={columns}
|
||||
selectionMode={this.state.isModalSelection ? SelectionMode.multiple : SelectionMode.none}
|
||||
setKey="set"
|
||||
layoutMode={DetailsListLayoutMode.justified}
|
||||
isHeaderVisible={true}
|
||||
selection={this._selection}
|
||||
selectionPreservedOnEmptyClick={true}
|
||||
onItemInvoked={this._onItemInvoked}
|
||||
enterModalSelectionOnTouch={true}
|
||||
/>
|
||||
</MarqueeSelection>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
public componentDidUpdate(previousProps: any, previousState: IDetailsListDocumentsExampleState) {
|
||||
if (previousState.isModalSelection !== this.state.isModalSelection) {
|
||||
this._selection.setModal(this.state.isModalSelection);
|
||||
}
|
||||
}
|
||||
|
||||
private _onChangeCompactMode = (checked: boolean): void => {
|
||||
this.setState({ isCompactMode: checked });
|
||||
}
|
||||
|
||||
private _onChangeModalSelection = (checked: boolean): void => {
|
||||
this.setState({ isModalSelection: checked });
|
||||
}
|
||||
|
||||
private _onChangeText = (text?: string): void => {
|
||||
this.setState({ items: text ? _items.filter(i => i.name.toLowerCase().indexOf(text) > -1) : _items });
|
||||
}
|
||||
|
||||
private _onItemInvoked(item: any): void {
|
||||
alert(`Item invoked: ${item.name}`);
|
||||
}
|
||||
|
||||
private _randomDate(start: Date, end: Date): { value: number; dateFormatted: string } {
|
||||
const date: Date = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
|
||||
const dateData = {
|
||||
value: date.valueOf(),
|
||||
dateFormatted: date.toLocaleDateString()
|
||||
};
|
||||
return dateData;
|
||||
}
|
||||
|
||||
private _randomFileIcon(): { docType: string; url: string } {
|
||||
const docType: string = fileIcons[Math.floor(Math.random() * fileIcons.length) + 0].name;
|
||||
return {
|
||||
docType,
|
||||
url: `https://static2.sharepointonline.com/files/fabric/assets/brand-icons/document/svg/${docType}_16x1.svg`
|
||||
};
|
||||
}
|
||||
|
||||
private _randomFileSize(): { value: string; rawSize: number } {
|
||||
const fileSize: number = Math.floor(Math.random() * 100) + 30;
|
||||
return {
|
||||
value: `${fileSize} KB`,
|
||||
rawSize: fileSize
|
||||
};
|
||||
}
|
||||
|
||||
private _getSelectionDetails(): string {
|
||||
const selectionCount = this._selection.getSelectedCount();
|
||||
|
||||
switch (selectionCount) {
|
||||
case 0:
|
||||
return 'No items selected';
|
||||
case 1:
|
||||
return '1 item selected: ' + (this._selection.getSelection()[0] as any).name;
|
||||
default:
|
||||
return `${selectionCount} items selected`;
|
||||
}
|
||||
}
|
||||
|
||||
private _onColumnClick = (ev: React.MouseEvent<HTMLElement>, column: IColumn): void => {
|
||||
const { columns, items } = this.state;
|
||||
let newItems: IDocument[] = items.slice();
|
||||
const newColumns: IColumn[] = columns.slice();
|
||||
const currColumn: IColumn = newColumns.filter((currCol: IColumn, idx: number) => {
|
||||
return column.key === currCol.key;
|
||||
})[0];
|
||||
newColumns.forEach((newCol: IColumn) => {
|
||||
if (newCol === currColumn) {
|
||||
currColumn.isSortedDescending = !currColumn.isSortedDescending;
|
||||
currColumn.isSorted = true;
|
||||
} else {
|
||||
newCol.isSorted = false;
|
||||
newCol.isSortedDescending = true;
|
||||
}
|
||||
});
|
||||
newItems = this._sortItems(newItems, currColumn.fieldName || '', currColumn.isSortedDescending);
|
||||
this.setState({
|
||||
columns: newColumns,
|
||||
items: newItems
|
||||
});
|
||||
}
|
||||
|
||||
private _sortItems = (items: IDocument[], sortBy: string, descending = false): IDocument[] => {
|
||||
if (descending) {
|
||||
return items.sort((a: IDocument, b: IDocument) => {
|
||||
if (a[sortBy] < b[sortBy]) {
|
||||
return 1;
|
||||
}
|
||||
if (a[sortBy] > b[sortBy]) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
return items.sort((a: IDocument, b: IDocument) => {
|
||||
if (a[sortBy] < b[sortBy]) {
|
||||
return -1;
|
||||
}
|
||||
if (a[sortBy] > b[sortBy]) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
export interface ILoaderProps {
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
@import '~office-ui-fabric-react/dist/sass/_References.scss';
|
||||
|
||||
.loader {
|
||||
.container {
|
||||
max-width: 700px;
|
||||
margin: 0px auto;
|
||||
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.row {
|
||||
@include ms-Grid-row;
|
||||
@include ms-fontColor-white;
|
||||
background-color: $ms-color-themeDark;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.column {
|
||||
@include ms-Grid-col;
|
||||
@include ms-lg10;
|
||||
@include ms-xl8;
|
||||
@include ms-xlPush2;
|
||||
@include ms-lgPush1;
|
||||
}
|
||||
|
||||
.title {
|
||||
@include ms-font-xl;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.subTitle {
|
||||
@include ms-font-l;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.description {
|
||||
@include ms-font-l;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.button {
|
||||
// Our button
|
||||
text-decoration: none;
|
||||
height: 32px;
|
||||
|
||||
// Primary Button
|
||||
min-width: 80px;
|
||||
background-color: $ms-color-themePrimary;
|
||||
border-color: $ms-color-themePrimary;
|
||||
color: $ms-color-white;
|
||||
|
||||
// Basic Button
|
||||
outline: transparent;
|
||||
position: relative;
|
||||
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
font-size: $ms-font-size-m;
|
||||
font-weight: $ms-font-weight-regular;
|
||||
border-width: 0;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
padding: 0 16px;
|
||||
|
||||
.label {
|
||||
font-weight: $ms-font-weight-semibold;
|
||||
font-size: $ms-font-size-m;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
margin: 0 4px;
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
import * as React from 'react';
|
||||
import styles from './Loader.module.scss';
|
||||
import { ILoaderProps } from './ILoaderProps';
|
||||
import * as ReactDom from 'react-dom';
|
||||
|
||||
export interface ILoaderState {
|
||||
currentTime: string;
|
||||
}
|
||||
|
||||
export default class Loader extends React.Component<ILoaderProps, ILoaderState> {
|
||||
|
||||
constructor(props: ILoaderProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
currentTime: ''
|
||||
};
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<ILoaderProps> {
|
||||
return (
|
||||
<div className={styles.loader}>
|
||||
<button onClick={this._loadDocumentsClicked.bind(this)}>
|
||||
Load Documents
|
||||
</button>
|
||||
<button onClick={this._loadMomentClicked.bind(this)}>
|
||||
Load moment js
|
||||
</button>
|
||||
<div className="momentContainer">
|
||||
{this.state.currentTime}
|
||||
</div>
|
||||
<div className="detailsContainer">
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
private async _loadDocumentsClicked() {
|
||||
const component = await import(
|
||||
/* webpackChunkName: 'documentdetails-component' */
|
||||
'./DetailsListComponent' //Custom component from the solution
|
||||
);
|
||||
|
||||
const element: React.ReactElement<any> = React.createElement(
|
||||
component.DetailsListDocumentsComponent
|
||||
);
|
||||
|
||||
const currentElement = ReactDom.findDOMNode(this);
|
||||
const detailsContainerElement = currentElement.getElementsByClassName("detailsContainer")[0];
|
||||
|
||||
ReactDom.render(element, detailsContainerElement);
|
||||
}
|
||||
|
||||
private async _loadMomentClicked() {
|
||||
const moment = await import(
|
||||
/* webpackChunkName: 'moment-js' */
|
||||
'moment'
|
||||
);
|
||||
this.setState({
|
||||
currentTime: moment().calendar()
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "Description",
|
||||
"BasicGroupName": "Group Name",
|
||||
"DescriptionFieldLabel": "Description Field"
|
||||
}
|
||||
});
|
10
samples/react-components-dynamicloading/src/webparts/loader/loc/mystrings.d.ts
vendored
Normal file
10
samples/react-components-dynamicloading/src/webparts/loader/loc/mystrings.d.ts
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
declare interface ILoaderWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
BasicGroupName: string;
|
||||
DescriptionFieldLabel: string;
|
||||
}
|
||||
|
||||
declare module 'LoaderWebPartStrings' {
|
||||
const strings: ILoaderWebPartStrings;
|
||||
export = strings;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "lib",
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
"./node_modules/@microsoft"
|
||||
],
|
||||
"types": [
|
||||
"es6-promise",
|
||||
"webpack-env"
|
||||
],
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"lib"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"rulesDirectory": [
|
||||
"tslint-microsoft-contrib"
|
||||
],
|
||||
"rules": {
|
||||
"class-name": false,
|
||||
"export-name": false,
|
||||
"forin": false,
|
||||
"label-position": false,
|
||||
"member-access": true,
|
||||
"no-arg": false,
|
||||
"no-console": false,
|
||||
"no-construct": false,
|
||||
"no-duplicate-variable": true,
|
||||
"no-eval": false,
|
||||
"no-function-expression": true,
|
||||
"no-internal-module": true,
|
||||
"no-shadowed-variable": true,
|
||||
"no-switch-case-fall-through": true,
|
||||
"no-unnecessary-semicolons": true,
|
||||
"no-unused-expression": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-with-statement": true,
|
||||
"semicolon": true,
|
||||
"trailing-comma": false,
|
||||
"typedef": false,
|
||||
"typedef-whitespace": false,
|
||||
"use-named-parameter": true,
|
||||
"variable-name": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue