field-details.blade.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. @php
  2. $html ??= []; $class = $html['class'] ?? null;
  3. @endphp
  4. <b style="line-height: 2;"><code>{{ $name }}</code></b>&nbsp;&nbsp;
  5. @if($type)<small>{{ $type }}</small>@endif&nbsp;
  6. @if($isInput && !$required)<i>optional</i>@endif &nbsp;
  7. @if($isInput && empty($hasChildren))
  8. @php
  9. $isList = Str::endsWith($type, '[]');
  10. $fullName = str_replace('[]', '.0', $fullName ?? $name);
  11. $baseType = $isList ? substr($type, 0, -2) : $type;
  12. // Ignore the first '[]': the frontend will take care of it
  13. while (\Str::endsWith($baseType, '[]')) {
  14. $fullName .= '.0';
  15. $baseType = substr($baseType, 0, -2);
  16. }
  17. // When the body is an array, the item names will be ".0.thing"
  18. $fullName = ltrim($fullName, '.');
  19. $inputType = match($baseType) {
  20. 'number', 'integer' => 'number',
  21. 'file' => 'file',
  22. default => 'text',
  23. };
  24. @endphp
  25. @if($type === 'boolean')
  26. <label data-endpoint="{{ $endpointId }}" style="display: none">
  27. <input type="radio" name="{{ $fullName }}"
  28. value="{{$component === 'body' ? 'true' : 1}}"
  29. data-endpoint="{{ $endpointId }}"
  30. data-component="{{ $component }}" @if($class)class="{{ $class }}"@endif
  31. >
  32. <code>true</code>
  33. </label>
  34. <label data-endpoint="{{ $endpointId }}" style="display: none">
  35. <input type="radio" name="{{ $fullName }}"
  36. value="{{$component === 'body' ? 'false' : 0}}"
  37. data-endpoint="{{ $endpointId }}"
  38. data-component="{{ $component }}" @if($class)class="{{ $class }}"@endif
  39. >
  40. <code>false</code>
  41. </label>
  42. @elseif($isList)
  43. <input type="{{ $inputType }}" style="display: none"
  44. @if($inputType === 'number')step="any"@endif
  45. name="{{ $fullName."[0]" }}" @if($class)class="{{ $class }}"@endif
  46. data-endpoint="{{ $endpointId }}"
  47. data-component="{{ $component }}">
  48. <input type="{{ $inputType }}" style="display: none"
  49. name="{{ $fullName."[1]" }}" @if($class)class="{{ $class }}"@endif
  50. data-endpoint="{{ $endpointId }}"
  51. data-component="{{ $component }}">
  52. @else
  53. <input type="{{ $inputType }}" style="display: none"
  54. @if($inputType === 'number')step="any"@endif
  55. name="{{ $fullName }}" @if($class)class="{{ $class }}"@endif
  56. data-endpoint="{{ $endpointId }}"
  57. value="{!! (isset($example) && (is_string($example) || is_numeric($example))) ? $example : '' !!}"
  58. data-component="{{ $component }}">
  59. @endif
  60. @endif
  61. <br>
  62. @php
  63. if($example !== null && $example !== '' && !is_array($example)) {
  64. $exampleAsString = $example;
  65. if (is_bool($example)) {
  66. $exampleAsString = $example ? "true" : "false";
  67. }
  68. $description .= " Example: `$exampleAsString`";
  69. }
  70. @endphp
  71. {!! Parsedown::instance()->text(trim($description)) !!}
  72. @if(!empty($enumValues))
  73. Must be one of:
  74. <ul style="list-style-type: square;">{!! implode(" ", array_map(fn($val) => "<li><code>$val</code></li>", $enumValues)) !!}</ul>
  75. @endif