Skip to content

Commit

Permalink
feat: indicate card has image even if only placeholder (#478)
Browse files Browse the repository at this point in the history
* fix: Card datebadge position

* feat: add has-image class to card if has placeholder
  • Loading branch information
thorbrink authored Nov 21, 2024
1 parent 76f8a6e commit 466765b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
48 changes: 48 additions & 0 deletions source/php/Component/Card/Card.Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace ComponentLibrary\Component\Card;

use ComponentLibrary\Cache\CacheInterface;
use PHPUnit\Framework\TestCase;

class CardTest extends TestCase {

/**
* @testdox Test that the class is added to the classList if image is truthy
*/
public function testFoo() {
$controller = $this->getController(['image' => true]);
$controller->init();


$this->assertContains('c-card--has-image', $controller->getData()['classList']);
}

/**
* @testdox Test that the class is added to the classList if hasPlaceholder and date is truthy
*/
public function testBar() {
$controller = $this->getController(['hasPlaceholder' => true]);
$controller->init();

$this->assertContains('c-card--has-image', $controller->getData()['classList']);
}

private function getController(array $data = []): Card
{
$default = [
'buttons' => false,
'classList' => [],
'collapsible' => false,
'content' => false,
'dateBadge' => false,
'hasPlaceholder' => false,
'image' => false,
'link' => false,
'ratio' => false,
'tags' => false,
];

return new Card(array_merge($default, $data), $this->createMock(CacheInterface::class));
}
}
2 changes: 1 addition & 1 deletion source/php/Component/Card/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function init()
$this->data['afterContentSlotHasData'] = $this->slotHasData('afterContent');
$this->data['floatingSlotHasData'] = $this->slotHasData('floating');

if ($image) {
if ($image || $hasPlaceholder) {
$this->data['classList'][] = $this->getBaseClass('has-image', true);
}

Expand Down
1 change: 1 addition & 0 deletions source/php/Component/Card/components/heading.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@group([
'classList' => [$baseClass."__heading-container"],
'justifyContent' => 'space-between',
'alignItems' => 'center',
])
Expand Down
1 change: 1 addition & 0 deletions source/php/Component/Card/partials/body.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="{{$baseClass}}__body">
@includeWhen($dateBadge && $date, 'Card.components.datebadge')
@if($floatingSlotHasData)
<div class="{{$baseClass}}__floating">
{!! $floating !!}
Expand Down
1 change: 0 additions & 1 deletion source/php/Component/Card/views/base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
$imageExists || ($hasPlaceholder && !$imageExists),
'Card.components.image'
)
@includeWhen($dateBadge && $date, 'Card.components.datebadge')
@includeWhen($collapsible || $heading || $subHeading || $meta || $date || $content || $floatingSlotHasData, 'Card.partials.body')
@includeWhen($tags || $buttons, 'Card.partials.footer')

0 comments on commit 466765b

Please sign in to comment.