DEV Community

Cover image for How to style a PCF like a standard Model Driven App control
Riccardo Gregori
Riccardo Gregori

Posted on

4

How to style a PCF like a standard Model Driven App control

After this article I had an interesting exchange with David Rivard on how to manually tweak the style of Fluent UI 9 controls to make it look like the standard, model-driven, ones.

In this post I will show the results of our try-and-errors, for future reference.

๐Ÿ’ฅ The problem

By default, even if you implement a new Virtual PCF Control, the theme used by standard Model-Driven App controls differs from the one employed in Canvas Apps, and both, in turn, differ from the default theme of Fluent UI, used out of the box by the PCF controls.

Differences between standard theme and Canvas/Model Driven One

In the thread David suggested to apply the following attribute to my control:

  • appearance="filled-darker"

Effectively, that did the trick when the form is active, but not when the form/control is disabled ๐Ÿ˜ .

Active vs Inactive

๐Ÿ’ก The solution

Stating from David suggestion, and after a lot of try-and-errors, I found the following workaround. I tested it with Input and Select controls, and it quite works.

๐ŸŽจ Step 1 - Create a custom style

Using Fluent UI makeStyles function, create a custom style with the following content:

import { makeStyles } from '@fluentui/react-components';

const useStyles = makeStyles({
  filledDarker: {
    ...shorthands.borderStyle('solid'),
    ...shorthands.borderWidth('1px'),
    ...shorthands.borderColor(tokens.colorNeutralBackground1Hover),
    'border-radius': "4px !important",
    backgroundColor: tokens.colorNeutralBackground1Hover,
    color: tokens.colorNeutralForeground1 + " !important",
    cursor: 'default',
    minWidth: "50px",
    '> input': {
      ...shorthands.borderStyle('none'),
      color: tokens.colorNeutralForeground1 + " !important",
      cornerRadius: tokens.borderRadiusMedium,
      cursor: 'text',
    },
    '> select': {
      ...shorthands.borderStyle('none'),
      color: tokens.colorNeutralForeground1 + " !important",
      cursor: 'default',
    },
    '> span': {
      ...shorthands.borderStyle('none'),
      color: tokens.colorNeutralForeground1 + " !important",
      cornerRadius: tokens.borderRadiusMedium,
      cursor: 'default',
    }
  },
});
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“ Step 2 - Apply the custom style to your control

Remember to apply both attributes:

  • className= to the style created above
  • appearance="filled-darker"
import * as React from 'react';
import { Input } from '@fluentui/react-components';

const MyComponent: React.FC = () => {

...

return (
    <Input 
      className={styles.filledDarker}
      appearance="filled-darker"
      ...
      />
  );
};
Enter fullscreen mode Exit fullscreen mode

๐Ÿค” Why does it "quite" works?

Standard controls, when disabled, have a nice dark-gray underline effect on focus:

Underline effect on disabled controls

I wasn't able to reproduce the same effect with my CSS.

๐Ÿ—จ๏ธ If you have any suggestion on how to make it work, drop a comment here! ๐Ÿ’ฌ

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadogโ€™s testing tunnel.

Download The Guide

๐Ÿ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someoneโ€™s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay