Modules/UniversalDashboard.Materialize/Scripts/tabs.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function New-UDTabContainer {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [ScriptBlock]$Tabs,
        [Parameter()]
        [string]$Id = ([Guid]::NewGuid()).ToString(),
        [Parameter()]
        [Switch]$RenderOnActive
    )

    End {
        @{
            isPlugin        = $true
            assetId         = $AssetId
            type            = "tab-container"
            tabs            = $Tabs.Invoke()
            id              = $id
            renderOnClick   = $RenderOnActive.IsPresent
        }
    }
}

function New-UDTab {
    [CmdletBinding()]
    param(
        [Parameter()]
        [string]$Text,
        [Parameter(Mandatory)]
        [ScriptBlock]$Content,
        [Parameter()]
        [string]$Id = ([Guid]::NewGuid()).ToString(),
        [Parameter()]
        [Alias('IsEndpoint')]
        [switch]$Dynamic,
        [Parameter()]
        [object]$Icon,
        [Parameter()]
        [switch]$RefreshWhenActive,
        [Parameter()]
        [switch]$Stacked
    )

    End {

        if ($null -ne $Content) {
            if ($IsEndpoint) {
                $TabEndpoint = New-UDEndpoint -Id $Id -Endpoint $Content 
            }
        }

        @{
            isPlugin = $true
            assetId  = $AssetId
            type     = "tab"
            label     = $Text
            icon = $Icon
            content  = $Content.Invoke()
            id       = $Id
            stacked = $Stacked.IsPresent
            refreshWhenActive = $RefreshWhenActive.IsPresent
            dynamic = $Dynamic.IsPresent
        }
    }
}