Initial commit

This commit is contained in:
flowerbot 2022-06-24 08:14:28 +10:00
commit 638b3992ae
34 changed files with 22843 additions and 0 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

33
.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

16
.npmignore Normal file
View File

@ -0,0 +1,16 @@
!dist
config
gulpfile.js
release
src
temp
tsconfig.json
tslint.json
*.log
.yo-rc.json
.vscode

5
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"recommendations": [
"msjsdiag.debugger-for-chrome"
]
}

27
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,27 @@
{
/**
* Install Chrome Debugger Extension for Visual Studio Code to debug your components with the
* Chrome browser: https://aka.ms/spfx-debugger-extensions
*/
"version": "0.2.0",
"configurations": [
{
"name": "Hosted workbench",
"type": "chrome",
"request": "launch",
"url": "https://enter-your-SharePoint-site/_layouts/workbench.aspx",
"webRoot": "${workspaceRoot}",
"sourceMaps": true,
"sourceMapPathOverrides": {
"webpack:///.././src/*": "${webRoot}/src/*",
"webpack:///../../../src/*": "${webRoot}/src/*",
"webpack:///../../../../src/*": "${webRoot}/src/*",
"webpack:///../../../../../src/*": "${webRoot}/src/*"
},
"runtimeArgs": [
"--remote-debugging-port=9222",
"-incognito"
]
}
]
}

13
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,13 @@
// Place your settings in this file to overwrite default and user settings.
{
// Configure glob patterns for excluding files and folders in the file explorer.
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/bower_components": true,
"**/coverage": true,
"**/lib-amd": true,
"src/**/*.scss.ts": true
},
"typescript.tsdk": ".\\node_modules\\typescript\\lib"
}

13
.yo-rc.json Normal file
View File

@ -0,0 +1,13 @@
{
"@microsoft/generator-sharepoint": {
"plusBeta": false,
"isCreatingSolution": true,
"environment": "spo",
"version": "1.13.1",
"libraryName": "palette-picker",
"libraryId": "1c5755b8-0a69-4e68-8582-e2a30be7462f",
"packageManager": "npm",
"isDomainIsolated": false,
"componentType": "webpart"
}
}

29
LICENSE Normal file
View File

@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2022, flowerbot
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

74
README.md Normal file
View File

@ -0,0 +1,74 @@
# palette-picker
## Summary
Custom Property Pane pain resolved (whew), color palette generator inspired by [Jhey](https://codepen.io/jh3y/pen/rNjbmBQ?editors=0011).
Built it to get an understanding of [Property Pane Portal](https://www.npmjs.com/package/property-pane-portal) and cuz I to build in a dynamic palette generator/css reader for my web parts.
## 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)
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram)
## Prerequisites
> Any special pre-requisites?
## Solution
Solution|Author(s)
--------|---------
folder name | Author details (name, company, twitter alias with link)
## Version history
Version|Date|Comments
-------|----|--------
1.1|March 10, 2021|Update comment
1.0|January 29, 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
Next step is see if I can make prism work with it (as per inspiring example), and then to have the generated colors applied to web part elements.
[picture of the solution in action, if possible]
This web part illustrates the following concepts:
- custom property pane
- dynamic css in spFx property pane (and later beyond)
- topic 3
> Notice that better pictures and documentation will increase the sample usage and the value you are providing for others. Thanks for your submissions advance.
> 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

18
config/config.json Normal file
View File

@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"palette-picker-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/palettePicker/PalettePickerWebPart.js",
"manifest": "./src/webparts/palettePicker/PalettePickerWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"PalettePickerWebPartStrings": "lib/webparts/palettePicker/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": "palette-picker",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,20 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "palette-picker-client-side-solution",
"id": "1c5755b8-0a69-4e68-8582-e2a30be7462f",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"isDomainIsolated": false,
"developer": {
"name": "",
"websiteUrl": "",
"privacyUrl": "",
"termsOfUseUrl": "",
"mpnId": "Undefined-1.13.1"
}
},
"paths": {
"zippedPackage": "solution/palette-picker.sppkg"
}
}

6
config/serve.json Normal file
View File

@ -0,0 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://tweednswgovau.sharepoint.com/sites/InfrastructurePlanning/_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
gulpfile.js 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'));

21537
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

34
package.json Normal file
View File

