| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Ui\Js; |
| 6: | |
| 7: | use Atk4\Core\DiContainerTrait; |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | class JsToast implements JsExpressionable |
| 15: | { |
| 16: | use DiContainerTrait; |
| 17: | |
| 18: | |
| 19: | public array $settings = []; |
| 20: | |
| 21: | |
| 22: | public $defaultCss = 'success'; |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | public function __construct($settings = null) |
| 28: | { |
| 29: | if (is_array($settings)) { |
| 30: | $this->settings = $settings; |
| 31: | } elseif (is_string($settings)) { |
| 32: | $this->settings['message'] = $settings; |
| 33: | } |
| 34: | |
| 35: | |
| 36: | if (!array_key_exists('class', $this->settings)) { |
| 37: | $this->settings['class'] = $this->defaultCss; |
| 38: | } |
| 39: | } |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | public function setMessage($msg): self |
| 49: | { |
| 50: | $this->settings['message'] = $msg; |
| 51: | |
| 52: | return $this; |
| 53: | } |
| 54: | |
| 55: | #[\Override] |
| 56: | public function jsRender(): string |
| 57: | { |
| 58: | return (new Jquery('body'))->toast($this->settings)->jsRender(); |
| 59: | } |
| 60: | } |
| 61: | |