Skip to content

novadaemon/filament-pretty-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

novadaemon/filament-pretty-json

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published