@ -0,0 +1,34 @@
{
"name": "palette-picker",
"version": "0.0.1",
"private": true,
"main": "lib/index.js",
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.13.1",
"@microsoft/sp-lodash-subset": "1.13.1",
"@microsoft/sp-office-ui-fabric-core": "1.13.1",
"@microsoft/sp-property-pane": "1.13.1",
"@microsoft/sp-webpart-base": "1.13.1",
"office-ui-fabric-react": "7.174.1",
"property-pane-portal": "^0.3.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-range": "^1.8.13"
},
"devDependencies": {
"@types/react": "16.9.51",
"@types/react-dom": "16.9.8",
"@microsoft/sp-build-web": "1.13.1",
"@microsoft/sp-tslint-rules": "1.13.1",
"@microsoft/sp-module-interfaces": "1.13.1",
"@microsoft/rush-stack-compiler-3.9": "0.4.47",
"gulp": "~4.0.2",
"ajv": "~5.2.2",
"@types/webpack-env": "1.13.1"
}
}

1
src/index.ts Normal file
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": "a573d807-cd8c-46f4-b37c-8a16ed7a73c0",
"alias": "PalettePickerWebPart",
"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": "Palette Picker" },
"description": { "default": "Palette Picker description" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "Palette Picker"
}
}]
}

View File

