diff --git a/components/image/Component.php b/components/image/Component.php new file mode 100644 index 0000000..25c6e51 --- /dev/null +++ b/components/image/Component.php @@ -0,0 +1,46 @@ +image = $image; + $this->alt = $alt; + $this->caption = $caption; + } + + /** + * Get the view / contents that represent the component. + */ + public function render(): View|Closure|string + { + return view('components.layout-image'); + } +} diff --git a/components/image/Layout.php b/components/image/Layout.php new file mode 100644 index 0000000..fc81aad --- /dev/null +++ b/components/image/Layout.php @@ -0,0 +1,72 @@ +fields([ + HikerImage::make('Image', 'image') + ->rules('required') + ->disk('public'), + + Text::make('Alternative text', 'alt') + ->rules('required') + ->help('Hidden. An alternative text is used to give a description of the content of an image so that the visually impaired and search engines can understand the image.'), + + Text::make('Caption', 'caption') + ->rules('required'), + ]), + ]; + } + + /** + * The layout's display components + */ + public function display(): array + { + return [ + DataList::make() + ->row('Image', ImageComponent::make(Storage::url($this->image))->aspectRatio('16/9')) + ->row('Alternative text', TextComponent::make($this->alt)) + ->row('Caption', TextComponent::make($this->caption)), + ]; + } + + /** + * Extract the values from the bag to store them in the database. + */ + public function fillAttributes(Baggage $bag): array + { + return $bag->only(['image', 'alt', 'caption']); + } +} diff --git a/components/image/style.scss b/components/image/style.scss new file mode 100644 index 0000000..209fd18 --- /dev/null +++ b/components/image/style.scss @@ -0,0 +1,31 @@ +.layout-image { + width: 100%; + margin: rem(32) 0; + + &__fig { + margin: 0 auto; + width: col(6, 12); + } + + &__img { + width: 100%; + } + + &__caption { + font-size: rem(12); + line-height: 130%; + margin-top: rem(12); + } + + @include mq($until: l) { + &__fig { + width: col(10, 12); + } + } + + @include mq($until: s) { + &__fig { + width: auto; + } + } +} diff --git a/components/image/view.blade.php b/components/image/view.blade.php new file mode 100644 index 0000000..1444177 --- /dev/null +++ b/components/image/view.blade.php @@ -0,0 +1,9 @@ +
bem('layout-image') }}> +
+ {{ $alt }} + + @if($caption) +
{{ $caption }}
+ @endif +
+
diff --git a/src/Components/Publishers/Image.php b/src/Components/Publishers/Image.php new file mode 100644 index 0000000..0e33a6c --- /dev/null +++ b/src/Components/Publishers/Image.php @@ -0,0 +1,60 @@ +`"; + } +}