v1.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace zin;
  3. class textarea extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'name?: string',
  10. 'id?: string',
  11. 'class?: string',
  12. 'required?: bool',
  13. 'placeholder?: string',
  14. 'rows?: int',
  15. 'cols?: int',
  16. 'value?: string',
  17. 'autoHeight?: bool'
  18. );
  19. /**
  20. * @var mixed[]
  21. */
  22. protected static $defaultProps = array(
  23. 'class' => 'form-control',
  24. 'rows' => 10
  25. );
  26. /**
  27. * @param mixed $child
  28. */
  29. protected function onAddChild($child)
  30. {
  31. if(is_string($child) && !$this->props->has('value'))
  32. {
  33. $this->setProp('value', $child);
  34. return false;
  35. }
  36. return $child;
  37. }
  38. protected function build()
  39. {
  40. $autoHeight = $this->prop('autoHeight');
  41. if($autoHeight) $this->setProp('rows', null);
  42. return h::textarea
  43. (
  44. set($this->props->pick(array('name', 'id', 'class', 'placeholder', 'rows', 'cols', 'disabled', 'readonly'))),
  45. $this->prop('required') ? setClass('is-required') : null,
  46. $this->prop('value'),
  47. $autoHeight ? on::init()->do('$element.autoHeight()') : null,
  48. $this->children()
  49. );
  50. }
  51. }