Merge pull request #2720 from pnp/fluent-ui-sample

Merging sample from #2629
This commit is contained in:
Hugo Bernier 2022-05-30 08:54:04 -07:00 committed by GitHub
commit b72ca38671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 23704 additions and 1 deletions

View File

@ -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"
}

View File

@ -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**********"

33
samples/react-fluentui-9/.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,16 @@
{
"@microsoft/generator-sharepoint": {
"plusBeta": false,
"isCreatingSolution": true,
"version": "1.14.0",
"libraryName": "react-fluentui-9",
"libraryId": "d955a989-7441-475a-b4eb-ff132968b3c5",
"environment": "spo",
"packageManager": "npm",
"solutionName": "react-fluentui-9",
"solutionShortDescription": "react-fluentui-9 description",
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"componentType": "webpart"
}
}

View File

@ -0,0 +1,90 @@
# Fluent UI 9 Demo
## Summary
This demos the use of the new [Fluent UI version 9](https://github.com/microsoft/fluentui/tree/master/packages/react-components) controls and theme provider. 1 UI framework which has native theming for Teams, SharePoint and Windows
![SharePoint View](assets/FQzNLB4XwAIFMRh.jpg "SharePoint View")
![Teams View](assets/FQzO9YjWUAgFlrU.jpg "Teams View")
## Compatibility
![SPFx 1.14](https://img.shields.io/badge/SPFx-1.14-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://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)
## Applies to
- [SharePoint Framework](https://aka.ms/spfx)
- [Microsoft 365 tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram)
## Solution
Solution|Author(s)
--------|---------
react-fluentui-9 | [Nick Brown](https://github.com/techienickb) ([@techienickb](https://twitter.com/techienickb) / [Jisc](https://jisc.ac.uk))
## Version history
Version|Date|Comments
-------|----|--------
1.0|April 20, 2022|Initial release
- 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-fluentui-9) then unzip it)
- From your command-line, change your current directory to the directory containing this sample (`react-fluentui-9`, 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 <https://aka.ms/spfx-devcontainer> for further instructions.
## Features
Very simple demo, the handling of the theme provider is interesting implementing it and handling the custom themes SharePoint can use.
## 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
- [Fluent UI version 9](https://github.com/microsoft/fluentui/tree/master/packages/react-components) - Converged Fluent UI components
## Help
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-fluentui-9%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-fluentui-9) 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-fluentui-9&template=bug-report.yml&sample=react-fluentui-9&authors=@techienickb&title=react-fluentui-9%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-fluentui-9&template=question.yml&sample=react-fluentui-9&authors=@techienickb&title=react-fluentui-9%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-fluentui-9&template=suggestion.yml&sample=react-fluentui-9&authors=@techienickb&title=react-fluentui-9%20-%20).
## 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.**
<img src="https://pnptelemetry.azurewebsites.net/sp-dev-fx-webparts/samples/react-fluentui-9" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB

View File

@ -0,0 +1,56 @@
[
{
"name": "pnp-sp-dev-spfx-web-parts-react-fluentui-9",
"source": "pnp",
"title": "Fluent UI 9 Demo",
"shortDescription": "description",
"url": "https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-fluentui-9",
"downloadUrl": "https://pnp.github.io/download-partial/?url=https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-fluentui-9",
"longDescription": [
"description"
],
"creationDateTime": "2022-04-20",
"updateDateTime": "2022-04-20",
"products": [
"SharePoint"
],
"metadata": [
{
"key": "CLIENT-SIDE-DEV",
"value": "React"
},
{
"key": "SPFX-VERSION",
"value": "1.14"
}
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://github.com/pnp/sp-dev-fx-webparts/raw/main/samples/react-fluentui-9/assets/FQzNLB4XwAIFMRh.jpg",
"alt": "Web Part Preview"
},
{
"type": "image",
"order": 100,
"url": "https://github.com/pnp/sp-dev-fx-webparts/raw/main/samples/react-fluentui-9/assets/FQzO9YjWUAgFlrU.jpg",
"alt": "Web Part Preview"
}
],
"authors": [
{
"gitHubAccount": "techienickb",
"pictureUrl": "https://github.com/techienickb.png",
"name": "Nick Brown"
}
],
"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/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part"
}
]
}
]

View File

@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"fluent-ui-9-demo-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/fluentUi9Demo/FluentUi9DemoWebPart.js",
"manifest": "./src/webparts/fluentUi9Demo/FluentUi9DemoWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"FluentUi9DemoWebPartStrings": "lib/webparts/fluentUi9Demo/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-fluentui-9",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,44 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "react-fluentui-9-client-side-solution",
"title": "SPFX + Fluent UI 9 Demo",
"id": "d955a989-7441-475a-b4eb-ff132968b3c5",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"developer": {
"name": "Nick Brown",
"websiteUrl": "https://nbdev.uk",
"privacyUrl": "",
"termsOfUseUrl": "",
"mpnId": "Undefined-1.14.0"
},
"metadata": {
"shortDescription": {
"default": "react-fluentui-9 description"
},
"longDescription": {
"default": "react-fluentui-9 description"
},
"screenshotPaths": [
"../assets/FQzNLB4XwAIFMRh.jpg",
"../assets/FQzO9YjWUAgFlrU.jpg"
],
"videoUrl": "",
"categories": []
},
"features": [
{
"title": "react-fluentui-9 Feature",
"description": "Demos the use of Fluent UI 9 in SPFX",
"id": "233521d9-d6d8-41ed-a43d-d30bb942c370",
"version": "1.0.0.0"
}
]
},
"paths": {
"zippedPackage": "solution/react-fluentui-9.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://enter-your-SharePoint-site/_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-fluentui-9/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'));

22806
samples/react-fluentui-9/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
{
"name": "react-fluentui-9",
"version": "0.0.1",
"private": true,
"main": "lib/index.js",
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@fluentui/react-components": "^9.0.0-rc.7",
"@microsoft/sp-core-library": "1.14.0",
"@microsoft/sp-lodash-subset": "1.14.0",
"@microsoft/sp-office-ui-fabric-core": "1.14.0",
"@microsoft/sp-property-pane": "1.14.0",
"@microsoft/sp-webpart-base": "1.14.0",
"office-ui-fabric-react": "7.174.1",
"react": "16.13.1",
"react-dom": "16.13.1"
},
"devDependencies": {
"@types/react": "16.9.51",
"@types/react-dom": "16.9.8",
"@microsoft/sp-build-web": "1.14.0",
"@microsoft/sp-tslint-rules": "1.14.0",
"@microsoft/sp-module-interfaces": "1.14.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,20 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "e27a9fe1-16cf-4f4b-adb7-6adb4d2d6c00",
"alias": "FluentUi9DemoWebPart",
"componentType": "WebPart",
"version": "*",
"manifestVersion": 2,
"requiresCustomScript": false,
"supportedHosts": ["SharePointWebPart", "TeamsPersonalApp", "TeamsTab", "SharePointFullPage"],
"supportsThemeVariants": true,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70",
"group": { "default": "Other" },
"title": { "default": "Fluent UI 9 Demo" },
"description": { "default": "Demos the use of Fluent UI 9 in SPFX complete with theme detection" },
"officeFabricIconFontName": "Page",
"properties": {}
}]
}

View File

@ -0,0 +1,105 @@
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import { IPropertyPaneConfiguration } from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import { IReadonlyTheme } from '@microsoft/sp-component-base';
import * as strings from 'FluentUi9DemoWebPartStrings';
import FluentUi9Demo from './components/FluentUi9Demo';
import { IFluentUi9DemoProps } from './components/IFluentUi9DemoProps';
import { FluentProvider, FluentProviderProps, teamsDarkTheme, teamsLightTheme, webLightTheme, webDarkTheme, Theme } from '@fluentui/react-components';
export enum AppMode {
SharePoint, SharePointLocal, Teams, TeamsLocal
}
export default class FluentUi9DemoWebPart extends BaseClientSideWebPart<{}> {
private _isDarkTheme: boolean = false;
private _environmentMessage: string = '';
private _appMode: AppMode = AppMode.SharePoint;
private _theme: Theme = webLightTheme;
protected onInit(): Promise<void> {
this._environmentMessage = this._getEnvironmentMessage();
//on initalizational set the App Mode
this._appMode = !!this.context.sdks.microsoftTeams ? (this.context.isServedFromLocalhost ? AppMode.TeamsLocal : AppMode.Teams) : (this.context.isServedFromLocalhost) ? AppMode.SharePointLocal : AppMode.SharePoint;
return super.onInit();
}
public render(): void {
const element: React.ReactElement<IFluentUi9DemoProps> = React.createElement(
FluentUi9Demo,
{
isDarkTheme: this._isDarkTheme,
environmentMessage: this._environmentMessage,
hasTeamsContext: !!this.context.sdks.microsoftTeams,
userDisplayName: this.context.pageContext.user.displayName,
context: this.context
}
);
//wrap the component with the Fluent UI 9 Provider.
const fluentElement: React.ReactElement<FluentProviderProps> = React.createElement(
FluentProvider,
{
theme : this._appMode === AppMode.Teams || this._appMode === AppMode.TeamsLocal ?
this._isDarkTheme ? teamsDarkTheme : teamsLightTheme :
this._isDarkTheme ? webDarkTheme : this._theme
},
element
);
ReactDom.render(fluentElement, this.domElement);
}
private _getEnvironmentMessage(): string {
if (!!this.context.sdks.microsoftTeams) return this.context.isServedFromLocalhost ? strings.AppLocalEnvironmentTeams : strings.AppTeamsTabEnvironment;
return this.context.isServedFromLocalhost ? strings.AppLocalEnvironmentSharePoint : strings.AppSharePointEnvironment;
}
protected onThemeChanged(currentTheme: IReadonlyTheme | undefined): void {
if (!currentTheme) return;
this._isDarkTheme = !!currentTheme.isInverted;
//if the app mode is sharepoint, adjust the fluent ui 9 web light theme to use the sharepoint theme color, teams/dark mode should be fine on default
if (this._appMode === AppMode.SharePoint || this._appMode === AppMode.SharePointLocal) {
this._theme = {...webLightTheme,
colorBrandBackground: currentTheme.palette.themePrimary,
colorBrandBackgroundHover: currentTheme.palette.themeDark,
colorBrandBackgroundPressed: currentTheme.palette.themeDarker,
colorCompoundBrandForeground1: currentTheme.palette.themePrimary,
colorCompoundBrandForeground1Hover: currentTheme.palette.themeDark,
colorCompoundBrandForeground1Pressed: currentTheme.palette.themeDarker,
colorNeutralForeground2BrandHover: currentTheme.palette.themeSecondary,
colorNeutralForeground2BrandPressed: currentTheme.palette.themeDarkAlt,
colorNeutralForeground2BrandSelected: currentTheme.palette.themeDarkAlt,
colorBrandForeground1: currentTheme.palette.themeSecondary,
colorBrandStroke1: currentTheme.palette.themePrimary,
colorBrandStroke2: currentTheme.palette.themeSecondary,
colorCompoundBrandStroke: currentTheme.palette.themePrimary,
colorCompoundBrandStrokeHover: currentTheme.palette.themeSecondary,
colorCompoundBrandStrokePressed: currentTheme.palette.themeDarkAlt,
colorCompoundBrandBackground: currentTheme.palette.themePrimary,
colorCompoundBrandBackgroundHover: currentTheme.palette.themeDark,
colorCompoundBrandBackgroundPressed: currentTheme.palette.themeDarker,
};
}
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
]
};
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -0,0 +1,70 @@
@import '~office-ui-fabric-react/dist/sass/References.scss';
.fluentUi9Demo {
overflow: hidden;
padding: 1em;
color: "[theme:bodyText, default: #323130]";
color: var(--bodyText);
&.teams {
font-family: $ms-font-family-fallbacks;
}
}
.stack {
display: flex;
flex-direction: column;
flex-wrap: 'nowrap';
gap: 5px;
width: auto;
}
.stackHoz {
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 5px;
}
.center {
align-items: center;
justify-content: center;
}
.stretch {
align-items: stretch;
}
.spaceEven {
justify-content: space-evenly;
}
.spaceAround {
justify-content: space-around;
}
.spaceBetween {
justify-content: space-between;
}
.welcome {
text-align: center;
}
.welcomeImage {
width: 100%;
max-width: 420px;
}
.links {
a {
text-decoration: none;
color: "[theme:link, default:#03787c]";
color: var(--link); // note: CSS Custom Properties support is limited to modern browsers only
&:hover {
text-decoration: underline;
color: "[theme:linkHovered, default: #014446]";
color: var(--linkHovered); // note: CSS Custom Properties support is limited to modern browsers only
}
}
}

View File

