Ver código fonte

Merge pull request #1361 from Abbotton/2.0

修复常用组件大小样式未生效的问题
Jiang Qinghua 3 anos atrás
pai
commit
cf383ffc7b

+ 21 - 0
src/Form/Field.php

@@ -225,6 +225,11 @@ class Field implements Renderable
      */
     protected $savingCallbacks = [];
 
+    /**
+     * @var string
+     */
+    protected $size = '';
+
     /**
      * Field constructor.
      *
@@ -239,6 +244,22 @@ class Field implements Renderable
         $this->callResolving();
     }
 
+    /**
+     * 设置为小尺寸.
+     */
+    public function small()
+    {
+        $this->size = 'sm';
+    }
+
+    /**
+     * 设置为大尺寸.
+     */
+    public function large()
+    {
+        $this->size = 'lg';
+    }
+
     /**
      * @param array $options
      *

+ 2 - 1
src/Form/Field/Checkbox.php

@@ -95,7 +95,8 @@ class Checkbox extends MultipleSelect
         $checkbox
             ->inline($this->inline)
             ->check($this->value())
-            ->class($this->getElementClassString());
+            ->class($this->getElementClassString())
+            ->size($this->size);
 
         $this->addVariables([
             'checkbox' => $checkbox,

+ 2 - 1
src/Form/Field/Radio.php

@@ -78,7 +78,8 @@ class Radio extends Field
         $radio
             ->inline($this->inline)
             ->check($this->value())
-            ->class($this->getElementClassString());
+            ->class($this->getElementClassString())
+            ->size($this->size);
 
         $this->addVariables([
             'radio' => $radio,

+ 5 - 0
src/Form/Field/Select.php

@@ -236,6 +236,11 @@ class Select extends Field
             'cascadeScript' => $this->getCascadeScript(),
         ]);
 
+        if ($this->size) {
+            $this->addElementClass('form-control-'.$this->size);
+            $this->setLabelClass('control-label-'.$this->size);
+        }
+
         $this->attribute('data-value', implode(',', Helper::array($this->value())));
 
         return parent::render();

+ 5 - 0
src/Form/Field/Text.php

@@ -28,6 +28,11 @@ class Text extends Field
     {
         $this->initPlainInput();
 
+        if ($this->size) {
+            $this->addElementClass('form-control-'.$this->size);
+            $this->setLabelClass('control-label-'.$this->size);
+        }
+
         $this->defaultAttribute('type', 'text')
             ->defaultAttribute('name', $this->getElementName())
             ->defaultAttribute('value', $this->value())

+ 0 - 20
src/Widgets/Radio.php

@@ -37,26 +37,6 @@ class Radio extends Widget
         return $this->setHtmlAttribute('name', $name);
     }
 
-    /**
-     * 设置为小尺寸.
-     *
-     * @return $this
-     */
-    public function small()
-    {
-        return $this->size('sm');
-    }
-
-    /**
-     * 设置为大尺寸.
-     *
-     * @return $this
-     */
-    public function large()
-    {
-        return $this->size('lg');
-    }
-
     /**
      * 尺寸设置.
      *