From 0f4c9bbf5aa440d2af12922a886f6535857b9e84 Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Wed, 19 Feb 2020 14:46:06 -0800 Subject: [PATCH] feature: add custom avatar ability in search --- README.md | 4 ++ src/ExternalImage.php | 68 +------------------------------- src/ExternalImageAsAvatar.php | 24 ++++++++++++ src/ExternalImageBase.php | 74 +++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 66 deletions(-) create mode 100644 src/ExternalImageAsAvatar.php create mode 100644 src/ExternalImageBase.php diff --git a/README.md b/README.md index 610f3c1..158e89d 100644 --- a/README.md +++ b/README.md @@ -74,3 +74,7 @@ Set the image with avatar-like style (rounded and fixed height + width). ExternalImage::make('Image') ->avatar(), ``` + +### Search Avatar + +If you want the external image to act as an [Avatar](https://nova.laravel.com/docs/2.0/resources/fields.html#avatar-field) in the search box use `ExternalImageAsAvatar` instead of `ExternalImage` diff --git a/src/ExternalImage.php b/src/ExternalImage.php index 4edccb6..24fbd18 100644 --- a/src/ExternalImage.php +++ b/src/ExternalImage.php @@ -2,69 +2,5 @@ namespace Chaseconey\ExternalImage; -use Laravel\Nova\Fields\Field; - -class ExternalImage extends Field -{ - /** - * The field's component. - * - * @var string - */ - public $component = 'external-image'; - - /** - * - * Add prefix to the image string provided - * - * @param string $prefix - * @return ExternalImage - */ - public function prefix(string $prefix) - { - return $this->withMeta(['prefix' => $prefix]); - } - - /** - * Set the image with avatar-like style - * - * @return $this - */ - public function avatar() - { - return $this->width(42)->height(42)->radius(99); - } - - /** - * Set the width of the image - * - * @param int $width - * @return $this - */ - public function width(int $width) - { - return $this->withMeta(['width' => $width]); - } - - /** - * Set the height of the image - * - * @param int $height - * @return $this - */ - public function height(int $height) - { - return $this->withMeta(['height' => $height]); - } - - /** - * Set the border-radius of the image - * - * @param int $radius - * @return $this - */ - public function radius(int $radius) - { - return $this->withMeta(['borderRadius' => $radius]); - } -} +class ExternalImage extends ExternalImageBase +{} diff --git a/src/ExternalImageAsAvatar.php b/src/ExternalImageAsAvatar.php new file mode 100644 index 0000000..c0c6225 --- /dev/null +++ b/src/ExternalImageAsAvatar.php @@ -0,0 +1,24 @@ +value; + } + + public function isRounded() + { + return $this->rounded; + } + +} diff --git a/src/ExternalImageBase.php b/src/ExternalImageBase.php new file mode 100644 index 0000000..754a241 --- /dev/null +++ b/src/ExternalImageBase.php @@ -0,0 +1,74 @@ +withMeta(['prefix' => $prefix]); + } + + /** + * Set the image with avatar-like style + * + * @return $this + */ + public function avatar() + { + $this->rounded = true; + + return $this->width(42)->height(42)->radius(99); + } + + /** + * Set the width of the image + * + * @param int $width + * @return $this + */ + public function width(int $width) + { + return $this->withMeta(['width' => $width]); + } + + /** + * Set the height of the image + * + * @param int $height + * @return $this + */ + public function height(int $height) + { + return $this->withMeta(['height' => $height]); + } + + /** + * Set the border-radius of the image + * + * @param int $radius + * @return $this + */ + public function radius(int $radius) + { + return $this->withMeta(['borderRadius' => $radius]); + } +}