added new react webpart for halloween

This commit is contained in:
Adam 2021-10-31 23:58:25 +01:00
parent 86cc07ac45
commit 2a3d87bcfa
36 changed files with 22027 additions and 0 deletions

33
samples/react-find-parker/.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
# Logs
logs
*.log
npm-debug.log*
# Dependency directories
node_modules
# Build generated files
dist
lib
release
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,16 @@
!dist
config
gulpfile.js
release
src
temp
tsconfig.json
tslint.json
*.log
.yo-rc.json
.vscode

View File

@ -0,0 +1,13 @@
{
"@microsoft/generator-sharepoint": {
"plusBeta": false,
"isCreatingSolution": true,
"environment": "spo",
"version": "1.13.0",
"libraryName": "react-find-parker",
"libraryId": "5659e702-453b-4b73-9ead-fa1859234a18",
"packageManager": "npm",
"isDomainIsolated": false,
"componentType": "webpart"
}
}

View File

@ -0,0 +1,64 @@
# react-find-parker
## Summary
Work is not about work 🤨, sometime a bit of fun is in order 🕹️.
This webpart is a simple find object game.
![parker](./assets/parker.gif)
User may set up how many elements will she or he be looking for in the property pane
![config](./assets/config.png)
By changing the icon svg image we may create a find easter egg 🥚 game or find pumpkins for Halloween 🎃🎃🎃
![halloween](./assets/halloween.gif)
![findpumpkin](./assets/findpumpkin.png)
or good old where's Wally game 😉
![findWally](./assets/findWally.png)
## Used SharePoint Framework Version
![version](https://img.shields.io/badge/version-1.13-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)
## Solution
Solution|Author(s)
--------|---------
react-find-parker | Adam Wojcik (https://github.com/Adam-it)
## Version history
Version|Date|Comments
-------|----|--------
1.0|october 31, 2021|Halloween 🎃🎃🎃 & 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**
## Features
This project contains sample client-side web parts built on the SharePoint Framework using React
- using React for building SharePoint Framework client-side web parts
## References
- [Getting started with SharePoint Framework](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
- [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: 194 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

View File

@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"find-parker-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/findParker/FindParkerWebPart.js",
"manifest": "./src/webparts/findParker/FindParkerWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"FindParkerWebPartStrings": "lib/webparts/findParker/loc/{locale}.js"
}
}

View File

@ -0,0 +1,7 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
"workingDir": "./release/assets/",
"account": "<!-- STORAGE ACCOUNT NAME -->",
"container": "react-find-parker",
"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-find-parker-client-side-solution",
"id": "5659e702-453b-4b73-9ead-fa1859234a18",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"developer": {
"name": "",
"websiteUrl": "",
"privacyUrl": "",
"termsOfUseUrl": "",
"mpnId": "Undefined-1.13.0"
}
},
"paths": {
"zippedPackage": "solution/react-find-parker.sppkg"
}
}

View File

@ -0,0 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://tenanttocheck.sharepoint.com/_layouts/workbench.aspx"
}

View File

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

16
samples/react-find-parker/gulpfile.js vendored Normal file
View File

@ -0,0 +1,16 @@
'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.`);
var getTasks = build.rig.getTasks;
build.rig.getTasks = function () {
var result = getTasks.call(build.rig);
result.set('serve', result.get('serve-deprecated'));
return result;
};
build.initialize(require('gulp'));

21373
samples/react-find-parker/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,32 @@
{
"name": "react-find-parker",
"version": "0.0.1",
"private": true,
"main": "lib/index.js",
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"react": "16.13.1",
"react-dom": "16.13.1",
"office-ui-fabric-react": "7.174.1",
"@microsoft/sp-core-library": "1.13.0",
"@microsoft/sp-property-pane": "1.13.0",
"@microsoft/sp-webpart-base": "1.13.0",
"@microsoft/sp-lodash-subset": "1.13.0",
"@microsoft/sp-office-ui-fabric-core": "1.13.0"
},
"devDependencies": {
"@types/react": "16.9.51",
"@types/react-dom": "16.9.8",
"@microsoft/sp-build-web": "1.13.0",
"@microsoft/sp-tslint-rules": "1.13.0",
"@microsoft/sp-module-interfaces": "1.13.0",
"@microsoft/rush-stack-compiler-3.9": "0.4.47",
"gulp": "~4.0.2",
"ajv": "~5.2.2",
"@types/webpack-env": "1.13.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,28 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "5a233f7d-d5aa-4af4-97b3-ada5befdf3cf",
"alias": "FindParkerWebPart",
"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", "TeamsPersonalApp", "TeamsTab", "SharePointFullPage"],
"supportsThemeVariants": true,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "FindParker" },
"description": { "default": "FindParker description" },
"officeFabricIconFontName": "Page",
"properties": {
"numberOfElements": 3
}
}]
}

View File

