|
4 | 4 | 'checked' => false,
|
5 | 5 | ])
|
6 | 6 |
|
7 |
| -<div class="float-left flex flex-col gap-1"> |
8 |
| - <!-- Label Text (Clickable) --> |
| 7 | +<div class="flex flex-col gap-1"> |
9 | 8 |
|
10 |
| - <label |
11 |
| - for="{{ $name }}" |
12 |
| - class="cursor-pointer text-sm font-medium text-slate-50" |
13 |
| - > |
| 9 | + <x-input.label for="{{ $name }}"> |
14 | 10 | {{ $label }}
|
15 |
| - </label> |
| 11 | + </x-input.label> |
16 | 12 |
|
17 |
| - <!-- Hidden Checkbox Input (Starts Unchecked) --> |
18 | 13 | <input
|
19 | 14 | type="checkbox"
|
20 | 15 | id="{{ $name }}"
|
21 | 16 | name="{{ $name }}"
|
22 |
| - @if($checked) checked @endif |
| 17 | + :checked="$checked" |
23 | 18 | class="peer hidden"
|
24 | 19 | />
|
25 | 20 |
|
26 |
| - <!-- Custom Visual Checkbox --> |
27 | 21 | <span
|
28 | 22 | tabindex="0"
|
29 | 23 | role="checkbox"
|
30 |
| - aria-checked="{{ $checked ? 'true' : 'false' }}" |
31 |
| - class="h-6 w-6 cursor-pointer justify-center rounded border-2 border-slate-50 bg-indigo-400 peer-checked:border-indigo-400 peer-checked:bg-slate-50" |
| 24 | + :aria-checked="$checked" |
| 25 | + class="size-5 cursor-pointer justify-center rounded border-2 border-indigo-400 bg-slate-50 peer-checked:border-indigo-400 peer-checked:bg-indigo-400" |
32 | 26 | onclick="toggleCheckbox('{{ $name }}')"
|
33 | 27 | onkeydown="handleKeyPress(event, '{{ $name }}')"
|
34 | 28 | >
|
35 |
| - <x-lucide-check class="h-5 w-5 text-slate-50" /> |
| 29 | + <x-lucide-check class="size-4 text-slate-50" /> |
36 | 30 | </span>
|
37 | 31 | </div>
|
38 | 32 |
|
39 | 33 | <script>
|
40 | 34 | function toggleCheckbox(checkboxId) {
|
41 | 35 | const checkbox = document.getElementById(checkboxId)
|
42 |
| - const visualCheckbox = checkbox.nextElementSibling // Get the <span> |
| 36 | + const visualCheckbox = checkbox.nextElementSibling |
43 | 37 |
|
44 |
| - checkbox.checked = !checkbox.checked // Toggle checkbox state |
| 38 | + checkbox.checked = !checkbox.checked |
45 | 39 | visualCheckbox.setAttribute(
|
46 | 40 | 'aria-checked',
|
47 | 41 | checkbox.checked ? 'true' : 'false',
|
48 |
| - ) // Update aria-checked |
49 |
| - checkbox.dispatchEvent(new Event('change')) // Fire change event for Livewire/Vue if needed |
| 42 | + ) |
50 | 43 | }
|
51 | 44 |
|
52 | 45 | function handleKeyPress(event, checkboxId) {
|
53 | 46 | if (event.key === 'Enter' || event.key === ' ') {
|
54 |
| - event.preventDefault() // Prevent scrolling on Space key |
| 47 | + event.preventDefault() |
55 | 48 | toggleCheckbox(checkboxId)
|
56 | 49 | }
|
57 | 50 | }
|
58 | 51 | </script>
|
| 52 | + |
| 53 | +</div> |
0 commit comments