您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

line-item-repeater.blade.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. @php
  2. use Filament\Forms\Components\Actions\Action;
  3. use Filament\Support\Enums\Alignment;
  4. use Filament\Support\Enums\MaxWidth;
  5. $containers = $getChildComponentContainersWithoutNestedSchema();
  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. foreach ($extraItemActions as $extraItemAction) {
  31. $visibleExtraItemActions = array_filter(
  32. $extraItemActions,
  33. fn (Action $action): bool => $action->isVisible(),
  34. );
  35. }
  36. $hasActions = $reorderAction->isVisible()
  37. || $cloneAction->isVisible()
  38. || $deleteAction->isVisible()
  39. || $moveUpAction->isVisible()
  40. || $moveDownAction->isVisible()
  41. || filled($visibleExtraItemActions);
  42. $hasNestedSchema = $hasNestedSchema();
  43. $totalColumns = count($headers) + ($hasActions ? 1 : 0);
  44. $nestedColspan = 4; // Nested schema spans the last 3 columns.
  45. $emptyColspan = $totalColumns - $nestedColspan;
  46. @endphp
  47. <x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
  48. <div
  49. x-data="{}"
  50. {{ $attributes->merge($getExtraAttributes())->class([
  51. 'table-repeater-component space-y-6 relative',
  52. 'streamlined' => $streamlined,
  53. match ($stackAt) {
  54. 'sm', MaxWidth::Small => 'break-point-sm',
  55. 'lg', MaxWidth::Large => 'break-point-lg',
  56. 'xl', MaxWidth::ExtraLarge => 'break-point-xl',
  57. '2xl', MaxWidth::TwoExtraLarge => 'break-point-2xl',
  58. default => 'break-point-md',
  59. }
  60. ]) }}
  61. >
  62. @if (count($containers) || $emptyLabel !== false)
  63. <div class="table-repeater-container rounded-xl relative ring-1 ring-gray-950/5 dark:ring-white/20">
  64. <table class="w-full">
  65. <thead @class([
  66. 'table-repeater-header-hidden sr-only' => ! $renderHeader,
  67. 'table-repeater-header rounded-t-xl overflow-hidden border-b border-gray-950/5 dark:border-white/20' => $renderHeader,
  68. ])>
  69. <tr class="text-xs md:divide-x md:divide-gray-950/5 dark:md:divide-white/20">
  70. @foreach ($headers as $key => $header)
  71. <th
  72. @class([
  73. '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',
  74. match($header->getAlignment()) {
  75. 'center', Alignment::Center => 'text-center',
  76. 'right', 'end', Alignment::Right, Alignment::End => 'text-end',
  77. default => 'text-start'
  78. }
  79. ])
  80. style="width: {{ $header->getWidth() }}"
  81. >
  82. {{ $header->getLabel() }}
  83. @if ($header->isRequired())
  84. <span class="whitespace-nowrap">
  85. <sup class="font-medium text-danger-700 dark:text-danger-400">*</sup>
  86. </span>
  87. @endif
  88. </th>
  89. @endforeach
  90. @if ($hasActions && count($containers))
  91. <th class="table-repeater-header-column w-px last:rounded-tr-xl p-2 bg-gray-100 dark:bg-gray-900/60">
  92. <span class="sr-only">
  93. {{ trans('table-repeater::components.repeater.row_actions.label') }}
  94. </span>
  95. </th>
  96. @endif
  97. </tr>
  98. </thead>
  99. <tbody
  100. x-sortable
  101. wire:end.stop="{{ 'mountFormComponentAction(\'' . $statePath . '\', \'reorder\', { items: $event.target.sortable.toArray() })' }}"
  102. class="table-repeater-rows-wrapper divide-y divide-gray-950/5 dark:divide-white/20"
  103. >
  104. @if (count($containers))
  105. @foreach ($containers as $uuid => $row)
  106. @php
  107. $visibleExtraItemActions = array_filter(
  108. $extraItemActions,
  109. fn (Action $action): bool => $action(['item' => $uuid])->isVisible(),
  110. );
  111. @endphp
  112. <tr
  113. wire:key="{{ $this->getId() }}.{{ $row->getStatePath() }}.{{ $field::class }}.item"
  114. x-sortable-item="{{ $uuid }}"
  115. class="table-repeater-row"
  116. >
  117. @php($counter = 0)
  118. @foreach($row->getComponents() as $cell)
  119. @if($cell instanceof \Filament\Forms\Components\Hidden || $cell->isHidden())
  120. {{ $cell }}
  121. @else
  122. <td
  123. @class([
  124. 'table-repeater-column',
  125. 'p-2' => ! $streamlined,
  126. 'has-hidden-label' => $cell->isLabelHidden(),
  127. match($headers[$counter++]->getAlignment()) {
  128. 'center', Alignment::Center => 'text-center',
  129. 'right', 'end', Alignment::Right, Alignment::End => 'text-end',
  130. default => 'text-start'
  131. }
  132. ])
  133. style="width: {{ $cell->getMaxWidth() ?? 'auto' }}"
  134. >
  135. {{ $cell }}
  136. </td>
  137. @endif
  138. @endforeach
  139. @if ($hasActions)
  140. <td class="table-repeater-column p-2 w-px">
  141. <ul class="flex items-center table-repeater-row-actions gap-x-3 px-2">
  142. @foreach ($visibleExtraItemActions as $extraItemAction)
  143. <li>
  144. {{ $extraItemAction(['item' => $uuid]) }}
  145. </li>
  146. @endforeach
  147. @if ($reorderAction->isVisible())
  148. <li x-sortable-handle class="shrink-0">
  149. {{ $reorderAction }}
  150. </li>
  151. @endif
  152. @if ($isReorderableWithButtons)
  153. @if (! $loop->first)
  154. <li>
  155. {{ $moveUpAction(['item' => $uuid]) }}
  156. </li>
  157. @endif
  158. @if (! $loop->last)
  159. <li>
  160. {{ $moveDownAction(['item' => $uuid]) }}
  161. </li>
  162. @endif
  163. @endif
  164. @if ($cloneAction->isVisible())
  165. <li>
  166. {{ $cloneAction(['item' => $uuid]) }}
  167. </li>
  168. @endif
  169. @if ($deleteAction->isVisible())
  170. <li>
  171. {{ $deleteAction(['item' => $uuid]) }}
  172. </li>
  173. @endif
  174. </ul>
  175. </td>
  176. @endif
  177. </tr>
  178. @if ($hasNestedSchema)
  179. <tr class="table-repeater-nested-row">
  180. {{-- Empty cells for the columns before the nested schema --}}
  181. @if ($emptyColspan > 0)
  182. <td colspan="{{ $emptyColspan }}"></td>
  183. @endif
  184. {{-- Nested schema spanning the last 3 columns --}}
  185. <td colspan="{{ $nestedColspan }}" class="p-4 bg-gray-50 dark:bg-gray-900">
  186. <div class="nested-schema-wrapper">
  187. @foreach ($getNestedSchema() as $nestedComponent)
  188. {{ $nestedComponent }}
  189. @endforeach
  190. </div>
  191. </td>
  192. </tr>
  193. @endif
  194. @endforeach
  195. @else
  196. <tr class="table-repeater-row table-repeater-empty-row">
  197. <td colspan="{{ count($headers) + intval($hasActions) }}"
  198. class="table-repeater-column table-repeater-empty-column p-4 w-px text-center italic">
  199. {{ $emptyLabel ?: trans('table-repeater::components.repeater.empty.label') }}
  200. </td>
  201. </tr>
  202. @endif
  203. </tbody>
  204. </table>
  205. </div>
  206. @endif
  207. @if ($addAction->isVisible() || filled($visibleExtraActions))
  208. <ul
  209. @class([
  210. 'relative flex gap-4',
  211. match ($getAddActionAlignment()) {
  212. Alignment::Start, Alignment::Left => 'justify-start',
  213. Alignment::End, Alignment::Right => 'justify-end',
  214. default => 'justify-center',
  215. },
  216. ])
  217. >
  218. @if ($addAction->isVisible())
  219. <li>
  220. {{ $addAction }}
  221. </li>
  222. @endif
  223. @if (filled($visibleExtraActions))
  224. @foreach ($visibleExtraActions as $extraAction)
  225. <li>
  226. {{ ($extraAction) }}
  227. </li>
  228. @endforeach
  229. @endif
  230. </ul>
  231. @endif
  232. </div>
  233. </x-dynamic-component>