diff --git a/CHANGELOG b/CHANGELOG index 503b017..54797ec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Version 1.2.x - Dec ---------------------------- - Enh: changes in README - Enh: added new type of alert "light" +- Enh: parameter button replaced with important, added examples of handling not important messages Version 1.2.0 - Dec 15, 2020 diff --git a/README.md b/README.md index 2de97e4..6fda6fb 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,39 @@ Flash::error('Second Message')->clear(); return redirect('somewhere'); ``` +## Hide Messages + +Generally you're expecting from the flash messages to be shown for a few seconds, and then they will be closed (if this message is not important). +To handle such behaviour, you may write a simple JavaScript code. For example, using jQuery, you might add the following snippet just before +the closing `` tag. + +```html + +``` + +or with pure CSS + +```html + +``` + ## Customization diff --git a/src/Apphp/Flash/FlashNotifier.php b/src/Apphp/Flash/FlashNotifier.php index 324f6d4..31939b5 100644 --- a/src/Apphp/Flash/FlashNotifier.php +++ b/src/Apphp/Flash/FlashNotifier.php @@ -39,48 +39,48 @@ function __construct(SessionFlashStore $session) * Return a primary message * * @param string|null $message - * @param bool $button + * @param bool $important * @return $this */ - public function primary($message = null, $button = false) + public function primary($message = null, $important = false) { - return $this->message($message, 'primary', $button); + return $this->message($message, 'primary', $important); } /** * Return a secondary message * * @param string|null $message - * @param bool $button + * @param bool $important * @return $this */ - public function secondary($message = null, $button = false) + public function secondary($message = null, $important = false) { - return $this->message($message, 'secondary', $button); + return $this->message($message, 'secondary', $important); } /** * Return a success message * * @param string|null $message - * @param bool $button + * @param bool $important * @return $this */ - public function success($message = null, $button = false) + public function success($message = null, $important = false) { - return $this->message($message, 'success', $button); + return $this->message($message, 'success', $important); } /** * Return an error message * * @param string|null $message - * @param bool $button + * @param bool $important * @return $this */ - public function error($message = null, $button = false) + public function error($message = null, $important = false) { - return $this->danger($message, $button); + return $this->danger($message, $important); } /** @@ -88,48 +88,48 @@ public function error($message = null, $button = false) * Alias to error() * * @param string|null $message - * @param bool $button + * @param bool $important * @return $this */ - public function danger($message = null, $button = false) + public function danger($message = null, $important = false) { - return $this->message($message, 'danger', $button); + return $this->message($message, 'danger', $important); } /** * Return a warning message * * @param string|null $message - * @param bool $button + * @param bool $important * @return $this */ - public function warning($message = null, $button = false) + public function warning($message = null, $important = false) { - return $this->message($message, 'warning', $button); + return $this->message($message, 'warning', $important); } /** * Return an information message * * @param string|null $message - * @param bool $button + * @param bool $important * @return $this */ - public function info($message = null, $button = false) + public function info($message = null, $important = false) { - return $this->message($message, 'info', $button); + return $this->message($message, 'info', $important); } /** * Return a simple light message * * @param string|null $message - * @param bool $button + * @param bool $important * @return $this */ - public function light($message = null, $button = false) + public function light($message = null, $important = false) { - return $this->message($message, 'light', $button); + return $this->message($message, 'light', $important); } /** @@ -137,10 +137,10 @@ public function light($message = null, $button = false) * * @param string|null $message * @param string|null $level - * @param bool $button + * @param bool $important * @return $this */ - public function message($message = null, $level = null, $button = false) + public function message($message = null, $level = null, $important = false) { if ( ! $message instanceof Message) { $message = new Message(compact('message', 'level')); @@ -148,7 +148,7 @@ public function message($message = null, $level = null, $button = false) $this->messages->push($message); - if ($button) { + if ($important) { $this->button(); } diff --git a/src/Apphp/Flash/Message.php b/src/Apphp/Flash/Message.php index ae101c8..c9923d8 100644 --- a/src/Apphp/Flash/Message.php +++ b/src/Apphp/Flash/Message.php @@ -29,11 +29,11 @@ class Message implements ArrayAccess public $level = 'info'; /** - * Whether to show button or not + * Whether this message important or not * * @var bool */ - public $button = false; + public $important = false; /** * Constructor - create a new message instance diff --git a/src/Apphp/Flash/functions.php b/src/Apphp/Flash/functions.php index 718480b..6841b7a 100644 --- a/src/Apphp/Flash/functions.php +++ b/src/Apphp/Flash/functions.php @@ -6,15 +6,15 @@ * * @param string|null $message * @param string $level - * @param bool $button + * @param bool $important * @return \Apphp\Flash\FlashNotifier */ - function flash($message = null, $level = 'info', $button = false) + function flash($message = null, $level = 'info', $important = false) { $notifier = app('flash'); if ( ! is_null($message)) { - return $notifier->message($message, $level, $button); + return $notifier->message($message, $level, $important); } return $notifier;