-
Notifications
You must be signed in to change notification settings - Fork 0
Core Concepts
Understanding the core concepts of MvRAdaptiveCards will help you build powerful and maintainable cards. The module is designed with several key concepts in mind:
1: Open source - MvRAdaptiveCards is fully open source, allowing you to inspect, modify, and contribute to the codebase. Collaborate on GitHub is encouraged to help improve the module for everyone and is therefore transparent in its development.
2: Strictly limited to Adaptive Cards - The module focuses exclusively on Adaptive Cards, ensuring that all features and functions align with the Adaptive Cards framework. This specialization allows for deep integration and support for the latest Adaptive Card features. This focus ensures that users can rely on the module for all their Adaptive Card needs without unnecessary bloat or unrelated features.
3: Built in/for PowerShell - The module is designed specifically for PowerShell users, leveraging PowerShell's strengths and idioms. This makes it easy for PowerShell users to adopt and use the module effectively. Users familiar with PowerShell will find the syntax and patterns intuitive and aligned with their existing knowledge.
4: Ready to go - The module is designed to be ready for immediate use, with sensible defaults and easy setup. Users can quickly create and display Adaptive Cards without extensive configuration, making it accessible for both beginners and experienced users. The module will use default settings to streamline the card creation process.
5: Strict dependency management - The module minimizes external dependencies, leveraging only well-known open source solutions and Microsoft-defined libraries/CDN-sources where necessary. This approach reduces potential risks associated with third-party dependencies, such as security vulnerabilities or compatibility issues. By relying on well-established and trusted sources, the module ensures stability and reliability for users.
Note: While the module minimizes dependencies, it may still utilize certain Microsoft-defined libraries or CDN sources to ensure compatibility with the Adaptive Cards framework.
6: No sketchy stuff - The module adheres to best practices in PowerShell module development, ensuring that it is secure, reliable, and maintainable. Users can trust that the module follows established guidelines and standards, providing a solid foundation for building Adaptive Cards. There is no telemetry, data collection, or any form of tracking implemented in the module. User privacy and security are prioritized, ensuring that no personal or usage data is collected or transmitted. (Microsoft libraries used are subject to their own privacy policies and terms of use.)
This commitment to quality ensures that users can confidently use the module in their projects without concerns about security or reliability.
An Adaptive Card has a hierarchical structure:
AdaptiveCard
├── Elements (Text, Images, Inputs, etc.)
├── Containers (Group elements)
│ └── Elements
└── Actions (Buttons, Submit, etc.)
New-AdaptiveCard {
# Header
New-CardTextBlock -Text "Card Title" -Size Large -Weight Bolder
# Content
New-CardContainer -Items {
New-CardTextBlock -Text "Content goes here"
}
# Actions
New-CardActionSet -Actions {
New-CardActionSubmit -Title "Submit"
}
}The module is designed around several key patterns to facilitate card creation and card usage.
-
Declarative Syntax: The module uses a declarative syntax that allows you to define your card structure in a clear and concise manner. This makes it easy to understand and modify your card layouts.
-
Hierarchical Structure: The use of nested containers and elements reflects the hierarchical nature of Adaptive Cards. This allows for complex layouts to be built up from simple components.
-
Reusable Components: The module encourages the creation of reusable card components. This means you can define a card layout once and reuse it across different cards, promoting consistency and reducing duplication. Through the use of templates, you can easily create dynamic cards that adapt to different data inputs.
-
Integration with PowerShell: The module is designed to work seamlessly with PowerShell, leveraging its features and idioms. This makes it easy for PowerShell users to adopt and use the module effectively.
-
Extensibility: The module is built to be extensible, allowing users to create custom elements and actions as needed. This ensures that the module can evolve with the needs of its users. These extensions can be easily integrated into the existing card structure.
Elements are the building blocks of a card. They display content but don't contain other elements.
Common Elements:
-
New-CardTextBlock- Display text -
New-CardImage- Display images -
New-CardIcon- Display Fluent UI icons -
New-CardRichTextBlock- Rich formatted text -
New-CardProgressBar- Progress indicators -
New-CardBadge- Status badges - Charts:
New-CardChartDonut,New-CardChartGauge,New-CardChartHorizontalBar
Input Elements:
-
New-CardInputText- Text input -
New-CardInputNumber- Number input -
New-CardInputDate- Date picker -
New-CardInputTime- Time picker -
New-CardInputToggle- Checkbox/toggle -
New-CardInputChoiceSet- Radio buttons/dropdowns
Containers hold and organize other elements. They provide layout and grouping. Some containers can also be used like elements trough the intergrated features of the module. (e.g., FactSet, Table)
Common Containers:
-
New-CardContainer- General container with-Items { } -
New-CardColumnSet- Multi-column layout with-Columns { } -
New-CardColumn- Single column (inside ColumnSet) -
New-CardFactSet- Key-value pairs -
New-CardTable- Tabular data -
New-CardImageSet- Image gallery -
New-CardActionSet- Group of actions
Actions provide interactivity. They can only be added within an ActionSet, or in the actions area of the card. They can respond to click or tap events, triggering behaviors like submitting data or opening URLs.
Common Actions:
-
New-CardActionSubmit- Submit form data -
New-CardActionOpenUrl- Open URL in browser -
New-CardActionOpenUrlDialog- Open URL in modal dialog -
New-CardActionToggleVisibility- Show/hide elements -
New-CardActionShowCard- Expand to show another card
The module uses scriptblocks for hierarchical structure:
# Parent element
New-CardContainer -Items {
# Child elements inside scriptblock
New-CardTextBlock -Text "Child 1"
New-CardTextBlock -Text "Child 2"
# Nested container
New-CardColumnSet -Columns {
New-CardColumn -Items {
New-CardTextBlock -Text "In column"
}
}
}- Natural hierarchy - Nesting reflects structure
- Readable - Easy to understand card layout
- Maintainable - Changes are localized
- PowerShell native - Familiar syntax
Templates allow dynamic content using {{placeholder}} syntax:
$data = @{
name = "John Doe"
email = "john@example.com"
}
New-AdaptiveCard {
New-CardTextBlock -Text "Welcome {{name}}!" -Size Large
New-CardTextBlock -Text "Email: {{email}}"
} | Build-CardFromTemplate -Data $data | Get-CardResponse -ViewMethod EdgeAppNew-AdaptiveCard {
New-CardTextBlock -Text "Status: !{{if status=='active'}}Active!{{else}}Inactive!{{/if}}"
}-
{{variable}}- Simple substitution -
!{{if condition}}...!{{/if}}- Conditional content -
!{{if condition}}...!{{else}}...!{{/if}}- If-else -
!{{each items}}...!{{/each}}- Loops
New-CardTextBlock -Text "Styled Text" `
-Size Large `
-Weight Bolder `
-Color Good `
-HorizontalAlignment Center `
-WrapSizes: Small, Default, Medium, Large, ExtraLarge
Weights: Lighter, Default, Bolder
Colors: Default, Dark, Light, Accent, Good, Warning, Attention
New-CardContainer -Items {
New-CardTextBlock -Text "Content"
} -Style Emphasis -Separator -Spacing MediumStyles: Default, Emphasis, Good, Warning, Attention, Accent
Spacing: None, Small, Default, Medium, Large, ExtraLarge, Padding
New-CardRichTextBlock -Text @"
This is {{bold}}bold text{{/bold}} and this is {{color:Good}}green text{{/color}}.
You can {{italic}}combine{{/italic}} {{bold}}{{color:Accent}}multiple{{/color}}{{/bold}} styles.
"@Supported tags:
- Style:
{{bold}},{{italic}},{{strikethrough}},{{underline}} - Color:
{{color:Good}},{{color:Warning}}, etc. - Size:
{{large}},{{small}},{{size:ExtraLarge}} - Font:
{{monospace}}
New-AdaptiveCard {
New-CardTextBlock -Text "Item 1"
New-CardTextBlock -Text "Item 2"
New-CardTextBlock -Text "Item 3"
}New-AdaptiveCard {
New-CardColumnSet -Columns {
New-CardColumn -Width "Auto" -Items {
New-CardImage -Url "icon.png" -Size Small
}
New-CardColumn -Width "Stretch" -Items {
New-CardTextBlock -Text "Title" -Weight Bolder
New-CardTextBlock -Text "Description" -Wrap
}
}
}New-AdaptiveCard {
New-CardFactSet -Facts @{
"Name" = "John Doe"
"Email" = "john@example.com"
"Status" = "Active"
}
}Control element visibility dynamically:
New-AdaptiveCard {
New-CardContainer -Id "Details" -Hidden -Items {
New-CardTextBlock -Text "Hidden by default"
}
New-CardActionSet -Actions {
New-CardActionToggleVisibility -Title "Show Details" -TargetElements "Details"
}
}New-AdaptiveCard {
New-CardContainer -Id "Page1" -Items {
New-CardTextBlock -Text "Page 1"
New-CardActionSet -Actions {
New-CardActionToggleVisibility -Title "Next" -TargetElements "Page1", "Page2"
}
}
New-CardContainer -Id "Page2" -Hidden -Items {
New-CardTextBlock -Text "Page 2"
New-CardActionSet -Actions {
New-CardActionToggleVisibility -Title "Back" -TargetElements "Page1", "Page2"
}
}
}Understanding how data flows through the module:
# 1. Build card structure
$card = New-AdaptiveCard {
New-CardInputText -Id "input1"
}
# 2. Display and capture response
$response = $card | Get-CardResponse -ViewMethod EdgeApp
# 3. Process response
if ($response) {
Write-Host "User entered: $($response.input1)"
}When a card is submitted, Get-CardResponse returns a hashtable with:
- Input IDs as keys
- User-entered values as values
- Action data (if provided with
-Dataparameter)
- Use IDs consistently - Especially for inputs and toggle targets
- Provide labels - Always label input fields for accessibility
-
Validate inputs - Use
-IsRequired,-Regex,-MinLength,-MaxLength - Organize with containers - Group related elements
- Use appropriate spacing - Control visual separation
- Test responsively - Cards should work at different widths
- Handle responses - Always check if response is not null
- Use templates for dynamic content - Separate data from structure
- See real-world examples in Examples Gallery
- Explore all functions in Function Reference
- Learn advanced techniques in Advanced Topics