Skip to content

Commit

Permalink
Update SupportServiceProvider.php
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Feb 5, 2025
1 parent 577c18a commit 41b1902
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions packages/support/src/SupportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,10 @@ public function packageBooted(): void

ComponentAttributeBag::macro('grid', function (array | int | null $columns = [], GridDirection $direction = GridDirection::Row): ComponentAttributeBag {
if (! is_array($columns)) {
$columns = ['@lg' => $columns];
$columns = ['lg' => $columns];
}

$columns = collect($columns)
->filter()
->mapWithKeys(fn (int $columns, string $breakpoint): array => [str_replace($breakpoint, '@', 'c') => $columns])
->all();
$columns = array_filter($columns);

$columns['default'] ??= 1;

Expand All @@ -188,8 +185,8 @@ public function packageBooted(): void
])
->style(array_map(
fn (string $breakpoint, int $columns): string => match ($direction) {
GridDirection::Row => "--cols-{$breakpoint}: repeat({$columns}, minmax(0, 1fr))",
GridDirection::Column => "--cols-{$breakpoint}: {$columns}",
GridDirection::Row => '--cols-' . str_replace('@', 'c', $breakpoint) . ": repeat({$columns}, minmax(0, 1fr))",
GridDirection::Column => '--cols-' . str_replace('@', 'c', $breakpoint) . ": {$columns}",
},
array_keys($columns),
array_values($columns),
Expand All @@ -205,15 +202,9 @@ public function packageBooted(): void
$start = ['default' => $start];
}

$span = collect($span)
->filter()
->mapWithKeys(fn (int | string $span, string $breakpoint): array => [str_replace($breakpoint, '@', 'c') => $span])
->all();
$span = array_filter($span);

$start = collect($start)
->filter()
->mapWithKeys(fn (int $start, string $breakpoint): array => [str_replace($breakpoint, '@', 'c') => $start])
->all();
$start = array_filter($start);

return $this
->class([
Expand All @@ -236,15 +227,15 @@ public function packageBooted(): void
])
->style([
...array_map(
fn (string $breakpoint, int | string $span): string => "--col-span-{$breakpoint}: " . match ($span) {
fn (string $breakpoint, int | string $span): string => "--col-span-" . str_replace('@', 'c', $breakpoint) . ": " . match ($span) {
'full' => '1 / -1',
default => "span {$span} / span {$span}",
},
array_keys($span),
array_values($span),
),
...array_map(
fn (string $breakpoint, int $start): string => "--col-start-{$breakpoint}: {$start}",
fn (string $breakpoint, int $start): string => "--col-start-" . str_replace('@', 'c', $breakpoint) . ": " . $start,
array_keys($start),
array_values($start),
),
Expand Down

0 comments on commit 41b1902

Please sign in to comment.