| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- require_once dirname(__FILE__) . '/' . 'Node.php';
- // - props[type] - string success|info|warning|danger|error
- // <div class="alert alert-success" role="alert">...</div>
- // <div class="alert alert-info" role="alert">...</div>
- // <div class="alert alert-warning" role="alert">...</div>
- // <div class="alert alert-danger" role="alert">...</div>
- class UI_Alert extends UI_Node implements UITagInterface {
- public $tagName, $props, $childrens;
- function __construct($tagName = null, $props = null, $childrens = null) {
- parent::__construct($tagName, $props, $childrens);
- // TODO: convert to base html tagName with childrens
- // or modify __toString() (NOTE: require implement tagName in frontend with name: 'P5UI__Alert' (prefix: 'p5:' -> 'P5UI__'))
- $DO_CONVERT_TO_NATIVE_HTML_TAGS = true;
- if ($DO_CONVERT_TO_NATIVE_HTML_TAGS) {
- $type = self::convertType($props['type']);
- unset($this->props['type']);
- $cls = "alert alert-{$type}";
- if (!empty($this->props['class'])) {
- if (is_array($this->props['class'])) $this->props['class'][] = "{$cls}";
- $this->props['class'] .= " {$cls}";
- } else {
- $this->props['class'] = $cls;
- }
- $this->tagName = 'div';
- } else { // modify __toString() (NOTE: require implement tagName in frontend with name: 'P5UI__Alert' (prefix: 'p5:' -> 'P5UI__'))
- }
- }
- /**
- * @param string $tagName = 'p5:Alert'
- * @param array $props
- * @param array $childrens
- *
- * @return string html code
- */
- static function h($tagName, $props = [], $childrens = []) {
- $type = self::convertType($props['type']);
- return UI::h('div', [ 'class' => "alert alert-{$type}" ], $childrens);
- }
- static function convertType($type) {
- switch (strtolower($type)) {
- case 'success': return 'success';
- case 'info': return 'info';
- case 'warning': return 'warning';
- case 'danger': return 'danger';
- case 'error': return 'danger';
- default: return 'info';
- }
- }
- }
|