Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
marco76tv committed Jan 4, 2024
1 parent a913daa commit f420601
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 1 deletion.
File renamed without changes.
38 changes: 38 additions & 0 deletions Database/Migrations/2023_07_05_150102_create_menus_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Schema\Blueprint;
use Modules\Xot\Database\Migrations\XotBaseMigration;

/**
* Class .
*/
class CreateMenusTable extends XotBaseMigration
{
/**
* Run the migrations.
*/
public function up(): void
{
// -- CREATE --
$this->tableCreate(
static function (Blueprint $table): void {
$table->id();

$table->string('name');
$table->text('items')->nullable();
// $table->timestamps();
}
);
// -- UPDATE --
$this->tableUpdate(
function (Blueprint $table): void {
// if (! $this->hasColumn('order_column')) {
// $table->integer('order_column')->nullable();
// }
$this->updateTimestamps(table: $table, hasSoftDeletes: false);
}
);
}
}
19 changes: 19 additions & 0 deletions Models/Menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Modules\UI\Models;

use Illuminate\Database\Eloquent\Model;

class Menu extends Model
{
protected $fillable = [
'name',
'items',
];

protected $casts = [
'items' => 'array',
];
}
12 changes: 12 additions & 0 deletions Resources/views/components/menu/v1.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ul class="ml-auto flex items-center space-x-4">
@foreach ($menu->items as $item)
<li>
<a
href="{{ $item['url'] }}"
@if ($item['type'] === 'external') target="_blank" @endif
>
{{ $item['title'] }}
</a>
</li>
@endforeach
</ul>
18 changes: 18 additions & 0 deletions Resources/views/components/std/banner.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@props(['image' => ''])

@php
$background = $image ? 'bg-black' : 'bg-gray-100';
@endphp

<div class="relative min-h-[200px] flex items-center justify-center {{ $background }}">
@if ($image)
<div
class="absolute inset-0 z-0 opacity-50"
style="background-image: url({{ $image }}); background-size: cover; background-position: center;"
></div>
@endif

<div class="relative z-1 p-2 text-4xl text-gray-700 lg:text-6xl">
{!! $slot !!}
</div>
</div>
9 changes: 9 additions & 0 deletions Resources/views/components/std/button.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@props(['label'])

<button
type="submit"
class="inline-flex justify-center rounded-md border border-transparent bg-green-700 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-700 focus:ring-offset-2"
{{ $attributes }}
>
{{ $label }}
</button>
16 changes: 16 additions & 0 deletions Resources/views/components/std/card.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@props(['post'])

<div>
<a class="block text-black" href="{{ route('post.show', ['slug' => $post->slug]) }}">
<img
class="h-[200px] w-full object-cover object-center bg-gray-100"
src="{{ $post->getMainImage() }}"
alt=""
loading="lazy"
>
<h2 class="mt-3 text-xl">{{ $post->title }}</h2>
</a>
<div class="mt-1">
<x-post-meta :post="$post" />
</div>
</div>
3 changes: 3 additions & 0 deletions Resources/views/components/std/container.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div {{ $attributes->merge(['class' => 'max-w-wide mx-auto p-2']) }}>
{!! $slot !!}
</div>
26 changes: 26 additions & 0 deletions Resources/views/components/std/input.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@props([
'name',
'label',
'id' => '',
'type' => 'text',
])

@php
$id = $id ?: "{$name}_input";
@endphp

<div>
<label for="{{ $id }}" class="block text-sm font-medium text-gray-700">{{ $label }}</label>

<input
type="{{ $type }}"
name="{{ $name }}"
id="{{ $id }}"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-green-700 focus:ring-green-700 sm:text-sm"
{{ $attributes }}
/>

@error($name)
<div class="mt-1 text-red-500">{{ $message }}</div>
@enderror
</div>
16 changes: 16 additions & 0 deletions Resources/views/components/std/menu.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@props(['name'])

@if ($menu = \App\Models\Menu::whereName($name)->first())
<ul class="ml-auto flex items-center space-x-4">
@foreach ($menu->items as $item)
<li>
<a
href="{{ $item['url'] }}"
@if ($item['type'] === 'external') target="_blank" @endif
>
{{ $item['title'] }}
</a>
</li>
@endforeach
</ul>
@endif
11 changes: 11 additions & 0 deletions Resources/views/components/std/post-footer.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@props(['blocks'])

@if ($blocks)
<div>
<h2>See also</h2>

