Anatomy
Input allows developers to specify a set of configurations that merchants can adjust to customize a component. Each setting provides a specific control, from simple text inputs to complex selectors.
Input settings are generally composed of standard attributes. We can classify them into two main categories:
Overview
A quick look at an input
configs type:
type Input = { type: InputType name: string label?: string configs?: ConfigsType condition?: string defaultValue?: | string | number | boolean | Partial<WeaverseImage> | { [x: string]: any } placeholder?: string helpText?: string shouldRevalidate?: boolean}
Attributes Details
Here's a breakdown of the available attributes in an input setting:
Attribute | Type | Description | Required |
---|---|---|---|
type | InputType | Specifies the kind of UI control the merchant will interact with. | ✅ |
name | string | The key of the value in the component's data. E.g., "title" binds to component.data.title . | ✅ |
defaultValue | string | number | boolean | WeaverseImage | Sets initial values for inputs and initial data for the component. | ➖ |
label | string | A label for the input to show in the Weaverse Studio's Inspector | ➖ |
placeholder | string | A placeholder text to show when the input is empty. | ➖ |
configs | AdditionalInputConfigs | Additional options for inputs require more configuration. (Available for select , toggle-group , and range input) | ➖ |
condition | string | Only displays the input if the specified condition matches. | ➖ |
helpText | string | Provides additional information or instructions for the input setting (HTML format supported). | ➖ |
shouldRevalidate | boolean | Automatically revalidate the page when the input changes to apply new data from loader function. | ➖ |
-
condition
The
condition
attribute enables developers to define conditions under which an input will be displayed. It supports the following operators: -
eq
: equals -
ne
: not equals -
gt
: greater than -
gte
: greater than or equal to -
lt
: less than -
lte
: less than or equal toThe format is as follows:
bindingName.conditionalOperator.value
.Examples:
-
clickAction.eq.openLink
- Displays the input if theclickAction
is set toopenLink
. -
imagesPerRow.gt.1
- Displays the input if the number ofimagesPerRow
is greater than 1.
-
-
helpText
The
helpText
attribute can utilize HTML, offering more expressive help instructions. This allows for the inclusion of links, emphasis using bold or italics, lists, and more.Example:
Learn more about<a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading" target="_blank" rel="noopener noreferrer" >image loading strategies</a>.
Will appear as:
Basic Inputs
text
The text input allows merchants to enter a single line of plain text. It's frequently used for capturing headings, button text, or short promotional messages.
Return: string
- The inputted text value.
Example:
{ type: "text", label: "Heading", name: "heading", defaultValue: "Testimonials", placeholder: "Enter section heading",}
Output:

textarea
The textarea input provides a multi-line text box suitable for longer descriptions, like testimonials, user reviews, or shipping and return policies.
Return: string
- The inputted multiline text value.
Example:
{ type: "textarea", label: "Customer testimonial", name: "customerTestimonial", defaultValue: "The shipping was fast, and the packaging was eco-friendly. I love shopping here!", placeholder: "Share customer shopping experience..."}
Output:

switch
The switch input provides a toggle option. This can be useful for enabling or disabling product availability, promotional features, or customer reviews.
Return: boolean
- Indicates whether the switch is turned on (true
) or off (false
).
Example:
{ type: "switch", label: "Enable discount", name: "enableDiscount", defaultValue: true,}
Output:

range
The range input lets merchants select a value within a set range. This can be used for adjusting quantities, setting percentages, or customizing display sizes.
Return: number
- The selected value within the defined range.
Example:
{ type: "range", label: "Discount percentage", name: "discountPercentage", defaultValue: 10, configs: { min: 5, max: 50, step: 1, unit: "%" }}
Output:

configs
details:
Property | Type | Description | Required |
---|---|---|---|
min | number | The minimum value the range input can have. | ✅ |
max | number | The maximum value the range input can have. | ✅ |
step | number | The intervals between values in the range. | ✅ |
unit | string | A unit of measure displayed next to the value (e.g., px , % ). Purely for display purposes. | ➖ |
select
The select input provides a dropdown list, allowing merchants to select one option from a predefined list of options.
Return: string
- The selected option's value.
Example:
{ type: "select", label: "Image aspect ratio", name: "imageAspectRatio", configs: { options: [ { value: "auto", label: "Adapt to image" }, { value: "1/1", label: "1/1" }, { value: "3/4", label: "3/4" }, { value: "4/3", label: "4/3" }, ] }, defaultValue: "auto"}
Output:


configs
details:
Property | Type | Description | Required |
---|---|---|---|
options | Array<OptionType> | An array containing all options. Each option must be an object. | ✅ |