Merge pull request #1538 from joaojmendes/custom-links
This commit is contained in:
commit
7eb68c09c0
|
@ -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,32 @@
|
|||
{
|
||||
"@pnp/generator-spfx": {
|
||||
"framework": "react",
|
||||
"pnpFramework": "reactjs.plus",
|
||||
"pnp-libraries": [
|
||||
"jquery@3",
|
||||
"msgraph",
|
||||
"@pnp/pnpjs",
|
||||
"@pnp/spfx-property-controls",
|
||||
"spfx-uifabric-themes",
|
||||
"lodash",
|
||||
"@pnp/spfx-controls-react",
|
||||
"ouifr@7",
|
||||
"rush@3.7"
|
||||
],
|
||||
"pnp-ci": "azure-preview",
|
||||
"pnp-vetting": [],
|
||||
"spfxenv": "spo",
|
||||
"pnp-testing": []
|
||||
},
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"environment": "spo",
|
||||
"framework": "react",
|
||||
"isCreatingSolution": true,
|
||||
"version": "1.11.0",
|
||||
"libraryName": "custom-links",
|
||||
"libraryId": "8dc9a791-d5e3-4e95-8f2c-484ab64178bb",
|
||||
"packageManager": "npm",
|
||||
"isDomainIsolated": false,
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
---
|
||||
page_type: sample
|
||||
products:
|
||||
- office-sp
|
||||
languages:
|
||||
- javascript
|
||||
- typescript
|
||||
extensions:
|
||||
contentType: samples
|
||||
technologies:
|
||||
- SharePoint Framework
|
||||
- Fluent UI React Controls
|
||||
platforms:
|
||||
- React
|
||||
createdDate: 5/10/2020 12:00:00 AM
|
||||
---
|
||||
|
||||
# React Custom Links
|
||||
|
||||
## Summary
|
||||
|
||||
In this web part you can full customize the background and foreground color, font size, width and height of links
|
||||
|
||||
|
||||
|
||||
|
||||
![CustomLinks](./assets/customlinks.gif)
|
||||
|
||||
![CustomLinks](./assets/customLinks01.PNG)
|
||||
|
||||
![CustomLinks](./assets/customLinks02.PNG)
|
||||
|
||||
|
||||
![CustomLinks](./assets/customLinks03.PNG)
|
||||
|
||||
|
||||
## Used SharePoint Framework Version
|
||||
|
||||
![1.11.0](https://img.shields.io/badge/version-1.11.0-green.svg)
|
||||
|
||||
## Applies to
|
||||
|
||||
* [SharePoint Framework](https://docs.microsoft.com/sharepoint/dev/spfx/sharepoint-framework-overview)
|
||||
* [Office 365 tenant](https://docs.microsoft.com/sharepoint/dev/spfx/set-up-your-development-environment)
|
||||
|
||||
## Solution
|
||||
|
||||
Solution|Author(s)
|
||||
--------|---------
|
||||
react-custom-links|João Mendes
|
||||
|
||||
|
||||
## Version history
|
||||
|
||||
Version|Date|Comments
|
||||
-------|----|--------
|
||||
1.0.0| October 5, 2020|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
|
||||
|
||||
Please follow all the steps:
|
||||
|
||||
- Clone this repository
|
||||
- in the command line run:
|
||||
- `npm install`
|
||||
- `gulp build`
|
||||
- `gulp bundle --ship`
|
||||
- `gulp package-solution --ship`
|
||||
- Add and deploy package to your tenant's App Catalog
|
||||
|
||||
|
||||
|
||||
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-custom-links" />
|
Binary file not shown.
After Width: | Height: | Size: 1.5 MiB |
Binary file not shown.
After Width: | Height: | Size: 387 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.7 MiB |
|
@ -0,0 +1,51 @@
|
|||
parameters:
|
||||
name: ''
|
||||
jobs:
|
||||
- job: ${{ parameters.name }}
|
||||
pool:
|
||||
vmImage: 'ubuntu-latest'
|
||||
demands:
|
||||
- npm
|
||||
- node.js
|
||||
- java
|
||||
variables:
|
||||
npm_config_cache: $(Pipeline.Workspace)/.npm
|
||||
|
||||
steps:
|
||||
- checkout: self
|
||||
|
||||
- task: NodeTool@0
|
||||
displayName: 'Use Node 10.x'
|
||||
inputs:
|
||||
versionSpec: 10.x
|
||||
checkLatest: true
|
||||
|
||||
- task: CacheBeta@1
|
||||
inputs:
|
||||
key: npm | $(Agent.OS) | package-lock.json
|
||||
path: $(npm_config_cache)
|
||||
cacheHitVar: CACHE_RESTORED
|
||||
- script: npm ci
|
||||
displayName: 'npm ci'
|
||||
|
||||
- task: Gulp@0
|
||||
displayName: 'Bundle project'
|
||||
inputs:
|
||||
targets: bundle
|
||||
arguments: '--ship'
|
||||
|
||||
- task: Gulp@0
|
||||
displayName: 'Package Solution'
|
||||
inputs:
|
||||
targets: 'package-solution'
|
||||
arguments: '--ship'
|
||||
|
||||
- task: CopyFiles@2
|
||||
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
|
||||
inputs:
|
||||
Contents: |
|
||||
sharepoint/**/*.sppkg
|
||||
TargetFolder: '$(Build.ArtifactStagingDirectory)'
|
||||
|
||||
- task: PublishBuildArtifacts@1
|
||||
displayName: 'Publish Artifact: drop'
|
|
@ -0,0 +1,39 @@
|
|||
parameters:
|
||||
# unique name of the job
|
||||
job_name: deploy_sppkg
|
||||
# friendly name of the job
|
||||
display_name: Upload & deploy *.sppkg to SharePoint app catalog
|
||||
# name of target enviroment deploying to
|
||||
target_environment: ''
|
||||
# app catalog scope (tenant|sitecollection)
|
||||
o365cli_app_catalog_scope: 'tenant'
|
||||
variable_group_name: ''
|
||||
jobs:
|
||||
- deployment: ${{ parameters.job_name }}
|
||||
displayName: ${{ parameters.display_name }}
|
||||
pool:
|
||||
vmImage: 'ubuntu-latest'
|
||||
environment: ${{ parameters.target_environment }}
|
||||
variables:
|
||||
- group: ${{parameters.variable_group_name}} #o365_user_login, o365_user_password, o365_app_catalog_site_url
|
||||
strategy:
|
||||
runOnce:
|
||||
deploy:
|
||||
steps:
|
||||
- checkout: none
|
||||
- download: current
|
||||
artifact: drop
|
||||
patterns: '**/*.sppkg'
|
||||
- script: sudo npm install --global @pnp/office365-cli
|
||||
displayName: Install Office365 CLI
|
||||
- script: o365 login $(o365_app_catalog_site_url) --authType password --userName $(o365_user_login) --password $(o365_user_password)
|
||||
displayName: Login to Office365
|
||||
- script: |
|
||||
CMD_GET_SPPKG_NAME=$(find $(Pipeline.Workspace)/drop -name '*.sppkg' -exec basename {} \;)
|
||||
echo "##vso[task.setvariable variable=SpPkgFileName;isOutput=true]${CMD_GET_SPPKG_NAME}"
|
||||
displayName: Get generated *.sppkg filename
|
||||
name: GetSharePointPackage
|
||||
- script: o365 spo app add --filePath "$(Pipeline.Workspace)/drop/sharepoint/solution/$(GetSharePointPackage.SpPkgFileName)" --appCatalogUrl $(o365_app_catalog_site_url) --scope ${{ parameters.o365cli_app_catalog_scope }} --overwrite
|
||||
displayName: Upload SharePoint package to Site Collection App Catalog
|
||||
- script: o365 spo app deploy --name $(GetSharePointPackage.SpPkgFileName) --appCatalogUrl $(o365_app_catalog_site_url) --scope ${{ parameters.o365cli_app_catalog_scope }}
|
||||
displayName: Deploy SharePoint package
|
|
@ -0,0 +1,26 @@
|
|||
name: $(TeamProject)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
|
||||
resources:
|
||||
- repo: self
|
||||
|
||||
trigger:
|
||||
branches:
|
||||
include:
|
||||
- master
|
||||
- develop
|
||||
|
||||
stages:
|
||||
- stage: build
|
||||
displayName: build
|
||||
jobs:
|
||||
- template: ./azure-pipelines-build-template.yml
|
||||
parameters:
|
||||
name: 'buildsolution'
|
||||
- stage: 'deployqa'
|
||||
# uncomment if you want deployments to occur only for a specific branch
|
||||
#condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/develop'))
|
||||
jobs:
|
||||
- template: ./azure-pipelines-deploy-template.yml
|
||||
parameters:
|
||||
job_name: deploy_solution
|
||||
target_environment: 'qa'
|
||||
variable_group_name: qa_configuration
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"custom-links-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/customLinks/CustomLinksWebPart.js",
|
||||
"manifest": "./src/webparts/customLinks/CustomLinksWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"CustomLinksWebPartStrings": "lib/webparts/customLinks/loc/{locale}.js",
|
||||
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js",
|
||||
"PropertyControlStrings": "node_modules/@pnp/spfx-property-controls/lib/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 @@
|
|||
{
|
||||
"includeExtensions": [
|
||||
"jpg",
|
||||
"png",
|
||||
"svg"
|
||||
]
|
||||
}
|
|
@ -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": "top-tasks",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "custom-links-client-side-solution",
|
||||
"id": "1774407c-58b4-4d81-98a2-5f228c1dcdd8",
|
||||
"version": "1.0.0.0",
|
||||
"includeClientSideAssets": true,
|
||||
|
||||
"skipFeatureDeployment": true,
|
||||
"isDomainIsolated": false,
|
||||
|
||||
"developer": {
|
||||
"name": "",
|
||||
"websiteUrl": "",
|
||||
"privacyUrl": "",
|
||||
"termsOfUseUrl": "",
|
||||
"mpnId": ""
|
||||
}
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/custom-links.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,29 @@
|
|||
'use strict';
|
||||
|
||||
// check if gulp dist was called
|
||||
if (process.argv.indexOf('dist') !== -1) {
|
||||
// add ship options to command call
|
||||
process.argv.push('--ship');
|
||||
}
|
||||
|
||||
const path = require('path');
|
||||
const gulp = require('gulp');
|
||||
const build = require('@microsoft/sp-build-web');
|
||||
const gulpSequence = require('gulp-sequence');
|
||||
|
||||
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||
|
||||
// Create clean distrubution package
|
||||
gulp.task('dist', gulpSequence('clean', 'bundle', 'package-solution'));
|
||||
// Create clean development package
|
||||
gulp.task('dev', gulpSequence('clean', 'bundle', 'package-solution'));
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Custom Framework Specific gulp tasks
|
||||
*/
|
||||
|
||||
|
||||
build.initialize(gulp);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"name": "custom-links",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test",
|
||||
"preversion": "node ./tools/pre-version.js",
|
||||
"postversion": "gulp dist"
|
||||
},
|
||||
"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/pnpjs": "^2.0.6",
|
||||
"@pnp/spfx-controls-react": "1.19.0",
|
||||
"@pnp/spfx-property-controls": "1.19.0",
|
||||
"@types/jquery": "^3.5.0",
|
||||
"jquery": "^3.5.1",
|
||||
"office-ui-fabric-react": "^7.123.1",
|
||||
"react": "16.8.5",
|
||||
"react-dom": "16.8.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/microsoft-graph-types": "^1.12.0",
|
||||
"@microsoft/rush-stack-compiler-3.7": "^0.6.x",
|
||||
"@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.9.43",
|
||||
"@types/react-dom": "16.8.3",
|
||||
"@types/webpack-env": "1.13.1",
|
||||
"ajv": "~5.2.2",
|
||||
"gulp": "~3.9.1",
|
||||
"gulp-sequence": "1.0.0",
|
||||
"lodash": "^4.17.15",
|
||||
"spfx-uifabric-themes": "^0.8.0",
|
||||
"typescript": "~3.7.x"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||
|
||||
.CustomLinks {
|
||||
.container {
|
||||
min-Height: 280px;
|
||||
padding-left: 25px;
|
||||
padding-right: 25px;
|
||||
padding-top: 25px;
|
||||
padding-bottom: 25px;
|
||||
min-width: 280px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.row {
|
||||
@include ms-Grid-row;
|
||||
@include ms-fontColor-white;
|
||||
background-color: $ms-color-themeDark;
|
||||
|
||||
}
|
||||
|
||||
.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;
|
||||
margin-bottom: 10px;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
font-weight: $ms-font-weight-semibold;
|
||||
}
|
||||
|
||||
.subTitle {
|
||||
@include ms-font-l;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.description {
|
||||
@include ms-font-l;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.label {
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
font-size: $ms-font-size-m;
|
||||
vertical-align: top;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.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;
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
import * as React from "react";
|
||||
import styles from "./CustomLinks.module.scss";
|
||||
import { ICustomLinksProps } from "./ICustomLinksProps";
|
||||
import { ICustomLinksState } from "./ICustomLinksState";
|
||||
import { escape } from "@microsoft/sp-lodash-subset";
|
||||
import { ILink } from "../../entities/ILink";
|
||||
import { Stack, FontIcon, Link, ILinkStyles } from "office-ui-fabric-react";
|
||||
import { Placeholder } from "@pnp/spfx-controls-react/lib/Placeholder";
|
||||
|
||||
export default class CustomLinks extends React.Component<
|
||||
ICustomLinksProps,
|
||||
{}
|
||||
> {
|
||||
constructor(props: ICustomLinksProps) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
public componentDidMount = (): void => {};
|
||||
|
||||
public componentDidUpdate = (
|
||||
prevProps: ICustomLinksProps,
|
||||
prevState: ICustomLinksState
|
||||
): void => {}
|
||||
|
||||
public render(): React.ReactElement<ICustomLinksProps> {
|
||||
console.log(this.props);
|
||||
const {
|
||||
links,
|
||||
color,
|
||||
backgroundColor,
|
||||
maxHeight,
|
||||
maxWidth,
|
||||
fontSize,
|
||||
title,
|
||||
themeVariant,
|
||||
} = this.props;
|
||||
|
||||
if (links.length === 0) {
|
||||
return (
|
||||
<Placeholder
|
||||
iconName="Edit"
|
||||
iconText="Configure your custom links web part"
|
||||
description="Please configure the web part."
|
||||
buttonLabel="Configure"
|
||||
onConfigure={this.props.onConfigure}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.CustomLinks}>
|
||||
<div
|
||||
className={styles.container}
|
||||
style={{
|
||||
backgroundColor: backgroundColor
|
||||
? backgroundColor
|
||||
: themeVariant.palette.themePrimary,
|
||||
maxWidth: maxWidth,
|
||||
maxHeight: maxHeight,
|
||||
overflow: "auto",
|
||||
}}
|
||||
>
|
||||
<Stack verticalAlign="start" tokens={{ childrenGap: 15 }}>
|
||||
<span style={{ color: color }} className={styles.title}>
|
||||
{title}
|
||||
</span>
|
||||
{links &&
|
||||
links.map((link: ILink, i: number) => {
|
||||
return (
|
||||
<Stack
|
||||
key={i}
|
||||
horizontal
|
||||
verticalAlign="center"
|
||||
tokens={{ childrenGap: 10 }}
|
||||
style={{ marginRight: 25 }}
|
||||
>
|
||||
<FontIcon
|
||||
iconName={link.linkIcon ? link.linkIcon : "link"}
|
||||
style={{
|
||||
width: fontSize + 8,
|
||||
height: fontSize + 8,
|
||||
fontSize: fontSize + 8,
|
||||
color: color,
|
||||
}}
|
||||
></FontIcon>
|
||||
<Link
|
||||
styles={{
|
||||
root: {
|
||||
color: color,
|
||||
fontSize: fontSize,
|
||||
width: "100%",
|
||||
selectors: {
|
||||
[":hover"]: {
|
||||
color: color,
|
||||
textDecoration: "underline",
|
||||
},
|
||||
[":visited"]: { color: color },
|
||||
[":focus"]: { color: color },
|
||||
[":active"]: { color: color },
|
||||
},
|
||||
},
|
||||
}}
|
||||
href={link.linkURL}
|
||||
target="_blank"
|
||||
title={link.linkName}
|
||||
>
|
||||
<div
|
||||
className={styles.label}
|
||||
style={{ fontSize: fontSize }}
|
||||
>
|
||||
{link.linkName}
|
||||
</div>
|
||||
</Link>
|
||||
</Stack>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import { ILink } from "../../entities/ILink";
|
||||
import { IReadonlyTheme } from '@microsoft/sp-component-base';
|
||||
export interface ICustomLinksProps {
|
||||
title: string;
|
||||
backgroundColor: string;
|
||||
links: ILink[];
|
||||
fontSize: number;
|
||||
color:string;
|
||||
maxWidth: number;
|
||||
maxHeight: number;
|
||||
themeVariant: IReadonlyTheme | undefined;
|
||||
onConfigure : () => void;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
import { ILink } from "../../entities/ILink";
|
||||
|
||||
export interface ICustomLinksState {
|
||||
isLoading: boolean;
|
||||
hasError: boolean;
|
||||
errorMessage: string;
|
||||
links: ILink[];
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
export interface ILink {
|
||||
linkIcon:string;
|
||||
linkName:string;
|
||||
linkURL: string;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "e9d0422b-bb5a-48fd-937b-c6ddac7c7ebd",
|
||||
"alias": "CustomLinksWebPart",
|
||||
"componentType": "WebPart",
|
||||
|
||||
// The "*" signifies that the version should be taken from the package.json
|
||||
"version": "*",
|
||||
"manifestVersion": 2,
|
||||
"supportsThemeVariants": true,
|
||||
// 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", "TeamsTab","TeamsPersonalApp"],
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||
"group": { "default": "SPFx Custom Web Parts " },
|
||||
"title": { "default": "Custom Links" },
|
||||
"description": { "default": "Custom Links" },
|
||||
"officeFabricIconFontName": "Link12",
|
||||
"properties": {
|
||||
"title": "Custom Links",
|
||||
"backgroundColor": "",
|
||||
"links": [],
|
||||
"fontSize": 16,
|
||||
"color": "#ffffff",
|
||||
"maxWidth": 400,
|
||||
"maxHeight": 550
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
import * as React from "react";
|
||||
import * as ReactDom from "react-dom";
|
||||
|
||||
import * as strings from "CustomLinksWebPartStrings";
|
||||
import { Stack } from "office-ui-fabric-react";
|
||||
import { FontIcon } from "office-ui-fabric-react/lib/Icon";
|
||||
|
||||
import {
|
||||
IReadonlyTheme,
|
||||
ThemeChangedEventArgs,
|
||||
ThemeProvider
|
||||
} from "@microsoft/sp-component-base";
|
||||
import { Version } from "@microsoft/sp-core-library";
|
||||
import {
|
||||
IPropertyPaneConfiguration,
|
||||
PropertyPaneSlider,
|
||||
PropertyPaneTextField
|
||||
} from "@microsoft/sp-property-pane";
|
||||
import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
|
||||
import { IconPicker } from "@pnp/spfx-controls-react/lib/IconPicker";
|
||||
import {
|
||||
CustomCollectionFieldType,
|
||||
PropertyFieldCollectionData
|
||||
} from "@pnp/spfx-property-controls/lib/PropertyFieldCollectionData";
|
||||
import {
|
||||
PropertyFieldColorPicker,
|
||||
PropertyFieldColorPickerStyle
|
||||
} from "@pnp/spfx-property-controls/lib/PropertyFieldColorPicker";
|
||||
|
||||
import CustomLinks from "../../components/CustomLinks/CustomLinks";
|
||||
import {
|
||||
ICustomLinksProps
|
||||
} from "../../components/CustomLinks/ICustomLinksProps";
|
||||
import { ILink } from "../../entities/ILink";
|
||||
|
||||
export interface ICustomLinksWebPartProps {
|
||||
title: string;
|
||||
backgroundColor: string;
|
||||
links: ILink[];
|
||||
fontSize: number;
|
||||
color:string;
|
||||
maxWidth: number;
|
||||
maxHeight: number;
|
||||
themeVariant: IReadonlyTheme | undefined;
|
||||
}
|
||||
|
||||
export default class CustomLinksWebPart extends BaseClientSideWebPart<
|
||||
ICustomLinksWebPartProps
|
||||
> {
|
||||
|
||||
private _themeProvider: ThemeProvider;
|
||||
private _themeVariant: IReadonlyTheme | undefined;
|
||||
protected async onInit(): Promise<void> {
|
||||
this._themeProvider = this.context.serviceScope.consume(ThemeProvider.serviceKey);
|
||||
// If it exists, get the theme variant
|
||||
this._themeVariant = this._themeProvider.tryGetTheme();
|
||||
this.properties.themeVariant = this._themeVariant;
|
||||
// Register a handler to be notified if the theme variant changes
|
||||
this._themeProvider.themeChangedEvent.add(this, this._handleThemeChangedEvent);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
|
||||
private _handleThemeChangedEvent(args: ThemeChangedEventArgs): void {
|
||||
this._themeVariant = args.theme;
|
||||
this.properties.themeVariant = this._themeVariant;
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
||||
public render(): void {
|
||||
|
||||
const element: React.ReactElement<ICustomLinksProps> = React.createElement(
|
||||
CustomLinks,
|
||||
{
|
||||
...this.properties,
|
||||
onConfigure: ()=> {
|
||||
this.context.propertyPane.open();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
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,
|
||||
},
|
||||
displayGroupsAsAccordion: true,
|
||||
groups: [
|
||||
{
|
||||
groupName: strings.linksLinksGroupName,
|
||||
|
||||
groupFields: [
|
||||
PropertyFieldCollectionData("links", {
|
||||
key: "collectionData",
|
||||
label: "",
|
||||
panelHeader: strings.PanelHeaderDataCollection,
|
||||
manageBtnLabel: strings.ManageBtnLabel,
|
||||
value: this.properties.links,
|
||||
fields: [
|
||||
|
||||
{
|
||||
id: "linkIcon",
|
||||
title: "Icon",
|
||||
type: CustomCollectionFieldType.custom,
|
||||
|
||||
onCustomRender: (
|
||||
field,
|
||||
value,
|
||||
onUpdate,
|
||||
item,
|
||||
itemId,
|
||||
onError
|
||||
) => {
|
||||
return (
|
||||
React.createElement(Stack,{ horizontal: true, horizontalAlign: "center", tokens: {childrenGap: 5}},
|
||||
React.createElement(FontIcon, {
|
||||
iconName: value,
|
||||
style: { fontSize: 26, marginRight: 25}
|
||||
}),
|
||||
React.createElement(IconPicker, {
|
||||
buttonLabel: "Icon",
|
||||
renderOption: "dialog",
|
||||
onSave: (iconName: string) => {
|
||||
onUpdate(field.id, iconName);
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "linkName",
|
||||
title: "Name",
|
||||
type: CustomCollectionFieldType.string,
|
||||
required: true
|
||||
},
|
||||
{
|
||||
id: "linkURL",
|
||||
title: "Url",
|
||||
type: CustomCollectionFieldType.string,
|
||||
required: true,
|
||||
onGetErrorMessage: (value, index)=>{
|
||||
try {
|
||||
const _url = new URL(value);
|
||||
return '';
|
||||
} catch (error) {
|
||||
return strings.URLMessageError;
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
disabled: false,
|
||||
}),
|
||||
],
|
||||
},
|
||||
{
|
||||
groupName: strings.WebPartPropertiesGroupName,
|
||||
isCollapsed: true,
|
||||
groupFields: [
|
||||
PropertyPaneTextField("title", {
|
||||
label: strings.TitleFieldLabel,
|
||||
}),
|
||||
PropertyFieldColorPicker("backgroundColor", {
|
||||
label: strings.BackgroundColorLabel,
|
||||
selectedColor: this.properties.backgroundColor ? this.properties.backgroundColor :this._themeVariant.palette.themePrimary ,
|
||||
onPropertyChange: this.onPropertyPaneFieldChanged,
|
||||
properties: this.properties,
|
||||
disabled: false,
|
||||
isHidden: false,
|
||||
alphaSliderHidden: false,
|
||||
style: PropertyFieldColorPickerStyle.Full,
|
||||
iconName: "Precipitation",
|
||||
key: "backgroundColorFieldId",
|
||||
}),
|
||||
PropertyFieldColorPicker("color", {
|
||||
label: strings.ColorLabel,
|
||||
selectedColor: this.properties.color ? this.properties.color : this._themeVariant.palette.white ,
|
||||
onPropertyChange: this.onPropertyPaneFieldChanged,
|
||||
properties: this.properties,
|
||||
disabled: false,
|
||||
isHidden: false,
|
||||
alphaSliderHidden: false,
|
||||
style: PropertyFieldColorPickerStyle.Full,
|
||||
iconName: "Precipitation",
|
||||
key: "colorFieldId",
|
||||
}),
|
||||
PropertyPaneSlider("fontSize", {
|
||||
label: strings.FontSizeLabel,
|
||||
step:1,
|
||||
value: this.properties.fontSize | 16,
|
||||
max: 30,
|
||||
min: 8,
|
||||
disabled: false,
|
||||
}),
|
||||
PropertyPaneSlider("maxWidth", {
|
||||
label: strings.MaxWidthLabel,
|
||||
step:1,
|
||||
value: this.properties.maxWidth ,
|
||||
max: 1200,
|
||||
min: 280,
|
||||
disabled: false,
|
||||
}),
|
||||
PropertyPaneSlider("maxHeight", {
|
||||
label: strings.MaxHeightLabel,
|
||||
step: 1,
|
||||
value: this.properties.maxHeight ,
|
||||
max: 800,
|
||||
min: 400,
|
||||
disabled: false,
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "Define links to easy access",
|
||||
"WebPartPropertiesGroupName": "Web Part Properties",
|
||||
"linksLinksGroupName": "Links",
|
||||
"TitleFieldLabel": "Web Part Title",
|
||||
"URLMessageError": "URL is not Valid",
|
||||
"MaxWidthLabel": "Max Width",
|
||||
"MaxHeightLabel": "Max Height",
|
||||
"FontSizeLabel": "Font Size",
|
||||
"ColorLabel": "Color",
|
||||
"BackgroundColorLabel": "Background Color",
|
||||
"PanelHeaderDataCollection": "Define links",
|
||||
"ManageBtnLabel": "Manage links"
|
||||
}
|
||||
});
|
|
@ -0,0 +1,20 @@
|
|||
declare interface ICustomLinksWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
WebPartPropertiesGroupName: string;
|
||||
linksLinksGroupName:string;
|
||||
TitleFieldLabel: string;
|
||||
URLMessageError:string;
|
||||
MaxWidthLabel: string;
|
||||
MaxHeightLabel: string;
|
||||
FontSizeLabel: string;
|
||||
ColorLabel: string;
|
||||
BackgroundColorLabel:string;
|
||||
PanelHeaderDataCollection:string;
|
||||
ManageBtnLabel:string;
|
||||
|
||||
}
|
||||
|
||||
declare module 'CustomLinksWebPartStrings' {
|
||||
const strings: ICustomLinksWebPartStrings;
|
||||
export = strings;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 383 B |
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* This script updates the package-solution version analogue to the
|
||||
* the package.json file.
|
||||
*/
|
||||
|
||||
if (process.env.npm_package_version === undefined) {
|
||||
|
||||
throw 'Package version cannot be evaluated';
|
||||
|
||||
}
|
||||
|
||||
// define path to package-solution file
|
||||
const solution = './config/package-solution.json',
|
||||
teams = './teams/manifest.json';
|
||||
|
||||
// require filesystem instance
|
||||
const fs = require('fs');
|
||||
|
||||
// get next automated package version from process variable
|
||||
const nextPkgVersion = process.env.npm_package_version;
|
||||
|
||||
// make sure next build version match
|
||||
const nextVersion = nextPkgVersion.indexOf('-') === -1 ?
|
||||
nextPkgVersion : nextPkgVersion.split('-')[0];
|
||||
|
||||
// Update version in SPFx package-solution if exists
|
||||
if (fs.existsSync(solution)) {
|
||||
|
||||
// read package-solution file
|
||||
const solutionFileContent = fs.readFileSync(solution, 'UTF-8');
|
||||
// parse file as json
|
||||
const solutionContents = JSON.parse(solutionFileContent);
|
||||
|
||||
// set property of version to next version
|
||||
solutionContents.solution.version = nextVersion + '.0';
|
||||
|
||||
// save file
|
||||
fs.writeFileSync(
|
||||
solution,
|
||||
// convert file back to proper json
|
||||
JSON.stringify(solutionContents, null, 2),
|
||||
'UTF-8');
|
||||
|
||||
}
|
||||
|
||||
// Update version in teams manifest if exists
|
||||
if (fs.existsSync(teams)) {
|
||||
|
||||
// read package-solution file
|
||||
const teamsManifestContent = fs.readFileSync(teams, 'UTF-8');
|
||||
// parse file as json
|
||||
const teamsContent = JSON.parse(teamsManifestContent);
|
||||
|
||||
// set property of version to next version
|
||||
teamsContent.version = nextVersion;
|
||||
|
||||
// save file
|
||||
fs.writeFileSync(
|
||||
teams,
|
||||
// convert file back to proper json
|
||||
JSON.stringify(teamsContent, null, 2),
|
||||
'UTF-8');
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"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"
|
||||
],
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.tsx"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"lib"
|
||||
]
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue