Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preview mode on with edit option #1220

Open
deepaksp opened this issue Mar 5, 2024 · 0 comments
Open

preview mode on with edit option #1220

deepaksp opened this issue Mar 5, 2024 · 0 comments

Comments

@deepaksp
Copy link

deepaksp commented Mar 5, 2024

Version

  • Carbon Fields: 3.6
  • WordPress: 6.4
  • PHP: 8.1

this is not an issue but a suggestion.

While Carbon Fields offers the option to disable or enable the preview mode, currently there is a limitation if you wish to display content while keeping the preview mode active. Presently, achieving this requires manually calling settings and setting the mode to preview. Here's an example:

$block = Block::make(__('Carousel'));
$block->settings['mode'] = 'preview';
$block->set_editor_style('block-preview')
    ->add_fields([
        Field::make('complex', 'vips_carousel', 'Carousel')
            ->set_layout('tabbed-horizontal')
            ->add_fields([
                Field::make('text', 'link'),
                Field::make('image', 'pc_image', 'For Desktop'),
                Field::make('image', 'm_image', 'For Mobile'),
            ]),
    ])
    ->set_render_callback(function ($fields, $attributes) {
        // Render callback logic here
    });

Screenshot 2024-03-05 190201

As seen above, the preview mode is enabled by default with an option to switch to edit mode.

One possible enhancement could be achieved by adding a new preview_edit array in the mode_map. This would allow for preview mode to be enabled by default while still providing the option to switch to edit mode.

protected $mode_map = array(
	'both' => array(
		'mode' => 'edit',
		'preview' => true,
	),
	'edit' => array(
		'mode' => 'edit',
		'preview' => false,
	),
	// this disable preview button with preview mode on
	'preview' => array(
		'mode' => 'preview',
		'preview' => false,
	),
	// preview mode on by default but we can switch to edit mode
	'preview_edit' => array(
		'mode' => 'preview',
		'preview' => true,
	),
);

It's worth noting that this approach may have drawbacks, such as initially not displaying anything when blocks load for the first time. Possible solutions to mitigate this could include adding an initial load only for the editor or utilizing CSS to add a placeholder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant