cpsloal / prototype_office-ui-fabric-react

Prototype/sample to give https://github.com/OfficeDev/office-ui-fabric-react a try

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool




prototype_office-ui-fabric-react

forthebadge

forthebadge forthebadge forthebadge

Overview

A React App prototype using Office UI Fabric components. Just to get familiar with Office UI Fabric components for a friend.

The End Goal is to be able to create Office Add-ins.

If you like raw, unrefined sugar, check out the Long Form Recipe for what seems like step-by-step thought process and the birth of this prototype.

Build Setup

# install dependencies
npm install

# serve the app from localhost:3000
npm start

# build application for production
npm run build

# run unit & end-to-end tests
npm test

Well, thats it folks. We are done! We can all go home now.

Long Form Recipe

This section contains step by step of how this prototype came to be (as its being built). If a blog is written, then the link would be here and contain a more user-friendly documentation and descriptions.

Chef's Choice (お任せ)

  1. create-react-app
  2. office-ui-fabric-react
  3. generator-office

In the beginning ...

Starting with ...

https://github.com/OfficeDev/office-ui-fabric-react/blob/master/ghdocs/OnBoarding/SampleApp.md

It is presumed that NodeJS is installed already. Then from command prompt:

# Install tool needed to generate a react app scaffolding
npm install -g create-react-app

# Create a scaffolded React App
create-react-app prototype_office-ui-fabric-react

Following are the settings used when generating the project scaffolding:

Readme generated by create-react-app is here


Then ...

# Install Office UI Fabric
cd prototype_office-ui-fabric-react
npm install office-ui-fabric-react --save

Add DocumentCardBasic component

Following the instrunctions here we now have the following:

Hello World

[see code changes]


Host this app already...

We need to serve this page somehwere! Going to follow the docs/recommendations here and going to try GitHub Pages

# Install tool needed to generate and publish to GitHub Pages
yarn add --dev gh-pages

# Update packages.json with deploy script command:
# "deploy": "gh-pages -d build"

# Now deploy the app to GitHub Pages
yarn run deploy

Yeeeeepy! deployed to GitHub Pages (see the URL woooo!)

deployed-to-github-pages.png

[see code changes]


Now ... Office Add-ins? Really?

https://docs.microsoft.com/en-us/office/dev/add-ins/overview/office-add-ins

https://docs.microsoft.com/en-us/office/dev/add-ins/quickstarts/excel-quickstart-jquery?tabs=visual-studio-code

hmm... looks like Office has Yeoman generators to create a Office Add-ins!

# Install Yeoman and the Office Add-ins generator
npm install -g yo generator-office

# Now scaffold the project :-(
yo office

Following is what I went through. The choices made for Yeoman generator!



     _-----_     ╭──────────────────────────╮
    |       |    │   Welcome to the Office  │
    |--(o)--|    │   Add-in generator, by   │
   `---------´   │ @OfficeDev! Let's create │
    ( _´U`_ )    │    a project together!   │
    /___A___\   /╰──────────────────────────╯
     |  ~  |     
   __'.___.'__   
 ´   `  |° ´ Y ` 

? Would you like to create a new subfolder for your project? No
? What do you want to name your add-in? prototype_office-ui-fabric-react Office Add-in
? Which Office client application would you like to support? Excel
? Would you like to create a new add-in? No, I already have a web app and only need a manifest file for my add-in.

For more information and resources on your next steps, we have created a resource.html file in your project.
? Would you like to open it now while we finish creating your project? Yes
----------------------------------------------------------------------------------

      Creating manifest for prototype_office-ui-fabric-react Office Add-in add-in

----------------------------------------------------------------------------------


 conflict package.json
? Overwrite package.json? overwrite this and all others

So turns out that running yeoman in an existing project is messy, removed whole bunch of stuff! Most likely not going to work. But lets try it aye!

The generated code is checkin (minus the package.json because its definitely messedup) Code changes are here.

Here are the changes added for the Office Add-in stuff in packages.json. The Office Add-in Generator should have modified existing package.json correctly or said what needed to be changed!

Move Office Add-in generated files to fit the React App structure. Here are the changes

Remove the resource.html generated help file by Office Add-in generator that were a bit wrong when trying to side-load the add-in on Office for Mac. Instead follow instructions here to side-load an Office Add-in on Office for Mac.

Now update Office Add-in manifest file and deploy.

Yes!!! now we are talking ...

Yey-Hello-World-Office-Add-in.png

Great 8( found a better doc! Here it is ... and its better than the fragmented documentation from folks at a big company.


Make the Excel Add-in do something 'interesting'

Using the instructions here got the Excel Add-in to work, and the code changes are here and the result:

make-it-green.png

The icons & branding for the Office Add-in ...

The icon was missing in the Office Ribbon to show the TaskPane. Just need to add the relevant icons and voila:

Yey-Hello-World-Office-Add-in-with-icons-annotated.png


Now change the button label and Add-in description is done in by chaning the manifest file and the results speak for themselves:

Office-Add-in-with-updated-manifest-01-ann.png

How about the tooltip with Add-in description? Office-Add-in-with-updated-manifest-02-ann.png

Tada! Office-Add-in-with-updated-manifest-03.png


Make it easier to live preview the add-in during development

Added a separate manifest file that loads this add-in from http://localhost:3000 so that when developing, the add-in can be live previewed and tested in Excel. Ideally the build process would make sure the right server is used when in development vs. publishing. Code changes

About

Prototype/sample to give https://github.com/OfficeDev/office-ui-fabric-react a try


Languages

Language:JavaScript 74.6%Language:HTML 22.4%Language:CSS 3.1%