wesselperik/nova-status-field

一个用于显示状态的 Laravel Nova 字段。

2.1.2 2022-09-14 19:06 UTC

This package is auto-updated.

Last update: 2024-09-14 23:51:53 UTC


README

Nova Status Field

Latest Version on Packagist Gitmoji

🚀 兼容 Laravel Nova 4.0!

一个用于在模型的索引和详情页面显示状态图标、可选的提示信息和文本信息的 Laravel Nova 字段。此包使用了来自 Heroicons 图标包(由设计师 Steve Schroger 提供),该图标包也被 Laravel Nova 使用。

安装

您可以使用 composer 安装此包。

composer require wesselperik/nova-status-field

接下来,将字段添加到您想要的 Nova 模型中。请参阅下面的示例。

// for example, in app/Nova/Blog.php

use WesselPerik\StatusField\StatusField;

// ...

public function fields(Request $request) {
    return [
        // Use a single value for tooltips and info...
        StatusField::make('Published')
            ->icons([
                'minus-circle' => $this->published == 0,
                'clock'        => $this->pending == 1 && $this->published == 0,
                'check-circle' => $this->pending == 0 && $this->published == 1
            ])
            ->color('primary') // optional
            ->solid(true) // optional
            ->tooltip($this->status) // optional
            ->info("Blog status: ".$this->status) // optional
            ->exceptOnForms()

        // ...or change text based on the value
        StatusField::make('Published')
            ->icons([
                'minus-circle' => $this->published == 0,
                'clock'        => $this->pending == 1 && $this->published == 0,
                'check-circle' => $this->pending == 0 && $this->published == 1
            ])
            ->tooltip([
                'minus-circle' => 'Not published',
                'clock'        => 'Pending publication',
                'check-circle' => 'Published'
            ])
            ->info([
                'minus-circle' => 'This blog is not published yet.',
                'clock'        => 'This blog is pending publication.',
                'check-circle' => 'This blog is published on '.$this->published_at->format('d-m-Y').'.'
            ])
            ->color([
                'minus-circle' => 'red-500',
                'clock'        => 'blue-500',
                'check-circle' => 'green-500'
            ])
            ->exceptOnForms()
    ];
}

可用的图标都是来自 HeroiconsSteve Schroger。默认情况下,图标使用轮廓样式,但您可以使用 solid() 函数将其更改为实心样式(请参阅上面的示例)。

可用的颜色如下 TailwindCSS 文本颜色,包括在 Laravel Nova 4 中,它们是

  • 主要
  • 灰色
  • 白色
  • 蓝色
  • 绿色
  • 红色

贡献者

许可证

MIT 许可证(MIT)。请参阅许可证文件以获取更多信息。