Skip to content

Commit

Permalink
Allow passing identifying classes down
Browse files Browse the repository at this point in the history
This will be helpful for locating HTML in tests...maybe.
  • Loading branch information
JSn1nj4 committed Jul 7, 2024
1 parent 91c19f7 commit a7ba50c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
18 changes: 13 additions & 5 deletions app/View/Components/Card/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,36 @@ class Wrapper extends Component
*
* @return void
*/
public function __construct(string $size = 'sm', string $type = 'default', ?string $margin = null, ?string $padding = null)
public function __construct(
string $size = 'sm',
string $type = 'default',
string|null $margin = null,
string|null $padding = null,
string $extraClasses = '',
)
{
$this->size = $size;
$this->type = $type;

if(isset($margin)) {
if (isset($margin)) {
$this->margin = $margin;
} else if($this->type === 'transparent') {
} else if ($this->type === 'transparent') {
$this->margin = '';
} else {
$this->margin = 'my-4';
}

if(isset($padding)) {
if (isset($padding)) {
$this->padding = $padding;
} else if($this->type === 'transparent') {
} else if ($this->type === 'transparent') {
$this->padding = 'px-4';
} else {
$this->padding = 'p-4';
}

$this->classes = "relative {$this->margin} max-w-{$this->size} w-full z-30 {$this->padding} {$this->typeClasses[$this->type]}";

if (strlen($extraClasses) > 0) $this->classes .= " {$extraClasses}";
}

/**
Expand Down
11 changes: 6 additions & 5 deletions app/View/Components/Post/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ class Card extends Component
* Create a new component instance.
*/
public function __construct(
public Post $post,
public string $size = 'sm',
public string|null $margin = null,
public string|null $padding = null,
public readonly bool $livewire = false,
public Post $post,
public string $size = 'sm',
public string|null $margin = null,
public string|null $padding = null,
public readonly bool $livewire = false,
public readonly string $extraClasses = '',
) {}

/**
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/post/card.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@php /** @var App\Models\Post $post */ @endphp
<x-card.wrapper :size="$size" :padding="$padding" :margin="$margin">
<x-card.wrapper :extra-classes='$extraClasses' :size="$size" :padding="$padding" :margin="$margin">
@if($post->image)
<x-card.thumbnail
href="{{ route('blog.show', compact('post')) }}"
Expand Down
9 changes: 8 additions & 1 deletion resources/views/livewire/blog-index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ public function with(): array
<root>
@if($this->hasPosts())
@foreach($posts as $post)
<x-post.card :post="$post" size="none" padding="p-0" margin="mb-12 last:mb-0" livewire />
<x-post.card
extra-classes='blog-post-card'
:post="$post"
size="none"
padding="p-0"
margin="mb-12 last:mb-0"
livewire
/>
@endforeach
{{ $posts->links() }}
@else
Expand Down

0 comments on commit a7ba50c

Please sign in to comment.