# Custom Components

Components in PowerShell Universal apps are exposed as functions. You can combine built in components to produce your own custom components.&#x20;

## Designer Support

You can include your custom components as part of a module to allow for the designer to present them in the component picker. Parameters will automatically be displayed as properties in the component properties drawer.&#x20;

Here's an example component the creates a textbox with a red border. It's required to include the `Category`attribute so that PowerShell Universal treats this function as an app component. You will need to define the `app/component` category and, optionally, a description and display name.

```powershell
function New-UDRedbox {
    [Category("app/component")]
    [Description("A redbox component.")]
    [DisplayName("Redbox")]
    param(
        [Parameter()]
        [string]$Id
    )

    New-UDStyle -style "border: 2px solid red" -Content {
        New-UDTextbox -Id $Id
    }
}
```

The component will now be available within the designer. Once added, you can adjust the parameters are desired.&#x20;

<figure><img src="https://427210397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZsd6kaluvxbsdXs9MWxX%2Fuploads%2FjcvgDpq3duiQMZIWdnPR%2Fimage.png?alt=media&#x26;token=9a1bf072-af36-408b-a530-a1b27546a486" alt=""><figcaption><p>Custom Component in Designer</p></figcaption></figure>

## Example: People Picker

<figure><img src="https://427210397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZsd6kaluvxbsdXs9MWxX%2Fuploads%2Fj5xX58kRILS5gwJ24otr%2Fimage.png?alt=media&#x26;token=40fb19aa-92ea-4120-9a34-792c44474525" alt=""><figcaption><p>People Picker</p></figcaption></figure>

The below example creates a `New-UDPeoplePicker` component from existing app components. You can use the `New-UDPeoplePicker` component in your apps. This function can either be defined within your app directly or within a [Module](https://docs.powershelluniversal.com/v4-beta/platform/modules).

This example users a published folder of avatars.&#x20;

```powershell
function Get-User {
    1..100 | ForEach-Object {
        [PSCustomObject]@{
            UserName = "User$_"
            First = "Bill"
            Last = $_
            Avatar = (Get-ChildItem "$Repository\Avatars" | Get-Random).Name
        }
    }
}

function New-UDPeoplePicker {
   $Session:Users = [System.Collections.Generic.List[object]]::new()

    New-UDAutocomplete -OnLoadOptions {
        Get-User | Where-Object { $_.UserName -like "*$UserName*" } | Select-Object -First 5 -ExpandProperty 'UserName' | ConvertTo-Json 
    } -OnChange {
        $Session:Users.Add((Get-User | Where-Object { $_.UserName -eq $EventData })) | Out-Null
        Sync-UDElement -Id 'users'
    }

    New-UDDynamic -Id 'users' -Content {
        New-UDList -Children {
            $Session:Users | ForEach-Object {
                New-UDListItem -Label $_.UserName -SubTitle "$($_.First) $($_.Last)" -AvatarType 'Avatar' -SecondaryAction {
                    $UserName = $_.UserName
                    New-UDIconButton -Icon (New-UDIcon -Icon 'Trash') -OnClick {
                        $RemoveUser = $Session:Users | Where-Object { $_.UserName -eq $UserName }
                        $Session:Users.Remove($RemoveUser) 
                        Sync-UDElement -Id 'users'
                    }
                } -Source "/avatars/$($_.Avatar)"

            }    
        }
    }
}

New-UDApp -Title 'PowerShell Universal' -Content {
    New-UDPeoplePicker
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.powershelluniversal.com/v4-beta/userinterfaces/components/custom-components.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
