Skip to content

Commit c75c206

Browse files
authored
Boolean filter for bootstrap (rappasoft#2244)
* Add BooleanFilter option for Bootstrap * Add BS4 Support * Update docs
1 parent f588ebc commit c75c206

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

docs/filter-types/filters-boolean.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ weight: 2
44
---
55

66
## Beta
7-
This is currently in beta, and will only work with Tailwind.
7+
This is currently in beta, but should work with Tailwind, Bootstrap 4 and Bootstrap 5 as of latest version
88

99
## Details
1010

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
@php
22
$defaultValue = ($filter->hasFilterDefaultValue() ? (bool) $filter->getFilterDefaultValue() : false)
33
@endphp
4-
<div class="flex flex-cols"
5-
x-data="newBooleanFilter('{{ $filter->getKey() }}', '{{ $tableName }}', '{{ $defaultValue }}')"
6-
>
7-
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />
8-
<input id="thisId" type="checkbox" name="switch" class="hidden" :checked="value" />
4+
@if($isTailwind)
5+
<div class="flex flex-cols" x-data="newBooleanFilter('{{ $filter->getKey() }}', '{{ $tableName }}', '{{ $defaultValue }}')">
6+
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />
7+
<input id="thisId" type="checkbox" name="switch" class="hidden" :checked="value" />
98

10-
<button x-cloak {{ $filterInputAttributes->merge([
11-
":class" => "(value == 1 || value == true) ? '".$filterInputAttributes['activeColor']."' : '".$filterInputAttributes['inactiveColor']."'",
12-
])
13-
->class([
14-
'relative inline-flex h-6 py-0.5 ml-4 focus:outline-none rounded-full w-10' => ($filterInputAttributes['default-styling'] ?? true)
15-
])
16-
->except(['default-styling','default-colors','activeColor','inactiveColor','blobColor'])
17-
}}>
18-
<span :class="(value == 1 || value == true) ? 'translate-x-[18px]' : 'translate-x-0.5'" class="w-5 h-5 duration-200 ease-in-out rounded-full shadow-md {{ $filterInputAttributes['blobColor'] }}"></span>
19-
</button>
20-
<template x-if="(value == 1 || value == true)">
21-
<button @click="toggleStatusWithReset" type="button"
22-
class="flex-shrink-0 ml-1 h-6 w-6 rounded-full inline-flex items-center justify-center text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:outline-none focus:bg-indigo-500 focus:text-white"
23-
>
24-
25-
<span class="sr-only">{{ __($localisationPath.'Remove filter option') }}</span>
26-
<x-heroicon-m-x-mark class="h-6 w-6" />
9+
<button x-cloak {{ $filterInputAttributes->merge([
10+
":class" => "(value == 1 || value == true) ? '".$filterInputAttributes['activeColor']."' : '".$filterInputAttributes['inactiveColor']."'",
11+
])
12+
->class([
13+
'relative inline-flex h-6 py-0.5 ml-4 focus:outline-none rounded-full w-10' => ($filterInputAttributes['default-styling'] ?? true)
14+
])
15+
->except(['default-styling','default-colors','activeColor','inactiveColor','blobColor'])
16+
}}>
17+
<span :class="(value == 1 || value == true) ? 'translate-x-[18px]' : 'translate-x-0.5'" class="w-5 h-5 duration-200 ease-in-out rounded-full shadow-md {{ $filterInputAttributes['blobColor'] }}"></span>
2718
</button>
28-
</template>
29-
</div>
19+
<template x-if="(value == 1 || value == true)">
20+
<button @click="toggleStatusWithReset" type="button"
21+
class="flex-shrink-0 ml-1 h-6 w-6 rounded-full inline-flex items-center justify-center text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:outline-none focus:bg-indigo-500 focus:text-white"
22+
>
23+
24+
<span class="sr-only">{{ __($localisationPath.'Remove filter option') }}</span>
25+
<x-heroicon-m-x-mark class="h-6 w-6" />
26+
</button>
27+
</template>
28+
</div>
29+
@elseif($isBootstrap4)
30+
<div class="custom-control custom-switch" x-data="newBooleanFilter('{{ $filter->getKey() }}', '{{ $tableName }}', '{{ $defaultValue }}')">
31+
<input type="checkbox" class="custom-control-input" id="customSwitch1" :checked="value" @click="toggleStatusWithUpdate" x-ref="switchButton">
32+
<x-livewire-tables::tools.filter-label class="custom-control-label" for="customSwitch1" :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />
33+
</div>
34+
@else
35+
<div class="form-check form-switch" x-data="newBooleanFilter('{{ $filter->getKey() }}', '{{ $tableName }}', '{{ $defaultValue }}')">
36+
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />
37+
<input id="thisId" type="checkbox" name="switch" class="form-check-input" role="switch" :checked="value" @click="toggleStatusWithUpdate" x-ref="switchButton"/>
38+
</div>
39+
@endif

0 commit comments

Comments
 (0)