Custom Componentss that utilise Material-UI

Product: PowerShell Universal
Version: 2.9.2

Hi all :wave:,

I’ve been following along with the blog post on Building Universal Dashboard v3 Custom Components.

Followed the steps - all good - with the caveat that in the Trying the Component section I couldn’t find where I was supposed to register the component. I just imported it as a module before I call New-UDDashboard and it appears to work. Is this just a bit outdated?

I wanted to add a few of the Material-UI components that I thought might be useful. I started with the Pagination component as it looks pretty simple.

I’ve done the below


import React from 'react';
import { withComponentFeatures } from 'universal-dashboard';
import Pagination from '@material-ui/lab/Pagination';

const UDPagination = props => {
    return (

export default withComponentFeatures(UDPagination)


import UDPagination from './pagination';

UniversalDashboard.register("ud-pagination", UDPagination);


$IndexJs = Get-ChildItem "$PSScriptRoot\index.*.bundle.js"
$AssetId = [UniversalDashboard.Services.AssetService]::Instance.RegisterAsset($IndexJs.FullName)

function New-UDPagination {
        [string]$Id = (New-Guid).ToString(),
        [ValidateSet('primary', 'secondary', 'standard')]
        $Color = 'standard',
        $Count = 1,
        $DefaultPage = 1,
        $Disabled = $false,
        $HideNextButton = $false,
        $HidePreviousButton = $false,
        $Page = 1,
        [ValidateSet('round', 'rounded')]
        $Shape = 'round',
        $ShowFirstButton = $false,
        $ShowLastButton = $false,
        $SiblingCount = 1,
        [ValidateSet('small', 'medium', 'large')]
        $Size = 'medium',
        [ValidateSet('outlined', 'text')]
        $Variant = 'text'
        assetId            = $AssetId 
        isPlugin           = $true 
        type               = 'ud-pagination'
        id                 = $Id
        color              = $Color
        count              = $Count
        defaultPage        = $DefaultPage
        disabled           = $Disabled
        hideNextButton     = $HideNextButton
        hidePreviousButton = $HidePreviousButton
        page               = $Page
        shape              = $Shape
        showFirstButton    = $ShowFirstButton
        showLastButton     = $ShowLastButton
        siblingCount       = $SiblingCount
        size               = $Size
        variant            = $Variant

In my dashboard I’m then calling:

New-UDPagination -Color primary -Count 10 -DefaultPage 8

The result:

I was pretty happy until I noticed that the buttons in the page header looked…off. Then I pressed the theme toggle.

The issue:


So there are two issues:

  1. Using the component is resetting some base styles.
  2. It’s not respecting the theme - in fact it appears to always follow the base MUI theme. I’ve set other themes and they are not respected.

I have half an idea that it could be a webpack issue and I’ m not correctly externalising material-ui but I’m honestly not sure.

Has anyone tried to make components that are theme aware before?

Any ideas @adam ?


What version of MUI did you include? If you are using a different version than UD, it might cause that issue with the styles.

As for the theme, we store the current theme in local storage.

localStorage.setItem('theme', next);

That said, you won’t be notified of changes to the theme. You could try reading it during render. I think we’ll need to add that feature to our NPM package.

I’m using these:

"@material-ui/core": "^4.12.3",
"@material-ui/lab": "^4.0.0-alpha.60",

What versions of these packages is UD using and I’ll test that out?

Hmmm UD is using the same versions.

 "@material-ui/core": "^4.12.3",
    "@material-ui/icons": "^4.11.2",
    "@material-ui/lab": "^4.0.0-alpha.60",
    "@material-ui/pickers": "^3.3.10",
    "@material-ui/system": "^4.12.1",

You might be able to inspect element on those buttons to see which stylesheet the style is coming from to narrow down if we have a conflict somewhere.