From c25552bd2a9b4c919047aa1d1cae77d5eb77d0b8 Mon Sep 17 00:00:00 2001 From: Hugo Bernier Date: Sun, 21 Aug 2022 18:20:03 -0400 Subject: [PATCH] Added sample.json and fixed readme --- .../.devcontainer/devcontainer.json | 39 ++++++++ .../.devcontainer/spfx-startup.sh | 33 +++++++ samples/react-palette-picker/README.md | 85 ++++++++++++------ .../palettePickerWebPart.gif | Bin ...alettePickerWebPartAfterSaveAndRefresh.gif | Bin .../react-palette-picker/assets/sample.json | 50 +++++++++++ samples/react-palette-picker/gulpfile.js | 15 ++++ .../palettePicker/PalettePickerWebPart.tsx | 2 +- .../palettePicker/components/Colors.tsx | 2 +- .../components/CustomPropertyPane.tsx | 62 ++++++------- .../components/PalettePicker.tsx | 79 ++++++++-------- 11 files changed, 269 insertions(+), 98 deletions(-) create mode 100644 samples/react-palette-picker/.devcontainer/devcontainer.json create mode 100644 samples/react-palette-picker/.devcontainer/spfx-startup.sh rename samples/react-palette-picker/{images => assets}/palettePickerWebPart.gif (100%) rename samples/react-palette-picker/{images => assets}/palettePickerWebPartAfterSaveAndRefresh.gif (100%) create mode 100644 samples/react-palette-picker/assets/sample.json diff --git a/samples/react-palette-picker/.devcontainer/devcontainer.json b/samples/react-palette-picker/.devcontainer/devcontainer.json new file mode 100644 index 000000000..3e7ba6ebb --- /dev/null +++ b/samples/react-palette-picker/.devcontainer/devcontainer.json @@ -0,0 +1,39 @@ +// For more information on how to run this SPFx project in a VS Code Remote Container, please visit https://aka.ms/spfx-devcontainer +{ + "name": "SPFx 1.13.1", + "image": "docker.io/m365pnp/spfx:1.13.1", + // Set *default* container specific settings.json values on container create. + "settings": {}, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "editorconfig.editorconfig", + "dbaeumer.vscode-eslint" + ], + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 4321, + 35729 + ], + "portsAttributes": { + "4321": { + "protocol": "https", + "label": "Manifest", + "onAutoForward": "silent", + "requireLocalPort": true + }, + // Not needed for SPFx>= 1.12.1 + // "5432": { + // "protocol": "https", + // "label": "Workbench", + // "onAutoForward": "silent" + // }, + "35729": { + "protocol": "https", + "label": "LiveReload", + "onAutoForward": "silent", + "requireLocalPort": true + } + }, + "postCreateCommand": "bash .devcontainer/spfx-startup.sh", + "remoteUser": "node" +} \ No newline at end of file diff --git a/samples/react-palette-picker/.devcontainer/spfx-startup.sh b/samples/react-palette-picker/.devcontainer/spfx-startup.sh new file mode 100644 index 000000000..456d6aea8 --- /dev/null +++ b/samples/react-palette-picker/.devcontainer/spfx-startup.sh @@ -0,0 +1,33 @@ +echo +echo -e "\e[1;94mInstalling Node dependencies\e[0m" +npm install + +## commands to create dev certificate and copy it to the root folder of the project +echo +echo -e "\e[1;94mGenerating dev certificate\e[0m" +gulp trust-dev-cert + +# Convert the generated PEM certificate to a CER certificate +openssl x509 -inform PEM -in ~/.rushstack/rushstack-serve.pem -outform DER -out ./spfx-dev-cert.cer + +# Copy the PEM ecrtificate for non-Windows hosts +cp ~/.rushstack/rushstack-serve.pem ./spfx-dev-cert.pem + +## add *.cer to .gitignore to prevent certificates from being saved in repo +if ! grep -Fxq '*.cer' ./.gitignore + then + echo "# .CER Certificates" >> .gitignore + echo "*.cer" >> .gitignore +fi + +## add *.pem to .gitignore to prevent certificates from being saved in repo +if ! grep -Fxq '*.pem' ./.gitignore + then + echo "# .PEM Certificates" >> .gitignore + echo "*.pem" >> .gitignore +fi + +echo +echo -e "\e[1;92mReady!\e[0m" + +echo -e "\n\e[1;94m**********\nOptional: if you plan on using gulp serve, don't forget to add the container certificate to your local machine. Please visit https://aka.ms/spfx-devcontainer for more information\n**********" \ No newline at end of file diff --git a/samples/react-palette-picker/README.md b/samples/react-palette-picker/README.md index c358c25c3..c944a7266 100644 --- a/samples/react-palette-picker/README.md +++ b/samples/react-palette-picker/README.md @@ -1,4 +1,4 @@ -# palette-picker +# Palette Picker ## Summary @@ -8,65 +8,98 @@ Built it to get an understanding of [Property Pane Portal](https://www.npmjs.com ![property pane view](images/palettePickerWebPart.gif) ![after save and refresh](images/palettePickerWebPartAfterSaveAndRefresh.gif) -## Used SharePoint Framework Version +## Compatibility -![version](https://img.shields.io/badge/version-1.13-green.svg) +![SPFx 1.13.1](https://img.shields.io/badge/SPFx-1.12.1-green.svg) +![Node.js v14 | v12](https://img.shields.io/badge/Node.js-v14%20%7C%20v12-green.svg) +![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg) +![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower") +![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1") +![Local Workbench Unsupported](https://img.shields.io/badge/Local%20Workbench-Unsupported-red.svg "Local workbench is no longer available as of SPFx 1.13 and above") +![Hosted Workbench Compatible](https://img.shields.io/badge/Hosted%20Workbench-Compatible-green.svg) +![Compatible with Remote Containers](https://img.shields.io/badge/Remote%20Containers-Compatible-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) +* [SharePoint Framework](https://docs.microsoft.com/sharepoint/dev/spfx/sharepoint-framework-overview) +* [Microsoft 365 tenant](https://docs.microsoft.com/sharepoint/dev/spfx/set-up-your-development-environment) > Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram) - ## Solution Solution|Author(s) --------|--------- react Palette Picker Web Part | [Linda K](https://github.com/flowerbot) + ## Version history Version|Date|Comments -------|----|-------- 1.0|August, 2022|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.** +## Prerequisites ---- + -- Clone this repository -- Ensure that you are at the solution folder -- in the command-line run: - - **npm install** - - **gulp serve** +## Minimal path to awesome + + +* Clone this repository (or [download this solution as a .ZIP file](https://pnp.github.io/download-partial/?url=https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/REACT-PALETTE-PICKER) then unzip it) +* From your command line, change your current directory to the directory containing this sample (`REACT-PALETTE-PICKER`, located under `samples`) +* in the command line run: + * `npm install` + * `gulp serve` + +> This sample can also be opened with [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview). Visit for further instructions. ## Features -Multi-parameter sliders* in property pane from [react-range](https://www.npmjs.com/package/react-range), dynamic colour updating, css snippet generation, apply colours to MS dropdown component options. +Multi-parameter sliders* in property pane from [react-range](https://www.npmjs.com/package/react-range), dynamic color updating, CSS snippet generation, apply colors to MS dropdown component options. *\* PnP - please consider :)* This web part illustrates the following concepts: -- custom property pane -- dynamic css in spFx property pane -- custom css colour on dropdown options +* custom property pane +* dynamic CSS in SPFx property pane +* custom CSS color on dropdown options +## Help -> 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. +We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues. + +If you're having issues building the solution, please run [spfx doctor](https://pnp.github.io/cli-microsoft365/cmd/spfx/spfx-doctor/) from within the solution folder to diagnose incompatibility issues with your environment. + +You can try looking at [issues related to this sample](https://github.com/pnp/sp-dev-fx-webparts/issues?q=label%3A%22sample%3A%20REACT-PALETTE-PICKER%22) to see if anybody else is having the same issues. + +You can also try looking at [discussions related to this sample](https://github.com/pnp/sp-dev-fx-webparts/discussions?discussions_q=REACT-PALETTE-PICKER) and see what the community is saying. + +If you encounter any issues using this sample, [create a new issue](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected%2Csample%3A%20REACT-PALETTE-PICKER&template=bug-report.yml&sample=REACT-PALETTE-PICKER&authors=@flowerbot&title=REACT-PALETTE-PICKER%20-%20). + +For questions regarding this sample, [create a new question](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Aquestion%2Csample%3A%20REACT-PALETTE-PICKER&template=question.yml&sample=REACT-PALETTE-PICKER&authors=@flowerbot&title=REACT-PALETTE-PICKER%20-%20). + +Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Aenhancement%2Csample%3A%20REACT-PALETTE-PICKER&template=suggestion.yml&sample=REACT-PALETTE-PICKER&authors=@flowerbot&title=REACT-PALETTE-PICKER%20-%20). ## References -- [Property Pane Portal](https://blog.pathtosharepoint.com/2021/07/29/introducing-the-property-pane-portal/) (thank you Christophe!) -- [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 \ No newline at end of file +* [Property Pane Portal](https://blog.pathtosharepoint.com/2021/07/29/introducing-the-property-pane-portal/) (thank you Christophe!) +* [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 + +## 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.** + + diff --git a/samples/react-palette-picker/images/palettePickerWebPart.gif b/samples/react-palette-picker/assets/palettePickerWebPart.gif similarity index 100% rename from samples/react-palette-picker/images/palettePickerWebPart.gif rename to samples/react-palette-picker/assets/palettePickerWebPart.gif diff --git a/samples/react-palette-picker/images/palettePickerWebPartAfterSaveAndRefresh.gif b/samples/react-palette-picker/assets/palettePickerWebPartAfterSaveAndRefresh.gif similarity index 100% rename from samples/react-palette-picker/images/palettePickerWebPartAfterSaveAndRefresh.gif rename to samples/react-palette-picker/assets/palettePickerWebPartAfterSaveAndRefresh.gif diff --git a/samples/react-palette-picker/assets/sample.json b/samples/react-palette-picker/assets/sample.json new file mode 100644 index 000000000..b9221e26f --- /dev/null +++ b/samples/react-palette-picker/assets/sample.json @@ -0,0 +1,50 @@ +[ + { + "name": "pnp-sp-dev-spfx-web-parts-react-palette-picker", + "source": "pnp", + "title": "Palette Picker", + "shortDescription": "Custom Property Pane pain resolved (whew), color palette generator inspired by [Jhey](https://codepen.io/jh3y/pen/rNjbmBQ?editors=0011).", + "url": "https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-palette-picker", + "downloadUrl": "https://pnp.github.io/download-partial/?url=https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-palette-picker", + "longDescription": [ + "Built it to get an understanding of [Property Pane Portal](https://www.npmjs.com/package/property-pane-portal) and cuz I want to eventually build in a dynamic palette generator/css reader for my web parts." + ], + "creationDateTime": "2022-08-01", + "updateDateTime": "2022-08-01", + "products": [ + "SharePoint" + ], + "metadata": [ + { + "key": "CLIENT-SIDE-DEV", + "value": "React" + }, + { + "key": "SPFX-VERSION", + "value": "1.13.1" + } + ], + "thumbnails": [ + { + "type": "image", + "order": 100, + "url": "https://github.com/pnp/sp-dev-fx-webparts/raw/main/samples/react-palette-picker/assets/YOUR-IMAGE-NAME-HERE", + "alt": "Web Part Preview" + } + ], + "authors": [ + { + "gitHubAccount": "flowerbot", + "pictureUrl": "https://github.com/flowerbot.png", + "name": "author" + } + ], + "references": [ + { + "name": "Build your first SharePoint client-side web part", + "description": "Client-side web parts are client-side components that run in the context of a SharePoint page. Client-side web parts can be deployed to SharePoint environments that support the SharePoint Framework. You can also use modern JavaScript web frameworks, tools, and libraries to build them.", + "url": "https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part" + } + ] + } +] \ No newline at end of file diff --git a/samples/react-palette-picker/gulpfile.js b/samples/react-palette-picker/gulpfile.js index be2918708..b4eea8e0f 100644 --- a/samples/react-palette-picker/gulpfile.js +++ b/samples/react-palette-picker/gulpfile.js @@ -3,6 +3,21 @@ 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.addSuppression(`Warning - [sass] The local CSS class 'slider-track' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'toolbar-item' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'code-toolbar' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'inline-color' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'inline-color-wrapper' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'line-numbers-rows' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'line-numbers' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'attr-value' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'class-name' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'function-name' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'attr-name' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'block-comment' is not camelCase and will not be type-safe.`); +build.addSuppression(`Warning - [sass] The local CSS class 'slider-thumb' is not camelCase and will not be type-safe.`); + + var getTasks = build.rig.getTasks; build.rig.getTasks = function () { diff --git a/samples/react-palette-picker/src/webparts/palettePicker/PalettePickerWebPart.tsx b/samples/react-palette-picker/src/webparts/palettePicker/PalettePickerWebPart.tsx index b4c7a0e93..075b35236 100644 --- a/samples/react-palette-picker/src/webparts/palettePicker/PalettePickerWebPart.tsx +++ b/samples/react-palette-picker/src/webparts/palettePicker/PalettePickerWebPart.tsx @@ -40,7 +40,7 @@ export default class PalettePickerWebPart extends BaseClientSideWebPart = (props) => { Object.keys(props.colorObject).map((key) => { return (
{`${key}: ${props.colorObject[key]}`};
- ) + ); }) } diff --git a/samples/react-palette-picker/src/webparts/palettePicker/components/CustomPropertyPane.tsx b/samples/react-palette-picker/src/webparts/palettePicker/components/CustomPropertyPane.tsx index f06d6766e..f159a5376 100644 --- a/samples/react-palette-picker/src/webparts/palettePicker/components/CustomPropertyPane.tsx +++ b/samples/react-palette-picker/src/webparts/palettePicker/components/CustomPropertyPane.tsx @@ -17,19 +17,19 @@ export const CustomPropertyPane: React.FunctionComponent { 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 + const HUE_STEP = (hue[1] - hue[0]) / shades; + const LIGHT_STEP = (lightness[1] - lightness[0]) / shades; + const SAT_STEP = (saturation[1] - saturation[0]) / shades; 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) + 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"); } return obj; - } + }; const[colorObj, setColorObj] = React.useState({}); @@ -61,11 +61,11 @@ export const CustomPropertyPane: React.FunctionComponent ( + renderTrack={({ props: innerProps, children }) => (
)} - renderThumb={({ props }) => ( + renderThumb={({ props: innerProps }) => (
( + renderTrack={({ props: innerProps, children }) => (
)} - renderThumb={({ props }) => ( + renderThumb={({ props: innerProps }) => (
( + renderTrack={({ props: innerProps, children }) => (
)} - renderThumb={({ props }) => ( + renderThumb={({ props: innerProps }) => (
( + renderTrack={({ props: innerProps, children }) => (
)} - renderThumb={({ props }) => ( + renderThumb={({ props: innerProps }) => (
{ let newObj = {}; Object.keys(obj).map((key, i) => { - newObj[`.ms-Dropdown-item:nth-of-type(${i+1})`] = { "backgroundColor": obj[key] }; + newObj[`.ms-Dropdown-item:nth-of-type(${i + 1})`] = { "backgroundColor": obj[key] }; }); return newObj; -} +}; export default class PalettePicker extends React.Component { -constructor(props: IPalettePickerProps) { - super(props); + constructor(props: IPalettePickerProps) { + super(props); - -} + + } private dropdownStyles: Partial = { root: this.props.cssObject, - label: {color: this.props.fontColor}, - /* dropdownItem: { - backgroundColor: 'pink' - }, */ - /* dropdownItemsWrapper: { - style: this.props.cssObject ? this.props.cssObject : {}, - }, */ + label: { color: this.props.fontColor }, + /* dropdownItem: { + backgroundColor: 'pink' + }, */ + /* dropdownItemsWrapper: { + style: this.props.cssObject ? this.props.cssObject : {}, + }, */ - dropdownItems: { + dropdownItems: { selectors: returnCss(this.props.cssObject), - dropdown: { width: 300 - } - - } + dropdown: { + width: 300 + } + + } + + }; -} - public render(): React.ReactElement { -console.log("styles:", this.dropdownStyles); -console.log("obj", returnCss(this.props.cssObject)); + console.log("styles:", this.dropdownStyles); + console.log("obj", returnCss(this.props.cssObject)); return ( -
+
-
-
- Here's a Palette Picker for you! -

Allow users to select a color palette for your web part.

-
- {Object.keys(this.props.cssObject).map((key,i) =>{ - return
- })} +
+
+ Here's a Palette Picker for you! +

Allow users to select a color palette for your web part.

+
+ {Object.keys(this.props.cssObject).map((key, i) => { + return
; + })}
- - + + Learn more -
 {JSON.stringify(this.props.cssObject, null, 4)}
+
 {JSON.stringify(this.props.cssObject, null, 4)}