@ -0,0 +1,192 @@
import * as React from 'react';
import styles from './FluentUi9Demo.module.scss';
import { IFluentUi9DemoProps } from './IFluentUi9DemoProps';
import { escape } from '@microsoft/sp-lodash-subset';
import { Button, Link, Text, Caption, Body, Avatar, useId, ToggleButton, Slider, Menu, MenuTrigger, MenuButtonProps, MenuPopover, MenuList, MenuItem, SplitButton, Divider } from '@fluentui/react-components';
import { Card, Tab, TabList, CardHeader, CardPreview, CardFooter, Label, Input, Checkbox, RadioGroup, Radio, Switch } from '@fluentui/react-components/unstable';
import { ArrowReplyRegular, ShareRegular, DocumentText24Regular } from '@fluentui/react-icons';
export default function FluentUi9Demo(props: IFluentUi9DemoProps) {
const { isDarkTheme, environmentMessage, hasTeamsContext, userDisplayName } = props;
const [tab, setTab] = React.useState<string | unknown>("buttons");
const [me, setMe] = React.useState<string|undefined>();
const outlineId = useId('input-outline');
const underlineId = useId('input-underline');
React.useEffect(() => {
props.context.msGraphClientFactory.getClient().then(async (client) => {
await client
.api('/me/photo/$value')
.responseType("blob")
.get()
.then((blob: Blob) : Promise<any> => {
return new Promise(resolve => {
const url = URL.createObjectURL(blob);
setMe(url);
resolve(url);
});
});
});
}, []);
return (
<section className={`${styles.fluentUi9Demo} ${hasTeamsContext ? styles.teams : ''}`}>
<div className={styles.welcome}>
<img alt="" src={isDarkTheme ? require('../assets/welcome-dark.png') : require('../assets/welcome-light.png')} className={styles.welcomeImage} />
<h2>Well done, {escape(userDisplayName)}!</h2>
<div>{environmentMessage}</div>
</div>
<div>
<h3>Welcome to SharePoint Framework!</h3>
<p>
This demos the use of Fluent UI 9 instead of using FabircUI. The new framework combines Northstar and FluentUI. Below are some demo's and they should render in Teams style when inside Teams.
</p>
<Text as="h3">Demo components</Text>
<div className={styles.stack}>
<TabList onTabSelect={(e, data) => setTab(data.value)} defaultSelectedValue="buttons">
<Tab value="buttons">Buttons</Tab>
<Tab value="cards">Cards</Tab>
<Tab value="inputs">Inputs</Tab>
</TabList>
{tab === 'buttons' && <div className={styles.stack} style={{padding: 10}}>
<Divider appearance='brand'>Button</Divider>
<div className={`${styles.stackHoz} ${styles.spaceBetween}`}>
<Button>Default</Button><Button appearance="primary">Primary</Button><Button appearance="outline">Outline</Button><Button appearance="subtle">Subtle</Button><Button appearance="transparent">Transparent</Button>
</div>
<Divider appearance='brand'>Toggle Button</Divider>
<div className={`${styles.stackHoz} ${styles.spaceBetween}`}>
<ToggleButton>Default</ToggleButton>
<ToggleButton appearance="primary">Primary</ToggleButton>
<ToggleButton appearance="outline">Outline</ToggleButton>
<ToggleButton appearance="subtle">Subtle</ToggleButton>
<ToggleButton appearance="transparent">Transparent</ToggleButton>
</div>
<Divider appearance='brand'>Split Button</Divider>
<div className={`${styles.stackHoz} ${styles.spaceBetween}`}>
<Menu positioning="below-end">
<MenuTrigger>
{(triggerProps: MenuButtonProps) => <SplitButton menuButton={triggerProps}>Default</SplitButton>}
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuItem>Item a</MenuItem>
<MenuItem>Item b</MenuItem>
</MenuList>
</MenuPopover>
</Menu>
<Menu positioning="below-end">
<MenuTrigger>
{(triggerProps: MenuButtonProps) => (
<SplitButton menuButton={triggerProps} appearance="primary">
Primary
</SplitButton>
)}
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuItem>Item a</MenuItem>
<MenuItem>Item b</MenuItem>
</MenuList>
</MenuPopover>
</Menu>
<Menu positioning="below-end">
<MenuTrigger>
{(triggerProps: MenuButtonProps) => (
<SplitButton menuButton={triggerProps} appearance="outline">
Outline
</SplitButton>
)}
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuItem>Item a</MenuItem>
<MenuItem>Item b</MenuItem>
</MenuList>
</MenuPopover>
</Menu>
<Menu positioning="below-end">
<MenuTrigger>
{(triggerProps: MenuButtonProps) => (
<SplitButton menuButton={triggerProps} appearance="subtle">
Subtle
</SplitButton>
)}
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuItem>Item a</MenuItem>
<MenuItem>Item b</MenuItem>
</MenuList>
</MenuPopover>
</Menu>
<Menu positioning="below-end">
<MenuTrigger>
{(triggerProps: MenuButtonProps) => (
<SplitButton menuButton={triggerProps} appearance="transparent">
Transparent
</SplitButton>
)}
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuItem>Item a</MenuItem>
<MenuItem>Item b</MenuItem>
</MenuList>
</MenuPopover>
</Menu>
</div>
</div>}
{tab === 'cards' && <>
<Card>
<CardHeader
image={<Avatar name={userDisplayName} image={me ? {src: me } : null} />}
header={
<Body>
<b>{userDisplayName}</b> mentioned
</Body>
}
description={<Caption>5h ago · About us - Overview</Caption>}
/>
<CardPreview logo={<DocumentText24Regular />}>
<img src={isDarkTheme ? require('../assets/welcome-dark.png') : require('../assets/welcome-light.png')} alt="Preview of a Word document " />
</CardPreview>
<CardFooter>
<Button icon={<ArrowReplyRegular fontSize={16} />}>Reply</Button>
<Button icon={<ShareRegular fontSize={16} />}>Share</Button>
</CardFooter>
</Card>
</>}
{tab === 'inputs' && <div style={{padding: 10}} className={styles.stack}>
<div><Label htmlFor={outlineId}>Outline (default)</Label><Input appearance="outline" id={outlineId} /></div>
<div><Label htmlFor={underlineId}>Underline</Label><Input appearance="underline" id={underlineId} /></div>
<Checkbox label="Option 1" /><Checkbox label="Option 2" checked /><Checkbox label="Option 3" checked="mixed" />
<RadioGroup layout="horizontal"><Radio value="A" label="Option A" /><Radio value="B" label="Option B" /><Radio value="C" label="Option C" /><Radio value="D" label="Option D" /></RadioGroup>
<Switch />
<Slider defaultValue={20} />
</div>}
</div>
<h4>Learn more about SPFx development:</h4>
<ul className={styles.links}>
<li><Link href="https://aka.ms/spfx" target="_blank">SharePoint Framework Overview</Link></li>
<li><Link href="https://aka.ms/spfx-yeoman-graph" target="_blank">Use Microsoft Graph in your solution</Link></li>
<li><Link href="https://aka.ms/spfx-yeoman-teams" target="_blank">Build for Microsoft Teams using SharePoint Framework</Link></li>
<li><Link href="https://aka.ms/spfx-yeoman-viva" target="_blank">Build for Microsoft Viva Connections using SharePoint Framework</Link></li>
<li><Link href="https://aka.ms/spfx-yeoman-store" target="_blank">Publish SharePoint Framework applications to the marketplace</Link></li>
<li><Link href="https://aka.ms/spfx-yeoman-api" target="_blank">SharePoint Framework API reference</Link></li>
<li><Link href="https://aka.ms/m365pnp" target="_blank">Microsoft 365 Developer Community</Link></li>
<li><Link href="https://aka.ms/fluentui-storybook" target="_blank">Microsoft Fluent UI v9</Link></li>
</ul>
</div>
</section>
);
}

