-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor checkbox and toggle editable columns & toggle Blade component
- Loading branch information
Showing
25 changed files
with
531 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
docs-assets/app/public/js/filament/tables/components/columns/checkbox.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
docs-assets/app/public/js/filament/tables/components/columns/toggle.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
147 changes: 26 additions & 121 deletions
147
packages/forms/resources/views/components/toggle.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,41 @@ | ||
@php | ||
$offColor = $getOffColor() ?? 'gray'; | ||
$onColor = $getOnColor() ?? 'primary'; | ||
use Illuminate\View\ComponentAttributeBag; | ||
$statePath = $getStatePath(); | ||
$toggleAttributes = (new ComponentAttributeBag()) | ||
->merge([ | ||
'aria-checked' => 'false', | ||
'autofocus' => $isAutofocused(), | ||
'disabled' => $isDisabled(), | ||
'id' => $getId(), | ||
'offColor' => $getOffColor() ?? 'gray', | ||
'offIcon' => $getOffIcon(), | ||
'onColor' => $getOnColor() ?? 'primary', | ||
'onIcon' => $getOnIcon(), | ||
'state' => '$wire.' . $applyStateBindingModifiers('$entangle(\'' . $statePath . '\')'), | ||
'wire:loading.attr' => 'disabled', | ||
'wire:target' => $statePath, | ||
], escape: false) | ||
->merge($getExtraAttributes(), escape: false) | ||
->merge($getExtraAlpineAttributes(), escape: false) | ||
->class(['fi-fo-toggle']); | ||
@endphp | ||
|
||
<x-dynamic-component | ||
:component="$getFieldWrapperView()" | ||
:field="$field" | ||
:inline-label-vertical-alignment="\Filament\Support\Enums\VerticalAlignment::Center" | ||
> | ||
@capture($content) | ||
<button | ||
x-data="{ | ||
state: $wire.{{ $applyStateBindingModifiers("\$entangle('{$statePath}')") }}, | ||
}" | ||
x-bind:aria-checked="state?.toString()" | ||
x-on:click="state = ! state" | ||
x-bind:class=" | ||
state | ||
? '{{ | ||
\Illuminate\Support\Arr::toCssClasses([ | ||
match ($onColor) { | ||
'gray' => 'bg-gray-200 dark:bg-gray-700', | ||
default => 'fi-color-custom bg-custom-600', | ||
}, | ||
is_string($onColor) ? "fi-color-{$onColor}" : null, | ||
]) | ||
}}' | ||
: '{{ | ||
\Illuminate\Support\Arr::toCssClasses([ | ||
match ($offColor) { | ||
'gray' => 'bg-gray-200 dark:bg-gray-700', | ||
default => 'fi-color-custom bg-custom-600', | ||
}, | ||
is_string($offColor) ? "fi-color-{$offColor}" : null, | ||
]) | ||
}}' | ||
" | ||
x-bind:style=" | ||
state | ||
? '{{ | ||
\Filament\Support\get_color_css_variables( | ||
$onColor, | ||
shades: [600], | ||
alias: 'forms::components.toggle.on', | ||
) | ||
}}' | ||
: '{{ | ||
\Filament\Support\get_color_css_variables( | ||
$offColor, | ||
shades: [600], | ||
alias: 'forms::components.toggle.off', | ||
) | ||
}}' | ||
" | ||
{{ | ||
$attributes | ||
->merge([ | ||
'aria-checked' => 'false', | ||
'autofocus' => $isAutofocused(), | ||
'disabled' => $isDisabled(), | ||
'id' => $getId(), | ||
'role' => 'switch', | ||
'type' => 'button', | ||
'wire:loading.attr' => 'disabled', | ||
'wire:target' => $statePath, | ||
], escape: false) | ||
->merge($getExtraAttributes(), escape: false) | ||
->merge($getExtraAlpineAttributes(), escape: false) | ||
->class(['fi-fo-toggle relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent outline-none transition-colors duration-200 ease-in-out disabled:pointer-events-none disabled:opacity-70']) | ||
}} | ||
> | ||
<span | ||
class="pointer-events-none relative inline-block size-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out" | ||
x-bind:class="{ | ||
'translate-x-5 rtl:-translate-x-5': state, | ||
'translate-x-0': ! state, | ||
}" | ||
> | ||
<span | ||
class="absolute inset-0 flex h-full w-full items-center justify-center transition-opacity" | ||
aria-hidden="true" | ||
x-bind:class="{ | ||
'opacity-0 ease-out duration-100': state, | ||
'opacity-100 ease-in duration-200': ! state, | ||
}" | ||
> | ||
@if ($hasOffIcon()) | ||
<x-filament::icon | ||
:icon="$getOffIcon()" | ||
@class([ | ||
'fi-fo-toggle-off-icon size-3', | ||
match ($offColor) { | ||
'gray' => 'text-gray-400 dark:text-gray-700', | ||
default => 'text-custom-600', | ||
}, | ||
]) | ||
/> | ||
@endif | ||
</span> | ||
|
||
<span | ||
class="absolute inset-0 flex h-full w-full items-center justify-center transition-opacity" | ||
aria-hidden="true" | ||
x-bind:class="{ | ||
'opacity-100 ease-in duration-200': state, | ||
'opacity-0 ease-out duration-100': ! state, | ||
}" | ||
> | ||
@if ($hasOnIcon()) | ||
<x-filament::icon | ||
:icon="$getOnIcon()" | ||
x-cloak="x-cloak" | ||
@class([ | ||
'fi-fo-toggle-on-icon size-3', | ||
match ($onColor) { | ||
'gray' => 'text-gray-400 dark:text-gray-700', | ||
default => 'text-custom-600', | ||
}, | ||
]) | ||
/> | ||
@endif | ||
</span> | ||
</span> | ||
</button> | ||
@endcapture | ||
|
||
@if ($isInline()) | ||
<x-slot name="labelPrefix"> | ||
{{ $content() }} | ||
<x-filament::toggle | ||
:attributes="\Filament\Support\prepare_inherited_attributes($toggleAttributes)" | ||
/> | ||
</x-slot> | ||
@else | ||
{{ $content() }} | ||
<x-filament::toggle | ||
:attributes="\Filament\Support\prepare_inherited_attributes($toggleAttributes)" | ||
/> | ||
@endif | ||
</x-dynamic-component> |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
packages/support/resources/css/components/tables/columns/checkbox.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.fi-ta-checkbox { | ||
@apply flex items-center; | ||
|
||
&:not(.fi-inline) { | ||
@apply px-3 py-4; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/support/resources/css/components/tables/columns/toggle.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.fi-ta-toggle { | ||
&:not(.fi-inline) { | ||
@apply px-3 py-4; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
.fi-toggle { | ||
@apply relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent outline-none transition-colors duration-200 ease-in-out disabled:pointer-events-none disabled:opacity-70; | ||
|
||
&:disabled { | ||
@apply pointer-events-none opacity-70; | ||
} | ||
|
||
&.fi-color-custom { | ||
@apply bg-custom-600; | ||
} | ||
|
||
&:not(.fi-color-custom) { | ||
@apply bg-gray-200 dark:bg-gray-700; | ||
} | ||
|
||
& > :first-child { | ||
@apply pointer-events-none relative inline-block size-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out; | ||
|
||
& > * { | ||
@apply absolute inset-0 flex h-full w-full items-center justify-center transition-opacity; | ||
|
||
& > .fi-icon { | ||
@apply size-3; | ||
|
||
&:is(.fi-color-custom .fi-icon) { | ||
@apply text-custom-600; | ||
} | ||
|
||
&:not(.fi-color-custom .fi-icon) { | ||
@apply text-gray-400 dark:text-gray-700; | ||
} | ||
} | ||
} | ||
} | ||
|
||
&.fi-toggle-on { | ||
& > :first-child { | ||
@apply translate-x-5 rtl:-translate-x-5; | ||
|
||
& > :first-child { | ||
@apply opacity-0 ease-out duration-100; | ||
} | ||
|
||
& > :last-child { | ||
@apply opacity-100 ease-in duration-200; | ||
} | ||
} | ||
} | ||
|
||
&.fi-toggle-off { | ||
& > :first-child { | ||
@apply translate-x-0; | ||
|
||
& > :first-child { | ||
@apply opacity-100 ease-in duration-200; | ||
} | ||
|
||
& > :last-child { | ||
@apply opacity-0 ease-out duration-100; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/support/resources/views/components/toggle.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@php | ||
use Illuminate\Support\Arr; | ||
@endphp | ||
|
||
@props([ | ||
'state', | ||
'offColor' => 'gray', | ||
'offIcon' => null, | ||
'onColor' => 'primary', | ||
'onIcon' => null, | ||
]) | ||
|
||
<button | ||
x-data="{ state: {{ $state }} }" | ||
x-bind:aria-checked="state?.toString()" | ||
x-on:click="state = ! state" | ||
x-bind:class="state ? @js(Arr::toCssClasses([ | ||
'fi-toggle-on', | ||
match ($onColor) { | ||
null, 'gray' => null, | ||
default => 'fi-color-custom', | ||
}, | ||
is_string($onColor) ? "fi-color-{$onColor}" : null, | ||
])) : @js(Arr::toCssClasses([ | ||
'fi-toggle-off', | ||
match ($offColor) { | ||
null, 'gray' => null, | ||
default => 'fi-color-custom bg-custom-600', | ||
}, | ||
is_string($offColor) ? "fi-color-{$offColor}" : null, | ||
]))" | ||
x-bind:style="state ? @js(\Filament\Support\get_color_css_variables( | ||
$onColor, | ||
shades: [600], | ||
alias: 'toggle.on', | ||
)) : @js(\Filament\Support\get_color_css_variables( | ||
$offColor, | ||
shades: [600], | ||
alias: 'toggle.off', | ||
))" | ||
{{ | ||
$attributes | ||
->merge([ | ||
'role' => 'switch', | ||
'type' => 'button', | ||
], escape: false) | ||
->class(['fi-toggle']) | ||
}} | ||
> | ||
<div> | ||
<div aria-hidden="true"> | ||
{{ \Filament\Support\generate_icon_html($offIcon) }} | ||
</div> | ||
|
||
<div aria-hidden="true"> | ||
{{ \Filament\Support\generate_icon_html( | ||
$onIcon, | ||
attributes: (new \Illuminate\View\ComponentattributeBag())->merge(['x-cloak' => true], escape: false)), | ||
}} | ||
</div> | ||
</div> | ||
</button> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.