diff --git a/resources/views/partials/layouts/td.blade.php b/resources/views/partials/layouts/td.blade.php index 2c01e6261..800e33f45 100644 --- a/resources/views/partials/layouts/td.blade.php +++ b/resources/views/partials/layouts/td.blade.php @@ -1,6 +1,9 @@ - $width, + "$style" => $style, + ]) >
@isset($render) diff --git a/src/Screen/TD.php b/src/Screen/TD.php index 596c396ef..aca0bd2fa 100644 --- a/src/Screen/TD.php +++ b/src/Screen/TD.php @@ -39,6 +39,14 @@ class TD extends Cell * @var string|null|int */ protected $width; + /** + * @var string|null + */ + protected $style; + /** + * @var string|null + */ + protected $class; /** * @var string */ @@ -93,6 +101,26 @@ public function width($width): self return $this; } + /** + * @param string $style + */ + public function style($style): self + { + $this->style = $style; + + return $this; + } + + /** + * @param string $class + */ + public function class($class): self + { + $this->class = $class; + + return $this; + } + /** * @param string|\Orchid\Screen\Field $filter */ @@ -194,7 +222,7 @@ public function colspan(int $colspan): self public function buildTh() { return view('platform::partials.layouts.th', [ - 'width' => $this->width, + 'width' => is_numeric($this->width) ? $this->width.'px' : $this->width, 'align' => $this->align, 'sort' => $this->sort, 'sortUrl' => $this->buildSortUrl(), @@ -262,7 +290,9 @@ public function buildTd($repository, object $loop = null) 'value' => $value, 'render' => $this->render, 'slug' => $this->sluggable(), - 'width' => $this->width, + 'width' => is_numeric($this->width) ? $this->width.'px' : $this->width, + 'style' => $this->style, + 'class' => $this->class, 'colspan' => $this->colspan, ]); } diff --git a/tests/Unit/Screen/TDForTableTest.php b/tests/Unit/Screen/TDForTableTest.php index d8609da60..2f9dc94c7 100644 --- a/tests/Unit/Screen/TDForTableTest.php +++ b/tests/Unit/Screen/TDForTableTest.php @@ -26,6 +26,34 @@ public function testTdWidth(): void $this->assertStringContainsString('style="min-width:'.$width.'', $view); } + public function testTdStyle(): void + { + $style = 'border-color: red;'; + + $view = TD::make('name')->style($style)->buildTd(new Repository(['name' => 'value'])); + + $this->assertStringContainsString('style="'.$style.'', $view); + } + + public function testTdClass(): void + { + $class = 'my-custom-class'; + + $view = TD::make('name')->class($class)->buildTd(new Repository(['name' => 'value'])); + + $this->assertStringContainsString('text-start text-truncate '.$class.'', $view); + } + + public function testTdWidthWithCustomStyle(): void + { + $width = '100px'; + $style = 'border-color: red;'; + + $view = TD::make('name')->width($width)->style($style)->buildTd(new Repository(['name' => 'value'])); + + $this->assertStringContainsString('style="min-width:'.$width.'; '.$style.'', $view); + } + public function testTdWithoutWidth(): void { $view = TD::make('name')->buildTd(new Repository(['name' => 'value']));