Td

# Make

Поле Td предназначено для модификации отображения ячейки таблицы в режиме preview.

make(Closure|string $label, ?Closure $fields = null)
  • $label - название колонки,
  • $fields - замыкание возвращающее массив полей.
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
 
//...
 
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
]),
];
}
 
//...

Поле Td не отображается в формах, оно предназначено только для режима preview!

Замыкание может принимать в качестве параметра текущий элемент.

use MoonShine\ActionButtons\ActionButton;
use MoonShine\Decorations\Flex;
use MoonShine\Fields\Switcher;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
 
//...
 
public function indexFields(): array
{
return [
Td::make('Column', function (Article $v) {
if($v->active) {
return [
Text::make('Title'),
];
}
 
return [
Flex::make([
ActionButton::make('Click me', $this->detailPageUrl($v)),
Text::make('Title'),
Switcher::make('Active'),
])
];
}),
];
}
 
//...

# Поля

Указать какие поля будут отображаться в ячейке можно также через метод fields().

fields(Fields|Closure|array $fields)
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
 
//...
 
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
]),
];
}
 
//...

# Подписи полей

Метод withLabels() позволяет отобразить Label у полей в ячейке.

use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
 
//...
 
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
])
->withLabels(),
];
}
 
//...

# Атрибуты

Полю Td можно задать дополнительные атрибуты через метод tdAttributes().

/**
* @param Closure(mixed $data, ComponentAttributeBag $attributes, $td self): ComponentAttributeBag $attributes
*/
tdAttributes(Closure $attributes)
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
 
//...
 
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
])
->tdAttributes(fn (Article $data, ComponentAttributeBag $attr) => $data->getKey() === 2 ? $attr->merge([
'style' => 'background: lightgray'
]) : $attr),
];
}
 
//...