Skip to content

Commit

Permalink
Apply imageStyles to placeholder and main img tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrckvzn committed Jan 14, 2022
1 parent 233c870 commit b5a6fc2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ or
|`lqip`|`boolean`|See config|Use LQIP|
|`sizes`|`string`| |The image sizes attributes|
|`width`|`int`|`1000`|Used with `layout` `constrained` and `fixed`|
|`imageStyles`|`array`|`[]`|Apply styles to placeholder and main `img` tags (ex.: `[['object-fit' => 'contain']]`|

#### Examples

Expand Down
12 changes: 11 additions & 1 deletion src/ViewModels/ImageViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class ImageViewModel extends ViewModel implements Arrayable
*/
protected $width;

/**
* @var int $imageStyles Styles applied to the placeholder and main img tag
*/
protected $imageStyles;

/**
* @var ImageStyles
*/
Expand Down Expand Up @@ -123,7 +128,8 @@ public function __construct($data, $overrides = [])
$this->layout,
$this->backgroundColor,
$this->width,
$this->height
$this->height,
$this->imageStyles
);
}

Expand Down Expand Up @@ -162,6 +168,10 @@ protected function setAttributes($overrides)
$this->width = $overrides['width'] ?? null;

$this->height = $overrides['height'] ?? null;

$this->imageStyles
= $overrides['imageStyles']
?? [];
}

/**
Expand Down

0 comments on commit b5a6fc2

Please sign in to comment.