@ -0,0 +1,58 @@
import * as React from 'react';
import * as ReactDom from 'react-dom';
import * as strings from 'FindParkerWebPartStrings';
import { Version } from '@microsoft/sp-core-library';
import { IPropertyPaneConfiguration, PropertyPaneSlider } from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import FindParker from './components/FindParker/FindParker';
import { IFindParkerProps } from './components//FindParker/IFindParkerProps';
import { IFindParkerWebPartProps } from './IFindParkerWebPartProps';
export default class FindParkerWebPart extends BaseClientSideWebPart<IFindParkerWebPartProps> {
public render(): void {
const element: React.ReactElement<IFindParkerProps> = React.createElement(
FindParker,
{
numberOfElements: this.properties.numberOfElements
}
);
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.PropertyPaneBasicGroupName,
groupFields: [
PropertyPaneSlider('numberOfElements', {
label: strings.PropertyPaneNumberOfElementsFieldLabel,
min: 1,
max: 20,
value: 5,
showValue: true,
step: 1
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,3 @@
export interface IFindParkerWebPartProps {
numberOfElements: number;
}

View File

@ -0,0 +1,41 @@
@import "~office-ui-fabric-react/dist/sass/References.scss";
@import "../../../styles/Common.module.scss";
.findParker {
.container {
background-color: $neutralLight;
padding-top: 10px;
padding-bottom: 10px;
.row {
@include ms-Grid-row;
.column {
@include ms-Grid-col;
@include ms-lg10;
@include ms-xl8;
@include ms-xlPush2;
@include ms-lgPush1;
.title {
@include ms-font-xxl;
text-align: center;
}
.label {
@include ms-font-m;
text-align: justify;
margin-top: 0px;
margin-bottom: 5px;
}
}
}
}
}
.parkersContener {
.parker {
position: absolute;
z-index: 1000;
}
}

View File

@ -0,0 +1,146 @@
import * as React from 'react';
import * as strings from 'FindParkerWebPartStrings';
import styles from './FindParker.module.scss';
import { IFindParkerProps } from './IFindParkerProps';
import { IFindParkerState } from './IFindParkerState';
import { DefaultButton } from '@microsoft/office-ui-fabric-react-bundle/node_modules/office-ui-fabric-react/lib/Button';
import Constants from '../../model/Constants';
import Icon from '../../model/Icon';
import IParker from '../../model/IParker';
export default class FindParker extends React.Component<IFindParkerProps, IFindParkerState> {
constructor(props: IFindParkerProps) {
super(props);
this.state = {
numberOfFoundElements: 0,
gameStarted: false,
gameFinsihed: false,
listOfParkers: [],
elements: []
};
}
public componentDidMount(): void {
const { numberOfElements } = this.props;
const listOfParkers = this.createListOfParkers(numberOfElements);
this.setState({ listOfParkers: listOfParkers });
}
public render(): React.ReactElement<IFindParkerProps> {
const {
gameStarted,
gameFinsihed,
numberOfFoundElements,
elements } = this.state;
const { numberOfElements } = this.props;
return (
<div id='findParkerId' className={styles.findParker}>
<div className={styles.container}>
<div className={styles.row}>
<div className={styles.column}>
<p className={styles.title}>{strings.GameTitle}</p>
<p className={styles.label}>{strings.GameDescription}</p>
</div>
</div>
{!gameStarted ?
<div className={styles.row}>
<div className={styles.column}>
<DefaultButton onClick={() => this.startGame()}>{strings.StartGameButton}</DefaultButton>
</div>
</div>
:
<div className={styles.row}>
{!gameFinsihed ?
<div className={styles.column}>
<p className={styles.label}>{strings.GameProgressELementsLabel} <strong>{numberOfElements}</strong></p>
<p className={styles.label}>{strings.GameProgressLabel} <strong>{numberOfFoundElements}</strong></p>
</div>
:
<div className={styles.column}>
<p className={styles.label}>{strings.EndGameMessage}</p>
<DefaultButton onClick={() => this.restartGame()}>{strings.RestartGameButton}</DefaultButton>
</div>
}
<div className={styles.parkersContener}>
{elements}
</div>
</div>
}
</div>
</div>
);
}
private renderParkers(listOfParkers: Array<IParker>): void {
let items = [];
listOfParkers.forEach(parker => {
const style = {
top: parker.top,
left: parker.left,
transform: parker.transform
};
items.push(<img alt='pnpParker' src={Icon.svg} width='65' className={styles.parker} style={style} onClick={() => this.parkerFound(parker.id)} />);
});
this.setState({ elements: items });
}
private parkerFound(id: number): void {
let numberOfFoundElements = this.state.numberOfFoundElements + 1;
this.setState({ numberOfFoundElements: numberOfFoundElements });
let parkers = this.state.listOfParkers;
parkers = parkers.filter(parker => parker.id !== id);
this.setState({ listOfParkers: parkers });
this.renderParkers(parkers);
if (numberOfFoundElements === this.props.numberOfElements) {
this.setState({ gameFinsihed: true });
}
}
private startGame(): void {
this.setState({ gameStarted: true });
this.renderParkers(this.state.listOfParkers);
}
private restartGame(): void {
const { numberOfElements } = this.props;
this.setState({ gameFinsihed: false });
const listOfParkers = this.createListOfParkers(numberOfElements);
this.setState({
listOfParkers: listOfParkers,
numberOfFoundElements: 0
});
this.renderParkers(listOfParkers);
}
private createListOfParkers(numberOfElements: number): Array<IParker> {
const pageHeight: number = document.querySelector(Constants.mainPageContent).scrollHeight;
const pageWidth: number = document.querySelector(Constants.mainPageContent).scrollWidth;
const findParkerWebPart = document.getElementById('findParkerId').getBoundingClientRect();
let listOfParkers = [];
for (let index = 0; index < numberOfElements; index++) {
const y: number = this.randomNumber((0 - findParkerWebPart.y + 185), (pageHeight - findParkerWebPart.y - 300));
const x: number = this.randomNumber((0 - findParkerWebPart.x + 100), (pageWidth - findParkerWebPart.x - 300));
const rotate: number = this.randomNumber(0, 180);
const parker: IParker = {
id: index,
left: x,
top: y,
transform: `rotate(${rotate}deg)`
};
listOfParkers.push(parker);
}
return listOfParkers;
}
private randomNumber(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}
}

View File

@ -0,0 +1,3 @@
export interface IFindParkerProps {
numberOfElements: number;
}

View File

@ -0,0 +1,9 @@
import IParker from "../../model/IParker";
export interface IFindParkerState {
numberOfFoundElements: number;
listOfParkers: Array<IParker>;
elements: Array<React.ReactElement>;
gameStarted: boolean;
gameFinsihed: boolean;
}

View File

@ -0,0 +1,14 @@
define([], function() {
return {
"PropertyPaneDescription": "Settings",
"PropertyPaneBasicGroupName": "Elements settings",
"PropertyPaneNumberOfElementsFieldLabel": "number of elements to find",
"GameTitle": "Find Parker",
"GameDescription": "🎯 The goal of the game is to find all elements on the page.",
"StartGameButton": "🎮 Start the game !",
"RestartGameButton": "🎮 It was fun, lets try again",
"EndGameMessage": "Congrats! You are awasome 👍👍👍",
"GameProgressELementsLabel": "🔍 Elements to find: ",
"GameProgressLabel": "👉 You found: "
}
});

View File

@ -0,0 +1,17 @@
declare interface IFindParkerWebPartStrings {
PropertyPaneDescription: string;
PropertyPaneBasicGroupName: string;
PropertyPaneNumberOfElementsFieldLabel: string;
GameTitle: string;
GameDescription: string;
StartGameButton: string;
RestartGameButton: string;
EndGameMessage: string;
GameProgressELementsLabel: string;
GameProgressLabel: string;
}
declare module 'FindParkerWebPartStrings' {
const strings: IFindParkerWebPartStrings;
export = strings;
}

View File

@ -0,0 +1,3 @@
export default class Constants {
public static mainPageContent: string = 'div[data-automation-id=\'contentScrollRegion\'][role=\'main\']';
}

View File

@ -0,0 +1,6 @@
export default class IParker {
public id: number;
public top: number;
public left: number;
public transform: string;
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,28 @@
@import "~office-ui-fabric-react/dist/sass/References.scss";
// colors
$themePrimary: "[theme: themePrimary, default: #0078d7]";
$themeLighterAlt: "[theme: themeLighterAlt, default: #eff6fc]";
$themeLighter: "[theme: themeLighter, default: #deecf9]";
$themeLight: "[theme: themeLight, default: #c7e0f4]";
$themeTertiary: "[theme: themeTertiary, default: #71afe5]";
$themeSecondary: "[theme: themeSecondary, default: #2b88d8]";
$themeDarkAlt: "[theme: themeDarkAlt, default: #106ebe]";
$themeDark: "[theme: themeDark, default: #005a9e]";
$themeDarker: "[theme: themeDarker, default: #004578]";
$neutralLighterAlt: "[theme: neutralLighterAlt, default: #f8f8f8]";
$neutralLighter: "[theme: neutralLighter, default: #f4f4f4]";
$neutralLight: "[theme: neutralLight, default: #eaeaea]";
$neutralQuaternaryAlt: "[theme: neutralQuaternaryAlt, default: #dadada]";
$neutralQuaternary: "[theme: neutralQuaternary, default: #d0d0d0]";
$neutralTertiaryAlt: "[theme: neutralTertiaryAlt, default: #c8c8c8]";
$neutralTertiary: "[theme: neutralTertiary, default: #a6a6a6]";
$neutralSecondaryAlt: "[theme: neutralSecondaryAlt, default: #767676]";
$neutralSecondary: "[theme: neutralSecondary, default: #666666]";
$neutralPrimaryAlt: "[theme: neutralPrimaryAlt, default: #3c3c3c]";
$neutralPrimary: "[theme: neutralPrimary, default: #333]";
$neutralDark: "[theme: neutralDark, default: #212121]";
$black: "[theme: black, default: #000000]";
$white: "[theme: white, default: #fff]";
$primaryBackground: "[theme: primaryBackground, default: #fff]";
$primaryText: "[theme: primaryText, default: #333]";

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

View File

@ -0,0 +1,35 @@
{
"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": [
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection",
"es2015.promise"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
]
}

View File

@ -0,0 +1,29 @@
{
"extends": "./node_modules/@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
}
}