Skip to content

Commit

Permalink
because of lightbox
Browse files Browse the repository at this point in the history
  • Loading branch information
mlantz committed Feb 6, 2024
1 parent 8683c18 commit 66a3e47
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Components/Lightbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Grafite\Html\Components;

use Grafite\Html\Components\HtmlComponent;
use Grafite\Html\Tags\Lightbox as LightboxTag;

class Lightbox extends HtmlComponent
{
public $gallery;
public $css;
public $images = [];

/**
* Create a new component instance.
*
* @return void
*/
public function __construct(
$gallery = null,
$images = null,
$css = null,
) {
$this->gallery = $gallery;
$this->images = $images;
$this->css = $css;
}

/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return function (array $data) {
return LightboxTag::make()
->items($this->images)
->thumbnailCss($this->css)
->gallery($this->gallery)
->render();
};
}
}
2 changes: 2 additions & 0 deletions src/HtmlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public function boot()
'countdown' => Components\Countdown::class,
'video' => Components\Video::class,
'image-compare' => Components\ImageCompare::class,
'parallax' => Components\Parallax::class,
'lightbox' => Components\Lightbox::class,
] as $alias => $component
) {
$blade->component($component, $alias, 'html');
Expand Down
78 changes: 78 additions & 0 deletions src/Tags/Lightbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Grafite\Html\Tags;

use Illuminate\Support\Str;
use Grafite\Html\Tags\HtmlComponent;

class Lightbox extends HtmlComponent
{
public static $gallery;
public static $thumbnailCss;

public static function gallery($value)
{
self::$gallery = $value;

return new static();
}

public static function thumbnailCss($value)
{
self::$thumbnailCss = $value;

return new static();
}

public static function stylesheets()
{
return [];
}

public static function scripts()
{
return [
'//cdn.jsdelivr.net/npm/[email protected]/index.min.js',
];
}

public static function js()
{
$id = self::$id;
$gallery = self::$gallery;

return <<<JS
document.addEventListener('DOMContentLoaded', (event) => {
});
JS;
}

public static function styles()
{
return <<<CSS
CSS;
}

public static function process()
{
self::$id = static::$attributes['id'] ?? 'html_' . Str::uuid();
self::$gallery = self::$gallery ?? 'lightbox_' . Str::uuid();

$id = self::$id;
$html = '<div id="'.$id.'" class="lightbox-gallery">';
$gallery = self::$gallery;
$items = self::$items;
$thumbnailCss = self::$thumbnailCss;

foreach ($items as $key => $item) {
$html .= "<a class='lightbox-image-container' href='{$item}' data-fslightbox='{$gallery}'>
<img class='{$thumbnailCss}' src='{$item}'>
</a>";
}

$html .= '</div>';

self::$html = $html;
}
}

0 comments on commit 66a3e47

Please sign in to comment.