Product: PowerShell Universal
Version: 2.9.2
Hi all ,
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
pagination.jsx
import React from 'react';
import { withComponentFeatures } from 'universal-dashboard';
import Pagination from '@material-ui/lab/Pagination';
const UDPagination = props => {
return (
<Pagination
color={props.color}
count={props.count}
defaultPage={props.defaultPage}
disabled={props.disabled}
hideNextButton={props.hideNextButton}
hidePreviousButton={props.hidePreviousButton}
shape={props.shape}
showFirstButton={props.showFirstButton}
showLastButton={props.showLastButton}
siblingCount={props.siblingCount}
size={props.size}
variant={props.variant}
/>
);
}
export default withComponentFeatures(UDPagination)
index.js
import UDPagination from './pagination';
UniversalDashboard.register("ud-pagination", UDPagination);
Universal.Component.psm1
$IndexJs = Get-ChildItem "$PSScriptRoot\index.*.bundle.js"
$AssetId = [UniversalDashboard.Services.AssetService]::Instance.RegisterAsset($IndexJs.FullName)
function New-UDPagination {
param(
[Parameter()]
[string]$Id = (New-Guid).ToString(),
[Parameter()]
[ValidateSet('primary', 'secondary', 'standard')]
[string]
$Color = 'standard',
[Parameter()]
[int]
$Count = 1,
[Parameter()]
[int]
$DefaultPage = 1,
[Parameter()]
[bool]
$Disabled = $false,
[Parameter()]
[bool]
$HideNextButton = $false,
[Parameter()]
[bool]
$HidePreviousButton = $false,
[Parameter()]
[int]
$Page = 1,
[Parameter()]
[ValidateSet('round', 'rounded')]
[string]
$Shape = 'round',
[Parameter()]
[bool]
$ShowFirstButton = $false,
[Parameter()]
[bool]
$ShowLastButton = $false,
[Parameter()]
[int]
$SiblingCount = 1,
[Parameter()]
[ValidateSet('small', 'medium', 'large')]
[string]
$Size = 'medium',
[Parameter()]
[ValidateSet('outlined', 'text')]
[string]
$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:
- Using the component is resetting some base styles.
- 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 ?
Thanks,