v1.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace zin;
  3. class btnGroup extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'items?:array',
  10. 'disabled?:bool',
  11. 'size?:string'
  12. );
  13. public function onBuildItem($item)
  14. {
  15. if(!($item instanceof item)) $item = item(set($item));
  16. return btn(inherit($item));
  17. }
  18. private function getClassName()
  19. {
  20. $disabled = $this->prop('disabled');
  21. $size = $this->prop('size');
  22. $className = 'btn-group';
  23. if(!empty($disabled)) $className .= ' disabled';
  24. if(!empty($size)) $className .= " size-$size";
  25. return $className;
  26. }
  27. protected function build()
  28. {
  29. $items = $this->prop('items');
  30. $className = $this->getclassName();
  31. return div
  32. (
  33. setClass($className),
  34. set($this->getRestProps()),
  35. is_array($items) ? array_map(array($this, 'onBuildItem'), $items) : null,
  36. $this->children()
  37. );
  38. }
  39. }