---
source_url: https://itmustbecode.com/pcf-control-generate-shields-io-badges-in-the-powerplatform/
title: PCF control - Generate Shields.IO Badges in the PowerPlatform
date: 2022-04-07T02:49:10+00:00
categories:
  - blog
  - projects-and-tools
tags:
  - dataverse
  - pcf
  - powerapps
word_count: 1133
reading_time_minutes: 6
type: posts
---

One of the thing I like the most about **PCF controls** for the PowerPlatform is the ability to change the normal behavior and rendering of forms attributes to add a new twist to the user experience.

With that in mind, for my latest communityPCF control, [ShieldsIO.Badge.PCF](https://github.com/drivardxrm/ShieldsIO.Badge.PCF), I wanted to bring the ability to render custom (and awesome ) **Shields.IO badges** to the **PowerPlatform**.

Using badges in Model-driven or Canvas Apps forms is a great way to provide **concise**, **actionable** and **visually appealing** controls to end users.

For example, these out-of-the-box Model-driven forms fields :

{{< figure src="./image-11.png" alt="" caption="" >}}

Can be turned into these slick looking badges :

{{< figure src="./image-12.png" alt="" caption="" >}}

## What is Shields.IO

But, before we dive into the PCF control implementation, let's introduce the **Shields.IO** service.

Even if you are not familiar with **[Shields.IO](https://shields.io/)** badges, chances are that you've already seen them (virally) poping here and there while browsing your favorite platforms. The service is very popular especialy to display **status badges**.

You can see some good example in the [read.me](https://github.com/badges/shields) of the Shields.IO project github repo.

{{< figure src="./image-3.png" alt="" caption="" >}}

> 💸 If you like Shields.IO , please consider **donating** here : [shields.io - Open Collective](https://opencollective.com/shields) 💸

The concept behind Shields.IO is to render **dynamic badges**(images) that are expressed with **URLs** that contains the needed **metadata**.

```
badgeurl = https://img.shields.io/{badge-metadata}
```

So, when an **URL** is defined as the source of an html image tag **<img src= {badgeurl} />** , the image is dynamically fetched and served from the **shields.io** service when requested.

This makes the Shields.IO badges very useful to display **dynamic** data that changes over time like build status, download count, social media followers... you name it.

### **Predefined badges**

There are a ton of **predefined** badges model for different popular services like github, nuget, twitter just to name a few. (Check the official [shields.io](https://shields.io/) site for more examples)

As can be seen in this screenshot of one of my [github repo](https://github.com/drivardxrm/XTB.CustomApiManager) . These **nuget** badges Urls will render the **download count** and the **current version** badges of my package.

```
https://img.shields.io/nuget/dt/XTB.CustomApiManager
https://img.shields.io/nuget/v/XTB.CustomApiManager
```

{{< figure src="./image.png" alt="" caption="" >}}

Or this one that will render a follow link to my Twitter acount with my follower count.

```
https://img.shields.io/twitter/follow/david_rivard?style=social
```

[![Twitter Follow](https://img.shields.io/twitter/follow/david_rivard?style=social)](https://twitter.com/david_rivard)

### **Custom badges**

Most importantly, one of the great feature of **Shields.IO** is the **custom badges** system that uses a **generic** notation that looks like this :

```
https://img.shields.io/badge/<LABEL>-<MESSAGE>-<COLOR>
```

Hence, using this URL :

```
https://img.shields.io/badge/shields.io-rocks!-orange
```

Will render a badge that looks like this :

![](https://img.shields.io/badge/shields.io-rocks!-orange)

In addition, there are also a bunch of other switches that can be added as **querystrings** to provide additional features like styling, logos and much more.

It is this **custom badge** system that is leveraged in my new **PCF control** to render badges inside the PowerPlatform.

## **Shields.IO Badge PCF control**

To try out the PCF control, wait no more and download the latest version of the **ShieldsIO.Bagde.PCF** from [**this github repo**](https://github.com/drivardxrm/ShieldsIO.Badge.PCF) (or find it exposed on the great [**PCF gallery**](https://pcf.gallery/shieldsio-badge/)) and install the solution in your Dataverse environment.

> Note : My examples are focused on **Model-Driven apps**, but the ShieldsIO.Badge PCF control also works in **Canvas Apps** and **PowerApps Portals**.

_Unfortunaltely at the time of writing, you still need to use the classic form editor to configure a PCF Control_ on a form.

Now, navigate to any compatible field of a form, open the property editor and choose the **ShieldsIO Badge** from the **Control** Tab.

{{< figure src="./image-9.png" alt="" caption="" >}}

{{< figure src="./image-15.png" alt="" caption="" >}}

The **selected field** will be bound to the **Message** parameter. Values supplied in the other parameters will also have an effect on the final rendering of the badge (styling color etc...).

{{< figure src="./image-10.png" alt="" caption="" >}}

### Control Parameters

- **Message** : Main Message of the badge, can be bound to any available field type
- **Show Label**: Display a label on the left side of the badge (true / false)
- **Custom Label**: (Optional) Custom label text, if blank the display name of the field will be shown
- **Color** : (Optional) Color of the Message 🎨
- **Label Color** : (Optional) Color of the Label 🎨
- **Style**: Style of the Badge (plastic / flat /flat-squared / for-the-badge / social)
- **Logo**: (Optional) Logo. see [https://simpleicons.org/](https://simpleicons.org/) for available logos
- **Logo Color** : (Optional) Color of the Logo 🎨
- **Url**: (Optional) Redirect to this URL on click of the badge

> 🎨 for color paramaters : hex, rgb, rgba, hsl, hsla and css named colors supported

### **Bind your badges to (almost) any field on your form**

I have made the control as **generic** as possible and it's compatible with all the field types **currently supported** by the PCF framework. ([see official doc here](https://docs.microsoft.com/en-us/powerapps/developer/component-framework/manifest-schema-reference/type) for a list of supported types)

As can be seen below, in badges generated from more complex field types.

**Lookup field**

{{< figure src="./image-16.png" alt="" caption="" >}}

{{< figure src="./image-17.png" alt="" caption="" >}}

**Currency field**

{{< figure src="./image-4.png" alt="" caption="" >}}

{{< figure src="./image-5.png" alt="" caption="" >}}

**Choice field**

{{< figure src="./image-18.png" alt="" caption="" >}}

{{< figure src="./image-19.png" alt="" caption="" >}}

### **Style your badges like a Boss**

When setting up a badge, you can supply a **Style** parameter. The parameter offers 5 different styles to choose from :

{{< figure src="./image-2.png" alt="" caption="" >}}

{{< figure src="./image-1.png" alt="" caption="" >}}

As you can see, the same badge will render differently depending on the chosen **style**.

{{< figure src="./shieldsbadge.png" alt="" caption="" >}}

### **Badges look better with a logo**

Don't be shy to include logos in your badges when applicable, a visual cue is always appreciated by users.

To include a logo, just set the **Logo** parameter of the PCF control. **Shields.io** can natively render any icons exposed by the **[simpleicons](https://simpleicons.org/)** service.

Here are some examples that I have used in my demos :

**logo value****badge**microsoftteams![](https://img.shields.io/badge/Open_in-Teams-6264a7?style=plastic&labelColor=6264a7&logo=microsoftteams&logoColor=white)visa![](https://img.shields.io/badge/Payment-$500.00-007ACC?style=plastic&labelColor=1A1F71&logo=visa&logoColor=null)linkedin![](https://img.shields.io/badge/-davidrivard-0A66C2?style=plastic&labelColor=null&logo=linkedin&logoColor=null)

### **Add some magic with calculated fields**

A good way to provide **dynamic** data to the badges is to use **calculated fields** as data sources.

Take this example where the color of a Percent field is calculated based on the percent value (red, yellow, green).

{{< figure src="./image-2-1.png" alt="" caption="" >}}

{{< figure src="./image-3-1.png" alt="" caption="" >}}

See the results when the calculated field is passed as the Color parameter of a badge.

{{< figure src="./shieldsiobadges_calculated.gif" alt="" caption="" >}}

### **Make your badges clickable**

A great way to add usability to the badges is to make them **actionable** by supplying a redirect link in the **Url** parameter.

As you can see below, It's quite easy to render clickable badges that redirects to a contact social media landing pages.

{{< figure src="./shieldsiobadges_social.gif" alt="" caption="" >}}

## Takeaway

With some imagination, I think that the use of the **ShieldsIO badge PCF** control can really add some depth to the forms and provide a rich UX.

I'm really curious to see the kind of use cases and cool badges some of you will come up with.

Have fun!

## Links


{{< linkcard url="https://shields.io/" title="Shields.io: Quality metadata badges for open source projects" summary="We serve fast and scalable informational images as badges for GitHub, Travis CI, Jenkins, WordPress and many more services. Use them to track the state of your projects, or for promotional purposes." image="/linkcards/5062ac7f517e2280.svg" domain="shields.io" new_tab="true" nofollow="true" >}}


{{< linkcard url="https://opencollective.com/shields" title="shields.io - Open Collective" summary="Concise, consistent, and legible badges… in a readme near you." image="/linkcards/607a3d0e0f302d45.png" domain="opencollective.com" new_tab="true" nofollow="true" >}}


{{< linkcard url="https://github.com/drivardxrm/ShieldsIO.Badge.PCF" title="GitHub - drivardxrm/ShieldsIO.Badge.PCF: PCF control to render Shields.io badges" summary="PCF control to render Shields.io badges. Contribute to drivardxrm/ShieldsIO.Badge.PCF development by creating an account on GitHub." image="/linkcards/9209d03544a8c199.png" domain="github.com" new_tab="true" nofollow="true" >}}


{{< linkcard url="https://pcf.gallery/shieldsio-badge/" title="ShieldsIO Badge" summary="A Control to render Shields.IO badges from Dataverse data Can be bound to most of the available fields type Provide a redirect URL to make badges clickable" image="/linkcards/b13fdbdc7a98bf38.jpg" domain="pcf.gallery" new_tab="true" nofollow="true" >}}

