{"id":23183,"date":"2020-03-26T12:31:49","date_gmt":"2020-03-26T12:31:49","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=23183"},"modified":"2022-06-24T14:49:23","modified_gmt":"2022-06-24T09:19:23","slug":"how-to-develop-pcf-control-using-office-ui-fabric","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/03\/how-to-develop-pcf-control-using-office-ui-fabric\/","title":{"rendered":"How to develop PCF control using Office UI Fabric"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p style=\"text-align: justify;\">PCF stands for PowerApps Component Framework. PCF is used to build the full custom component to enrich user experience. On the other hand, Office UI Fabric is a responsive, mobile-first, front-end framework for developers which is designed to make it simple to create web experiences quickly using the Office Design Language.<\/p>\n<p style=\"text-align: justify;\">Recently, we had a requirement to show the rating for account so we developed the PCF control using fabric UI. For this, the first step is create the PCF project. To create PCF project use below command:<br \/>\n<strong>pac pcf init &#8211;namespace RatingControl &#8211;name Rating &#8211;template field<\/strong><\/p>\n<p>Next, to use the UI fabric in PCF project, we need to install it by using the following command:<br \/>\n<strong>npm install office-ui-fabric-react<\/strong><\/p>\n<p>Once the above command is executed, it will then install office-ui-fabric-react necessary to build and use UI fabric control. Now, we are ready to develop the PCF using UI fabric.<br \/>\nTo use office ui fabric control, create react file with extension .tsx (). The proper way is to first create component folder and add .tsx file inside it. Now, name it as rating.tsx. As we want to create rating component, we need to include following in rating.tsx file:<br \/>\n<strong>import * as React from &#8216;react&#8217;;<\/strong><br \/>\n<strong>import { Rating, RatingSize } from &#8216;office-ui-fabric-react\/lib\/Rating&#8217;;<\/strong><\/p>\n<p>Make sure you extend the rating class by using the following command:<br \/>\n<strong>export class RatingControl extends React.Component.<\/strong><\/p>\n<p>Now, here is the full code of Rating.tsx file:<\/p>\n<p>import * as React from &#8216;react&#8217;;<br \/>\nimport { Rating, RatingSize } from &#8216;office-ui-fabric-react\/lib\/Rating&#8217;;<br \/>\nimport { getTheme, createTheme, ITheme } from &#8216;office-ui-fabric-react\/lib\/Styling&#8217;;<br \/>\nexport class RatingControl extends React.Component&lt; {}, { rating?: number; largeStarRating?: number; smallStarRating?: number; tenStarRating?: number; themedStarRating?: number; customIconStarRating?: number; } &gt; {<br \/>\nprivate _customTheme: ITheme;<br \/>\nconstructor(props: {}) {<br \/>\nsuper(props);<br \/>\nthis.state = {<br \/>\nlargeStarRating: undefined<br \/>\n};<br \/>\nthis._customTheme = createTheme(getTheme());<br \/>\nthis._customTheme.semanticColors.bodySubtext = &#8216;#DFDFDF&#8217;;<br \/>\nthis._customTheme.semanticColors.bodyTextChecked = &#8216;#1E9FE8&#8217;;<br \/>\n}<br \/>\npublic render(): JSX.Element {<br \/>\nreturn (<\/p>\n<div><\/div>\n<p>); }<br \/>\nprivate _onFocus = () =&gt; {<br \/>\n};<br \/>\nprivate _onBlur = () =&gt; {<br \/>\n};<br \/>\nprivate _onLargeStarChange = (ev: React.FocusEvent, rating: any): void =&gt; {<br \/>\nthis.setState({ largeStarRating: rating });<br \/>\n};<br \/>\nprivate _getRatingComponentAriaLabel(rating: number, maxRating: number): string {<br \/>\nreturn `Rating value is ${rating} of ${maxRating}`;<br \/>\n}<br \/>\n}<br \/>\nexport default RatingControl<br \/>\nTo call this Rating control we need to add below code in init method of Index.ts file<br \/>\nthis._container = document.createElement(&#8220;div&#8221;);<br \/>\ncontainer.appendChild(this._container);<br \/>\nReactDOM.render(<br \/>\nReact.createElement(RatingControl)<br \/>\n, this._container<br \/>\n);<\/p>\n<p style=\"text-align: justify;\">After that, make required changes in manifest file and then build the PCF project. To deploy rating PCF control in CRM you can use solution or directly push using command.<br \/>\nOnce rating control is deployed in CRM, we can use it as per our requirement. Here, we have used it for Account, as shown below screenshot:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-23184\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/03\/PCF.png\" alt=\"\" width=\"497\" height=\"316\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/03\/PCF.png 497w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/03\/PCF-300x191.png 300w\" sizes=\"(max-width: 497px) 100vw, 497px\" \/><\/p>\n<p>Also there are many controls available in <a href=\"https:\/\/developer.microsoft.com\/en-us\/fabric#\/controls\">office ui fabric<\/a> that we can use to enhance user experience.<\/p>\n<p><strong>Conclusion:<\/strong><\/p>\n<p>Thus, as illustrated above, with the help of office ui fabric we can develop rich controls to enhance user experience.<\/p>\n<h2 style=\"text-align: left;\"><div class=\"su-heading su-heading-style-default su-heading-align-center\" id=\"\" style=\"font-size:15px;margin-bottom:5px\"><div class=\"su-heading-inner\">Cut short 90% of your manual work and repetitive data entry!<\/div><\/div><\/h2>\n<p style=\"text-align: left;\"><em>Get 1 Click apps and say goodbye to all repetitive data entry in CRM &#8211;<\/em><br \/>\n<em><strong><a href=\"https:\/\/bit.ly\/3oH7dYw\" target=\"_blank\" rel=\"noopener noreferrer\">Click2Clone<\/a> <\/strong>\u2013 Clone\/Copy Dynamics 365 CRM records in 1 Click<\/em><br \/>\n<em><strong><a href=\"https:\/\/bit.ly\/3EPjAYc\" target=\"_blank\" rel=\"noopener noreferrer\">Click2Export<\/a><\/strong> \u2013 Export Dynamics 365 CRM Report\/CRM Views\/Word\/Excel template in 1 Click<\/em><br \/>\n<em><strong><a href=\"https:\/\/bit.ly\/3EN8h2v\" target=\"_blank\" rel=\"noopener noreferrer\">Click2Undo<\/a><\/strong> \u2013 Undo &amp; Restore Dynamics 365 CRM data in 1 Click<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction PCF stands for PowerApps Component Framework. PCF is used to build the full custom component to enrich user experience. On the other hand, Office UI Fabric is a responsive, mobile-first, front-end framework for developers which is designed to make it simple to create web experiences quickly using the Office Design Language. Recently, we had\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/03\/how-to-develop-pcf-control-using-office-ui-fabric\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":23186,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[18,19,44,1929,1985],"tags":[1941],"class_list":["post-23183","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365-v9-2","category-dynamics-crm","category-power-apps","category-pcf","category-power-automate","tag-pcf-control"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/23183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=23183"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/23183\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/23186"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=23183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=23183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=23183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}