@@ -20,20 +20,18 @@ Displays a native alert dialog with customizable buttons.
20
20
** Parameters:**
21
21
- ` string $title ` - The alert title
22
22
- ` string $message ` - The alert message
23
- - ` array $buttons ` - Array of button configurations
24
- - ` callable $callback ` - Callback function for button presses
23
+ - ` array $buttons ` - Array of button labels (max 3 buttons)
24
+
25
+ ** Button Positioning:**
26
+ - ** 1 button** - Positive (OK/Confirm)
27
+ - ** 2 buttons** - Negative (Cancel) + Positive (OK/Confirm)
28
+ - ** 3 buttons** - Negative (Cancel) + Neutral (Maybe) + Positive (OK/Confirm)
25
29
26
30
``` php
27
31
Dialog::alert(
28
32
'Confirm Action',
29
33
'Are you sure you want to delete this item?',
30
- [
31
- ['text' => 'Cancel', 'style' => 'cancel'],
32
- ['text' => 'Delete', 'style' => 'destructive']
33
- ],
34
- function($buttonIndex) {
35
- // Handle button press
36
- }
34
+ ['Cancel', 'Delete']
37
35
);
38
36
```
39
37
@@ -71,22 +69,26 @@ Dialog::share(
71
69
72
70
Fired when a button is pressed in an alert dialog.
73
71
74
- ** Payload:** ` int $buttonIndex ` - Index of the pressed button (0-based)
72
+ ** Payload:**
73
+ - ` int $index ` - Index of the pressed button (0-based)
74
+ - ` string $label ` - Label/text of the pressed button
75
75
76
76
``` php
77
77
use Livewire\Attributes\On;
78
78
use Native\Mobile\Events\Alert\ButtonPressed;
79
79
80
80
#[On('native:' . ButtonPressed::class)]
81
- public function handleAlertButton(int $buttonIndex )
81
+ public function handleAlertButton($index, $label )
82
82
{
83
- switch ($buttonIndex ) {
83
+ switch ($index ) {
84
84
case 0:
85
85
// First button (usually Cancel)
86
+ Dialog::toast("You pressed '{$label}'");
86
87
break;
87
88
case 1:
88
89
// Second button (usually OK/Confirm)
89
90
$this->performAction();
91
+ Dialog::toast("You pressed '{$label}'");
90
92
break;
91
93
}
92
94
}
@@ -112,24 +114,21 @@ class ItemManager extends Component
112
114
Dialog::alert(
113
115
'Delete Item',
114
116
'This action cannot be undone. Are you sure?',
115
- [
116
- ['text' => 'Cancel', 'style' => 'cancel'],
117
- ['text' => 'Delete', 'style' => 'destructive']
118
- ],
119
- null
117
+ ['Cancel', 'Delete']
120
118
);
121
119
}
122
120
123
121
#[On('native:' . ButtonPressed::class)]
124
- public function handleDeleteConfirmation(int $buttonIndex )
122
+ public function handleDeleteConfirmation($index, $label )
125
123
{
126
- if ($buttonIndex === 1 && $this->itemToDelete) {
124
+ if ($index === 1 && $this->itemToDelete) {
127
125
// User confirmed deletion
128
126
$this->performDelete($this->itemToDelete);
129
127
Dialog::toast('Item deleted successfully');
130
128
$this->itemToDelete = null;
131
129
} else {
132
130
// User cancelled
131
+ Dialog::toast("You pressed '{$label}'");
133
132
$this->itemToDelete = null;
134
133
}
135
134
}
@@ -163,31 +162,36 @@ class ItemManager extends Component
163
162
}
164
163
```
165
164
166
- ## Alert Button Styles
167
-
168
- ### iOS Button Styles
169
- - ` 'default' ` - Standard blue button
170
- - ` 'cancel' ` - Bold cancel button (usually on the left)
171
- - ` 'destructive' ` - Red destructive action button
172
-
173
- ### Android Button Styles
174
- - ` 'positive' ` - Primary action button
175
- - ` 'negative' ` - Cancel/dismiss button
176
- - ` 'neutral' ` - Additional option button
165
+ ## Alert Button Examples
177
166
167
+ ### Simple Confirmation
178
168
``` php
179
- // Cross-platform alert with proper styling
180
169
Dialog::alert(
181
170
'Delete Account',
182
171
'This will permanently delete your account and all data.',
183
- [
184
- ['text' => 'Cancel', 'style' => 'cancel'],
185
- ['text' => 'Delete', 'style' => 'destructive']
186
- ],
187
- null
172
+ ['Cancel', 'Delete']
188
173
);
189
174
```
190
175
176
+ ### Three Button Options
177
+ ``` php
178
+ Dialog::alert(
179
+ 'Save Changes',
180
+ 'Do you want to save your changes before closing?',
181
+ ['Cancel', 'Don\'t Save', 'Save']
182
+ );
183
+ ```
184
+
185
+ ### Single Button Alert
186
+ ``` php
187
+ Dialog::alert(
188
+ 'Welcome!',
189
+ 'Thanks for downloading our app!',
190
+ ['OK']
191
+ );
192
+ ```
193
+
194
+
191
195
## Toast Guidelines
192
196
193
197
### Best Practices
0 commit comments