定制 unexpectedjourney/filament-toolbox 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

unexpectedjourney/filament-toolbox

Composer 安装命令:

composer require unexpectedjourney/filament-toolbox

包简介

A collection of Filament components.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Filament Toolbox is a collection of components for the Filament ecosystem.

Installation

You can install the package via composer:

composer require unexpectedjourney/filament-toolbox

Components

  • Table Columns
    • Heading and Detail Column
    • Flag Column

Heading and Detail Column

Heading and Detail Column example

The Heading and Detail Column is a way to display two separate values in the same column. This can be done natively in Filament with a TextColumn and description() but it lacks some features like built in limiting of the detail and automatic tooltips when either the heading or detail is limited.

Usage

Create a HeadingDetailColumn just like you would a TextColumn and chain a call to detail() to provide the detail contents.

use UnexpectedJourney\FilamentToolbox\Tables\Columns\HeadingDetailColumn;

HeadingDetailColumn::make('sku')
    ->detail(fn(Product $record): string => $record->name)

To control exactly what content shows in the heading you may use the heading() method.

use UnexpectedJourney\FilamentToolbox\Tables\Columns\HeadingDetailColumn;

HeadingDetailColumn::make('sku')
    ->heading(fn(Product $record): string => str($record->sku)->upper())
    ->detail(fn(Product $record): string => $record->name)

Use the limit() or words() methods to apply a limit to the number or characters or words displayed in both the heading and detail. The column detects when the limit is applied and adds a Tooltip with the full content when necessary.

HeadingDetailColumn::make('sku')
    ->detail(fn(Product $record): string => $record->name)
    ->limit(30)

Use the limitHeading(), wordsHeading(), limitDetail(), and wordsDetail() methods to limit the number of characters or words displayed in the heading or detail separately. Tooltips will be intelligently added as needed.

HeadingDetailColumn::make('sku')
    ->detail(fn(Product $record): string => $record->name)
    ->limitHeading(100)
    ->limitDetail(30)

If you do not want tooltips displayed you can disable them using the showTooltipsWhenLimited() to handle display for tooltips for both the heading and detail or by using showHeadingTooltipWhenLimited() and showDetailTooltipWhenLimited() methods to manage tooltips for the heading and detail respectively.

HeadingDetailColumn::make('sku')
    ->detail(fn(Product $record): string => $record->name)
    ->showTooltipsWhenLimited(false)
    ->limitDetail(30)

Flag Column

Heading and Detail Column example

The Flag column is used to display boolean icons for a number of true/false values on your model. Similar results can be had using Filament's built in IconColumn but the Flag Column has some extra features like tooltips or urls for each icon and displaying the icons in a grid.

Usage

Preparing your model

Your model needs an attribute that returns an array where the keys are the name of the flag and the values are the active state. This can be a JSON column or a custom Attribute getter.

Add the column

Add the FlagColumn to your columns array and call flags() passing an array of Flags to it. Each Flag must have a name that corresponds to the name of a flag in the column's state and an optional icon name for display.

use UnexpectedJourney\FilamentToolbox\Tables\Columns\FlagColumn;
use UnexpectedJourney\FilamentToolbox\Tables\Columns\FlagColumn\Flag;

FLagColumn::make('flags')
    ->flags([
        Flag::make('trashed', 'heroicon-o-trash'),
        Flag::make('on_sale', 'heroicon-o-tag'),
        Flag::make('bundle', 'heroicon-o-archive-box')
    ])

Note: If the name used when making the flag does not exist as a key in the column's state, it will be considered inactive.

You may specify the icon used by using the dedicated icon() method if you prefer. Where ever you specify the icon you may pass a closure instead of a string. Using Filament's magic closures, add $active as one of the arguments to get the active state of the flag .

FLagColumn::make('flags')
    ->flags([
        Flag::make('trashed', 'heroicon-o-trash'),
        Flag::make('on_sale', 'heroicon-o-tag'),
        Flag::make('bundle', 'heroicon-o-archive-box'),
        Flag::make('visible')
            ->icon(fn(bool $active): string => $active
                ? 'heroicon-o-eye'
                : 'heroicon-o-eye-slash')
        
    ])
Customizing the display order

The flags are displayed in the order they appear in the flags() method and by default flags that are inactive are hidden.

Showing inactive flags

