Scripts/New-UDWindow.ps1

<#
.SYNOPSIS
    Movable window in your Universal Dashboard.
.DESCRIPTION
    Movable window in your Universal Dashboard
.PARAMETER Id
    An id for the component default value will be generated by new-guid.
.PARAMETER Title
    Title in string-format for your Window.
.PARAMETER X
    X coordinate to set the initial position of your window. Default 0
.PARAMETER Y
    Y coordinate to set the initial position of your window. Default 0
.PARAMETER Content
    Content inside your Window in the form of a scriptblock.
.PARAMETER MinimizedSize
    Width of your Window (in pixels) when it is minimzed, note: this should be global across all Windows per page. Default is 200.
    Settings a wider width might allow more text in the title, but limit the max count of minimized windows per line on the "dock"
.PARAMETER onClose
    onClose endpoint / scriptblock that is triggered whenever the window is "closed". If nothing is presented the window will close without promting user for validation upon pressing the red button.
.EXAMPLE
    PS C:\> New-UDWindow -title "Hello" -content {new-udhtml -markup "<p>hello2</p>"}
    Makes a movable window, with the title "Hello", and content of "Hello2"
.INPUTS
    Inputs (if any)
.OUTPUTS
    Output (if any)
.NOTES
     
#>

function New-UDWindow {
    param(
        [Parameter()]
        [string]$Id = (New-Guid).ToString(),
        [Parameter()]
        [string]$Title,
        [Parameter()]
        [int]$X = 0,
        [Parameter()]
        [int]$Y = 0,
        [Parameter()]
        [scriptblock]$Content,
        # Minimized size in px
        [Parameter(
            Mandatory = $false
        )]
        [int]
        $MinimizedSize = 200,
        [Parameter()]
        [object]$OnClose
    )
    Begin {
        if ($null -ne $OnClose) {
            if ($OnClose -is [scriptblock]) {
                $OnClose = New-UDEndpoint -Endpoint $OnClose -Id $Id
            }
            elseif ($OnClose -isnot [UniversalDashboard.Models.Endpoint]) {
                throw "OnClick must be a script block or UDEndpoint"
            }
        }
    }

    End {

        @{
            # The AssetID of the main JS File
            assetId         = $AssetId
            # Tell UD this is a plugin
            isPlugin        = $true
            # This ID must be the same as the one used in the JavaScript to register the control with UD
            type            = "UD-Window"
            # An ID is mandatory
            id              = $Id

            # This is where you can put any other properties. They are passed to the React control's props
            # The keys are case-sensitive in JS.
            title           = $Title
            x               = $X
            y               = $Y
            content         = $Content.Invoke()
            minimizedSize   = $MinimizedSize
            onClose         = $onClose.Name
        }

    }
}