Conditionals
Three properties control whether a widget renders:
| Property | Shape |
|---|---|
include | { in: ['stateName'] } — render only when all named states are active. Or { when: '<expr>' } — render only when the expression is truthy. |
exclude | Same shape as include, but inverted — render only when the named states are not active. |
Examples
Section titled “Examples”import { gui } from '@golemui/gui-shared';
// Render only when the 'hasDiscount' state is activegui.inputs.textInput('discountCode', { label: 'Discount code', include: { in: ['hasDiscount'] },});
// Render only when an inline expression is truthygui.inputs.numberInput('pets', { label: 'Number of pets', include: { when: '$form.includePets === true' },});
// Hide a button when 'submitting' is activegui.actions.button({ label: 'Submit', exclude: { in: ['submitting'] },});When to use each
Section titled “When to use each”includewithin— the condition has a name, used in multiple places.includewithwhen— one-off, expressed inline.exclude— sometimes a “hide-when” rule reads more naturally than the corresponding “show-when”.
See also
Section titled “See also”- States — declaring named conditions.
- Features / States / Inline
when— when to inline vs name.