v1.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace zin;
  3. class cell extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'flex?: string', // flex 类型或具体的值,例如:'auto'、'none'、'1'、'auto 1 1'。
  10. 'order?: int', // flex-order 属性。
  11. 'grow?: int', // flex-grow 属性。
  12. 'shrink?: int', // flex-shrink 属性。
  13. 'width?: string|int', // flex-basis 属性,支持数值或百分比,例如 128px、1/3、30%、128px。
  14. 'align?: string' // align-self 属性,例如 'auto'、'flex-start'、'flex-end'、'center'、'baseline'、'stretch'。
  15. );
  16. protected function build()
  17. {
  18. $basis = null;
  19. $class = array('cell');
  20. $width = $this->prop('width');
  21. $flex = $this->prop('flex');
  22. if(!empty($width))
  23. {
  24. $basis = $width;
  25. if(is_numeric($width)) $basis = $width . 'px';
  26. elseif(preg_match('/^(\d+)\/(\d+)$/', $width, $matches) !== 0) $basis = ((int)$matches[1] / (int)$matches[2] * 100) . '%';
  27. }
  28. if(!empty($flex))
  29. {
  30. if(strpos($flex, ' ') !== false) $style['flex'] = $flex;
  31. else $class[] = "flex-$flex";
  32. }
  33. $style = array();
  34. $style['order'] = $this->prop('order');
  35. $style['flex-grow'] = $this->prop('grow');
  36. $style['flex-shrink'] = $this->prop('shrink');
  37. $style['flex-basis'] = $basis;
  38. $style['align-self'] = $this->prop('align');
  39. return div
  40. (
  41. setClass($class),
  42. setStyle($style),
  43. set($this->getRestProps()),
  44. $this->children()
  45. );
  46. }
  47. }