Skip to content

Commit

Permalink
add lang component and remove filament-translatable
Browse files Browse the repository at this point in the history
this will provide better UI and UX
  • Loading branch information
atmonshi committed Mar 11, 2024
1 parent d0e4cad commit b805dd4
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 121 deletions.
210 changes: 105 additions & 105 deletions composer.lock

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions resources/views/forms/Components/multi-lang.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@php
$statePath = $getStatePath();
$id = $getId();
$label = $getLabel();
@endphp

<div class="fi-contained rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10">
<div x-data="{ activeTab: 'tab-ar' }">
<x-filament::tabs class="!py-1 !px-2 !flex-none !m-0" :contained="true">
<div class="w-full flex items-center justify-between gap-10">
<x-filament::tabs.item icon="ri-translate" class="!px-2 !py-0.5">
<span class="!text-sm !text-primary-600">
{{ $label }}
</span>
</x-filament::tabs.item>

<div class="flex">
@foreach(config('app.locales') as $lang => $info)
<x-filament::tabs.item
class="!px-2 !py-0.5"
alpine-active="activeTab === 'tab-{{ $lang }}'"
x-on:click="activeTab = 'tab-{{ $lang }}'"
>
{{ $lang }}
</x-filament::tabs.item>
@endforeach
</div>
</div>
</x-filament::tabs>

@foreach(config('app.locales') as $lang => $info)
<div x-show="activeTab === 'tab-{{ $lang }}'" class="p-2">
<x-filament::input.wrapper :valid="! $errors->has($statePath)">
<x-filament::input
wire:model="{{ $statePath }}.{{ $lang }}"
:attributes="
\Filament\Support\prepare_inherited_attributes($getExtraInputAttributeBag())
->merge([
'id' => $id.$lang,
'placeholder' => $getPlaceholder(),
'required' => $isRequired(),
'type' => 'text',
], escape: false)
"
/>
</x-filament::input.wrapper>
</div>
@endforeach
</div>
</div>
3 changes: 0 additions & 3 deletions src/Filament/ChaosResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

namespace LaraZeus\Chaos\Filament;

use Filament\Resources\Concerns\Translatable;
use Filament\Resources\Resource;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class ChaosResource extends Resource
{
use Translatable;

protected static ?string $navigationIcon = 'tabler-point-filled';

public static function langFile(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Filament/ChaosResource/ChaosTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function make(
->label(__('zeus-chaos::core.deleted_at'))
->dateTime()
->searchable(false)
->toggleable(isToggledHiddenByDefault: true)
->toggleable(isToggledHiddenByDefault: true),
])
->actions([
Tables\Actions\ActionGroup::make([
Expand Down
4 changes: 0 additions & 4 deletions src/Filament/ChaosResource/Pages/ChaosCreateRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

namespace LaraZeus\Chaos\Filament\ChaosResource\Pages;

use Filament\Actions\LocaleSwitcher;
use Filament\Resources\Pages\CreateRecord;

class ChaosCreateRecord extends CreateRecord
{
use CreateRecord\Concerns\Translatable;

protected function getHeaderActions(): array
{
return [
...parent::getHeaderActions(),
LocaleSwitcher::make(),
];
}
}
4 changes: 0 additions & 4 deletions src/Filament/ChaosResource/Pages/ChaosEditRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
namespace LaraZeus\Chaos\Filament\ChaosResource\Pages;

use Filament\Actions;
use Filament\Actions\LocaleSwitcher;
use Filament\Resources\Pages\EditRecord;

class ChaosEditRecord extends EditRecord
{
use EditRecord\Concerns\Translatable;

protected function getHeaderActions(): array
{
return [
...parent::getHeaderActions(),
LocaleSwitcher::make(),
Actions\ViewAction::make()->visible(static::getResource()::hasPage('view')),
Actions\DeleteAction::make(),
];
Expand Down
4 changes: 0 additions & 4 deletions src/Filament/ChaosResource/Pages/ChaosListRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
namespace LaraZeus\Chaos\Filament\ChaosResource\Pages;

use Filament\Actions;
use Filament\Actions\LocaleSwitcher;
use Filament\Resources\Pages\ListRecords;

class ChaosListRecords extends ListRecords
{
use ListRecords\Concerns\Translatable;

protected function getHeaderActions(): array
{
return [
...parent::getHeaderActions(),
LocaleSwitcher::make(),
Actions\CreateAction::make()->visible(static::getResource()::hasPage('create')),
];
}
Expand Down
10 changes: 10 additions & 0 deletions src/Forms/Components/MultiLang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace LaraZeus\Chaos\Forms\Components;

use Filament\Forms\Components\TextInput;

class MultiLang extends TextInput
{
protected string $view = 'zeus-chaos::forms.components.multi-lang';
}

0 comments on commit b805dd4

Please sign in to comment.