-
-
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
d07960e
commit 1693b9a
Showing
7 changed files
with
113 additions
and
5 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
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,48 @@ | ||
<?php | ||
|
||
namespace Kirby\Panel\Ui\FilePreviews; | ||
|
||
use Kirby\Cms\File; | ||
use Kirby\Toolkit\I18n; | ||
|
||
/** | ||
* @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 FileImagePreview extends FileDefaultPreview | ||
{ | ||
public string $component = 'k-file-image-preview'; | ||
|
||
public static function accepts(File $file): bool | ||
{ | ||
return $file->type() === 'image'; | ||
} | ||
|
||
public function details(): array | ||
{ | ||
return [ | ||
...parent::details(), | ||
[ | ||
'title' => I18n::translate('dimensions'), | ||
'text' => $this->file->dimensions() . ' ' . I18n::translate('pixel') | ||
], | ||
[ | ||
'title' => I18n::translate('orientation'), | ||
'text' => I18n::translate('orientation.' . $this->file->dimensions()->orientation()) | ||
] | ||
]; | ||
} | ||
|
||
public function props(): array | ||
{ | ||
return [ | ||
...parent::props(), | ||
'focusable' => $this->file->panel()->isFocusable() | ||
]; | ||
} | ||
} |
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
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,57 @@ | ||
<?php | ||
|
||
namespace Kirby\Panel\Ui\FilePreviews; | ||
|
||
use Kirby\Cms\File; | ||
use Kirby\Cms\Page; | ||
use Kirby\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Kirby\Panel\Ui\FilePreviews\FileImagePreview | ||
* @covers ::__construct | ||
*/ | ||
class FileImagePreviewTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::accepts | ||
*/ | ||
public function testAccepts() | ||
{ | ||
$page = new Page(['slug' => 'test']); | ||
|
||
$file = new File(['filename' => 'test.jpg', 'parent' => $page]); | ||
$this->assertTrue(FileImagePreview::accepts($file)); | ||
|
||
$file = new File(['filename' => 'test.xls', 'parent' => $page]); | ||
$this->assertFalse(FileImagePreview::accepts($file)); | ||
} | ||
|
||
/** | ||
* @covers ::details | ||
*/ | ||
public function testDetails() | ||
{ | ||
$page = new Page(['slug' => 'test']); | ||
$file = new File(['filename' => 'test.jpg', 'parent' => $page]); | ||
$preview = new FileImagePreview($file); | ||
$details = $preview->details(); | ||
|
||
$detail = array_pop($details); | ||
$this->assertSame('Orientation', $detail['title']); | ||
|
||
$detail = array_pop($details); | ||
$this->assertSame('Dimensions', $detail['title']); | ||
} | ||
|
||
/** | ||
* @covers ::props | ||
*/ | ||
public function testProps() | ||
{ | ||
$page = new Page(['slug' => 'test']); | ||
$file = new File(['filename' => 'test.xls', 'parent' => $page]); | ||
$preview = new FileImagePreview($file); | ||
$props = $preview->props(); | ||
$this->assertFalse($props['focusable']); | ||
} | ||
} |