From 1ccfee6e3efed9479c2401d4699b12bf41c9bfb6 Mon Sep 17 00:00:00 2001 From: Grigoriy Ivanov Date: Mon, 16 Oct 2023 16:12:02 +0300 Subject: [PATCH 1/3] Add tests for class and style in TD --- tests/Unit/Screen/TDForTableTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Unit/Screen/TDForTableTest.php b/tests/Unit/Screen/TDForTableTest.php index d8609da607..2f9dc94c74 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'])); From 0ebb80e5e177644bbf4ae4b5f8f03d1b6c8576cc Mon Sep 17 00:00:00 2001 From: Grigoriy Ivanov Date: Mon, 16 Oct 2023 16:12:59 +0300 Subject: [PATCH 2/3] add style and class for td.blade --- resources/views/partials/layouts/td.blade.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/resources/views/partials/layouts/td.blade.php b/resources/views/partials/layouts/td.blade.php index 2c01e6261b..800e33f45e 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) From a0f6044745cafd8fdcfde9a6ffc07fb613f5fa53 Mon Sep 17 00:00:00 2001 From: Grigoriy Ivanov Date: Mon, 16 Oct 2023 16:13:31 +0300 Subject: [PATCH 3/3] Add style and class for TD --- src/Screen/TD.php | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Screen/TD.php b/src/Screen/TD.php index 596c396ef6..aca0bd2fa4 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, ]); }