From 9bfe92b80c59aa30babb23697b6ed819af82c236 Mon Sep 17 00:00:00 2001 From: vvjlan Date: Tue, 8 Oct 2024 11:07:57 +0200 Subject: [PATCH] feat: pass inline styles --- src/Picturesque.php | 14 ++++++++++++++ src/Tags/Picture.php | 10 +++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Picturesque.php b/src/Picturesque.php index 1954897..b83e997 100644 --- a/src/Picturesque.php +++ b/src/Picturesque.php @@ -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; @@ -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 .= ''; @@ -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'; diff --git a/src/Tags/Picture.php b/src/Tags/Picture.php index f987c32..c36a422 100644 --- a/src/Tags/Picture.php +++ b/src/Tags/Picture.php @@ -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 @@ -146,6 +153,7 @@ protected function output($asset) $this->handleAltText($picture); $this->handleCssClasses($picture); + $this->handleInlineStyles($picture); $this->handleWrapperCssClasses($picture); $this->handleLazyLoading($picture);