You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aquaculture/app/Admin/Extensions/Div.php

48 lines
1.3 KiB

<?php
namespace App\Admin\Extensions;
use Illuminate\Contracts\Support\Renderable; // 引入 Renderable 接口
class Div implements Renderable
{
protected $id; // div 元素的 ID
protected $width = '100%'; // div 元素的宽度,默认值为 100%
protected $height = '300px'; // div 元素的高度,默认值为 300px
/**
* Div constructor.
*
* @param string $id div 元素的 ID
* @param string|null $width div 元素的宽度,默认为 null
* @param string|null $height div 元素的高度,默认为 null
*/
public function __construct($id, $width = null, $height = null)
{
$this->id = $id; // 设置 div 的 ID
// 如果提供了宽度,则设置宽度
if (!is_null($width)) {
$this->width = $width; // 更新 div 的宽度
}
// 如果提供了高度,则设置高度
if (!is_null($height)) {
$this->height = $height; // 更新 div 的高度
}
}
/**
* 渲染 div 元素的 HTML.
*
* @return string 返回包含 div 的 HTML 字符串
*/
public function render()
{
// 使用 heredoc 语法返回包含 div 的 HTML 代码
return <<<div
<div id="{$this->id}" style="width: {$this->width}; height: {$this->height}"></div>
div;
}
}