Fixes for react-video-banner

This commit is contained in:
Mohamed Derhalli 2021-04-02 18:21:38 -04:00
parent f261fef89f
commit 5593c75040
25 changed files with 19991 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

32
samples/react-video-banner/.gitignore vendored Normal file
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": {
"version": "1.11.0",
"libraryName": "video-background",
"libraryId": "69d93904-1b0f-4f8a-9619-446fce2702ef",
"environment": "spo",
"packageManager": "npm",
"isCreatingSolution": true,
"isDomainIsolated": false,
"componentType": "webpart"
}
}

View File

@ -0,0 +1,74 @@
# React-Video-Banner
## Summary
Use this Web Part to add a video banner with a text on top of it to your pages.
![](https://github.com/derhallim/Resources/raw/main/react-video-banner-demo1.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)
## Solution
Solution|Author(s)
--------|---------
react-video-banner | Mohamed Derhalli, https://sharepoint-thoughts.com - [@MohamedDerhalli](https://twitter.com/MohamedDerhalli)
## Version history
Version|Date|Comments
-------|----|--------
1.0|April 2nd, 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
- Clone this repository
- Ensure that you are at the solution folder
- in the command-line run:
- **npm install**
- **gulp serve**
> Include any additional steps as needed.
## Features
This web part illustrates the following concepts:
- React Hooks (useRef, useEffect)
- Usage of SPFx Reusable Controls (File Picker)
- CSS Styles
> Share your web part with others through Microsoft 365 Patterns and Practices program to get visibility and exposure. More details on the community, open-source projects and other activities from http://aka.ms/m365pnp.
## References
- [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

View File

@ -0,0 +1,19 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"video-background-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/videoBackground/VideoBackgroundWebPart.js",
"manifest": "./src/webparts/videoBackground/VideoBackgroundWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"VideoBackgroundWebPartStrings": "lib/webparts/videoBackground/loc/{locale}.js",
"PropertyControlStrings": "node_modules/@pnp/spfx-property-controls/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": "video-background",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,21 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "PnP Video Banner",
"id": "69d93904-1b0f-4f8a-9619-446fce2702ef",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"developer": {
"name": "",
"websiteUrl": "",
"privacyUrl": "",
"termsOfUseUrl": "",
"mpnId": ""
}
},
"paths": {
"zippedPackage": "solution/video-banner.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'));

19386
samples/react-video-banner/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
{
"name": "video-banner",
"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/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-property-controls": "2.4.0",
"office-ui-fabric-react": "6.214.0",
"react": "16.8.5",
"react-dom": "16.8.5"
},
"devDependencies": {
"@types/react": "16.8.8",
"@types/react-dom": "16.8.3",
"@microsoft/sp-build-web": "1.11.0",
"@microsoft/sp-tslint-rules": "1.11.0",
"@microsoft/sp-module-interfaces": "1.11.0",
"@microsoft/sp-webpart-workbench": "1.11.0",
"@microsoft/rush-stack-compiler-3.9": "0.4.37",
"gulp": "~3.9.1",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"ajv": "~5.2.2",
"@types/webpack-env": "1.13.1",
"@types/es6-promise": "0.0.33"
}
}

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,32 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "0b29f385-2ece-4129-bd35-f9e143962878",
"alias": "VideoBackgroundWebPart",
"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,
"supportedHosts": ["SharePointWebPart"],
"supportsFullBleed": true,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "Video Banner" },
"description": { "default": "Web Part to display banner video background with text on top." },
"officeFabricIconFontName": "VideoSolid",
"properties": {
"wpTitle": "SharePoint Community Rocks",
"videoUrl": "https://sharepoint-thoughts.com/wp-content/uploads/2021/04/Deal.mp4",
"height": 200,
"brightness": 70,
"color": "#d1d1f2"
}
}]
}

View File

