whitecube / nova-flexible-content

Flexible Content & Repeater Fields for Laravel Nova
MIT License
788 stars 228 forks source link

Collapsed Preview Attribute #406

Open fedeisas opened 1 year ago

fedeisas commented 1 year ago

This implements the preview attribute for the collapsed view as suggested on #378

image

Usage

use Whitecube\NovaFlexibleContent\Layouts\Layout;
use Laravel\Nova\Fields\Text;

class MyLayout extends Layout
{
    protected $name = 'checkbox';

    protected $title = 'Checkbox';

    // You can define which attribute will be bind for the collapsed preview here
    public $collapsedPreviewAttribute = 'label';

    public function fields(): array
    {
        return [
            Text::make('Label', 'label'),
            Text::make('Label', 'title'),
        ];
    }

    // ...or here
    public function collapsedPreviewAttribute()
    {
        return 'title';
    }
}

Usage

This is an optional feature. It improves the UI by allowing differentiation between layouts by marking some attribute (probably the key or something unique) to be displayed on the collapsable header for hints.

voidgraphics commented 1 year ago

Hello, thanks for the PR. What field types does this work with? Just textfields, or do selects work as well?

fedeisas commented 1 year ago

Yes, I guess Booleans can be casted to Yes/No and from Selects we could use "selection.name" not sure though. What are your ideas on it @voidgraphics?

fedeisas commented 1 year ago

@voidgraphics just did a quick check, as it displays field.value:

LorenzoAlu commented 1 year ago

I'll try this branch but doesn't works.

Maybe you have to versioned dist folder?

fedeisas commented 1 year ago

Yes, you need to build the dist files

LorenzoAlu commented 1 year ago

@fedeisas thanks ;)

Maybe you can commit dist folder on this branch?

fedeisas commented 1 year ago

@LorenzoAlu I think a PR with a committed dist/ folder has even fewer chances to get merged. I'm hoping @voidgraphics will merge this someday.

I'm using this branch in the meantime.

LorenzoAlu commented 1 year ago

@fedeisas thank you 💣

fedeisas commented 6 months ago

@voidgraphics ping