fleetCatalogue/resources/views/components/table/row.blade.php

32 lines
1.5 KiB
PHP

@props(['header' => false, 'values', 'mode'])
@php
if (!function_exists('getFieldHtml')) {
function getFieldHtml(array $args, string $field, bool $header, string $mode): string {
$type = $args['type'];
$value = $args['value'] ?? ($type === 'int' ? 0 : '');
$rowType = 'div';
$classes = ['p-3 border-opacity-40 border-red-400 grow basis-0 border min-w-[10rem] min-h-[5rem]', ($type === 'int' ? 'text-right' : 'text-left'), ($mode === 'tableVertical' ? 'min-w-[10rem] min-h-[5rem]' : ''), ($header ? 'font-bold' : '')];
$html = '<' . $rowType . ' class="' . implode(' ', $classes) . '">';
$valueHtml = match ($type) {
'string' => $value,
'int' => $value . ($args['unit'] ?? ''),
'image' => '<img class="max-h-[3.5rem]" src="' . $value . '" alt="' . $field . '">'
};
if (!empty($args['link'])) {
$html .= '<a class="text-red-400" href="' . $args['link'] . '">' . $valueHtml . '</a>';
} else {
$html .= $valueHtml;
}
$html .= '</' . $rowType . '>';
return $html;
}
}
@endphp
<div class="bg-zinc-800 hover:bg-zinc-700 first:hover:bg-zinc-800 flex {{ $mode === 'tableVertical' ? 'flex-col' : 'last:rounded-b-[1rem] first:rounded-t-[1rem]' }} {{ $header ? 'sticky self-start ' . ($mode === 'tableVertical' ? 'left-0' : 'top-0') : '' }}">
@foreach($values as $field => $value)
{!! getFieldHtml($value, $field, $header, $mode) !!}
@endforeach
</div>