<div class="grid gap-4 grid-cols-1 sm:grid-cols-2">
<x-render-blocks :blocks="$blocks" />
</div>
</div>
@endif
8 changes: 8 additions & 0 deletions Resources/views/components/std/post-meta.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@props(['post'])

@if ($post->published_at)
Published on {{ $post->published_at->format('M jS, Y') }}
in <a href="{{ route('post.index', ['category' => $post->category->slug]) }}">{{ $post->category->name }}</a>
@else
[Not published]
@endif
3 changes: 3 additions & 0 deletions Resources/views/components/std/render-block.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@props(['block'])

@component("components.blocks.{$block['type']}", $block['data'] ?? []) @endcomponent
5 changes: 5 additions & 0 deletions Resources/views/components/std/render-blocks.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@props(['blocks'])

@foreach ($blocks as $block)
<x-render-block :block="$block" />
@endforeach
24 changes: 24 additions & 0 deletions Resources/views/components/std/select.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@props([
'name',
'label' => '',
'id' => '',
])

@php
$id = $id ?: "{$name}_input";
@endphp

<div>
@if ($label)
<label for="{{ $id }}" class="mb-1 block text-sm font-medium text-gray-700">{{ $label }}</label>
@endif

<select
name="{{ $name }}"
id="{{ $id }}"
class="block w-full rounded-md border-gray-300 shadow-sm focus:border-green-700 focus:ring-green-700 sm:text-sm"
{{ $attributes }}
>
{!! $slot !!}
</select>
</div>
20 changes: 20 additions & 0 deletions Resources/views/components/std/textarea.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@props([
'name',
'label',
'id' => '',
])

@php
$id = $id ?: "{$name}_input";
@endphp

<div>
<label for="{{ $id }}" class="block text-sm font-medium text-gray-700">{{ $label }}</label>

<textarea
name="{{ $name }}"
id="{{ $id }}"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-green-700 focus:ring-green-700 sm:text-sm"
{{ $attributes }}
></textarea>
</div>
42 changes: 42 additions & 0 deletions View/Components/Menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Modules\UI\View\Components;

use Illuminate\Contracts\Support\Renderable;
use Illuminate\View\Component;
use Modules\UI\Models\Menu as MenuModel;
use Modules\Xot\Actions\GetViewAction;

// use Modules\Xot\View\Components\XotBaseComponent;

/**
* .
*/
class Menu extends Component
{
public function __construct(
public string $name,
public string $tpl = 'v1')
{
}

public function render(): Renderable
{
/**
* @phpstan-var view-string
*/
$view = app(GetViewAction::class)->execute($this->tpl);
$menu = MenuModel::firstOrCreate(['name' => $this->name]);
$view_params = [
'menu' => $menu,
];
if (null === $menu->items) {
$menu->items = [];
$menu->save();
}

return view($view, $view_params);
}
}
37 changes: 37 additions & 0 deletions View/Components/Std.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Modules\UI\View\Components;

use Illuminate\Contracts\Support\Renderable;
use Illuminate\View\Component;
use Modules\Blog\Models\Post;
use Modules\Xot\Actions\GetViewAction;

// use Modules\Xot\View\Components\XotBaseComponent;

/**
* .
*/
class Std extends Component
{
public function __construct(
// public Post $article,
// public bool $showAuthor = false,
public string $tpl = 'v1')
{
}

public function render(): Renderable
{
/**
* @phpstan-var view-string
*/
$view = app(GetViewAction::class)->execute($this->tpl);

$view_params = [];

return view($view, $view_params);
}
}
2 changes: 1 addition & 1 deletion View/Components/_components.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"class_name":"BreadLink","comp_name":"bread-link","comp_ns":"Modules\\UI\\View\\Components\\BreadLink"},{"class_name":"Svg","comp_name":"svg","comp_ns":"Modules\\UI\\View\\Components\\Svg"}]
[{"class_name":"BreadLink","comp_name":"bread-link","comp_ns":"Modules\\UI\\View\\Components\\BreadLink"},{"class_name":"Menu","comp_name":"menu","comp_ns":"Modules\\UI\\View\\Components\\Menu"},{"class_name":"Std","comp_name":"std","comp_ns":"Modules\\UI\\View\\Components\\Std"},{"class_name":"Svg","comp_name":"svg","comp_ns":"Modules\\UI\\View\\Components\\Svg"}]

0 comments on commit f420601

Please sign in to comment.