novadaemon/filament-pretty-json

Read-only field to show pretty json in your filamentphp forms

Installs: 26 984

Dependents: 0

Suggesters: 0

Security: 0

Stars: 17

Watchers: 1

Forks: 4

Open Issues: 2

Language:JavaScript

v2.1.0 2024-03-18 14:59 UTC

This package is auto-updated.

Last update: 2024-05-04 23:32:01 UTC


README

Read-only field to show pretty json in your filamentphp forms.

Installation

You can install the package via composer:

composer require novadaemon/filament-pretty-json

This package supports Laravel 9, Laravel 10 and Laravel 11.

Usage

Simply use the component as you'd use any other Filament field. It's especially perfect for the resource view page where it blends right in.

use Novadaemon\FilamentPrettyJson\PrettyJson;

class FileResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                PrettyJson::make('json')
            ]);
    }
}

The value of the field can be an array or a json string

/**
 * @var string[]
 */
protected $casts = [
    'json' => 'array',
];

Customize

Optionally, you can publish the views using

php artisan vendor:publish --tag="filament-pretty-json-views"

Also, you can overwrite the css rules in your stylesheets.

pre.prettyjson {
    color: black;
    background-color: ghostwhite;
    border: 1px solid silver;
    padding: 10px 20px;
    border-radius: 4px;
    overflow: auto;
}

:is(.dark) pre.prettyjson {
    opacity: .7;
    --tw-bg-opacity: 1;
    --tw-border-opacity: 1;
    background-color: rgb(55 65 81/var(--tw-bg-opacity));
    border: 1px solid rgb(75 85 99/var(--tw-border-opacity));
    color: rgb(209 213 219/var(--tw-text-opacity));
}

:is(.dark) pre.prettyjson span.json-key {
    color: red !important;
}

:is(.dark) pre.prettyjson span.json-string {
    color: aquamarine !important;
}

:is(.dark) pre.prettyjson span.json-value {
    color: deepskyblue !important;
}

Contributing

Contributing is pretty chill and is highly appreciated! Just send a PR and/or create an issue!

Credits

License

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

Screenshot

Screenshot