v1.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'toolbar' . DS . 'v1.php';
  4. class panel extends wg
  5. {
  6. /**
  7. * @var mixed[]
  8. */
  9. protected static $defineProps = array(
  10. 'id?: string',
  11. 'class?: string="rounded ring-0 bg-canvas"', // 类名。
  12. 'size?: "sm"|"lg"', // 额外尺寸。
  13. 'title?: string', // 标题。
  14. 'shadow?: bool=true', // 阴影效果。
  15. 'titleIcon?: string', // 标题图标。
  16. 'titleClass?: string', // 标题类名。
  17. 'titleProps?: array', // 标题属性。
  18. 'headingClass?: string', // 标题栏类名。
  19. 'headingProps?: array', // 标题栏属性。
  20. 'headingActions?: array[]', // 标题栏操作按钮。
  21. 'headingActionsClass?: string', // 头部操作按钮栏类名。
  22. 'bodyClass?: string', // 主体类名。
  23. 'bodyProps?: array', // 主体属性。
  24. 'footerActions?: array[]', // 底部操作按钮。
  25. 'footerClass?: string', // 底部类名。
  26. 'footerProps?: array', // 底部属性。
  27. 'container?: bool' // 是否使用 Container 层。
  28. );
  29. /**
  30. * @var mixed[]
  31. */
  32. protected static $defineBlocks = array(
  33. 'heading' => array(),
  34. 'headingActions' => array('map' => 'toolbar'),
  35. 'titleSuffix' => array(),
  36. 'footer' => array('map' => 'nav')
  37. );
  38. protected function getHeadingActions()
  39. {
  40. return $this->prop('headingActions', array());
  41. }
  42. protected function buildHeadingActions()
  43. {
  44. $actions = $this->getHeadingActions();
  45. $headingActionsClass = $this->prop('headingActionsClass');
  46. $actionsBlock = $this->block('headingActions');
  47. if(empty($actions) && empty($actionsBlock)) return null;
  48. return div
  49. (
  50. setClass('panel-actions', $headingActionsClass),
  51. empty($actions) ? null : toolbar::create($actions),
  52. $actionsBlock
  53. );
  54. }
  55. /**
  56. * @return mixed[]|\zin\node
  57. */
  58. protected function buildContainer()
  59. {
  60. $content = func_get_args();
  61. if(!$this->prop('container')) return $content;
  62. return div(setClass('container'), $content);
  63. }
  64. protected function buildHeading()
  65. {
  66. list($title, $size) = $this->prop(array('title', 'size'));
  67. $headingBlock = $this->block('heading');
  68. $actions = $this->buildHeadingActions();
  69. if(empty($title) && empty($headingBlock) && empty($actions)) return null;
  70. return div
  71. (
  72. setClass('panel-heading', $this->prop('headingClass')),
  73. set($this->prop('headingProps')),
  74. $this->buildContainer
  75. (
  76. empty($title) ? null : div
  77. (
  78. setClass('panel-title', $this->prop('titleClass', empty($size) ? null : "text-$size")),
  79. $this->prop('titleIcon') ? icon($this->prop('titleIcon')) : null,
  80. set($this->prop('titleProps')),
  81. $title,
  82. $this->block('titleSuffix')
  83. ),
  84. $headingBlock,
  85. $actions
  86. )
  87. );
  88. }
  89. protected function buildBody()
  90. {
  91. list($bodyClass, $bodyProps) = $this->prop(array('bodyClass', 'bodyProps'));
  92. return div
  93. (
  94. setClass('panel-body', $bodyClass),
  95. set($bodyProps),
  96. $this->buildContainer($this->children())
  97. );
  98. }
  99. protected function buildFooter()
  100. {
  101. list($footerActions) = $this->prop(array('footerActions'));
  102. $footerBlock = $this->block('footer');
  103. if(empty($footerActions) && empty($footerBlock)) return null;
  104. return div
  105. (
  106. setClass('panel-footer', $this->prop('footerClass')),
  107. set($this->prop('footerProps')),
  108. $this->buildContainer
  109. (
  110. $footerBlock,
  111. empty($footerActions) ? null : toolbar(set::items($footerActions))
  112. )
  113. );
  114. }
  115. protected function buildProps()
  116. {
  117. list($id, $class, $size, $shadow) = $this->prop(array('id', 'class', 'size', 'shadow'));
  118. return array(setID($id), setClass('panel', $class, empty($size) ? null : "size-$size", $shadow ? 'shadow' : null));
  119. }
  120. protected function build()
  121. {
  122. return div
  123. (
  124. $this->buildProps(),
  125. set($this->getRestProps()),
  126. $this->buildHeading(),
  127. $this->buildBody(),
  128. $this->buildFooter()
  129. );
  130. }
  131. }