Updated/Improved Icon Search

Product: PowerShell Universal
Version: 5.5.1

I pulled the icon search code from the documentation and did, what I consider, an improved version of it. Feel free to use or adjust how you wish. Its form based (so you can type and hit enter). It is responsive as xs, s, m, l sizes

New-UDApp -Title "Icon Search" -Content {
    New-UDForm -Content {
        New-UDTextbox -Id 'txtIconSearch' -Label 'Search' 
    } -OnValidate {
        if ([string]::IsNullOrWhiteSpace($EventData.txtIconSearch)) {
            New-UDValidationResult -ValidationError 'Please enter a search term'
        }
        else {
            New-UDValidationResult -Valid
        }
    } -OnSubmit {
        Sync-UDElement -Id 'icons'
    }

    New-UDHtml -Markup '<hr />'

    New-UDDynamic -Id 'icons' -Content {
        $IconSearch = (Get-UDElement -Id 'txtIconSearch').value
        if ([string]::IsNullOrWhiteSpace($IconSearch)) {
            return
        }
        
        $Icons = Find-UDIcon -Name $IconSearch
        if (-not $Icons) {
            New-UDAlert -Severity info -Text "No icons found matching '$IconSearch'"
            return
        }

        New-UDGrid -Container -Content {
            foreach ($icon in $icons) {
                try {
                    New-UDGrid -Item -ExtraSmallSize 12 -SmallSize 8 -MediumSize 4 -LargeSize 2 -Content {
                        New-UDChip -Label $icon -Icon (New-UDIcon -Icon $icon)
                    }
                }
                catch {
                    New-UDChip -Label "$icon Unknown" 
                }
            }
        } -Spacing 2
    }
}


4 Likes