@ -0,0 +1,97 @@
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 'PalettePickerWebPartStrings';
import PalettePicker from './components/PalettePicker';
import { IPalettePickerProps } from './components/IPalettePickerProps';
import { CustomPropertyPane } from './components/CustomPropertyPane';
import { PropertyPaneHost } from 'property-pane-portal';
import { update } from '@microsoft/sp-lodash-subset';
export interface IPalettePickerWebPartProps {
description: string;
hueSlider: any;
}
export default class PalettePickerWebPart extends BaseClientSideWebPart<IPalettePickerWebPartProps> {
public render(): void {
const mainElement: React.ReactElement<IPalettePickerProps> = React.createElement(
PalettePicker,
{
description: this.properties.description
}
);
const ppProps = {
description: "blah"
}
const customPropertyPaneProperties = {
context: this.context,
properties: this.properties,
updateWebPartProperty: this.updateWebPartProperty.bind(this),
};
ReactDom.render(
<>
<PalettePicker {... ppProps}/>
<CustomPropertyPane {... customPropertyPaneProperties} />
</>
, this.domElement);
}
public updateWebPartProperty(property, value) {
update(this.properties, property, () => value);
this.render();
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
const hostProperties = {
context: this.context
};
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneHost('fieldSetHue', hostProperties),
PropertyPaneHost('fieldSetSat', hostProperties),
PropertyPaneHost('fieldSetLight', hostProperties),
PropertyPaneHost('fieldSetShades', hostProperties),
PropertyPaneHost('fieldSetDisplay', hostProperties),
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,21 @@
import * as React from 'react';
import { IColorsProps } from './IColorsProps';
export const Colors: React.FC<IColorsProps> = (props) => {
return (
<div>
{
Object.keys(props.colorObject).map((key) => {
return (
<div style={{backgroundColor: props.colorObject[key]}} ><code>{`${key}: ${props.colorObject[key]}`};</code></div>
)
})
}
</div>
);
};

View File

@ -0,0 +1,387 @@
@import '~office-ui-fabric-react/dist/sass/References.scss';
.CustomPropertyPane {
/* PrismJS 1.23.0
https://prismjs.com/download.html#themes=prism-tomorrow&languages=css+css-extras&plugins=line-numbers+inline-color+toolbar+copy-to-clipboard */
/**
* prism.js tomorrow night eighties for JavaScript, CoffeeScript, CSS and HTML
* Based on https://github.com/chriskempson/tomorrow-theme
* @author Rose Pritchard
*/
code[class*="language-"],
pre[class*="language-"] {
color: #ccc;
background: none;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: 1em;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
/* Code blocks */
pre[class*="language-"] {
padding: 2rem;
margin: 0;
overflow: auto;
outline: transparent;
}
:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #2d2d2d;
}
/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}
.token.comment,
.token.block-comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: #999;
}
.token.punctuation {
color: #ccc;
}
.token.tag,
.token.attr-name,
.token.namespace,
.token.deleted {
color: #e2777a;
}
.token.function-name {
color: #6196cc;
}
.token.boolean,
.token.number,
.token.function {
color: #f08d49;
}
.token.property,
.token.class-name,
.token.constant,
.token.symbol {
color: #f8c555;
}
.token.selector,
.token.important,
.token.atrule,
.token.keyword,
.token.builtin {
color: #cc99cd;
}
.token.string,
.token.char,
.token.attr-value,
.token.regex,
.token.variable {
color: #7ec699;
}
.token.operator,
.token.entity,
.token.url {
color: #67cdcc;
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}
.token.inserted {
color: green;
}
pre[class*="language-"].line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}
pre[class*="language-"].line-numbers > code {
position: relative;
white-space: inherit;
}
.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em; /* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.line-numbers-rows > span {
display: block;
counter-increment: linenumber;
}
.line-numbers-rows > span:before {
content: counter(linenumber);
color: #999;
display: block;
padding-right: 0.8em;
text-align: right;
}
span.inline-color-wrapper {
/*
* The background image is the following SVG inline in base 64:
*
* <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 2">
* <path fill="gray" d="M0 0h2v2H0z"/>
* <path fill="white" d="M0 0h1v1H0zM1 1h1v1H1z"/>
* </svg>
*
* SVG-inlining explained:
* https://stackoverflow.com/a/21626701/7595472
*/
background: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyIDIiPjxwYXRoIGZpbGw9ImdyYXkiIGQ9Ik0wIDBoMnYySDB6Ii8+PHBhdGggZmlsbD0id2hpdGUiIGQ9Ik0wIDBoMXYxSDB6TTEgMWgxdjFIMXoiLz48L3N2Zz4=");
/* This is to prevent visual glitches where one pixel from the repeating pattern could be seen. */
background-position: center;
background-size: 110%;
display: inline-block;
height: 1.333ch;
width: 1.333ch;
margin: 0 .333ch;
box-sizing: border-box;
border: 1px solid white;
outline: 1px solid rgba(0,0,0,.5);
overflow: hidden;
}
span.inline-color {
display: block;
/* To prevent visual glitches again */
height: 120%;
width: 120%;
}
div.code-toolbar {
position: relative;
}
div.code-toolbar > .toolbar {
position: absolute;
top: .3em;
right: .2em;
opacity: 1;
}
div.code-toolbar:hover > .toolbar {
opacity: 1;
}
/* Separate line b/c rules are thrown out if selector is invalid.
IE11 and old Edge versions don't support :focus-within. */
div.code-toolbar:focus-within > .toolbar {
opacity: 1;
}
div.code-toolbar > .toolbar .toolbar-item {
display: inline-block;
}
div.code-toolbar > .toolbar a {
cursor: pointer;
}
div.code-toolbar > .toolbar button {
background: none;
border: 0;
color: inherit;
font: inherit;
line-height: normal;
overflow: visible;
padding: 0;
-webkit-user-select: none; /* for button */
-moz-user-select: none;
-ms-user-select: none;
}
div.code-toolbar > .toolbar a,
div.code-toolbar > .toolbar button {
color: #bbb;
font-size: 1rem;
padding: 0.5rem;
font-family: sans-serif;
background: hsl(0, 0%, 25%);
border-radius: .5em;
outline: transparent;
cursor: pointer;
}
div.code-toolbar > .toolbar a:hover,
div.code-toolbar > .toolbar a:focus,
div.code-toolbar > .toolbar button:hover,
div.code-toolbar > .toolbar button:focus,
div.code-toolbar > .toolbar span:hover,
div.code-toolbar > .toolbar span:focus {
background: hsl(0, 0%, 40%);
text-decoration: none;
}
* {
box-sizing: border-box;
}
body {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
//background: 'hsl(%s, 50%, 98%)' % var(--hue, 0);
overflow-x: hidden;
overflow-y: scroll;
}
#app {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 2rem;
}
.scene {
display: flex;
width: 100vw;
align-items: start;
justify-content: center;
padding-bottom: 3rem;
}
#hue,
#saturation,
#lightness {
width: 200px;
}
label {
font-family: sans-serif;
font-weight: bold;
color: hsl(0, 0%, 14%);
}
.controls {
display: grid;
grid-template-columns: auto 1fr;
grid-template-rows: auto auto auto auto;
align-items: center;
grid-gap: 2rem 2rem;
width: 50%;
max-width: 400px;
padding: 2rem;
position: fixed;
left: 50%;
top: 50%;
transform: translate(0, -50%);
}
.result {
display: grid;
grid-template-columns: 1fr auto;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 2rem 3rem -2rem hsl(0, 0%, 10%);
position: absolute;
top: 50%;
right: 50%;
transform: translate(0, -116px);
}
.palette {
display: grid;
// grid-template-rows: repeat(var(--shades, 8), 1fr);
height: 100%;
// background: linear-gradient(var(--color-1), var(--bg));
}
.palette__shade {
// background: var(--color, var(--color-one));
width: 41px;
}
.slider-thumb {
background: transparent;
position: relative;
&:after {
content: '';
position: absolute;
top: 50%;
left: 50%;
border-radius: 50%;
transform: translate(-50%, -50%);
// background: 'hsl(%s, 25%, 50%)' % var(--hue, 0);
height: 24px;
width: 24px;
//border: '2px solid hsl(%s, 25%, 50%)' % var(--hue, 0)
}
&:active {
// border: '2px solid hsl(%s, 25%, 50%)' % var(--hue, 0);
}
}
.slider-track {
height: 10px;
width: 100%;
background: hsl(0, 0%, 90%);
border: 1px solid hsl(0, 0%, 70%);
}
.labelContainer {
height: 35px;
}
}

