|
1 | 1 | function New-BTButton { |
2 | 2 | <# |
3 | 3 | .SYNOPSIS |
4 | | - Creates a new clickable button for a Toast Notification. |
| 4 | + Creates a new clickable button for a Toast Notification, with optional color styling. |
5 | 5 |
|
6 | 6 | .DESCRIPTION |
7 | 7 | The New-BTButton function creates a new button for a Toast Notification. Up to five buttons can be added to a single Toast notification. |
8 | | - Buttons may have display text, an icon, an optional activation type, argument string, or serve as system managed Dismiss/Snooze buttons. |
| 8 | + Buttons may have display text, an icon, an optional activation type, argument string, serve as system managed Dismiss/Snooze buttons, and may optionally be rendered with colored button styles by specifying -Color. |
| 9 | +
|
| 10 | + If -Color is set to 'Green' or 'Red', the button will be displayed with a "Success" (green) or "Critical" (red) style in supported environments. |
9 | 11 |
|
10 | 12 | .PARAMETER Snooze |
11 | 13 | Switch. Creates a system-handled snooze button. When paired with a selection box on the toast, the snooze time is customizable. |
|
28 | 30 | .PARAMETER Id |
29 | 31 | String. Specifies an ID associated with another toast control (textbox or selection box). For standard buttons, this aligns the button next to a control, for snooze buttons it associates with a selection box. |
30 | 32 |
|
| 33 | + .PARAMETER Color |
| 34 | + String. Optional. If specified as 'Green' or 'Red', the button will be visually styled as "Success" (green) or "Critical" (red) where supported. Use for indicating primary/positive or destructive actions. |
| 35 | +
|
31 | 36 | .INPUTS |
32 | 37 | None. You cannot pipe input to this function. |
33 | 38 |
|
|
57 | 62 | New-BTButton -Content 'View Picture' -Arguments $pic -ImageUri $pic |
58 | 63 | Button with a picture to the left, launches the image file. |
59 | 64 |
|
| 65 | + .EXAMPLE |
| 66 | + New-BTButton -Content 'Approve' -Arguments 'approve' -Color 'Green' |
| 67 | + Creates a button with a green "Success" style intended for positive actions like approval. |
| 68 | +
|
| 69 | + .EXAMPLE |
| 70 | + New-BTButton -Content 'Delete' -Arguments 'delete' -Color 'Red' |
| 71 | + Creates a button with a red "Critical" style indicating a destructive action. |
| 72 | +
|
60 | 73 | .LINK |
61 | 74 | https://github.com/Windos/BurntToast/blob/main/Help/New-BTButton.md |
62 | 75 | #> |
|
97 | 110 | [Parameter(ParameterSetName = 'Button')] |
98 | 111 | [Parameter(ParameterSetName = 'Snooze')] |
99 | 112 | [alias('TextBoxId', 'SelectionBoxId')] |
100 | | - [string] $Id |
| 113 | + [string] $Id, |
| 114 | + |
| 115 | + [ValidateSet('Green', 'Red')] |
| 116 | + [string] $Color |
101 | 117 | ) |
102 | 118 |
|
103 | 119 | switch ($PsCmdlet.ParameterSetName) { |
|
125 | 141 | if ($Id) { |
126 | 142 | $Button.SelectionBoxId = $Id |
127 | 143 | } |
128 | | - |
| 144 | + |
129 | 145 | if ($ImageUri) { |
130 | 146 | $Button.ImageUri = $ImageUri |
131 | 147 | } |
|
139 | 155 | } |
140 | 156 | } |
141 | 157 |
|
| 158 | + if ($Color) { |
| 159 | + $Button = $Button.SetHintActionId($Color) |
| 160 | + } |
| 161 | + |
142 | 162 | switch ($Button.GetType().Name) { |
143 | 163 | ToastButton { if($PSCmdlet.ShouldProcess("returning: [$($Button.GetType().Name)]:Content=$($Button.Content):Arguments=$($Button.Arguments):ActivationType=$($Button.ActivationType):ImageUri=$($Button.ImageUri):TextBoxId=$($Button.TextBoxId)")) { $Button }} |
144 | 164 | ToastButtonSnooze { if($PSCmdlet.ShouldProcess("returning: [$($Button.GetType().Name)]:CustomContent=$($Button.CustomContent):ImageUri=$($Button.ImageUri):SelectionBoxId=$($Button.SelectionBoxId)")) { $Button } } |
|
0 commit comments