Product: PowerShell Universal
Version: 5.5.0
I’m trying to see if I can do some dynamic icons for processing/complete states. As a basic idea: click the button, show a spinner; then once code is processed, change spinner to a checkmark. I’ve attempted two variants of this problem.
First - using style to show/hide based on CSS display
. This doesn’t throw any errors but also doesn’t actually do anything.
New-UDDashboard -Title "Icon Test" -Content {
New-UDCard -Content {
New-UDGrid -Container -Children {
New-UDGrid -Item -Children {
New-UDButton -Text "Test" -OnClick {
try {
# Show spinner
Set-UDElement -Id "testSpinner" -Properties @{
Style = @{display = "block"}
}
Set-UDElement -Id "testCheckmark" -Properties @{
Style = @{display = "none"}
}
# Simulate work
Start-Sleep -Seconds 2
# Show checkmark
Set-UDElement -Id "testSpinner" -Properties @{
Style = @{display = "none"}
}
Set-UDElement -Id "testCheckmark" -Properties @{
Style = @{display = "block"}
}
}
catch {
Show-UDToast -Message "Error: $($_.Exception.Message)" -Duration 5000 -Position "topRight" -MessageColor "red"
}
}
}
New-UDGrid -Item -Children {
New-UDIcon -Icon 'Spinner' -Spin -Size 'lg' -Id 'testSpinner' -Style @{display = "none"}
New-UDIcon -Icon 'CheckCircle' -Size 'lg' -Id 'testCheckmark' -Style @{display = "none"; color = "green"}
}
}
}
}
Second, I tried doing it via “state management”, which throws parameter errors at me, because i’m sure i’m missing something.
New-UDDashboard -Title "Icon Test (State)" -Content {
New-UDCard -Content {
New-UDGrid -Container -Children {
New-UDGrid -Item -Children {
New-UDButton -Text "Test" -OnClick {
try {
# Set state to spinning
Set-UDElement -Id "iconState" -Content {
New-UDTypography -Id 'State' -Text "spinning"
}
# Simulate work
Start-Sleep -Seconds 2
# Set state to complete
Set-UDElement -Id "iconState" -Content {
New-UDTypography -Id 'State' -Text "complete"
}
}
catch {
Show-UDToast -Message "Error: $($_.Exception.Message)" -Duration 5000 -Position "topRight" -MessageColor "red"
}
}
}
New-UDGrid -Item -Children {
New-UDHidden -Content {
New-UDElement -Id 'iconState' -Content {
New-UDTypography -Id 'State' -Text "none"
}
}
New-UDDynamic -Content {
$state = Get-UDElement -Id "iconState"
if ($state.Value -eq "spinning") {
New-UDIcon -Icon 'Spinner' -Spin -Size 'lg'
}
elseif ($state.Value -eq "complete") {
New-UDIcon -Icon 'CheckCircle' -Size 'lg' -Color 'green'
}
} -Id "iconDisplay" -AutoRefresh -AutoRefreshInterval 3
}
}
}
}
At any rate, has anyone gotten this to work? Any suggestions? Thanks in advance!