To show all flags including inactive, use the showInactive() method on the FlagColumn itself.

FLagColumn::make('flags')
    ->showInactive()
    ->flags([
        Flag::make('trashed', 'heroicon-o-trash'),
        Flag::make('on_sale', 'heroicon-o-tag'),
        Flag::make('bundle', 'heroicon-o-archive-box')
    ])

Showing or hiding inactive flags can also be done on a per-flag basis by calling showWhenInactive(). You may pass a closure to conditionally show the icon if it's inactive.

FLagColumn::make('flags')
    ->flags([
        Flag::make('trashed', 'heroicon-o-trash')
            ->showWhenInactive(),
        Flag::make('on_sale', 'heroicon-o-tag'),
        Flag::make('bundle', 'heroicon-o-archive-box')
    ])

Note: Using showWhenInactive() on a flag will override showInactive() called on the FlagColumn.

Changing the colors

By default, active flags will use the primary color of your Filament theme and inactive flags will use a gray color. You may change this for the entire FlagColumn or on each specific flag by calling the activeColor() and inactiveColor() methods.

Note: Colors defined on a flag will override colors defined on the FlagColumn.

use Filament\Support\Colors\Color;

FLagColumn::make('flags')
    ->activeColor('success')
    ->inactiveColor(Color::Stone)
    ->flags([
        Flag::make('trashed', 'heroicon-o-trash')
            ->activeColor('danger'),
        Flag::make('on_sale', 'heroicon-o-tag'),
        Flag::make('bundle', 'heroicon-o-archive-box')
    ])
Default icons

If an icon is not specified for a flag a default icon will be used. The default active icon is 'heroicon-o-check-circle' and the default inactive icon is 'heroicon-o-x-circle'. Call the 'activeIcon()' and 'inactiveIcon()' methods on the FlagColumn to set their respective icons.

FLagColumn::make('flags')
    ->activeIcon('heroicon-o-check')
    ->inactiveIcon('heroicon-o-x-mark')
    ->flags([...])
Customizing the grid

By default, the FlagColumn displays the flags in a grid of 3 icons. This is controlled much the same way that Filament layout components like Filament\Tables\Columns\Layout\Grid control their grid. Call the columns(). Refer to Filament's documentation for further details: https://filamentphp.com/docs/3.x/tables/layout#controlling-column-width-using-a-grid


##### Tooltips
Tooltips are hidden by default but can be shown for all flags calling the `showTooltips()` method on the `FlagColumn`. 

```PHP
FLagColumn::make('flags')
    ->showTooltips()
    ->flags([...])

Tooltips are a title cased string automatically generated from the name of the flag. You may specify your own tooltip by calling the tooltip() method on an individual flag. You may pass a closure to this method and access the active state of the flag by adding an $active argument.

FLagColumn::make('flags')
    ->showTooltips()
    ->flags([
        Flag::make('published', 'heroicon-o-calendar')
            ->tootip(fn(bool $active, Model $record): string => $active 
                ? 'Published on '.$record->published_at
                : 'Not published')
    ])

Note: Tooltips will always be displayed for a flag when it is explicitly set even if the FlagColumn is not configured to show tooltips.

Urls

Each individual flag can optionally be a link. Call the url() method on the flag to turn it into a link. This method accepts a string or a closure. You have access to the active state of the flag by adding an $active argument to your closure.

FLagColumn::make('flags')
    ->showTooltips()
    ->flags([
        Flag::make('published', 'heroicon-o-calendar')
            ->url(fn(bool $active, Model $record): ?string => $active 
                ? $record->getUrl()
                : null)
    ])

You can open urls in a new tab by setting the openInNewTab parameter of the url() method or by calling the dedicated openUrlInNewTab() method on the flag.

FLagColumn::make('flags')
    ->showTooltips()
    ->flags([
        Flag::make('published', 'heroicon-o-calendar')
            ->url(...)
            ->openUrlInNewTab()
    ])

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

unexpectedjourney/filament-toolbox 适用场景与选型建议

unexpectedjourney/filament-toolbox 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「unexpectedjourney」 「filament-toolbox」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 unexpectedjourney/filament-toolbox 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 unexpectedjourney/filament-toolbox 我们能提供哪些服务?
定制开发 / 二次开发

基于 unexpectedjourney/filament-toolbox 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-03