From 7edfcb0640a5c4566beae6b6fe4ac6a8d83307cc Mon Sep 17 00:00:00 2001 From: dingyongliang Date: Wed, 15 Feb 2023 17:07:10 +0800 Subject: [PATCH] * zin: add flex widget. --- zin/func.php | 4 ++++ zin/wg/cell/v1.php | 43 +++++++++++++++++++++++++++++++++++++++++++ zin/wg/center/v1.php | 23 +++++++++++++++++++++++ zin/wg/column/v1.php | 27 +++++++++++++++++++++++++++ zin/wg/row/v1.php | 27 +++++++++++++++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 zin/wg/cell/v1.php create mode 100644 zin/wg/center/v1.php create mode 100644 zin/wg/column/v1.php create mode 100644 zin/wg/row/v1.php diff --git a/zin/func.php b/zin/func.php index f510cb448e..aec24256d8 100644 --- a/zin/func.php +++ b/zin/func.php @@ -20,3 +20,7 @@ function page() {return createWg('page', func_get_args());} function btngroup() {return createWg('btngroup', func_get_args());} function checkbox() {return createWg('checkbox', func_get_args());} function pagemain() {return createWg('pagemain', func_get_args());} +function row() {return createWg('row', func_get_args());} +function column() {return createWg('column', func_get_args());} +function center() {return createWg('center', func_get_args());} +function cell() {return createWg('cell', func_get_args());} diff --git a/zin/wg/cell/v1.php b/zin/wg/cell/v1.php new file mode 100644 index 0000000000..b2bcf94844 --- /dev/null +++ b/zin/wg/cell/v1.php @@ -0,0 +1,43 @@ +addToBlock('inner', $child); + return false; + } + return null; + } + + protected function build() + { + $order = empty($this->prop('order')) ? '0' : $this->prop('order'); + $grow = empty($this->prop('grow')) ? '0' : $this->prop('grow'); + $shrink = empty($this->prop('shrink')) ? '1' : $this->prop('shrink'); + $basis = empty($this->prop('width')) ? 'auto' : $this->prop('width'); + $align = empty($this->prop('align')) ? 'auto' : $this->prop('align'); + $flex = empty($this->prop('flex')) ? '0 1 auto' : $this->prop('flex'); + + if(is_numeric($basis)) $basis .= 'px'; + elseif(preg_match('/^(\d+)\/(\d+)$/', $basis, $matches) !== 0) { + $basis = ((int)$matches[1] / (int)$matches[2] * 100) . '%'; + } + return div( + setStyle(array( + 'order' => $order, + 'flex-grow' => $grow, + 'flex-shrink' => $shrink, + 'basis' => $basis, + 'align-self' => $align, + 'flex' => $flex + )), + $this->block('inner'), + ); + } +} diff --git a/zin/wg/center/v1.php b/zin/wg/center/v1.php new file mode 100644 index 0000000000..33920e0e67 --- /dev/null +++ b/zin/wg/center/v1.php @@ -0,0 +1,23 @@ +addToBlock('inner', $child); + return false; + } + return null; + } + + protected function build() + { + return div( + setClass("flex justify-center items-center"), + $this->block('inner'), + ); + } +} diff --git a/zin/wg/column/v1.php b/zin/wg/column/v1.php new file mode 100644 index 0000000000..f144633de4 --- /dev/null +++ b/zin/wg/column/v1.php @@ -0,0 +1,27 @@ +addToBlock('inner', $child); + return false; + } + return null; + } + + protected function build() + { + $justify = empty($this->prop('justify')) ? 'start' : $this->prop('justify'); + $align = empty($this->prop('align')) ? 'start' : $this->prop('align'); + return div( + setClass("col justify-$justify items-$align"), + $this->block('inner'), + ); + } +} diff --git a/zin/wg/row/v1.php b/zin/wg/row/v1.php new file mode 100644 index 0000000000..67cf4b0415 --- /dev/null +++ b/zin/wg/row/v1.php @@ -0,0 +1,27 @@ +addToBlock('inner', $child); + return false; + } + return null; + } + + protected function build() + { + $justify = empty($this->prop('justify')) ? 'start' : $this->prop('justify'); + $align = empty($this->prop('align')) ? 'start' : $this->prop('align'); + return div( + setClass("row justify-$justify items-$align"), + $this->block('inner'), + ); + } +}