Skip to content
QwryAI
Documentation
Pages

Widgets

States

Show or hide parts of a Widget based on its data, with states and conditions.

What are States?

States show or hide parts of a Widget based on its current data. Each state has a name and a visibility setting, and wraps a section of the Widget's code. While the state is visible, its content shows. Otherwise the content is hidden.

Manage states in the builder's States tab.

A Widget with no states yet.

Using States in the Code

In the code, a state is a Stack element: an invisible wrapper whose widgetStateName is the state's name and whose visible holds its condition. For example, a state named "Loading" that shows while fetchStatus is loading:

jsx
<Card size="md">
  <Stack key="loading" widgetStateName="Loading" visible={{ "$state": "/fetchStatus", "eq": "loading" }}>
    <Text value="Please wait..." />
  </Stack>
  <Title value={title} size="sm" />
  <Text value={description} />
</Card>

While fetchStatus is loading, the "Please wait..." text shows. The rest of the Widget shows as usual whatever the state.

You don't need to write visible by hand. Wrap the content in a Stack with a key, click Add state in the States tab and set the condition there; the builder writes visible for you. Add state uses the first Stack that isn't a state yet, and names it NewState.

To show a loading state while a function runs, set the variable its condition checks in the function's On start follow-up.

Multiple Visible States

Several states can be visible at once. Each state controls only its own content.

jsx
<Card size="md">
  <Stack key="signedIn" widgetStateName="SignedIn" visible={{ "$state": "/customerName" }}>
    <Text value={`Welcome back, ${customerName}`} />
  </Stack>
  <Stack key="hasItems" widgetStateName="HasItems" visible={{ "$state": "/itemCount", "gt": 0 }}>
    <Text value={`You have ${itemCount} items in your cart`} />
  </Stack>
  <Button label="Continue" onClickAction={{ functionName: "next" }} />
</Card>

Here, when both "SignedIn" and "HasItems" are visible, the visitor sees the welcome, the item count and the button. When only "SignedIn" is visible, the item count is hidden, but the welcome and the button still show.

Visibility Modes

Each state's Visibility decides when its content shows.

ModeBehavior
Always visibleThe content always shows.
Always hiddenThe content never shows.
ConditionalThe content shows only when the conditions are met.

Operators

With Conditional visibility, each condition compares a Widget variable with a value using an operator.

OperatorDescription
equal toExactly matches the value.
not equal toDoesn't match the value.
containsThe variable contains the value as text.
not containsThe variable doesn't contain the value as text.
greater thanThe variable is greater than a number.
greater than or equalThe variable is greater than or equal to a number.
less thanThe variable is less than a number.
less than or equalThe variable is less than or equal to a number.
is emptyThe variable has no value. No comparison value is needed.
is not emptyThe variable has a value. No comparison value is needed.

Combining Conditions

Click Add condition to add more conditions, and join them with And or Or.

  • And: every condition must be true for the content to show.
  • Or: at least one condition must be true.

Each condition after the first has a connector to the one before it. This lets you build rules like:

status equal to "Shipped" And trackingUrl is not empty

Condition Groups

For more complex rules, click Add group to put conditions in groups. Each group is checked as a unit, and groups are joined to each other with And or Or.

This lets you write rules like:

(status equal to "Shipped" And carrier equal to "DHL") Or (status equal to "Shipped" And carrier equal to "UPS")

Here, the content shows when the order has shipped with either DHL or UPS. Use Delete group to remove a group, and Remove all to clear the conditions.

States Tab in the Builder

Manage states in the States tab. Click a state to open it. Each state has:

  • Name: the state's name, for example Loading, Error or Success. It's saved in the code as widgetStateName.
  • Visibility: Always visible, Always hidden or Conditional.
  • Conditions: with Conditional, one or more conditions with a variable, an operator, a value and connectors.

Changes apply as you make them, and the preview updates straight away. To remove a state, use Delete state. Its content stays in the Widget and shows as usual.

When a Widget has no states, the tab shows No states defined yet with Add your first state, as in the screenshot above.

Next steps

Explore the documentation