Skip to content

Commit e208f1f

Browse files
committed
fix: render checkbox list infolist as disabled checkboxes instead of text
Replace TextEntry with ViewEntry using a custom Blade template that shows all options as disabled checkboxes, making it easy to see which are checked vs unchecked instead of a wall of text.
1 parent 392e17e commit e208f1f

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@php
2+
$state = $getState();
3+
$options = $state['options'] ?? [];
4+
$selected = $state['selected'] ?? [];
5+
$optionColors = $state['optionColors'] ?? [];
6+
@endphp
7+
8+
<x-dynamic-component :component="$getEntryWrapperView()" :entry="$entry">
9+
@if (empty($options))
10+
<span class="text-gray-400 dark:text-gray-500">&mdash;</span>
11+
@else
12+
<div class="flex flex-col gap-2">
13+
@foreach ($options as $value => $label)
14+
@php
15+
$isChecked = in_array($value, $selected, false);
16+
$color = $optionColors[$value] ?? null;
17+
@endphp
18+
<label class="flex items-center gap-x-3">
19+
<input
20+
type="checkbox"
21+
disabled
22+
@checked($isChecked)
23+
@if ($color)
24+
style="--c-400: {{ $color }}; --c-600: {{ $color }};"
25+
@endif
26+
class="fi-checkbox-input rounded border-gray-300 text-primary-600 shadow-sm focus:ring-0 disabled:opacity-70 dark:border-gray-600 dark:bg-gray-800"
27+
/>
28+
<span class="text-sm text-gray-950 dark:text-white">{{ $label }}</span>
29+
</label>
30+
@endforeach
31+
</div>
32+
@endif
33+
</x-dynamic-component>

src/Filament/Integration/Components/Infolists/MultiChoiceEntry.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,42 @@
44

55
namespace Relaticle\CustomFields\Filament\Integration\Components\Infolists;
66

7-
use Filament\Infolists\Components\Entry;
8-
use Filament\Infolists\Components\TextEntry as BaseTextEntry;
7+
use Filament\Infolists\Components\ViewEntry;
8+
use Relaticle\CustomFields\Enums\CustomFieldsFeature;
9+
use Relaticle\CustomFields\FeatureSystem\FeatureManager;
910
use Relaticle\CustomFields\Filament\Integration\Base\AbstractInfolistEntry;
10-
use Relaticle\CustomFields\Filament\Integration\Concerns\Shared\ConfiguresBadgeColors;
11+
use Relaticle\CustomFields\Models\Contracts\HasCustomFields;
1112
use Relaticle\CustomFields\Models\CustomField;
12-
use Relaticle\CustomFields\Services\ValueResolver\LookupMultiValueResolver;
1313

1414
final class MultiChoiceEntry extends AbstractInfolistEntry
1515
{
16-
use ConfiguresBadgeColors;
17-
18-
public function __construct(
19-
private readonly LookupMultiValueResolver $valueResolver
20-
) {}
21-
22-
public function make(CustomField $customField): Entry
16+
public function make(CustomField $customField): ViewEntry
2317
{
24-
$entry = BaseTextEntry::make($customField->getFieldName())
25-
->label($customField->name);
26-
27-
$entry = $this->applyBadgeColorsIfEnabled($entry, $customField);
18+
$options = $customField->options->pluck('name', 'id')->all();
19+
$optionColors = $this->resolveOptionColors($customField);
20+
21+
return ViewEntry::make($customField->getFieldName())
22+
->label($customField->name)
23+
->view('custom-fields::infolists.checkbox-list-entry')
24+
->state(fn (HasCustomFields $record): array => [
25+
'options' => $options,
26+
'selected' => $record->getCustomFieldValue($customField) ?? [],
27+
'optionColors' => $optionColors,
28+
]);
29+
}
2830

29-
return $entry->state(fn (mixed $record): array => $this->valueResolver->resolve($record, $customField));
31+
/** @return array<int, string> */
32+
private function resolveOptionColors(CustomField $customField): array
33+
{
34+
if (! FeatureManager::isEnabled(CustomFieldsFeature::FIELD_OPTION_COLORS)
35+
|| ! $customField->settings->enable_option_colors
36+
|| $customField->lookup_type) {
37+
return [];
38+
}
39+
40+
return $customField->options
41+
->filter(fn ($option): bool => filled($option->settings->color))
42+
->pluck('settings.color', 'id')
43+
->all();
3044
}
3145
}

0 commit comments

Comments
 (0)