Use cascading style sheets with Universal Dashboard.
You can use a cascading style sheet (CSS) by add a .css
file to a published folder and then passing it to the -Stylesheets
parameter for New-UDDashboard
.
For example, the dashboard.ps1
file would look like this.
You could then setup a published folder to provide the assets route. This is what the contents of publishedFolders.ps1
will look like.
Within the C:\assets
folder, you can place any assets you'd like to access on the /assets
route.
You can then create a style sheet to manipulate whatever portion of the dashboard you'd like.
This produces a dashboard with a background image of Austin the dog sleeping in a pile of dirt.
Every Material UI component has a series of global class names that you can use to apply styles throughout your dashboard. To determine the correct class names, you can view the a particular component's API documentation. There is a list of the global class names that apply to that component.
For example, here is the CSS documentation for the Alert component.
Within your CSS file, you can use these class names to override styles throughout your dashboard. If you wanted to set all success alerts to have a red background, you could create a CSS file like this.
UDStyle component for Universal Dashboard
You can apply styles to individual components within Universal Dashboard by using the UDStyle
component. This component will need to be added to your dashboard and is part of the core components included with PowerShell Universal.
To apply a style to a component or a set of components, you call the New-UDStyle
cmdlet, specify a CSS style and then include the components you wish to style within the -Content
script block.
Each Material UI component has a set of built in classes that you can override using New-UDStyle
. To determine the class names that you need to override, you can view the API documentation for the component you are trying to modify on the Material UI site. For example, here is a listing of the Alert component's CSS class names.
When using a success alert, you will have the .MuiAlert-standardSuccess
class applied to your component. You can override this default style like this.
The resulting alert will be red instead of the default green.
Universal Dashboard v3 is built on Material UI. Material UI provides a built-in theme system that UD now takes advantage of. You can utilize this theme system by providing a hashtable of options to the New-UDDashboard
's -Theme
parameter.
Here's an example of changing the theme's main color.
Note that when specifying keys that require a number, ensure that the key is specified as a string.
You can set the default theme to either Light or Dark using the -DefaultTheme
parameter.
You can change the page background color by setting the background default color. To adjust the header background color, set the primary main color.
To support dark and light palettes, you can define a dark and light sections in your hashtable. They have the same properties as a theme.
To change the font size, set the typography fontSize property.
For a full list of options available for the theme system, you can look at the default theme for Material UI.
You can override any component CSS value using the theme engine. In order to override a component's base theming, you will need to identify the CSS class name applied to that element.
To identify a component's CSS classes, use the developer tools of your browser. Right click on the component you wish to style and click Inspect Element.
This will highlight the HTML elements that make up that component. In the image below, you will see we have numerous CSS classes being applied such as:
MuiButtonBase-root
MuiButton-root
MuiButton-label
MuiTouchRipple-root
In order to override these various elements, you will need to add an overrides
key to your theme.
Next, you'll need to add keys to the overrides for each element you wish to modify. Notice that I have not included the portion of the class name after the hyphen.
Now, add the subitems you wish to modify to the class name.
The last step is to define the CSS properties you wish to apply to elements that use these classes.
For more examples, look at the Onepirate and Paperbase themes below that include many component overrides.
Based on the Material UI theme, Onepirate.
The dashboard used to generate the above image is included below.
Based on the Material UI theme, Paperbase.
This the dashboard used to create the above image.