react-company-stories sample webpart added

This commit is contained in:
luismanez 2021-03-31 11:38:47 +02:00
parent 953d4dd489
commit 52f3df5907
27 changed files with 19655 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,12 @@
{
"@microsoft/generator-sharepoint": {
"isCreatingSolution": true,
"environment": "spo",
"version": "1.11.0",
"libraryName": "react-company-stories",
"libraryId": "9ac063b7-aed6-4fcb-a226-5813ac363fad",
"packageManager": "npm",
"isDomainIsolated": false,
"componentType": "webpart"
}
}

View File

View File

@ -0,0 +1,74 @@
# Company Stories Webpart
## Summary
This webpart allows you to add images to a SharePoint List, and renders them with a UX very similar to Instagram Stories (or Twitter Reels, or [Place your Social network here]). It is a way to engage employees, showing relevant content in a well-known visual appearance.
![react-company-stories](./assets/react-company-stories.gif)
## Used SharePoint Framework Version
![version](https://img.shields.io/badge/version-1.11-green.svg)
## Applies to
- [SharePoint Framework](https://aka.ms/spfx)
- [Microsoft 365 tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram)
## Prerequisites
- A SharePoint list called "Stories" with the following fields:
- Image: image field type
- Content: multi-line field type
- Author: Person field type
![stories-list](./assets/stories-list.png)
- Permission _User.ReadBasic.All_ to the Graph API
## Solution
Solution|Author(s)
--------|---------
react-company-stories | Luis Mañez (MVP, [ClearPeople](http://www.clearpeople.com), @luismanez)
## Version history
Version|Date|Comments
-------|----|--------
1.0|March 31, 2021|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
- Configure SharePoint permissions to Graph API (see Prerequisites). Suggest you to use the [Microsoft 365 CLI](https://blog.mastykarz.nl/grant-api-permissions-office-365-cli/)
- Clone this repository
- Ensure that you are at the solution folder
- In the command-line run:
- **npm install**
- **gulp serve --nobrowser**
- Add the webpart to the SharePoint Workbench (same Site where the List was created)
## Features
This webpart illustrates the following concepts:
- Using the Microsoft Graph Toolkit react components: [Person component](https://docs.microsoft.com/en-us/graph/toolkit/components/person)
- Using FluentUI components
- Using [react-insta-stories](https://www.npmjs.com/package/react-insta-stories) package
- Using SP REST API
## References
About SPFx:
- [Getting started with SharePoint Framework](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
- [Building for Microsoft teams](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/build-for-teams-overview)
- [Use Microsoft Graph in your solution](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/using-microsoft-graph-apis)
- [Publish SharePoint Framework applications to the Marketplace](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/publish-to-marketplace-overview)
- [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) - Guidance, tooling, samples and open-source controls for your Microsoft 365 development

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

View File

@ -0,0 +1,19 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"sharepoint-stories-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/sharePointStories/SharePointStoriesWebPart.js",
"manifest": "./src/webparts/sharePointStories/SharePointStoriesWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"SharePointStoriesWebPartStrings": "lib/webparts/sharePointStories/loc/{locale}.js",
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
"deployCdnPath": "temp/deploy"
}

View File

@ -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": "react-company-stories",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,21 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "react-sharepoint-stories",
"id": "9ac063b7-aed6-4fcb-a226-5813ac363fad",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"developer": {
"name": "",
"websiteUrl": "",
"privacyUrl": "",
"termsOfUseUrl": "",
"mpnId": ""
}
},
"paths": {
"zippedPackage": "solution/react-sharepoint-stories.sppkg"
}
}

View File

@ -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/"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->"
}

View File

@ -0,0 +1,7 @@
'use strict';
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(require('gulp'));

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,44 @@
{
"name": "react-company-stories",
"version": "0.0.1",
"private": true,
"main": "lib/index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/mgt": "^1.3.6",
"@microsoft/mgt-react": "^2.0.0-preview.8",
"@microsoft/sp-core-library": "1.11.0",
"@microsoft/sp-lodash-subset": "1.11.0",
"@microsoft/sp-office-ui-fabric-core": "1.11.0",
"@microsoft/sp-property-pane": "1.11.0",
"@microsoft/sp-webpart-base": "1.11.0",
"@pnp/spfx-controls-react": "2.2.0",
"office-ui-fabric-react": "6.214.0",
"react": "16.8.5",
"react-dom": "16.8.5",
"react-insta-stories": "^2.1.3"
},
"devDependencies": {
"@microsoft/rush-stack-compiler-3.3": "0.3.5",
"@microsoft/rush-stack-compiler-3.7": "^0.6.35",
"@microsoft/sp-build-web": "1.11.0",
"@microsoft/sp-module-interfaces": "1.11.0",
"@microsoft/sp-tslint-rules": "1.11.0",
"@microsoft/sp-webpart-workbench": "1.11.0",
"@types/chai": "3.4.34",
"@types/es6-promise": "0.0.33",
"@types/mocha": "2.2.38",
"@types/react": "16.8.8",
"@types/react-dom": "16.8.3",
"@types/webpack-env": "1.13.1",
"ajv": "~5.2.2",
"gulp": "~3.9.1"
}
}

View File

@ -0,0 +1 @@
// A file is required to be in the root of the /src directory by the TypeScript compiler

View File

@ -0,0 +1,23 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "076de2d7-509f-469c-ab79-42f88611ae13",
"alias": "SharePointStoriesWebPart",
"componentType": "WebPart",
"version": "*",
"manifestVersion": 2,
"requiresCustomScript": false,
"supportedHosts": ["SharePointWebPart", "TeamsTab"],
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70",
"group": { "default": "Other" },
"title": { "default": "SharePointStories" },
"description": { "default": "Kind of IG Stories for SharePoint!" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "SharePointStories"
}
}]
}

View File

@ -0,0 +1,66 @@
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import * as strings from 'SharePointStoriesWebPartStrings';
import SharePointStories from './components/SharePointStories';
import { ISharePointStoriesProps } from './components/ISharePointStoriesProps';
import { Providers, SharePointProvider } from '@microsoft/mgt';
export interface ISharePointStoriesWebPartProps {
description: string;
}
export default class SharePointStoriesWebPart extends BaseClientSideWebPart<ISharePointStoriesWebPartProps> {
protected async onInit(): Promise<void> {
Providers.globalProvider = new SharePointProvider(this.context);
}
public render(): void {
const element: React.ReactElement<ISharePointStoriesProps> = React.createElement(
SharePointStories,
{
webpartContext: this.context
}
);
ReactDom.render(element, this.domElement);
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,5 @@
import { WebPartContext } from "@microsoft/sp-webpart-base";
export interface ISharePointStoriesProps {
webpartContext: WebPartContext;
}

View File

@ -0,0 +1,5 @@
import { Story } from "react-insta-stories/dist/interfaces";
export interface ISharePointStoriesState {
stories: Story[];
}

View File

@ -0,0 +1,74 @@
@import '~office-ui-fabric-react/dist/sass/References.scss';
.SharePointStories {
.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;
}
}
}

View File

@ -0,0 +1,94 @@
import * as React from "react";
import styles from "./SharePointStories.module.scss";
import { ISharePointStoriesProps } from "./ISharePointStoriesProps";
import { ISharePointStoriesState } from "./ISharePointStoriesState";
import Stories from "react-insta-stories";
import { SPHttpClient} from '@microsoft/sp-http';
import { Header, Renderer, Story } from "react-insta-stories/dist/interfaces";
import { WithHeader } from 'react-insta-stories';
import { Person } from '@microsoft/mgt-react';
import { PersonViewType } from "@microsoft/mgt";
import { WithSeeMore } from 'react-insta-stories';
export default class SharePointStories extends React.Component<ISharePointStoriesProps, ISharePointStoriesState> {
private _spHttpClient: SPHttpClient;
constructor(props: ISharePointStoriesProps) {
super(props);
this._spHttpClient = this.props.webpartContext.spHttpClient;
this.state = {
stories: []
};
}
public componentDidMount(): void {
const endpoint: string =
`${this.props.webpartContext.pageContext.site.absoluteUrl}/_api/web/lists/GetByTitle('Stories')/RenderListDataAsStream`;
this._spHttpClient.post(endpoint, SPHttpClient.configurations.v1, { })
.then((response) => {
response.json()
.then(data => {
var listItems = data.Row;
var stories = listItems.map(item => {
return this._getStoryFromListItem(item);
});
this.setState({
stories: stories
});
});
});
}
public render(): React.ReactElement<ISharePointStoriesProps> {
if (!this.state.stories.length) return <div>Loading stories...</div>;
return <div>
<Stories
stories={this.state.stories}
loop
keyboardNavigation />
</div>;
}
private _getStoryFromListItem(item: any): Story {
const contentStyle = {
width: '100%',
height: '100%',
padding: 0
};
var storyRenderer: Renderer = ({ action, isPaused, story, config}) => {
return <WithSeeMore story={story} action={action}>
<div style={{ ...contentStyle, backgroundImage: `url("${story.url}")`, backgroundRepeat: 'no-repeat', paddingTop: '50px' }}>
<div>
<Person userId={authorId} avatarSize={'large'} view={PersonViewType.twolines} />
</div>
</div></WithSeeMore>;
};
var image = item.Image;
var fullImageUrl = `${image.serverUrl}${image.serverRelativeUrl}`;
var authorId: string = item.Author0[0].sip;
var content: string = item.Content;
var story: Story = {
url: fullImageUrl,
duration: 4000,
content: storyRenderer
};
if (content) {
story.seeMore = ({ close }) => {
return <div style={{backgroundColor: 'white'}} onClick={close}>{content}</div>;
};
}
return story;
}
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
});

View File

@ -0,0 +1,10 @@
declare interface ISharePointStoriesWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'SharePointStoriesWebPartStrings' {
const strings: ISharePointStoriesWebPartStrings;
export = strings;
}

View File

@ -0,0 +1,39 @@
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.7/includes/tsconfig-web.json",
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "lib",
"inlineSources": false,
"strictNullChecks": false,
"noUnusedLocals": false,
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"node_modules",
"lib"
]
}

View File

@ -0,0 +1,29 @@
{
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
"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-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"variable-name": false,
"whitespace": false
}
}