Preview
#
IntroductionRicos editor is able to switch between several modes of previewing content that is being created within the editor itself.
A similar concept is sometimes used in social media applications (like previewing how a website link would expand into a card, or how user-generated text would look on a background). The Preview mode creates a shortened content display, ready to be expanded and is based on rules that can be modified.
The core idea is to transform the content state and to display it within RicosViewer
. This transformation is a product of content state metadata and a set of rules defined by the consumer.
It's really best to see it in action, and we suggest you check out visual examples on our storybook page.
#
Example#
Tweaking the PreviewThere are 3 fields which can be configured (optional):
transformation
#
The transformation consists of:
- the predicate the content metadata is tested for
- an action to perform if the predicate returns
true
Example:
The example above defines the following transformation rule: "if content contains more than 4 images, the preview should display four of them as a grid gallery with image counter above the last image".
- default value: Default Transformation
contentInteractionMappers
#
Allows passing interaction mappings, similar to typeMappers
and inlineStyleMappers
.
#
Content InteractionsContent interactions indicate that the preview content is collapsed and provide a way to expand it. Content interactions work at a block level and every interaction comprises the following elements:
The
preview
builder parameter - allows adding an interaction to the preview state and configuring it.In the example above, the
readMore
interaction is being applied to the previousplain
block.block data interactions array
- contains configuration data for all interactions applied to the blockUI component
- defines the appearance of the interaction element
#
Predefined InteractionsThe wix-rich-content-preview
introduces three predefined interactions (which include both preview builder API and UI components): Image Counter
, See Full Post
, and Read More
.
#
Read MoreThe Read More
interaction shortens textual content to a set number of lines and appends an ellipsis at the end.
#
See Full PostThe See Full Post
displays a text label over an overlay. Mouse click expands the full content.
#
Image CounterThe Image Counter
displays hidden image counter. By default, the counter +N
label is placed above the last visible image element. The image elements are selected by the role='img'
attribute.
- default value: Default Interaction Map
onPreviewExpand
#
A callback that's triggered upon preview expand click. Occurs once in a viewer session.
- default value: undefined