mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Add Toggle form field
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"/js/filament.js": "/js/filament.js?id=210c4f5bc98fdf1aa267",
|
||||
"/css/filament.css": "/css/filament.css?id=4fc1a354ff8b971c2d1f"
|
||||
"/css/filament.css": "/css/filament.css?id=8efc876eb25ed3f4b6ba"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<x-forms::field-group
|
||||
:column-span="$formComponent->getColumnSpan()"
|
||||
:error-key="$formComponent->getName()"
|
||||
:for="$formComponent->getId()"
|
||||
:help-message="$formComponent->getHelpMessage()"
|
||||
:hint="$formComponent->getHint()"
|
||||
:label="$formComponent->getLabel()"
|
||||
:required="$formComponent->isRequired()"
|
||||
>
|
||||
<button
|
||||
x-data="{ enabled: @entangle($formComponent->getName()){{ Str::of($formComponent->getBindingAttribute())->after('wire:model') }} }"
|
||||
x-on:click.prevent="enabled = !enabled"
|
||||
type="button"
|
||||
{!! $formComponent->getId() ? "id=\"{$formComponent->getId()}\"" : null !!}
|
||||
{!! $formComponent->isAutofocused() ? 'autofocus' : null !!}
|
||||
{!! $formComponent->isDisabled() ? 'disabled' : null !!}
|
||||
class="relative inline-flex flex-shrink-0 h-[30px] w-[74px] border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75"
|
||||
role="switch"
|
||||
tabindex="0"
|
||||
:class="enabled ? 'bg-primary-600' : 'bg-gray-300'"
|
||||
:aria-checked="enabled ? 'true' : 'false'"
|
||||
>
|
||||
<span
|
||||
class="pointer-events-none inline-block h-[26px] w-[26px] rounded-full bg-white shadow-lg ring-0 transform transition ease-in-out duration-200"
|
||||
:class="enabled ? 'translate-x-11' : 'translate-x-0'"
|
||||
aria-hidden="true">
|
||||
</span>
|
||||
</button>
|
||||
</x-forms::field-group>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Forms\Components;
|
||||
|
||||
use Filament\Forms\Components\Concerns;
|
||||
use Filament\Forms\Components\Field;
|
||||
|
||||
class Toggle extends Field
|
||||
{
|
||||
use Concerns\CanBeAutofocused;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->default(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Resources\Forms\Components;
|
||||
|
||||
use Filament\Resources\Forms\Components\Concerns;
|
||||
|
||||
class Toggle extends \Filament\Forms\Components\Toggle
|
||||
{
|
||||
use Concerns\InteractsWithResource;
|
||||
}
|
||||
Reference in New Issue
Block a user