v1.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'btn' . DS . 'v1.php';
  4. require_once dirname(__DIR__) . DS . 'input' . DS . 'v1.php';
  5. require_once dirname(__DIR__) . DS . 'inputcontrol' . DS . 'v1.php';
  6. require_once dirname(__DIR__) . DS . 'picker' . DS . 'v1.php';
  7. class inputGroup extends wg
  8. {
  9. /**
  10. * @var mixed[]
  11. */
  12. protected static $defineProps = array(
  13. 'items?:array',
  14. 'seg?:bool'
  15. );
  16. public function onBuildItem($item)
  17. {
  18. if(is_string($item)) $item = new item(set(array('control' => 'addon', 'text' => $item)));
  19. elseif(is_array($item)) $item = new item(set($item));
  20. elseif($item instanceof node || is_null($item)) return $item;
  21. list($control, $type) = $item->prop(array('control', 'type'));
  22. if(is_array($control))
  23. {
  24. $controlProps = $control;
  25. if(isset($control['control']))
  26. {
  27. $control = $control['control'];
  28. unset($controlProps['control']);
  29. $item->setProp('control', $control);
  30. }
  31. $item->setProp($controlProps);
  32. }
  33. if(is_null($control) && !is_null($type))
  34. {
  35. $control = $type;
  36. $type = null;
  37. $item->setProp('control', $control);
  38. $item->setProp('type', null);
  39. }
  40. if($control === 'addon') return h::span(setClass('input-group-addon'), set($item->props->skip('control,text')), $item->prop('text'));
  41. if($control === 'span') return h::span(setClass('px-2 h-8 flex items-center'), set($item->props->skip('control,text')), $item->prop('text'));
  42. if($control === 'btn') return new btn(set($item->props->skip('control')));
  43. if($control === 'picker') return new picker(set($item->props->skip('control')));
  44. if($control === 'datePicker') return new datePicker(set($item->props->skip('control')));
  45. if(!empty($control)) return createWg($control, set($item->props->skip('control')), 'input');
  46. return new input(set::type($control), set($item->props->skip('control')));
  47. }
  48. protected function build()
  49. {
  50. list($items, $seg) = $this->prop(['items', 'seg']);
  51. $children = $this->children();
  52. return div
  53. (
  54. setClass('input-group', $seg ? 'input-group-segment' : null),
  55. set($this->getRestProps()),
  56. is_array($items) ? array_map(array($this, 'onBuildItem'), $items) : null,
  57. is_array($children) ? array_map(array($this, 'onBuildItem'), $children) : null
  58. );
  59. }
  60. }