v1.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'actionitem' . DS . 'v1.php';
  4. class nav extends wg
  5. {
  6. /**
  7. * @var mixed[]
  8. */
  9. protected static $defineProps = array(
  10. 'stacked?: bool', // 是否为垂直模式。
  11. 'justified?: bool', // 是否为自适应模式。
  12. 'compact?: bool', // 是否为紧凑模式。
  13. 'type?: string', // 导航类型,包括 primary, tabs, secondary,pills
  14. 'items?:array', // 使用数组指定导航中的每一项。
  15. 'responsive?:array|bool' // 响应式导航配置。
  16. );
  17. public function onBuildItem($item)
  18. {
  19. return new actionItem
  20. (
  21. set('name', 'nav'),
  22. set('outerClass', 'item'),
  23. $item instanceof item ? inherit($item) : set($item)
  24. );
  25. }
  26. protected function build()
  27. {
  28. list($items, $type, $stacked, $justified, $compact, $responsive) = $this->prop(array('items', 'type', 'stacked', 'justified', 'compact', 'responsive'));
  29. $responsiveOptions = is_array($responsive) ? $responsive : null;
  30. return h::menu
  31. (
  32. setClass('nav', $type ? "nav-$type" : null, $stacked ? 'nav-stacked' : '', $justified ? 'nav-justified' : '', $compact ? 'nav-compact' : ''),
  33. set($this->getRestProps()),
  34. is_array($items) ? array_map(array($this, 'onBuildItem'), $items) : null,
  35. ($responsive || is_array($responsive)) ? zui::create('ResponsiveNavHelper', $responsiveOptions) : null,
  36. $this->children()
  37. );
  38. }
  39. }