diff --git a/src/Panel/Ui/FilePreviews/FileDefaultPreview.php b/src/Panel/Ui/FilePreviews/FileDefaultPreview.php deleted file mode 100644 index c17341af3a..0000000000 --- a/src/Panel/Ui/FilePreviews/FileDefaultPreview.php +++ /dev/null @@ -1,49 +0,0 @@ - - * @link https://getkirby.com - * @copyright Bastian Allgeier - * @license https://getkirby.com/license - * @since 5.0.0 - * @internal - */ -class FileDefaultPreview extends FilePreview -{ - public string $component = 'k-file-default-preview'; - - /** - * Accepts any file as last resort - */ - public static function accepts(File $file): bool - { - return true; - } - - /** - * Icon or image to display as thumbnail - */ - public function image(): array|null - { - return $this->file->panel()->image([ - 'back' => 'transparent', - 'ratio' => '1/1' - ], 'cards'); - } - - public function props(): array - { - return [ - ...parent::props(), - 'image' => $this->image() - ]; - } -} diff --git a/src/Panel/Ui/FilePreviews/FileImagePreview.php b/src/Panel/Ui/FilePreviews/FileImagePreview.php index 6b970bc51d..66a8f86201 100644 --- a/src/Panel/Ui/FilePreviews/FileImagePreview.php +++ b/src/Panel/Ui/FilePreviews/FileImagePreview.php @@ -3,6 +3,7 @@ namespace Kirby\Panel\Ui\FilePreviews; use Kirby\Cms\File; +use Kirby\Panel\Ui\FilePreview; use Kirby\Toolkit\I18n; /** @@ -14,9 +15,13 @@ * @since 5.0.0 * @internal */ -class FileImagePreview extends FileDefaultPreview +class FileImagePreview extends FilePreview { - public string $component = 'k-file-image-preview'; + public function __construct( + public File $file, + public string $component = 'k-file-image-preview' + ) { + } public static function accepts(File $file): bool { diff --git a/tests/Panel/Ui/FilePreviewTest.php b/tests/Panel/Ui/FilePreviewTest.php index 78648f2fe3..89d1a2085f 100644 --- a/tests/Panel/Ui/FilePreviewTest.php +++ b/tests/Panel/Ui/FilePreviewTest.php @@ -63,7 +63,7 @@ public function testDetails() public function testFactory() { $page = new Page(['slug' => 'test']); - $file = new File(['filename' => 'test.jpg', 'parent' => $page]); + $file = new File(['filename' => 'test.pdf', 'parent' => $page]); $preview = FilePreview::factory($file); $this->assertInstanceOf(FilePreview::class, $preview); diff --git a/tests/Panel/Ui/FilePreviews/FileDefaultPreviewTest.php b/tests/Panel/Ui/FilePreviews/FileDefaultPreviewTest.php deleted file mode 100644 index 3eb194d923..0000000000 --- a/tests/Panel/Ui/FilePreviews/FileDefaultPreviewTest.php +++ /dev/null @@ -1,41 +0,0 @@ - 'test']); - $file = new File(['filename' => 'test.jpg', 'parent' => $page]); - - $this->assertTrue(FileDefaultPreview::accepts($file)); - } - - /** - * @covers ::image - * @covers ::props - */ - public function testProps() - { - $page = new Page(['slug' => 'test']); - $file = new File(['filename' => 'test.jpg', 'parent' => $page]); - $component = new FileDefaultPreview($file); - $props = $component->props(); - - $this->assertSame('image', $props['image']['icon']); - $this->assertFalse($props['image']['cover']); - $this->assertIsString($props['image']['src']); - } -}