@props([ 'delta' => null, // float | null. null => no prior baseline ("new"); 0 => flat; >0 up; <0 down 'comparisonLabel' => null, // optional small label e.g. "vs last week" 'size' => 'sm', // 'sm' | 'xs' ]) @php $isNew = $delta === null; $isFlat = !$isNew && abs($delta) < 0.05; $isUp = !$isNew && !$isFlat && $delta > 0; $cls = match (true) { $isNew => 'bg-indigo-100/80 text-indigo-700 ring-indigo-200/60', $isFlat => 'bg-zinc-100/80 text-zinc-600 ring-zinc-200/60', $isUp => 'bg-emerald-100/80 text-emerald-700 ring-emerald-200/60', default => 'bg-rose-100/80 text-rose-700 ring-rose-200/60', }; $padding = $size === 'xs' ? 'px-1.5 py-0.5 text-[10px]' : 'px-2 py-0.5 text-xs'; @endphp @if ($isNew) New @elseif ($isFlat) Flat @elseif ($isUp) {{ number_format(abs($delta), 1) }}% @else {{ number_format(abs($delta), 1) }}% @endif @if ($comparisonLabel) {{ $comparisonLabel }} @endif