You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

journal-entry-repeater.blade.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. @php
  2. use Filament\Forms\Components\Actions\Action;
  3. use Filament\Support\Enums\Alignment;
  4. use Filament\Support\Enums\MaxWidth;
  5. $containers = $getChildComponentContainers();
  6. $addAction = $getAction($getAddActionName());
  7. $cloneAction = $getAction($getCloneActionName());
  8. $deleteAction = $getAction($getDeleteActionName());
  9. $moveDownAction = $getAction($getMoveDownActionName());
  10. $moveUpAction = $getAction($getMoveUpActionName());
  11. $reorderAction = $getAction($getReorderActionName());
  12. $isReorderableWithButtons = $isReorderableWithButtons();
  13. $extraItemActions = $getExtraItemActions();
  14. $extraActions = $getExtraActions();
  15. $visibleExtraItemActions = [];
  16. $visibleExtraActions = [];
  17. $headers = $getHeaders();
  18. $renderHeader = $shouldRenderHeader();
  19. $stackAt = $getStackAt();
  20. $hasContainers = count($containers) > 0;
  21. $emptyLabel = $getEmptyLabel();
  22. $streamlined = $isStreamlined();
  23. $statePath = $getStatePath();
  24. foreach ($extraActions as $extraAction) {
  25. $visibleExtraActions = array_filter(
  26. $extraActions,
  27. fn (Action $action): bool => $action->isVisible(),
  28. );
  29. }
  30. $hasActions = $reorderAction->isVisible()
  31. || $cloneAction->isVisible()
  32. || $deleteAction->isVisible()
  33. || $moveUpAction->isVisible()
  34. || $moveDownAction->isVisible()
  35. || filled($visibleExtraItemActions);
  36. @endphp
  37. <x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
  38. <div
  39. x-data="{}"
  40. {{ $attributes->merge($getExtraAttributes())->class([
  41. 'table-repeater-component space-y-6 relative',
  42. 'streamlined' => $streamlined,
  43. match ($stackAt) {
  44. 'sm', MaxWidth::Small => 'break-point-sm',
  45. 'lg', MaxWidth::Large => 'break-point-lg',
  46. 'xl', MaxWidth::ExtraLarge => 'break-point-xl',
  47. '2xl', MaxWidth::TwoExtraLarge => 'break-point-2xl',
  48. default => 'break-point-md',
  49. }
  50. ]) }}
  51. >
  52. @if (count($containers) || $emptyLabel !== false)
  53. <div class="table-repeater-container rounded-xl relative ring-1 ring-gray-950/5 dark:ring-white/20">
  54. <table class="w-full">
  55. <thead @class([
  56. 'table-repeater-header-hidden sr-only' => ! $renderHeader,
  57. 'table-repeater-header rounded-t-xl overflow-hidden border-b border-gray-950/5 dark:border-white/20' => $renderHeader,
  58. ])>
  59. <tr class="text-xs md:divide-x md:divide-gray-950/5 dark:md:divide-white/20">
  60. @foreach ($headers as $key => $header)
  61. <th
  62. @class([
  63. 'table-repeater-header-column p-2 font-medium first:rounded-tl-xl last:rounded-tr-xl bg-gray-100 dark:text-gray-300 dark:bg-gray-900/60',
  64. match($header->getAlignment()) {
  65. 'center', Alignment::Center => 'text-center',
  66. 'right', 'end', Alignment::Right, Alignment::End => 'text-end',
  67. default => 'text-start'
  68. }
  69. ])
  70. style="width: {{ $header->getWidth() }}"
  71. >
  72. {{ $header->getLabel() }}
  73. @if ($header->isRequired())
  74. <span class="whitespace-nowrap">
  75. <sup class="font-medium text-danger-700 dark:text-danger-400">*</sup>
  76. </span>
  77. @endif
  78. </th>
  79. @endforeach
  80. @if (count($containers))
  81. <th class="table-repeater-header-column w-px last:rounded-tr-xl p-2 bg-gray-100 dark:bg-gray-900/60">
  82. <span class="sr-only">
  83. {{ trans('table-repeater::components.repeater.row_actions.label') }}
  84. </span>
  85. </th>
  86. @endif
  87. </tr>
  88. </thead>
  89. <tbody
  90. x-sortable
  91. wire:end.stop="{{ 'mountFormComponentAction(\'' . $statePath . '\', \'reorder\', { items: $event.target.sortable.toArray() })' }}"
  92. class="table-repeater-rows-wrapper divide-y divide-gray-950/5 dark:divide-white/20"
  93. >
  94. @if (count($containers))
  95. @foreach ($containers as $uuid => $row)
  96. @php
  97. $visibleExtraItemActions = array_filter(
  98. $extraItemActions,
  99. fn (Action $action): bool => $action(['item' => $uuid])->isVisible(),
  100. );
  101. @endphp
  102. <tr
  103. wire:key="{{ $this->getId() }}.{{ $row->getStatePath() }}.{{ $field::class }}.item"
  104. x-sortable-item="{{ $uuid }}"
  105. class="table-repeater-row"
  106. >
  107. @php($counter = 0)
  108. @foreach($row->getComponents() as $cell)
  109. @if($cell instanceof \Filament\Forms\Components\Hidden || $cell->isHidden())
  110. {{ $cell }}
  111. @else
  112. <td
  113. @class([
  114. 'table-repeater-column',
  115. 'p-2' => ! $streamlined,
  116. 'has-hidden-label' => $cell->isLabelHidden(),
  117. match($headers[$counter++]->getAlignment()) {
  118. 'center', Alignment::Center => 'text-center',
  119. 'right', 'end', Alignment::Right, Alignment::End => 'text-end',
  120. default => 'text-start'
  121. }
  122. ])
  123. style="width: {{ $cell->getMaxWidth() ?? 'auto' }}"
  124. >
  125. {{ $cell }}
  126. </td>
  127. @endif
  128. @endforeach
  129. <td class="table-repeater-column p-2 w-px">
  130. <ul class="flex items-center table-repeater-row-actions gap-x-3 px-2">
  131. @foreach ($visibleExtraItemActions as $extraItemAction)
  132. <li>
  133. {{ $extraItemAction(['item' => $uuid]) }}
  134. </li>
  135. @endforeach
  136. @if ($reorderAction->isVisible())
  137. <li x-sortable-handle class="shrink-0">
  138. {{ $reorderAction }}
  139. </li>
  140. @endif
  141. @if ($isReorderableWithButtons)
  142. @if (! $loop->first)
  143. <li>
  144. {{ $moveUpAction(['item' => $uuid]) }}
  145. </li>
  146. @endif
  147. @if (! $loop->last)
  148. <li>
  149. {{ $moveDownAction(['item' => $uuid]) }}
  150. </li>
  151. @endif
  152. @endif
  153. @if ($cloneAction->isVisible())
  154. <li>
  155. {{ $cloneAction(['item' => $uuid]) }}
  156. </li>
  157. @endif
  158. <li
  159. @class([
  160. 'invisible' => ! $deleteAction->isVisible(),
  161. ])
  162. >
  163. {{ $deleteAction(['item' => $uuid]) }}
  164. </li>
  165. </ul>
  166. </td>
  167. </tr>
  168. @endforeach
  169. @else
  170. <tr class="table-repeater-row table-repeater-empty-row">
  171. <td colspan="{{ count($headers) + intval($hasActions) }}"
  172. class="table-repeater-column table-repeater-empty-column p-4 w-px text-center italic">
  173. {{ $emptyLabel ?: trans('table-repeater::components.repeater.empty.label') }}
  174. </td>
  175. </tr>
  176. @endif
  177. </tbody>
  178. </table>
  179. </div>
  180. @endif
  181. @if ($addAction->isVisible() || filled($visibleExtraActions) || $hasFooterItem())
  182. <div class="flex justify-between items-start">
  183. <!-- Actions grouped to the left -->
  184. @if ($addAction->isVisible() || filled($visibleExtraActions))
  185. <ul class="flex gap-4">
  186. @if ($addAction->isVisible())
  187. <li>
  188. {{ $addAction }}
  189. </li>
  190. @endif
  191. @if (filled($visibleExtraActions))
  192. @foreach ($visibleExtraActions as $extraAction)
  193. <li>
  194. {{ $extraAction }}
  195. </li>
  196. @endforeach
  197. @endif
  198. </ul>
  199. @endif
  200. <!-- Container for Footer Item to the right -->
  201. @if($hasFooterItem())
  202. <div>
  203. {{ $getFooterItem() }}
  204. </div>
  205. @endif
  206. </div>
  207. @endif
  208. </div>
  209. </x-dynamic-component>