nova-flexible-content icon indicating copy to clipboard operation
nova-flexible-content copied to clipboard

Collapsed Preview Attribute

Open fedeisas opened this issue 3 years ago • 9 comments

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.

fedeisas avatar Oct 13 '22 01:10 fedeisas

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

voidgraphics avatar Oct 13 '22 07:10 voidgraphics

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 avatar Oct 13 '22 14:10 fedeisas

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

  • for BooleanGroups it shows a JSON encoded representation
  • for Select it shows the option key
  • for Boolean it shows true|false as string

fedeisas avatar Oct 13 '22 15:10 fedeisas

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

Maybe you have to versioned dist folder?

LorenzoAlu avatar Jan 19 '23 13:01 LorenzoAlu

Yes, you need to build the dist files

fedeisas avatar Jan 19 '23 13:01 fedeisas

@fedeisas thanks ;)

Maybe you can commit dist folder on this branch?

LorenzoAlu avatar Jan 19 '23 13:01 LorenzoAlu

@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.

fedeisas avatar Jan 19 '23 15:01 fedeisas

@fedeisas thank you 💣

LorenzoAlu avatar Jan 19 '23 15:01 LorenzoAlu

@voidgraphics ping

fedeisas avatar Feb 18 '24 14:02 fedeisas