martin-ro/filament-charcount-field

此包已被废弃,不再维护。未建议替代包。

具有字符计数的 Filament 字段。

0.1.5 2022-06-03 04:51 UTC

This package is auto-updated.

Last update: 2023-02-03 06:22:00 UTC


README

filament-charcounted-field

为 Filament 提供字符计数 TextInput & Textarea。

此包为 Filament Admin 和 Forms 提供具有字符计数显示的 TextInput 和 Textarea 组件。

TextInput

use MartinRo\FilamentCharcountField\Components\CharcountedTextInput;

CharcountedTextInput::make('title')
    ->minCharacters(5)
    ->maxCharacters(10),

Textarea

use MartinRo\FilamentCharcountField\Components\CharcountedTextarea;

CharcountedTextarea::make('title')
    ->minCharacters(5)
    ->maxCharacters(10),

以下是组件外观的示例: Filament 字符计数字段组件示例

演示

Demo of Filament Charcounted Field components

安装

首先,安装包

composer require martin-ro/filament-charcount-field

将组件添加到 Filament 资源表单中

<?php

namespace App\Filament\Resources;

// ...
use MartinRo\FilamentCharcountField\Components\CharcountedTextInput;
use MartinRo\FilamentCharcountField\Components\CharcountedTextarea;

class PostResource extends Resource
{
    // ...
    public static function form(Form $form): Form
    {
        return $form->schema([
            // ...
            
            // TextInput
            CharcountedTextInput::make('title')
                ->label('Title')
                ->hintIcon('heroicon-o-code')
                ->hint('Title tag in header')
                ->helperText('While Google does not specify a length for title tags, usually the first 50–60 characters are displayed.')
                ->minCharacters(50)
                ->maxCharacters(60),
                           
           // Textarea 
            CharcountedTextarea::make('description')
                ->label('Description')
                ->rows(4)
                ->hintIcon('heroicon-o-code')
                ->hint('Meta description tag in header')
                ->helperText('Meta descriptions can technically be any length, but Google generally truncates snippets to ~155-160 characters.')
                ->minCharacters(155)
                ->maxCharacters(160),
                
            // ..
        ]);
    }
    // ...
}