Alert.php 1003 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. // UI::hAttributes($params);
  3. // UI::hChildrens($childrens);
  4. // - props[type] - string success|info|warning|danger|error
  5. // <div class="alert alert-success" role="alert">...</div>
  6. // <div class="alert alert-info" role="alert">...</div>
  7. // <div class="alert alert-warning" role="alert">...</div>
  8. // <div class="alert alert-danger" role="alert">...</div>
  9. class UI_Alert implements UITagInterface {
  10. /**
  11. * @param string $tagName = 'p5:Alert'
  12. * @param array $props
  13. * @param array $childrens
  14. *
  15. * @return string html code
  16. */
  17. static function h($tagName, $props = [], $childrens = []) {
  18. $type = self::convertType($props['type']);
  19. return UI::h('div', [ 'class' => "alert alert-{$type}" ], $childrens);
  20. }
  21. static function convertType($type) {
  22. switch (strtolower($type)) {
  23. case 'success': return 'success';
  24. case 'info': return 'info';
  25. case 'warning': return 'warning';
  26. case 'danger': return 'danger';
  27. case 'error': return 'danger';
  28. default: return 'info';
  29. }
  30. }
  31. }