initialValue
object in the widget file.
Firstly, it’s essential to understand the initialValue
object and its fields, along with how they are specified and assigned values.
In each widget file, you will encounter the initialValue
object, which is necessary and should be assigned to the widgetProperties
in Widget.createWidget()
. In this object, you will find the default
key, where you need to pass the initialValue
object as a stringified value within the attribute
key. This setup allows you to access the value in the props of the integrated component of the widget.
component_content
, Where component_content
is a reserved keyword for the experro-storefront, and that key will be accessible in the component’s props. However, ensure consistency by using the same key on both sides: the key you pass in the widget file’s attribute should be accessed with the same key in the component’s props.cta-layout-1.tsx
widget in the base-theme
.
cta-banner
widget incorporates multiple traits such as selecting the ‘Data Source’ via a Drop Down
, a trait for ‘Show Heading’ represented by a checkbox
, ‘Heading Text’ which is a text
input, ‘Heading color’ trait offered through a color-picker
, and several Widget
file.
To enable these traits to appear on the CTA Banner
or any other Widget's
side panel, you must specify the configuration for each trait in the widget file of the Widget
file.
Here is a initialValue
object of CTA Banner
,
initialValue
object shows how traits are configured. Each object in the traitConfig
array represents a trait visible on the side panel. It’s important to understand terms like dependent
, subDependency
, and dependencyConfig
, and know when to use them based on your needs. This understanding is key to setting up traits effectively.
props
and comonent_content
as well. You can access the trait values using the key you specified in the trait object as the ‘internalName’. Where it is must to provide the ‘internalName’ for each trait exapt some trait type which are already metioned in ###Available trait types.
For example,
internalName: "showHeadingText",
internalName: "preLoadImage"
.
traitConfig
.
experro-storefront
. To use it, you only need to specify the type
in the traitConfig
object, as shown in the initialValue
object above.
This trait provides a dropdown with two values to select from: “Content Library” and “Free Form”. The selected value will be available in the dataSource
key, which is predefined.
exp_contentModalPopUp
.
pop-up
listing all the records associated with that Content Model in Experro’s admin panel.
modelInternalName: 'zig-zag-banner'
An important aspect to note is that after selecting a record from the pop-up, the details of the selected ‘Content Library Record’ will be available under the key ‘contentModel’. You can access this data in props by destructuring ‘component_content’ and accessing the key “contentModel”. From the records data, you can retrieve the actual record data by making an API call. You’ll need to pass the data obtained in ‘contentModel’ as parameters for the API call.
Next, you can see the key provided is ‘dependent’ and ‘subDependency’.
exp_checkbox
.
config
array containing all dependencyConfig
objects structured as { name: 'internalName Of Other Trait' , value: 'Value for which you are binding a trait'}
.
Finally, you’ll need to specify an operator
for the dependencyConfig. You can use ‘AND’ to ensure that all the objects passed in dependencyConfig’s config must match the cases. Alternatively, you can use ‘OR’ to match any one case from the config.
exp_text
with dependencyConfig
.
headingText
’.
Let’s break down the dependencyConfig for better understanding. In the config array, you can see that this trait relies on two other traits: ‘showHeadingText’ must be ‘on’, and ‘dataSource’ must be ‘freeForm’. Since we’ve set the operator as ‘AND’, both conditions must be met for the dependency to take effect.
exp_imageSelector
type,
internalName
attribute, which is set as backgroundImage. Therefore, you will retrieve the value of this trait from the component’s props under the key named backgroundImage.
You simply need to assign that value to the src
prop of the ExpImage Common-component.