Skip to content

Commit fe816c3

Browse files
committed
Refactor TasksBoard to replace Flex with CardFlex for improved layout and responsiveness
1 parent b98dfd5 commit fe816c3

File tree

3 files changed

+189
-2
lines changed

3 files changed

+189
-2
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
@php
2+
use Filament\Actions\Action;
3+
use Filament\Actions\ActionGroup;
4+
use Filament\Schemas\Components\Component;
5+
6+
$gap = $getGap();
7+
$wrap = $shouldWrap();
8+
$justify = $getJustify();
9+
$align = $getAlign();
10+
@endphp
11+
12+
<div
13+
{{
14+
$attributes
15+
->merge($getExtraAttributes(), escape: false)
16+
->class([
17+
'flex',
18+
// Gap classes optimized for cards
19+
'gap-1' => $gap === 'xs',
20+
'gap-2' => $gap === 'sm',
21+
'gap-3' => $gap === 'md',
22+
'gap-4' => $gap === 'lg',
23+
// Wrap settings
24+
'flex-wrap' => $wrap,
25+
'flex-nowrap' => !$wrap,
26+
// Justify settings
27+
'justify-start' => $justify === 'start',
28+
'justify-center' => $justify === 'center',
29+
'justify-end' => $justify === 'end',
30+
'justify-between' => $justify === 'between',
31+
'justify-around' => $justify === 'around',
32+
'justify-evenly' => $justify === 'evenly',
33+
// Align settings
34+
'items-start' => $align === 'start',
35+
'items-center' => $align === 'center',
36+
'items-end' => $align === 'end',
37+
'items-baseline' => $align === 'baseline',
38+
'items-stretch' => $align === 'stretch',
39+
])
40+
}}
41+
>
42+
@foreach ($getChildSchema()->getComponents() as $component)
43+
@if (($component instanceof Action) || ($component instanceof ActionGroup))
44+
<div class="flex-shrink-0">
45+
{{ $component }}
46+
</div>
47+
@else
48+
@php
49+
$hiddenJs = $component->getHiddenJs();
50+
$visibleJs = $component->getVisibleJs();
51+
$componentStatePath = $component->getStatePath();
52+
@endphp
53+
54+
<div
55+
x-data="filamentSchemaComponent({
56+
path: @js($componentStatePath),
57+
containerPath: @js($statePath),
58+
isLive: @js($schemaComponent->isLive()),
59+
$wire,
60+
})"
61+
@if ($afterStateUpdatedJs = $schemaComponent->getAfterStateUpdatedJs())
62+
x-init="{!! implode(';', array_map(
63+
fn (string $js): string => '$wire.watch(' . Js::from($componentStatePath) . ', ($state, $old) => ($state !== undefined) && eval(' . Js::from($js) . '))',
64+
$afterStateUpdatedJs,
65+
)) !!}"
66+
@endif
67+
@if (filled($visibilityJs = match ([filled($hiddenJs), filled($visibleJs)]) {
68+
[true, true] => "(! ({$hiddenJs})) && ({$visibleJs})",
69+
[true, false] => "! ({$hiddenJs})",
70+
[false, true] => $visibleJs,
71+
default => null,
72+
}))
73+
x-bind:class="{ 'fi-hidden': ! ({!! $visibilityJs !!}) }"
74+
x-cloak
75+
@endif
76+
@class([
77+
'flex-shrink-0' => !($component instanceof Component && $component->canGrow()),
78+
'flex-grow' => ($component instanceof Component) && $component->canGrow(),
79+
])
80+
>
81+
{{ $component }}
82+
</div>
83+
@endif
84+
@endforeach
85+
</div>

resources/views/livewire/card.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
<div
1111
@class([
12-
'mb-3 bg-white dark:bg-gray-900 rounded-lg shadow-sm border border-gray-200 dark:border-gray-800 overflow-hidden transition-all duration-150 hover:shadow-md',
12+
'mb-3 bg-white dark:bg-gray-900 rounded-lg shadow-sm border border-gray-200 dark:border-gray-800 overflow-hidden transition-all duration-100 hover:shadow-md',
1313
'cursor-pointer' => $hasActions || $hasCardAction,
14-
'cursor-pointer transition-all duration-200 ease-in-out hover:transform hover:-translate-y-0.5 hover:shadow-lg hover:border-gray-300 active:transform active:translate-y-0 active:shadow-md' => $hasCardAction,
14+
'cursor-pointer transition-all duration-100 ease-in-out hover:shadow-lg hover:border-neutral-400 active:shadow-md' => $hasCardAction,
1515
'cursor-default' => !$hasActions && !$hasCardAction,
1616
])
1717
@if($this->getBoard()->getReorderBy() !== null)

src/Components/CardFlex.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Relaticle\Flowforge\Components;
6+
7+
use Closure;
8+
use Filament\Actions\Action;
9+
use Filament\Actions\ActionGroup;
10+
use Filament\Schemas\Components\Component;
11+
use Illuminate\Contracts\Support\Htmlable;
12+
13+
class CardFlex extends Component
14+
{
15+
/**
16+
* @var view-string
17+
*/
18+
protected string $view = 'flowforge::components.card-flex';
19+
20+
protected string $gap = 'xs';
21+
protected bool $wrap = true;
22+
protected string $justify = 'start';
23+
protected string $align = 'center';
24+
25+
/**
26+
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $schema
27+
*/
28+
final public function __construct(array | Closure $schema)
29+
{
30+
$this->schema($schema);
31+
}
32+
33+
/**
34+
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $schema
35+
*/
36+
public static function make(array | Closure $schema): static
37+
{
38+
$static = app(static::class, ['schema' => $schema]);
39+
$static->configure();
40+
41+
return $static;
42+
}
43+
44+
/**
45+
* Enable/disable wrapping on smaller screens.
46+
*/
47+
public function wrap(bool $wrap = true): static
48+
{
49+
$this->wrap = $wrap;
50+
return $this;
51+
}
52+
53+
/**
54+
* Set horizontal justification.
55+
*/
56+
public function justify(string $justify): static
57+
{
58+
$this->justify = $justify;
59+
return $this;
60+
}
61+
62+
/**
63+
* Set vertical alignment.
64+
*/
65+
public function align(string $align): static
66+
{
67+
$this->align = $align;
68+
return $this;
69+
}
70+
71+
/**
72+
* Get the gap size.
73+
*/
74+
public function getGap(): string
75+
{
76+
return $this->gap;
77+
}
78+
79+
/**
80+
* Check if wrapping is enabled.
81+
*/
82+
public function shouldWrap(): bool
83+
{
84+
return $this->wrap;
85+
}
86+
87+
/**
88+
* Get justification setting.
89+
*/
90+
public function getJustify(): string
91+
{
92+
return $this->justify;
93+
}
94+
95+
/**
96+
* Get alignment setting.
97+
*/
98+
public function getAlign(): string
99+
{
100+
return $this->align;
101+
}
102+
}

0 commit comments

Comments
 (0)