-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ebd535
commit d07960e
Showing
4 changed files
with
105 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Kirby\Panel\Ui\FilePreviews; | ||
|
||
use Kirby\Cms\File; | ||
use Kirby\Panel\Ui\FilePreview; | ||
|
||
/** | ||
* Fallback file preview component | ||
* | ||
* @package Kirby Panel | ||
* @author Nico Hoffmann <[email protected]> | ||
* @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() | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Kirby\Panel\Ui\FilePreviews; | ||
|
||
use Kirby\Cms\File; | ||
use Kirby\Cms\Page; | ||
use Kirby\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Kirby\Panel\Ui\FilePreviews\FileDefaultPreview | ||
* @covers ::__construct | ||
*/ | ||
class FileDefaultPreviewTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::accepts | ||
*/ | ||
public function testAccepts() | ||
{ | ||
$page = new Page(['slug' => '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']); | ||
} | ||
} |