Skip to content

Commit

Permalink
Merge pull request #1382 from moonshine-software/vertical-span
Browse files Browse the repository at this point in the history
Vertical span
  • Loading branch information
lee-to authored Dec 18, 2024
2 parents b7bfce3 + 48e0d65 commit 491ab27
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Contracts/src/UI/TableBuilderContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public function editable(): static;
public function isEditable(): bool;

/**
* @param ?Closure(FieldContract $field, ComponentContract $default, static $ctx): ComponentContract $title
* @param ?Closure(FieldContract $field, ComponentContract $default, static $ctx): ComponentContract $value
* @param null|int|Closure(FieldContract $field, ComponentContract $default, static $ctx): ComponentContract $title
* @param null|int|Closure(FieldContract $field, ComponentContract $default, static $ctx): ComponentContract $value
*/
public function vertical(?Closure $title = null, ?Closure $value = null): static;
public function vertical(null|Closure|int $title = null, null|Closure|int $value = null): static;

public function isVertical(): bool;

Expand Down
5 changes: 4 additions & 1 deletion src/Laravel/src/Pages/Crud/DetailPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ protected function getDetailComponent(?DataWrapperContract $item, Fields $fields
return TableBuilder::make($fields)
->cast($this->getResource()->getCaster())
->items([$item])
->vertical()
->vertical(
title: $this->getResource()->isDetailInModal() ? 3 : 2,
value: $this->getResource()->isDetailInModal() ? 9 : 10,
)
->simple()
->preview();
}
Expand Down
12 changes: 8 additions & 4 deletions src/UI/src/Components/Table/TableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,21 @@ private function resolveRows(): TableRowsContract
$attributes = $field->getWrapperAttributes()->jsonSerialize();
$title = Column::make([
Heading::make($field->getLabel())->h(4),
])->columnSpan(1);
])->columnSpan(\is_int($this->verticalTitleCallback) ? $this->verticalTitleCallback : 2);

$value = Column::make([
Div::make([
$field,
])->customAttributes($attributes),
])->columnSpan(11);
])->columnSpan(\is_int($this->verticalTitleCallback) ? $this->verticalTitleCallback : 10);

$components[] = Grid::make([
\is_null($this->verticalTitleCallback) ? $title : \call_user_func($this->verticalTitleCallback, $field, $title, $this),
\is_null($this->verticalValueCallback) ? $value : \call_user_func($this->verticalValueCallback, $field, $value, $this),
\is_null($this->verticalTitleCallback) || \is_int($this->verticalTitleCallback)
? $title
: \call_user_func($this->verticalTitleCallback, $field, $title, $this),
\is_null($this->verticalValueCallback) || \is_int($this->verticalValueCallback)
? $value
: \call_user_func($this->verticalValueCallback, $field, $value, $this),
]);
}

Expand Down
10 changes: 5 additions & 5 deletions src/UI/src/Traits/Table/TableStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ trait TableStates

protected bool $isVertical = false;

protected ?Closure $verticalTitleCallback = null;
protected null|Closure|int $verticalTitleCallback = null;

protected ?Closure $verticalValueCallback = null;
protected null|Closure|int $verticalValueCallback = null;

protected bool $isEditable = false;

Expand Down Expand Up @@ -88,10 +88,10 @@ public function isEditable(): bool
}

/**
* @param ?Closure(FieldContract $field, ComponentContract $default, static $ctx): ComponentContract $title
* @param ?Closure(FieldContract $field, ComponentContract $default, static $ctx): ComponentContract $value
* @param null|int|Closure(FieldContract $field, ComponentContract $default, static $ctx): ComponentContract $title
* @param null|int|Closure(FieldContract $field, ComponentContract $default, static $ctx): ComponentContract $value
*/
public function vertical(?Closure $title = null, ?Closure $value = null): static
public function vertical(null|Closure|int $title = null, null|Closure|int $value = null): static
{
$this->isVertical = true;
$this->verticalTitleCallback = $title;
Expand Down

0 comments on commit 491ab27

Please sign in to comment.