-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
112 lines (106 loc) · 4.62 KB
/
functions.php
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
declare(strict_types=1);
namespace Flasher\SweetAlert\Prime;
use Flasher\Prime\Container\FlasherContainer;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Type;
if (!\function_exists('Flasher\SweetAlert\Prime\sweetalert')) {
/**
* Creates a Sweetalert notification or returns the Sweetalert factory.
*
* This function simplifies the process of creating Sweetalert notifications.
* When called with no arguments, it returns an instance of SweetAlertInterface.
* When called with arguments, it creates a Sweetalert notification and returns an Envelope.
*
* @param string|null $message the message content of the notification
* @param "success"|"info"|"warning"|"error"|"question" $type The type of the notification (e.g., success, error, warning, info).
* @param array{
* title?: string,
* titleText?: string,
* html?: string,
* text?: string,
* icon?: string,
* iconColor?: string,
* iconHtml?: string,
* showClass?: mixed,
* hideClass?: mixed,
* footer?: string,
* backdrop?: bool|string,
* toast?: bool,
* target?: string,
* input?: "text"|"email"|"password"|"number"|"tel"|"range"|"textarea"|"search"|"url"|"select"|"radio"|"checkbox"|"file"|"date"|"datetime-local"|"time"|"week"|"month",
* width?: string,
* padding?: string,
* background?: string,
* position?: "top"|"top-start"|"top-end"|"center"|"center-start"|"center-end"|"bottom"|"bottom-start"|"bottom-end",
* grow?: "column"|"fullscreen"|"row"|false,
* customClass?: array<"container"|"popup"|"header"|"title"|"closeButton"|"icon"|"image"|"content"|"input"|"inputLabel"|"validationMessage"|"actions"|"confirmButton"|"denyButton"|"cancelButton"|"loader"|"footer", string>,
* timer?: int,
* timerProgressBar?: bool,
* heightAuto?: bool,
* allowOutsideClick?: bool|string,
* allowEscapeKey?: bool|string,
* allowEnterKey?: bool|string,
* stopKeydownPropagation?: bool,
* keydownListenerCapture?: bool,
* showConfirmButton?: bool,
* showDenyButton?: bool,
* showCancelButton?: bool,
* confirmButtonText?: string,
* denyButtonText?: string,
* cancelButtonText?: string,
* confirmButtonColor?: string,
* denyButtonColor?: string,
* cancelButtonColor?: string,
* confirmButtonAriaLabel?: string,
* denyButtonAriaLabel?: string,
* cancelButtonAriaLabel?: string,
* buttonsStyling?: bool,
* reverseButtons?: bool,
* focusConfirm?: bool,
* focusDeny?: bool,
* focusCancel?: bool,
* showCloseButton?: bool,
* closeButtonHtml?: string,
* closeButtonAriaLabel?: string,
* loaderHtml?: string,
* showLoaderOnConfirm?: bool,
* scrollbarPadding?: bool,
* preConfirm?: bool|string,
* preDeny?: string,
* returnInputValueOnDeny?: bool,
* animation?: bool,
* imageUrl?: string,
* imageWidth?: int,
* imageHeight?: int,
* imageAlt?: string,
* inputLabel?: string,
* inputPlaceholder?: string,
* inputValue?: string,
* inputOptions?: string,
* inputAutoTrim?: bool,
* inputAttributes?: string,
* inputValidator?: string,
* validationMessage?: string,
* } $options additional options for the Sweetalert notification
* @param string|null $title the title of the notification
*
* @return Envelope|SweetAlertInterface Returns an Envelope containing the notification details when arguments are provided.
* Returns an instance of SweetAlertInterface when no arguments are provided.
*
* @phpstan-return ($message is empty ? SweetAlertInterface : Envelope)
*
* Usage:
* 1. Without arguments - Get the Sweetalert factory: $sweetalert = sweetalert();
* 2. With arguments - Create and return a Sweetalert notification:
* sweetalert('Message', Type::SUCCESS, ['option' => 'value'], 'Title');
*/
function sweetalert(?string $message = null, string $type = Type::SUCCESS, array $options = [], ?string $title = null): Envelope|SweetAlertInterface
{
$factory = FlasherContainer::create('flasher.sweetalert');
if (0 === \func_num_args()) {
return $factory;
}
return $factory->flash($type, $message, $options, $title);
}
}