View File

@ -0,0 +1,9 @@
import { WebPartContext } from "@microsoft/sp-webpart-base";
export interface IFluentUi9DemoProps {
isDarkTheme: boolean;
environmentMessage: string;
hasTeamsContext: boolean;
userDisplayName: string;
context: WebPartContext;
}

View File

@ -0,0 +1,11 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field",
"AppLocalEnvironmentSharePoint": "The app is running on your local environment as SharePoint web part",
"AppLocalEnvironmentTeams": "The app is running on your local environment as Microsoft Teams app",
"AppSharePointEnvironment": "The app is running on SharePoint page",
"AppTeamsTabEnvironment": "The app is running in Microsoft Teams"
}
});

View File

@ -0,0 +1,14 @@
declare interface IFluentUi9DemoWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
AppLocalEnvironmentSharePoint: string;
AppLocalEnvironmentTeams: string;
AppSharePointEnvironment: string;
AppTeamsTabEnvironment: string;
}
declare module 'FluentUi9DemoWebPartStrings' {
const strings: IFluentUi9DemoWebPartStrings;
export = strings;
}

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
}
}

View File

@ -49,7 +49,7 @@
{ {
"name": "Build your first SharePoint client-side web part", "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.", "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" "url": "https://docs.microsoft.com/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part"
} }
] ]
} }