v1.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace zin;
  3. class formLabel extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'text?: string',
  10. 'required?: bool',
  11. 'for?: string',
  12. 'hint?: string',
  13. 'hintIcon?: string',
  14. 'hintClass?: string',
  15. 'hintProps?: array',
  16. 'actions?: array',
  17. 'actionsClass?: string',
  18. 'actionsProps?: array',
  19. 'checkbox?: bool|array'
  20. );
  21. protected function build()
  22. {
  23. list($text, $required, $for, $hint, $hintClass, $hintProps, $hintIcon, $actions, $actionsClass, $actionsProps, $checkbox) = $this->prop(array('text', 'required', 'for', 'hint', 'hintClass', 'hintProps', 'hintIcon', 'actions', 'actionsClass', 'actionsProps', 'checkbox'));
  24. if(!empty($hint))
  25. {
  26. $hint = btn
  27. (
  28. set::size('sm'),
  29. set::icon(is_null($hintIcon) ? 'help' : $hintIcon),
  30. setClass('ghost form-label-hint text-gray-300', $hintClass),
  31. toggle::tooltip(array('title' => $hint, 'className' => 'text-gray border border-gray-300', 'type' => 'white', 'placement' => 'right')),
  32. set($hintProps)
  33. );
  34. }
  35. if(is_array($checkbox)) $checkbox = checkbox(set($checkbox));
  36. if(is_array($actions))
  37. {
  38. $actions = toolbar
  39. (
  40. setClass('form-label-actions size-sm', $actionsClass),
  41. set::btnClass('primary-ghost'),
  42. set::items($actions),
  43. set($actionsProps)
  44. );
  45. }
  46. return h::label
  47. (
  48. setClass('form-label', $required ? 'required' : null),
  49. set('for', $for),
  50. set($this->getRestProps()),
  51. span(setClass('text'), $text),
  52. $this->children(),
  53. $hint,
  54. $checkbox,
  55. $actions
  56. );
  57. }
  58. }