@ -0,0 +1,140 @@
import * as React from "react";
import * as ReactDom from "react-dom";
import { Version } from "@microsoft/sp-core-library";
import {
IPropertyPaneConfiguration,
PropertyPaneTextField,
PropertyPaneSlider,
PropertyPaneLabel
} from "@microsoft/sp-property-pane";
import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
import * as strings from "VideoBackgroundWebPartStrings";
import VideoBackground from "./components/VideoBackground";
import { IVideoBackgroundProps } from "./components/IVideoBackgroundProps";
import {
PropertyFieldFilePicker,
IPropertyFieldFilePickerProps,
IFilePickerResult,
} from "@pnp/spfx-property-controls/lib/PropertyFieldFilePicker";
import {
PropertyFieldColorPicker,
PropertyFieldColorPickerStyle,
} from "@pnp/spfx-property-controls/lib/PropertyFieldColorPicker";
export interface IVideoBackgroundWebPartProps {
wpTitle: string;
videoUrl: string;
filePickerResult: IFilePickerResult;
color: string;
brightness: number;
height: number;
}
export default class VideoBackgroundWebPart extends BaseClientSideWebPart<IVideoBackgroundWebPartProps> {
public render(): void {
const element: React.ReactElement<IVideoBackgroundProps> = React.createElement(
VideoBackground,
{
wpTitle: this.properties.wpTitle,
videoUrl: this.properties.videoUrl,
labelColor: this.properties.color,
brightness: this.properties.brightness,
height: this.properties.height,
}
);
ReactDom.render(element, this.domElement);
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription,
},
displayGroupsAsAccordion: true,
groups: [
{
groupName: strings.BasicGroupName,
isCollapsed: true,
groupFields: [
PropertyFieldFilePicker("filePicker", {
context: this.context,
filePickerResult: this.properties.filePickerResult,
onPropertyChange: () => {
this.onPropertyPaneFieldChanged.bind(this);
this.render();
},
properties: this.properties,
onSave: (e: IFilePickerResult) => {
this.properties.videoUrl = e.fileAbsoluteUrl;
this.render();
},
onChanged: (e: IFilePickerResult) => {
this.properties.videoUrl = e.fileAbsoluteUrl;
this.render();
},
key: "filePickerId",
buttonLabel: strings.selectVideo,
label: "",
accepts: [".mp4", ".vmw", ".avi"],
buttonIcon: "VideoSolid",
}),
PropertyPaneLabel("videoLabel", {
text: this.properties.videoUrl
}),
PropertyPaneTextField("wpTitle", {
label: strings.wpTitleLabel,
}),
],
},
{
groupName: strings.StylesGroupName,
isCollapsed: true,
groupFields: [
PropertyFieldColorPicker("color", {
label: strings.selectColor,
selectedColor: this.properties.color,
onPropertyChange: this.onPropertyPaneFieldChanged,
properties: this.properties,
disabled: false,
isHidden: false,
alphaSliderHidden: false,
style: PropertyFieldColorPickerStyle.Full,
iconName: "Precipitation",
key: "colorFieldId",
}),
PropertyPaneSlider("brightness", {
min: 10,
max: 100,
step: 10,
value: 50,
label: strings.selectBrightness,
showValue: true,
}),
PropertyPaneSlider("height", {
min: 200,
max: 500,
step: 1,
value: 300,
label: strings.selectHeight,
showValue: true,
}),
],
},
],
},
],
};
}
}

View File

@ -0,0 +1,8 @@
export interface IVideoBackgroundProps {
wpTitle: string;
videoUrl: string;
labelColor: string;
brightness: number;
height: number;
}

View File

@ -0,0 +1,31 @@
@import "~office-ui-fabric-react/dist/sass/References.scss";
.videoBackground {
// height: 324px;
overflow: hidden;
// max-height: 324px;
div {
position: absolute;
margin: auto;
width: 100%;
// height: 324px;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
h1{
font-size: 48px;
z-index: 1;
}
}
video{
height: 486px;
width: 1920px;
left: 0px;
top: -79px;
object-fit: cover
}
}

View File

@ -0,0 +1,41 @@
import * as React from "react";
import styles from "./VideoBackground.module.scss";
import { IVideoBackgroundProps } from "./IVideoBackgroundProps";
const VideoBackground = (props: IVideoBackgroundProps) => {
const vRef = React.useRef<HTMLVideoElement>(null)
const oldUrl = React.useRef(props.videoUrl)
console.debug("execution here")
React.useEffect(() => {
if(oldUrl.current !== props.videoUrl && vRef && vRef.current){
vRef.current.load()
oldUrl.current = props.videoUrl
}
}, [props.videoUrl])
return (
<div
className={styles.videoBackground}
style={{ height: `${props.height}px` }}
>
<div style={{ height: `${props.height}px` }}>
<h1 style={{ color: props.labelColor }}>{props.wpTitle}</h1>
</div>
<video
ref = {vRef}
autoPlay={true}
loop={true}
playsinline={true}
preload="auto"
tabIndex={-1}
muted={true}
style={{ filter: `brightness(${props.brightness}%` }}
>
<source src={props.videoUrl} type="video/mp4"></source>
</video>
</div>
);
};
export default VideoBackground;

View File

@ -0,0 +1,12 @@
define([], function() {
return {
"PropertyPaneDescription": "",
"BasicGroupName": "Basic Properties",
"StylesGroupName": "Styles",
"wpTitleLabel": "Title Text",
"selectVideo": "Select a video..",
"selectColor": "Title Color",
"selectBrightness": "Brightness",
"selectHeight": "Height"
}
});

View File

@ -0,0 +1,16 @@
declare interface IVideoBackgroundWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
StylesGroupName: string;
wpTitleLabel: string;
videoUrlLabel: string;
selectVideo: string;
selectColor: string;
selectBrightness: string;
selectHeight: string;
}
declare module 'VideoBackgroundWebPartStrings' {
const strings: IVideoBackgroundWebPartStrings;
export = strings;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

View File

@ -0,0 +1,39 @@
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.9/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,30 @@
{
"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-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
}
}