Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle date timestamp is null #514

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading