Col.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * FormBuilder表单生成器
  4. * Author: xaboy
  5. * Github: https://github.com/xaboy/form-builder
  6. */
  7. namespace FormBuilder\components;
  8. use FormBuilder\interfaces\FormComponentInterFace;
  9. use FormBuilder\traits\component\CallPropsTrait;
  10. /**
  11. * col栅格规则
  12. * Class Col
  13. *
  14. * @package FormBuilder\components
  15. * @method $this span(Number $span) 栅格的占位格数,可选值为0~24的整数,为 0 时,相当于display:none
  16. * @method $this order(Number $order) 栅格的顺序,在flex布局模式下有效
  17. * @method $this offset(Number $offset) 栅格左侧的间隔格数,间隔内不可以有栅格
  18. * @method $this push(Number $push) 栅格向右移动格数
  19. * @method $this pull(Number $pull) 栅格向左移动格数
  20. * @method $this labelWidth(Number $labelWidth) 表单域标签的的宽度, 默认150px
  21. * @method $this className(String $className) 自定义的class名称
  22. * @method $this xs(Number | Col $span) <768px 响应式栅格,可为栅格数或一个包含其他属性的对象
  23. * @method $this sm(Number | Col $span) ≥768px 响应式栅格,可为栅格数或一个包含其他属性的对象
  24. * @method $this md(Number | Col $span) ≥992px 响应式栅格,可为栅格数或一个包含其他属性的对象
  25. * @method $this lg(Number | Col $span) ≥1200px 响应式栅格,可为栅格数或一个包含其他属性的对象
  26. */
  27. class Col implements FormComponentInterFace
  28. {
  29. use CallPropsTrait;
  30. /**
  31. * @var array
  32. */
  33. protected $props;
  34. /**
  35. * @var array
  36. */
  37. protected static $propsRule = [
  38. 'span' => 'number',
  39. 'order' => 'number',
  40. 'offset' => 'number',
  41. 'push' => 'number',
  42. 'pull' => 'number',
  43. 'labelWidth' => 'number',
  44. 'className' => 'number',
  45. 'xs' => '',
  46. 'sm' => '',
  47. 'md' => '',
  48. 'lg' => '',
  49. ];
  50. /**
  51. * @var array
  52. */
  53. protected static $model = ['xs', 'sm', 'md', 'lg'];
  54. /**
  55. * Col constructor.
  56. *
  57. * @param int $span
  58. */
  59. public function __construct($span = 24)
  60. {
  61. $this->props['span'] = $span;
  62. }
  63. /**
  64. * @return array
  65. */
  66. public function build()
  67. {
  68. foreach (self::$model as $m) {
  69. if (isset($this->props[$m]) && $this->props[$m] instanceof Col) {
  70. $this->props[$m] = $this->props[$m]->build();
  71. }
  72. }
  73. return $this->props;
  74. }
  75. }