v1.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace zin;
  3. class checkboxGroup extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'title: array',
  10. 'items: array'
  11. );
  12. /**
  13. * @var mixed[]
  14. */
  15. private static $checkboxProps = array(
  16. 'checked' => false,
  17. 'disabled' => false
  18. );
  19. public static function getPageCSS()
  20. {
  21. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  22. }
  23. public static function getPageJS()
  24. {
  25. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  26. }
  27. private function buildTitle()
  28. {
  29. $title = array_merge(self::$checkboxProps, $this->prop('title'));
  30. return checkbox(set($title), setClass('checkbox-title'));
  31. }
  32. private function buildCheckboxList()
  33. {
  34. $items = $this->prop('items');
  35. $title = array_merge(self::$checkboxProps, $this->prop('title'));
  36. $list = ul(setClass('flex', 'flex-wrap', 'ml-1.5', 'checkbox-list', 'pl-3'));
  37. foreach($items as $item)
  38. {
  39. $item = array_merge(self::$checkboxProps, $item);
  40. if($title['checked'] === true) $item['checked'] = true;
  41. if($title['disabled'] === true) $item['disabled'] = true;
  42. $list->add
  43. (
  44. li
  45. (
  46. setClass('basis-1/2'),
  47. checkbox(set($item), setClass('checkbox-child'))
  48. )
  49. );
  50. }
  51. return $list;
  52. }
  53. public function build()
  54. {
  55. return div
  56. (
  57. set('data-on', 'click'),
  58. set('data-call', 'window.handleCheckboxGroupClick'),
  59. set('data-params', 'event'),
  60. setClass('checkbox-group'),
  61. $this->buildTitle(),
  62. $this->buildCheckboxList()
  63. );
  64. }
  65. }