Skip to content

Commit

Permalink
fix: handle date timestamp is null (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasNorin authored Feb 6, 2025
1 parent 7573425 commit 2cc03b8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion source/php/Component/Block/block.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
@endif

@if($date && $dateBadge)
@if($date && $date['timestamp'] && $dateBadge)
@datebadge(['date' => $date['timestamp'], 'classList' => ['u-margin--3', 'u-absolute--top-left@sm', 'u-absolute--top-left@md', 'u-absolute--top-left@lg', 'u-absolute--top-left@xl', 'u-level-1']])
@enddatebadge
@endif
Expand Down
7 changes: 7 additions & 0 deletions source/php/Component/Box/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public function init()
);
}

if ($date && !is_array($date)) {
$this->data['date'] = [
'timestamp' => $date,
'action' => 'formatDate'
];
}

//Make componet take string as ico param (backward compatibility)
if (is_string($icon) && !empty($icon)) {
$this->data['icon'] = ['name' => $icon];
Expand Down
15 changes: 5 additions & 10 deletions source/php/Component/Box/box.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- block.blade.php -->
<{{ $componentElement }} class="{{ $class }}" {!! $attribute !!}>

@if (!empty($date) && !empty($dateBadge))
@datebadge(['date' => $date, 'classList' => ['u-position--absolute', 'u-margin--3', 'u-fixed--top-left']])
@if (!empty($date) && $date['timestamp'] && !empty($dateBadge))
@datebadge(['date' => $date['timestamp'], 'classList' => ['u-position--absolute', 'u-margin--3', 'u-fixed--top-left']])
@enddatebadge
@endif

Expand All @@ -28,14 +28,9 @@
@endicon
@endif

@if (!empty($date) && empty($dateBadge))
@tags([
'tags' => [['label' => $date]],
'beforeLabel' => '',
'format' => false,
'classList' => [$baseClass . '__tags']
])
@endtags
@if (!empty($date) && $date['timestamp'] && empty($dateBadge))
@date($date)
@enddate
@endif

@if ($meta)
Expand Down
3 changes: 3 additions & 0 deletions source/php/Component/Box/box.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"link": "",
"ratio": "1:1",
"date": "",
"dateBadge": null,
"image": false,
"icon": ""
},
Expand All @@ -19,6 +20,7 @@
"link": "Simple href link",
"ratio": "Ratio of the block",
"date": "Preformatted date",
"dateBadge": "Display date as a badge.",
"image": "Image object (see image component), svg or raster image.",
"icon": "Icon name as a string."
},
Expand All @@ -30,6 +32,7 @@
"link": "string",
"ratio": "string",
"date": "string",
"dateBadge": "boolean",
"image": "array|boolean|ImageInterface",
"icon": "string"
},
Expand Down
2 changes: 1 addition & 1 deletion source/php/Component/Card/partials/body.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@endif
@includeWhen($meta && $metaFirst, 'Card.components.meta')
@includeWhen($heading || $subHeading || ($meta && !$metaFirst) || $icon, 'Card.components.heading')
@includeWhen($date && !$dateBadge, 'Card.components.date')
@includeWhen($date && $date['timestamp'] && !$dateBadge, 'Card.components.date')
@if ($aboveContentSlotHasData)
{!! $aboveContent !!}
@endif
Expand Down

0 comments on commit 2cc03b8

Please sign in to comment.