How To Create A Fabric JS Component In SharePoint Online

Introduction of Office UI Fabric JS 

Fabric JS is a JavaScript front-end framework, which provides visuals-focused components to extend, re-work and use in your Office and Office 365 experiences. Fabric JS uses styles from Office UI Fabric Core project. Fabric JS is a collection of responsive, mobile-first styles and tools designed to make it quick and simple for you to create Web experiences, using Office Design language.

Steps to create a Fabric JS component in SharePoint Online are given below.

  1. Navigate to SharePoint Online site.

  2. Edit the page and add Script Editor Webpart.

  3. Add the code snippet given below and save the page.

  1. <link href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-js/1.2.0/css/fabric.min.css" rel="stylesheet"/>
  2. <link href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-js/1.2.0/css/fabric.components.min.css" rel="stylesheet"/>
  3. <script src="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-js/1.2.0/js/fabric.min.js"></script>
  4. <button class="ms-Button ms-Button--primary"><span class="ms-Button-label">Create Account</span></button>   
  5. <script type="text/javascript">  
  6.   var ButtonElements = document.querySelectorAll(".ms-Button");  
  7.   for (var i = 0; i < ButtonElements.length; i++) {  
  8.     new fabric['Button'](ButtonElements[i], function() {  
  9.       alert("Clicked Create Account Button");   });  
  10.   }  
  11. </script>    

Result

Button component is displayed, as shown below,
 
Summary

In this blog, you have seen Fabric JS component in SharePoint Online.

Reference

  • https://dev.office.com/fabric-js/Components/Button/Button.html

 

Ebook Download
View all
Learn
View all