Skip to content

Commit

Permalink
Merge pull request #19 from visuellverstehen/feat/allow-inline-styles
Browse files Browse the repository at this point in the history
feat: pass inline styles
  • Loading branch information
juliawarnke authored Oct 8, 2024
2 parents b192376 + 9bfe92b commit a4d93f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Picturesque.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ public function css(string $css): self
return $this->class($css);
}

public function style(string $style): self
{
$this->options->put('style', $style);

return $this;
}

public function data(): array
{
return $this->data;
Expand Down Expand Up @@ -172,6 +179,7 @@ public function html(): string
$output .= empty($img['loading']) ? '' : " loading='{$img['loading']}'";
$output .= empty($img['width']) ? '' : " width='{$img['width']}'";
$output .= empty($img['height']) ? '' : " height='{$img['height']}'";
$output .= empty($img['style']) ? '' : " style='{$img['style']}'";
$output .= ">";

$output .= '</picture>';
Expand Down Expand Up @@ -340,6 +348,12 @@ private function makeImg()
$img['class'] = $css;
}

// inline style
$style = $this->options->get('style');
if (! empty($style)) {
$img['style'] = $style;
}

// lazy loading
if ($this->options->get('lazy')) {
$img['loading'] = 'lazy';
Expand Down
10 changes: 9 additions & 1 deletion src/Tags/Picture.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ protected function handleCssClasses(Picturesque &$picture)
$picture->css($class);
}
}


protected function handleInlineStyles(Picturesque &$picture)
{
if ($style = $this->params->get('style')) {
$picture->style($style);
}
}

protected function handleLazyLoading(Picturesque &$picture)
{
// if no param is set, config default is used
Expand Down Expand Up @@ -146,6 +153,7 @@ protected function output($asset)

$this->handleAltText($picture);
$this->handleCssClasses($picture);
$this->handleInlineStyles($picture);
$this->handleWrapperCssClasses($picture);
$this->handleLazyLoading($picture);

Expand Down

0 comments on commit a4d93f6

Please sign in to comment.