Created
December 4, 2024 08:22
-
-
Save Kovah/6286c97a516731a1904a93f6fc3d2e89 to your computer and use it in GitHub Desktop.
Health Dashboard: Trend View Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@props(['current' => 0, 'previous' => 0, 'negative' => false]) | |
@php | |
$icon = 'dash'; | |
$class = 'text-gray-500'; | |
$title = 'Not enough data'; | |
if ($current > 0 && $previous > 0) { | |
$diff = $current - $previous; | |
$diffPercent = round($diff / $current * 100, 2); | |
$title = sprintf('Previous: %s = %s', \Illuminate\Support\Number::format(round($previous, 2), locale: 'de_DE'), $diffPercent . '%'); | |
if ($diffPercent > 2.5) { | |
// negative means a rising value is colored red to indicate a bad increase (e.g. resting heart rate) | |
$class = $negative ? 'text-red-500' : 'text-green-500'; | |
$icon = $diffPercent > 5 ? 'angles-up' : 'angle-up'; | |
} elseif ($diffPercent < -2.5) { | |
$class = $negative ? 'text-green-500' : 'text-red-500'; | |
$icon = $diffPercent > 5 ? 'angles-down' : 'angle-down'; | |
} | |
} | |
@endphp | |
<span> | |
<x-icon :name="$icon" class="icon {{ $class }}" x-data="{}" x-tooltip="{ | |
content: '{{ $title }}', | |
theme: $store.theme, | |
}"/> | |
</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment