81 lines
2.0 KiB
PHP
Raw Normal View History

2022-06-01 10:15:55 +03:00
<?php
namespace App\View\Components\Table;
use App\Abstracts\View\Component;
class Td extends Component
{
public $class;
public $override;
public $kind;
public $hiddenMobile;
2022-06-01 10:15:55 +03:00
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(
string $class = '', string $override = '', string $kind = '', bool $hiddenMobile = false,
2022-06-01 10:15:55 +03:00
) {
$this->override = $this->getOverride($override);
$this->kind = $kind;
$this->hiddenMobile = $hiddenMobile;
2022-06-01 10:15:55 +03:00
$this->class = $this->getClass($class);
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|string
*/
public function render()
{
return view('components.table.td');
}
protected function getOverride($override)
{
return explode(',', $override);
}
protected function getClass($class)
{
if (in_array('class', $this->override)) {
return $class;
}
if ($this->hiddenMobile) {
$class = $class . ' ' . 'hidden sm:table-cell';
}
2022-06-01 10:15:55 +03:00
$default = 'py-4 whitespace-nowrap text-sm font-normal text-black truncate';
switch ($this->kind) {
case 'amount':
$default = $class . ' ltr:pl-6 rtl:pr-6 ltr:text-right rtl:text-left ' . $default;
break;
case 'right':
$default = $class . ' ltr:pl-6 rtl:pr-6 ltr:text-right rtl:text-left ' . $default;
break;
case 'bulkaction':
$default = $class . 'ltr:pr-6 rtl:pl-6 hidden sm:table-cell';
break;
2022-06-01 10:15:55 +03:00
case 'action':
$default = 'p-0';
break;
case 'cursor-none':
$default = $class . ' cursor-default ' . $default;
break;
default:
$default = $class . ' ltr:pr-6 rtl:pl-6 ltr:text-left rtl:text-right cursor-pointer ' . $default;
}
return $default;
}
}