View File

@ -0,0 +1,260 @@
import * as React from 'react';
import { PropertyPanePortal } from 'property-pane-portal';
import { ICustomPropertyPaneProps } from './ICustomPropertyPaneProps';
import styles from './CustomPropertyPane.module.scss';
import { Range } from 'react-range';
import { composeComponentAs } from 'office-ui-fabric-react';
import { Colors } from './Colors';
//ORIGINAL CODE
const getCode = (hue, saturation, lightness, shades) => {
/*document.documentElement.style.setProperty(
'--hue',
hue[1] - hue[0] + (hue[1] - hue[0]) / 2
) */
let RESULT= "";
try {
const HUE_STEP = (hue[1] - hue[0]) / shades
const LIGHT_STEP = (lightness[1] - lightness[0]) / shades
const SAT_STEP = (saturation[1] - saturation[0]) / shades
RESULT = `:root {\n`
for (let s = 0; s < shades + 1; s++) {
const HUE = Math.floor(hue[1] - s * HUE_STEP)
const LIGHTNESS = Math.floor(lightness[1] - s * LIGHT_STEP)
const SATURATION = Math.floor(saturation[1] - s * SAT_STEP)
RESULT += ` --color-${s +
1}: hsl(${HUE}, ${SATURATION}%, ${LIGHTNESS}%);\n`
}
console.log("RESULT:", RESULT);
}
catch (ex) {}
return (RESULT += '}')
}
//MADE AN OBJECT INSTEAD
const cssObj = (hue, saturation, lightness, shades) => {
let obj = {};
try {
const HUE_STEP = (hue[1] - hue[0]) / shades
const LIGHT_STEP = (lightness[1] - lightness[0]) / shades
const SAT_STEP = (saturation[1] - saturation[0]) / shades
//let RESULT = `:root {\n`
for (let s = 0; s < shades + 1; s++) {
const HUE = Math.floor(hue[1] - s * HUE_STEP)
const LIGHTNESS = Math.floor(lightness[1] - s * LIGHT_STEP)
const SATURATION = Math.floor(saturation[1] - s * SAT_STEP)
obj[`--color-${s + 1}`] = `hsl(${HUE}, ${SATURATION}%, ${LIGHTNESS}%)`;
}
} catch(ex) {console.log("obj problems"); }
// console.log("RESULT:", RESULT);
console.log("color obj:", obj);
return obj;
}
export const CustomPropertyPane: React.FunctionComponent<ICustomPropertyPaneProps> = (props) => {
const[colorObj, setColorObj] = React.useState({});
React.useEffect(() => {
try {
setColorObj(cssObj(props.properties["fieldSetHue"], props.properties["fieldSetSat"],props.properties["fieldSetLight"],props.properties["fieldSetShades"][0]));
}
catch(ex) {
console.log("color issues");
}
}, []); // empty array means useEffect only runs once (I think);
return (
<PropertyPanePortal context={props.context}>
<fieldset data-property="fieldSetHue" className={styles.CustomPropertyPane} >
<div className={styles.labelContainer}>
<label>Hue</label>
</div>
<Range
step={1}
min={0}
max={360}
values={ props.properties["fieldSetHue"] ? props.properties["fieldSetHue"] : [0, Math.floor(Math.random() * 360)] }
onChange={(values) => {
props.updateWebPartProperty("fieldSetHue", values);
setColorObj(cssObj(props.properties["fieldSetHue"], props.properties["fieldSetSat"],props.properties["fieldSetLight"],props.properties["fieldSetShades"][0]));
}}
renderTrack={({ props, children }) => (
<div
{...props}
style={{
...props.style,
height: '6px',
width: '100%',
backgroundColor: '#ccc'
}}
>
{children}
</div>
)}
renderThumb={({ props }) => (
<div
{...props}
style={{
...props.style,
height: '30px',
width: '30px',
backgroundColor: '#999'
}}
/>
)}
/>
</fieldset>
<fieldset data-property="fieldSetSat" className={styles.CustomPropertyPane} >
<div className={styles.labelContainer}><label>Saturation</label></div>
<Range
step={1}
min={0}
max={100}
values={props.properties["fieldSetSat"] ? props.properties["fieldSetSat"] : [0, 100]}
onChange={(values) => {
props.updateWebPartProperty("fieldSetSat", values);
setColorObj(cssObj(props.properties["fieldSetHue"], props.properties["fieldSetSat"],props.properties["fieldSetLight"],props.properties["fieldSetShades"][0]));
}
}
renderTrack={({ props, children }) => (
<div
{...props}
style={{
...props.style,
height: '6px',
width: '100%',
backgroundColor: '#ccc'
}}
>
{children}
</div>
)}
renderThumb={({ props }) => (
<div
{...props}
style={{
...props.style,
height: '30px',
width: '30px',
backgroundColor: '#999'
}}
/>
)}
/>
</fieldset>
<fieldset data-property="fieldSetLight" className={styles.CustomPropertyPane} >
<div className={styles.labelContainer}>
<label>
Lightness
</label>
</div>
<Range
step={1}
min={0}
max={100}
values={props.properties["fieldSetLight"] ? props.properties["fieldSetLight"] : [0, 100]}
onChange={(values) => {
props.updateWebPartProperty("fieldSetLight", values);
setColorObj(cssObj(props.properties["fieldSetHue"], props.properties["fieldSetSat"],props.properties["fieldSetLight"],props.properties["fieldSetShades"][0]));
}}
renderTrack={({ props, children }) => (
<div
{...props}
style={{
...props.style,
height: '6px',
width: '100%',
backgroundColor: '#ccc'
}}
>
{children}
</div>
)}
renderThumb={({ props }) => (
<div
{...props}
style={{
...props.style,
height: '30px',
width: '30px',
backgroundColor: '#999'
}}
/>
)}
/>
</fieldset>
<fieldset data-property="fieldSetShades" className={styles.CustomPropertyPane} >
<div className={styles.labelContainer}>
<label>Shades</label>
</div>
<Range
step={1}
min={0}
max={100}
values={props.properties["fieldSetShades"] ? props.properties["fieldSetShades"] : [7]}
onChange={(values) => {
props.updateWebPartProperty("fieldSetShades", values);
setColorObj(cssObj(props.properties["fieldSetHue"], props.properties["fieldSetSat"],props.properties["fieldSetLight"],props.properties["fieldSetShades"][0]));
}}
renderTrack={({ props, children }) => (
<div
{...props}
style={{
...props.style,
height: '6px',
width: '100%',
backgroundColor: '#ccc'
}}
>
{children}
</div>
)}
renderThumb={({ props }) => (
<div
{...props}
style={{
...props.style,
height: '30px',
width: '30px',
backgroundColor: '#999'
}}
/>
)}
/>
</fieldset>
<fieldset data-property="fieldSetDisplay" className={styles.CustomPropertyPane} >
<Colors
colorObject = {colorObj}
></Colors>
<div>
</div>
</fieldset>
</PropertyPanePortal>
);
};

