Skip to content

Commit

Permalink
Added ability to custom css classes
Browse files Browse the repository at this point in the history
fix #74
  • Loading branch information
realrashid committed Mar 31, 2020
1 parent 9a1bd30 commit d78f0ff
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 48 deletions.
103 changes: 55 additions & 48 deletions src/Toaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Toaster
public function __construct(SessionStore $session)
{
$this->setDefaultConfig();

$this->session = $session;
}

Expand All @@ -51,7 +50,22 @@ protected function setDefaultConfig()
'heightAuto' => config('sweetalert.height_auto'),
'padding' => config('sweetalert.padding'),
'showConfirmButton' => config('sweetalert.show_confirm_button'),
'showCloseButton' => config('sweetalert.show_close_button')
'showCloseButton' => config('sweetalert.show_close_button'),
'customClass' => [
'container' => config('sweetalert.customClass.container'),
'popup' => config('sweetalert.customClass.popup'),
'header' => config('sweetalert.customClass.header'),
'title' => config('sweetalert.customClass.title'),
'closeButton' => config('sweetalert.customClass.closeButton'),
'icon' => config('sweetalert.customClass.icon'),
'image' => config('sweetalert.customClass.image'),
'content' => config('sweetalert.customClass.content'),
'input' => config('sweetalert.customClass.input'),
'actions' => config('sweetalert.customClass.actions'),
'confirmButton' => config('sweetalert.customClass.confirmButton'),
'cancelButton' => config('sweetalert.customClass.cancelButton'),
'footer' => config('sweetalert.customClass.footer')
]
];
}

Expand All @@ -61,14 +75,9 @@ protected function setDefaultConfig()
* @return $config
* @author Rashid Ali <[email protected]>
*/
public function middleware()
{
unset($this->config['position']);
unset($this->config['heightAuto']);
unset($this->config['width']);
unset($this->config['padding']);
unset($this->config['showCloseButton']);
unset($this->config['timer']);
public function middleware()
{
unset($this->config['position'], $this->config['heightAuto'], $this->config['width'], $this->config['padding'], $this->config['showCloseButton'], $this->config['timer']);

$this->config['position'] = config('sweetalert.middleware.toast_position');
$this->config['showCloseButton'] = config('sweetalert.middleware.toast_close_button');
Expand All @@ -77,7 +86,7 @@ public function middleware()
$this->flash();

return $this;
}
}

/**
* Flash an alert message.
Expand Down Expand Up @@ -125,26 +134,26 @@ public function info($title = '', $text = '')
return $this;
}

/**
* Display a warning typed alert message with a text and a title.
*
* @param string $title
* @param string $text
* @author Rashid Ali <[email protected]>
*/
/**
* Display a warning typed alert message with a text and a title.
*
* @param string $title
* @param string $text
* @author Rashid Ali <[email protected]>
*/
public function warning($title = '', $text = '')
{
$this->alert($title, $text, 'warning');
return $this;
}

/**
* Display a question typed alert message with a text and a title.
*
* @param string $title
* @param string $text
* @author Rashid Ali <[email protected]>
*/
/**
* Display a question typed alert message with a text and a title.
*
* @param string $title
* @param string $text
* @author Rashid Ali <[email protected]>
*/
public function question($title = '', $text = '')
{
$this->alert($title, $text, 'question');
Expand Down Expand Up @@ -183,9 +192,9 @@ public function image($title = '', $text = '', $imageUrl, $imageWidth = 400, $im
$this->config['imageUrl'] = $imageUrl;
$this->config['imageWidth'] = $imageWidth;
$this->config['imageHeight'] = $imageHeight;
if(!is_null($imageAlt)){
if (!is_null($imageAlt)) {
$this->config['imageAlt'] = $imageAlt;
}else{
} else {
$this->config['imageAlt'] = $title;
}
$this->config['animation'] = false;
Expand All @@ -194,14 +203,14 @@ public function image($title = '', $text = '', $imageUrl, $imageWidth = 400, $im
return $this;
}

/**
* Display a html typed alert message with html code.
*
* @param string $title
* @param string $code
* @param string $icon
* @author Rashid Ali <[email protected]>
*/
/**
* Display a html typed alert message with html code.
*
* @param string $title
* @param string $code
* @param string $icon
* @author Rashid Ali <[email protected]>
*/
public function html($title = '', $code = '', $icon = '')
{
$this->config['title'] = $title;
Expand Down Expand Up @@ -245,14 +254,13 @@ public function toToast($position = '')
{
$this->config['toast'] = true;
$this->config['showCloseButton'] = true;
if(!empty($position)){
if (!empty($position)) {
$this->config['position'] = $position;
}else{
} else {
$this->config['position'] = config('sweetalert.toast_position');
}
$this->config['showConfirmButton'] = false;
unset($this->config['width']);
unset($this->config['padding']);
unset($this->config['width'], $this->config['padding']);

$this->flash();
return $this;
Expand Down Expand Up @@ -333,13 +341,13 @@ public function width($width = '32rem')
return $this;
}

/**
* Modal window padding.
* The default padding is 1.25rem.
*
* @param string $padding
* @author Rashid Ali <[email protected]>
*/
/**
* Modal window padding.
* The default padding is 1.25rem.
*
* @param string $padding
* @author Rashid Ali <[email protected]>
*/
public function padding($padding = '1.25rem')
{
$this->config['padding'] = $padding;
Expand Down Expand Up @@ -408,7 +416,7 @@ public function focusCancel($focus = false)
*/
public function animation($showAnimation, $hideAnimation)
{
if(!config('sweetalert.animation.enable')){
if (!config('sweetalert.animation.enable')) {
config(['sweetalert.animation.enable' => true]);
}
$this->config['showClass'] = ['popup' => "animated {$showAnimation}"];
Expand Down Expand Up @@ -578,7 +586,6 @@ public function reverseButtons()
return $this;
}


/**
* Remove the timer from config option.
*
Expand Down
25 changes: 25 additions & 0 deletions src/config/sweetalert.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,29 @@
'auto_display_error_messages' => env('SWEET_ALERT_AUTO_DISPLAY_ERROR_MESSAGES', false),
],

/*
|--------------------------------------------------------------------------
| Custom Class
|--------------------------------------------------------------------------
| A custom CSS class for the modal:
|
*/

'customClass' => [

'container' => env('SWEET_ALERT_CONTAINER_CLASS'),
'popup' => env('SWEET_ALERT_POPUP_CLASS'),
'header' => env('SWEET_ALERT_HEADER_CLASS'),
'title' => env('SWEET_ALERT_TITLE_CLASS'),
'closeButton' => env('SWEET_ALERT_CLOSE_BUTTON_CLASS'),
'icon' => env('SWEET_ALERT_ICON_CLASS'),
'image' => env('SWEET_ALERT_IMAGE_CLASS'),
'content' => env('SWEET_ALERT_CONTENT_CLASS'),
'input' => env('SWEET_ALERT_INPUT_CLASS'),
'actions' => env('SWEET_ALERT_ACTIONS_CLASS'),
'confirmButton' => env('SWEET_ALERT_CONFIRM_BUTTON_CLASS'),
'cancelButton' => env('SWEET_ALERT_CANCEL_BUTTON_CLASS'),
'footer' => env('SWEET_ALERT_FOOTER_CLASS'),
],

];

0 comments on commit d78f0ff

Please sign in to comment.