-
-
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.
Merge pull request #6576 from getkirby/v5/file-previews/3-image-preview
Previews 3 - Image preview class
- Loading branch information
Showing
8 changed files
with
144 additions
and
17 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
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,53 @@ | ||
<?php | ||
|
||
namespace Kirby\Panel\Ui\FilePreviews; | ||
|
||
use Kirby\Cms\File; | ||
use Kirby\Panel\Ui\FilePreview; | ||
use Kirby\Toolkit\I18n; | ||
|
||
/** | ||
* @package Kirby Panel | ||
* @author Nico Hoffmann <nico@getkirby.com> | ||
* @link https://getkirby.com | ||
* @copyright Bastian Allgeier | ||
* @license https://getkirby.com/license | ||
* @since 5.0.0 | ||
* @internal | ||
*/ | ||
class ImageFilePreview extends FilePreview | ||
{ | ||
public function __construct( | ||
public File $file, | ||
public string $component = 'k-image-file-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,69 @@ | ||
<?php | ||
|
||
namespace Kirby\Panel\Ui\FilePreviews; | ||
|
||
use Kirby\Cms\File; | ||
use Kirby\Cms\Page; | ||
use Kirby\Panel\Ui\FilePreview; | ||
use Kirby\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Kirby\Panel\Ui\FilePreviews\ImageFilePreview | ||
* @covers ::__construct | ||
*/ | ||
class ImageFilePreviewTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::accepts | ||
*/ | ||
public function testAccepts() | ||
{ | ||
$page = new Page(['slug' => 'test']); | ||
|
||
$file = new File(['filename' => 'test.jpg', 'parent' => $page]); | ||
$this->assertTrue(ImageFilePreview::accepts($file)); | ||
|
||
$file = new File(['filename' => 'test.xls', 'parent' => $page]); | ||
$this->assertFalse(ImageFilePreview::accepts($file)); | ||
} | ||
|
||
/** | ||
* @covers ::details | ||
*/ | ||
public function testDetails() | ||
{ | ||
$page = new Page(['slug' => 'test']); | ||
$file = new File(['filename' => 'test.jpg', 'parent' => $page]); | ||
$preview = new ImageFilePreview($file); | ||
$details = $preview->details(); | ||
|
||
$detail = array_pop($details); | ||
$this->assertSame('Orientation', $detail['title']); | ||
|
||
$detail = array_pop($details); | ||
$this->assertSame('Dimensions', $detail['title']); | ||
} | ||
|
||
/** | ||
* @coversNothing | ||
*/ | ||
public function testFactory() | ||
{ | ||
$page = new Page(['slug' => 'test']); | ||
$file = new File(['filename' => 'test.jpg', 'parent' => $page]); | ||
$preview = FilePreview::factory($file); | ||
$this->assertInstanceOf(ImageFilePreview::class, $preview); | ||
} | ||
|
||
/** | ||
* @covers ::props | ||
*/ | ||
public function testProps() | ||
{ | ||
$page = new Page(['slug' => 'test']); | ||
$file = new File(['filename' => 'test.xls', 'parent' => $page]); | ||
$preview = new ImageFilePreview($file); | ||
$props = $preview->props(); | ||
$this->assertFalse($props['focusable']); | ||
} | ||
} |