Skip to content

Commit

Permalink
Parameter button replaced with important, added examples of handling …
Browse files Browse the repository at this point in the history
…not important messages
  • Loading branch information
apphp committed Dec 17, 2020
1 parent 01bdce7 commit afb1bf3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `</body>` tag.

```html
<script>
$('div.alert').not('.alert-important').delay(5000).fadeOut(250);
</script>
```

or with pure CSS

```html
<style>
div.alert:not(.alert-important) {
-webkit-animation: cssAnimation 5s forwards;
animation: cssAnimation 5s forwards;
}
@keyframes cssAnimation {
0% {opacity: 1; height:auto; padding: 0.75rem 1.25rem; margin-bottom: 1rem;}
90% {opacity: 1; height:auto; padding: 0.75rem 1.25rem; margin-bottom: 1rem;}
100% {opacity: 0; height:0px; padding:0; margin:0;}
}
@-webkit-keyframes cssAnimation {
0% {opacity: 1; height:auto; padding: 0.75rem 1.25rem; margin-bottom: 1rem;}
90% {opacity: 1; height:auto; padding: 0.75rem 1.25rem; margin-bottom: 1rem;}
100% {opacity: 0; height:0px; padding:0; margin:0;}
}
</style>
```


## Customization

Expand Down
54 changes: 27 additions & 27 deletions src/Apphp/Flash/FlashNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,116 +39,116 @@ 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);
}

/**
* Return an error message
* 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);
}

/**
* Save a message
*
* @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'));
}

$this->messages->push($message);

if ($button) {
if ($important) {
$this->button();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Apphp/Flash/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Apphp/Flash/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit afb1bf3

Please sign in to comment.