Browse Source

1、为 Show\Field 添加了 bool() 和 bold() 方法;2、把 label 和 badge 中插入的 &nbsp 改为普通空格。

vagra 4 years ago
parent
commit
d2b04908f3
1 changed files with 37 additions and 2 deletions
  1. 37 2
      src/Show/Field.php

+ 37 - 2
src/Show/Field.php

@@ -334,7 +334,7 @@ HTML;
 
             return collect($value)->map(function ($name) use ($class, $background) {
                 return "<span class='label bg-{$class}' $background>$name</span>";
-            })->implode('&nbsp;');
+            })->implode(' ');
         });
     }
 
@@ -375,7 +375,7 @@ HTML;
 
             return collect($value)->map(function ($name) use ($class, $background) {
                 return "<span class='badge bg-{$class}' $background>$name</span>";
-            })->implode('&nbsp;');
+            })->implode(' ');
         });
     }
 
@@ -567,6 +567,41 @@ HTML;
         return $this;
     }
 
+    /**
+     * @param string $color
+     *
+     * @return $this
+     */
+    public function bold($color = null)
+    {
+        $color = $color ?: Admin::color()->dark80();
+
+        return $this->unescape()->as(function ($value) use ($color) {
+            if (! $value) {
+                return $value;
+            }
+
+            return "<b style='color: {$color}'>$value</b>";
+        });
+    }
+    
+    /**
+     * Display field as boolean , `✓` for true, and `✗` for false.
+     *
+     * @param array $map
+     * @param bool  $default
+     *
+     * @return $this
+     */
+    public function bool(array $map = [], $default = false)
+    {
+        return $this->unescape()->as(function ($value) use ($map, $default) {
+            $bool = empty($map) ? $value : Arr::get($map, $value, $default);
+
+            return $bool ? '<i class="feather icon-check font-md-2 font-w-600 text-primary"></i>' : '<i class="feather icon-x font-md-1 font-w-600 text-70"></i>';
+        });
+    }
+
     /**
      * @param  mixed  $value
      * @param  callable  $callback