Просмотр исходного кода

修复Column::help方法$style参数无效bug,并增加$placement参数用于设置提示框显示方位

jqh 6 лет назад
Родитель
Сommit
2f940e8f71
3 измененных файлов с 27 добавлено и 14 удалено
  1. 6 4
      src/Grid/Column.php
  2. 6 4
      src/Grid/Column/HasHeader.php
  3. 15 6
      src/Grid/Column/Help.php

+ 6 - 4
src/Grid/Column.php

@@ -382,13 +382,15 @@ class Column
     /**
     /**
      * Set help message for column.
      * Set help message for column.
      *
      *
-     * @param string $help
-     * @param null $style
+     * @param string|\Closure $help
+     * @param null|string $style 'green', 'blue', 'red', 'purple'
+     * @param null|string $placement 'bottom', 'left', 'right', 'top'
+     *
      * @return $this
      * @return $this
      */
      */
-    public function help($help = '', $style = null)
+    public function help($help = '', ?string $style = null, ?string $placement = 'bottom')
     {
     {
-        return $this->addHelp($help, $style);
+        return $this->addHelp($help, $style, $placement);
     }
     }
 
 
     /**
     /**

+ 6 - 4
src/Grid/Column/HasHeader.php

@@ -61,13 +61,15 @@ trait HasHeader
     /**
     /**
      * Add a help tooltip to column header.
      * Add a help tooltip to column header.
      *
      *
-     * @param $message
-     * @param null $style
+     * @param string|\Closure $message
+     * @param null|string $style 'green', 'blue', 'red', 'purple'
+     * @param null|string $placement 'bottom', 'left', 'right', 'top'
+     *
      * @return $this
      * @return $this
      */
      */
-    protected function addHelp($message, $style = null)
+    protected function addHelp($message, ?string $style = null, ? string $placement = 'bottom')
     {
     {
-        return $this->addHeader(new Help($message, $style));
+        return $this->addHeader(new Help($message, $style, $placement));
     }
     }
 
 
     /**
     /**

+ 15 - 6
src/Grid/Column/Help.php

@@ -18,15 +18,21 @@ class Help implements Renderable
      */
      */
     protected $style;
     protected $style;
 
 
+    /**
+     * @var null
+     */
+    protected $placement;
+
     /**
     /**
      * Help constructor.
      * Help constructor.
      *
      *
      * @param string $message
      * @param string $message
      */
      */
-    public function __construct($message = '', $style = null)
+    public function __construct($message = '', ?string $style = null, ?string $placement = 'bottom')
     {
     {
-        $this->message = $message;
-        $this->style = null;
+        $this->message = value($message);
+        $this->style = $style;
+        $this->placement = $placement;
     }
     }
 
 
     /**
     /**
@@ -40,12 +46,15 @@ class Help implements Renderable
 
 
         $tooltip = Tooltip::make('.grid-column-help-'.$random);
         $tooltip = Tooltip::make('.grid-column-help-'.$random);
 
 
-        if ($this->style && method_exists($tooltip, $this->style)) {
-            $tooltip->{$this->style};
+        if (in_array($this->style, ['green', 'blue', 'red', 'purple'])) {
+            $tooltip->{$this->style}();
+        }
+
+        if (in_array($this->placement, ['bottom', 'left', 'right', 'top'])) {
+            $tooltip->{$this->placement}();
         }
         }
 
 
         $tooltip->content($this->message)
         $tooltip->content($this->message)
-            ->bottom()
             ->render();
             ->render();
 
 
         return <<<HELP
         return <<<HELP