123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace crmeb\form\components;
- use crmeb\form\BuildInterface;
- class Alert implements BuildInterface
- {
-
- const NAME = 'alert';
-
- const INFO = 'info';
-
- const SUCCESS = 'success';
-
- const WARNING = 'warning';
-
- const ERROR = 'error';
-
- const TYPE = [self::INFO, self::SUCCESS, self::WARNING, self::ERROR];
-
- protected $rule = [
- 'title' => '',
- 'type' => '',
- 'closable' => false,
- 'showIcon' => false
- ];
-
- public function __construct(string $title, string $type = '', bool $closable = false, bool $showIcon = false)
- {
- $this->rule['type'] = in_array($type, self::TYPE) ? $type : '';
- $this->rule['title'] = $title;
- $this->rule['closable'] = $closable;
- $this->rule['showIcon'] = $showIcon;
- }
-
- public function type(string $type)
- {
- $this->rule['type'] = in_array($type, self::TYPE) ? $type : '';
- return $this;
- }
-
- public function closable(bool $closable = false)
- {
- $this->rule['closable'] = $closable;
- return $this;
- }
-
- public function showIcon(bool $showIcon = false)
- {
- $this->rule['showIcon'] = $showIcon;
- return $this;
- }
- public function toArray(): array
- {
- $this->rule['name'] = self::NAME;
- return $this->rule;
- }
- }
|