Details.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. // UI::hAttributes($params);
  3. // UI::hChildrens($childrens);
  4. // <details class="p5-details p5-details--{$props['theme']}">
  5. // <summary class="p5-details__summary">{$props['summary']}</summary>
  6. // <div class="p5-details__body">{$props['summary']}</div>
  7. // </details>
  8. // - props[summary] - mixed string|array passed to UI::hChildrens($params)
  9. // - props[type] - string success|info|warning|danger|error
  10. // - props[open] - boolean
  11. // - props[style] - string <details> style attribute value
  12. // - props[summary.style] - string <summary> style attribute value
  13. // - props[body.style] - string .p5-details__body style attribute value
  14. class UI_Details implements UITagInterface {
  15. /**
  16. * @param string $tagName = 'p5:Details'
  17. * @param array $props
  18. * @param array $childrens
  19. *
  20. * @return string html code
  21. */
  22. static function h($tagName, $props = [], $childrens = []) {
  23. if (empty($props['summary'])) throw new Exception("Missing details summary");
  24. $thisProps = [];
  25. $thisProps['style'] = (!empty($props['style'])) ? [ 'style' => $props['style'] ] : [];
  26. return UI::h('details', [
  27. 'class' => "p5-details" . (!empty($props['theme']) ? " p5-details--{$props['theme']}" : ""),
  28. 'style' => V::get('style', '', $props),
  29. 'open' => (true === $props['open']) ? true : false,
  30. 'test-attr-true' => true,
  31. 'test-attr-false' => false,
  32. ], [
  33. UI::h('summary', [
  34. 'class' => "p5-details__summary",
  35. 'style' => V::get('summary.style', '', $props),
  36. ], $props['summary']),
  37. UI::h('div', [
  38. 'class' => "p5-details__body",
  39. 'style' => V::get('body.style', '', $props),
  40. ], $childrens),
  41. ]);
  42. }
  43. }