diff --git a/src/Exceptions/ToastException.php b/src/Exceptions/ToastException.php
index d5fbbafc..f84533a0 100644
--- a/src/Exceptions/ToastException.php
+++ b/src/Exceptions/ToastException.php
@@ -2,7 +2,6 @@
namespace Mary\Exceptions;
-
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -10,14 +9,13 @@
class ToastException extends Exception
{
-
protected string $type = 'info';
protected ?string $title = null;
protected ?string $description = null;
- protected string $position = 'toast-top toast-middle';
+ protected string $position = 'toast-top toast-end';
protected string $icon = 'o-information-circle';
@@ -27,59 +25,108 @@ class ToastException extends Exception
protected bool $preventDefault = true;
- public static function typedMessage(string $type, string $message, ?string $title = null): self
- {
- $instance = new self(message: $message, code: 500);
+ public static function typedMessage(
+ string $type,
+ string $title,
+ string $description = null,
+ string $position = 'toast-top toast-end',
+ string $icon = 'o-information-circle',
+ string $css = 'alert-info',
+ int $timeout = 3000
+ ): self {
+ $instance = new self(message: $title, code: 500);
+
$instance->type = $type;
$instance->title = $title;
+ $instance->description = $description;
+ $instance->position = $position;
+ $instance->icon = $icon;
+ $instance->css = $css;
+ $instance->timeout = $timeout;
+
return $instance;
}
- public static function info(string $message, ?string $title = null, array $options = []): self
- {
- $default = ['css' => 'alert-info', 'icon' => 'o-information-circle'];
- return self::typedMessage(type: 'info', message: $message, title: $title)->options(
- options: [...$default, ...$options]
+ public static function info(
+ string $title,
+ string $description = null,
+ string $position = 'toast-top toast-end',
+ string $icon = 'o-information-circle',
+ string $css = 'alert-info',
+ int $timeout = 3000,
+ ): self {
+ return self::typedMessage(
+ type: 'info',
+ title: $title,
+ description: $description,
+ position: $position,
+ icon: $icon,
+ css: $css,
+ timeout: $timeout
);
}
- public static function success(string $message, ?string $title = null, array $options = []): self
- {
- $default = ['css' => 'alert-success', 'icon' => 'o-check-circle'];
- return self::typedMessage(type: 'success', message: $message, title: $title)->options(
- options: [...$default, ...$options]
+ public static function success(
+ string $title,
+ string $description = null,
+ string $position = 'toast-top toast-end',
+ string $icon = 'o-check-circle',
+ string $css = 'alert-success',
+ int $timeout = 3000,
+ ): self {
+ return self::typedMessage(
+ type: 'success',
+ title: $title,
+ description: $description,
+ position: $position,
+ icon: $icon,
+ css: $css,
+ timeout: $timeout
);
}
- public static function error(string $message, ?string $title = null, array $options = []): self
- {
- $default = ['css' => 'alert-error', 'icon' => 'o-x-circle'];
- return self::typedMessage(type: 'error', message: $message, title: $title)->options(
- options: [...$default, ...$options]
+ public static function error(
+ string $title,
+ string $description = null,
+ string $position = 'toast-top toast-end',
+ string $icon = 'o-x-circle',
+ string $css = 'alert-error',
+ int $timeout = 3000,
+ ): self {
+ return self::typedMessage(
+ type: 'error',
+ title: $title,
+ description: $description,
+ position: $position,
+ icon: $icon,
+ css: $css,
+ timeout: $timeout
);
}
- public static function warning(string $message, ?string $title = null, array $options = []): self
- {
- $default = ['css' => 'alert-warning', 'icon' => 'o-exclamation-triangle'];
- return self::typedMessage(type: 'warning', message: $message, title: $title)->options(
- options: [...$default, ...$options]
+ public static function warning(
+ string $title,
+ string $description = null,
+ string $position = 'toast-top toast-end',
+ string $icon = 'o-exclamation-triangle',
+ string $css = 'alert-warning',
+ int $timeout = 3000,
+ ): self {
+ return self::typedMessage(
+ type: 'warning',
+ title: $title,
+ description: $description,
+ position: $position,
+ icon: $icon,
+ css: $css,
+ timeout: $timeout
);
}
- public function options(array $options): self
- {
- $this->position = $options['position'] ?? $this->position;
- $this->icon = $options['icon'] ?? $this->icon;
- $this->css = $options['css'] ?? $this->css;
- $this->timeout = $options['timeout'] ?? $this->timeout;
- $this->preventDefault = $options['preventDefault'] ?? $this->preventDefault;
- return $this;
- }
-
public function permitDefault(): self
{
$this->preventDefault = false;
+
return $this;
}
@@ -90,7 +137,7 @@ public function render(Request $request): JsonResponse|false
'toast' => [
'type' => $this->type,
'title' => $this->title,
- 'description' => $this->getMessage(),
+ 'description' => $this->description,
'position' => $this->position,
'icon' => Blade::render(""),
@@ -103,5 +150,4 @@ public function render(Request $request): JsonResponse|false
return false;
}
-
}
diff --git a/src/View/Components/Toast.php b/src/View/Components/Toast.php
index bffad83a..06159b19 100644
--- a/src/View/Components/Toast.php
+++ b/src/View/Components/Toast.php
@@ -47,17 +47,18 @@ class="toast !whitespace-normal rounded-md fixed cursor-pointer z-50"