View File

@ -0,0 +1,4 @@
export interface IColorsProps {
colorObject: any;
// colorObjectString: string;
}

View File

@ -0,0 +1,8 @@
import { WebPartContext } from "@microsoft/sp-webpart-base";
import { IPalettePickerWebPartProps } from "../PalettePickerWebPart";
export interface ICustomPropertyPaneProps {
context: WebPartContext;
properties: IPalettePickerWebPartProps;
updateWebPartProperty: Function;
}

View File

@ -0,0 +1,3 @@
export interface IPalettePickerProps {
description: string;
}

View File

@ -0,0 +1,74 @@
@import '~office-ui-fabric-react/dist/sass/References.scss';
.palettePicker {
.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,25 @@
import * as React from 'react';
import styles from './PalettePicker.module.scss';
import { IPalettePickerProps } from './IPalettePickerProps';
import { escape } from '@microsoft/sp-lodash-subset';
export default class PalettePicker extends React.Component<IPalettePickerProps, {}> {
public render(): React.ReactElement<IPalettePickerProps> {
return (
<div className={ styles.palettePicker }>
<div className={ styles.container }>
<div className={ styles.row }>
<div className={ styles.column }>
<span className={ styles.title }>Welcome to SharePoint!</span>
<p className={ styles.subTitle }>Customize SharePoint experiences using Web Parts.</p>
<p className={ styles.description }>{escape(this.props.description)}</p>
<a href="https://aka.ms/spfx" className={ styles.button }>
<span className={ styles.label }>Learn more</span>
</a>
</div>
</div>
</div>
</div>
);
}
}

View File

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

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

35
tsconfig.json Normal file
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"
]
}

29
tslint.json Normal file
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
}
}