title('Settings') * ->body('Configure your preferences') * ->action(Button::make()->label('Save')) */ class Card extends Component { protected mixed $title = null; protected mixed $description = null; protected array $body = []; protected array $actions = []; /** * Set the card title. */ public function title(mixed $title): static { $this->title = $title; return $this; } /** * Set the card description (subtitle under title). */ public function description(mixed $description): static { $this->description = $description; return $this; } /** * Add content to the card body. */ public function body(mixed ...$items): static { foreach ($items as $item) { $this->body[] = $item; } return $this; } /** * Add action buttons/links to the card footer. */ public function actions(mixed ...$items): static { foreach ($items as $item) { $this->actions[] = $item; } return $this; } /** * Render the card to HTML. */ public function render(): string { $attrs = $this->buildAttributes(['card', 'rounded-lg', 'border', 'bg-white', 'dark:bg-zinc-800']); $html = ''; // Header (title + description) if ($this->title !== null || $this->description !== null) { $html .= '
'; if ($this->title !== null) { $html .= '

'.$this->resolve($this->title).'

'; } if ($this->description !== null) { $html .= '

'.$this->resolve($this->description).'

'; } $html .= '
'; } // Body if (! empty($this->body)) { $html .= '
'; foreach ($this->body as $item) { $html .= $this->raw($item); } $html .= '
'; } // Actions if (! empty($this->actions)) { $html .= '
'; foreach ($this->actions as $action) { $html .= $this->raw($action); } $html .= '
'; } $html .= ''; return $html; } }