> ## Documentation Index
> Fetch the complete documentation index at: https://prefab.prefect.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# If / Elif / Else

> Conditionally render components based on expressions.

export const ComponentPreview = ({json, height, resizable, bare, hideJson, playground, children}) => {
  const hostRef = React.useRef(null);
  const handleRef = React.useRef(null);
  const cardRef = React.useRef(null);
  const containerRef = React.useRef(null);
  const [previewWidth, setPreviewWidth] = React.useState(null);
  const [isDragging, setIsDragging] = React.useState(false);
  const [playgroundHref, setPlaygroundHref] = React.useState(null);
  React.useEffect(function () {
    if (!playground) return;
    var isLocal = location.hostname === "localhost" || location.hostname === "127.0.0.1";
    var path = isLocal ? "/playground" : "/docs/playground";
    var url = new URL(path, window.location.href);
    url.hash = "code=" + playground;
    setPlaygroundHref(url.href);
  }, [playground]);
  var jsonStr = typeof json === "string" ? json : JSON.stringify(json, null, 2);
  React.useEffect(function () {
    if (cardRef.current) {
      var card = cardRef.current.closest(".group");
      if (card) card.classList.remove("group");
    }
    var host = hostRef.current;
    if (!host || !json) return;
    function mount() {
      if (!window.__prefab || !host) return;
      var dark = document.documentElement.classList.contains("dark");
      handleRef.current = window.__prefab.mountPreview(host, jsonStr, {
        dark: dark
      });
      if (bare && host.shadowRoot) {
        var m = host.shadowRoot.querySelector("[data-prefab-mount]");
        if (m) m.style.background = "transparent";
      }
    }
    if (window.__prefab) {
      mount();
    } else {
      if (!window.__prefabLoading) {
        if (!window.__prefabReady) {
          var s = document.createElement("script");
          s.src = "/renderer.js";
          document.head.appendChild(s);
        }
        window.__prefabLoading = new Promise(function (resolve) {
          function check() {
            if (window.__prefabReady) {
              window.__prefabReady.then(resolve);
            } else {
              setTimeout(check, 10);
            }
          }
          check();
        });
      }
      window.__prefabLoading.then(mount);
    }
    var observer = new MutationObserver(function () {
      var dark = document.documentElement.classList.contains("dark");
      if (handleRef.current) handleRef.current.setDark(dark);
    });
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return function () {
      observer.disconnect();
      if (handleRef.current) {
        handleRef.current.unmount();
        handleRef.current = null;
      }
    };
  }, [json]);
  function startResize(e) {
    e.preventDefault();
    var startX = e.clientX;
    var startW = hostRef.current ? hostRef.current.offsetWidth : 0;
    var maxW = containerRef.current ? containerRef.current.offsetWidth - 10 : startW;
    setIsDragging(true);
    function onMove(ev) {
      var w = Math.max(260, Math.min(startW + (ev.clientX - startX), maxW));
      setPreviewWidth(w);
    }
    function onUp() {
      document.removeEventListener("mousemove", onMove);
      document.removeEventListener("mouseup", onUp);
      setIsDragging(false);
    }
    document.addEventListener("mousemove", onMove);
    document.addEventListener("mouseup", onUp);
  }
  if (bare) {
    return <div ref={hostRef} />;
  }
  if (resizable) {
    return <Card>
        <div ref={cardRef} />
        <div ref={containerRef} style={{
      display: "flex",
      position: "relative",
      overflow: "hidden"
    }}>
          <div ref={hostRef} style={{
      flex: previewWidth ? "none" : 1,
      width: previewWidth ? previewWidth + "px" : undefined,
      minWidth: 0
    }} />
          <div onMouseDown={startResize} style={{
      width: "14px",
      flexShrink: 0,
      cursor: "col-resize",
      background: isDragging ? "var(--border, #e5e7eb)" : "color-mix(in srgb, var(--border, #e5e7eb) 40%, transparent)",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      transition: "background 0.15s",
      userSelect: "none"
    }}>
            <svg width="6" height="24" style={{
      opacity: 0.5
    }}>
              <circle cx="2" cy="4" r="1.2" fill="currentColor" />
              <circle cx="2" cy="9" r="1.2" fill="currentColor" />
              <circle cx="2" cy="14" r="1.2" fill="currentColor" />
              <circle cx="2" cy="19" r="1.2" fill="currentColor" />
              <circle cx="5" cy="4" r="1.2" fill="currentColor" />
              <circle cx="5" cy="9" r="1.2" fill="currentColor" />
              <circle cx="5" cy="14" r="1.2" fill="currentColor" />
              <circle cx="5" cy="19" r="1.2" fill="currentColor" />
            </svg>
          </div>
          <div style={{
      flex: previewWidth ? 1 : "0 0 24px",
      minWidth: "24px",
      background: "repeating-linear-gradient(-45deg, transparent, transparent 3px, var(--border, #e5e7eb) 3px, var(--border, #e5e7eb) 4px)",
      opacity: 0.4
    }} />
          {previewWidth && <div style={{
      position: "absolute",
      bottom: "8px",
      right: "8px",
      background: "var(--background, white)",
      border: "1px solid var(--border, #e5e7eb)",
      borderRadius: "4px",
      padding: "1px 6px",
      fontSize: "11px",
      fontFamily: "monospace",
      color: "var(--muted-foreground, #6b7280)",
      pointerEvents: "none"
    }}>
              {previewWidth}px
            </div>}
        </div>
        {playgroundHref && <div style={{
      display: "flex",
      justifyContent: "flex-end",
      padding: "4px 0 8px"
    }}>
            <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
      fontSize: "11px",
      opacity: 0.4,
      textDecoration: "none",
      textDecorationLine: "none",
      borderBottom: "none",
      boxShadow: "none",
      display: "inline-flex",
      alignItems: "center",
      gap: "3px",
      transition: "opacity 0.15s",
      fontWeight: 400
    }} onMouseOver={function (e) {
      e.currentTarget.style.opacity = "0.6";
    }} onMouseOut={function (e) {
      e.currentTarget.style.opacity = "0.4";
    }}>
              Edit in Playground
              <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
            </a>
          </div>}
        <div style={{
      marginBottom: "-2rem"
    }}>{children}</div>
      </Card>;
  }
  return <Card>
      <div ref={cardRef} />
      <div ref={hostRef} />
      {playgroundHref && <div style={{
    display: "flex",
    justifyContent: "flex-end",
    padding: "4px 0 8px"
  }}>
          <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
    fontSize: "11px",
    opacity: 0.4,
    textDecoration: "none",
    textDecorationLine: "none",
    borderBottom: "none",
    boxShadow: "none",
    display: "inline-flex",
    alignItems: "center",
    gap: "3px",
    transition: "opacity 0.15s",
    fontWeight: 400
  }} onMouseOver={function (e) {
    e.currentTarget.style.opacity = "0.6";
  }} onMouseOut={function (e) {
    e.currentTarget.style.opacity = "0.4";
  }}>
            Edit in Playground
            <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
          </a>
        </div>}
      <div style={{
    marginBottom: "-2rem"
  }}>{children}</div>
    </Card>;
};

`If`, `Elif`, and `Else` let you conditionally render different components based on expression results. They mirror Python's own `if/elif/else` syntax and read the same way — no wrappers, no extra indentation.

## Basic Usage

The simplest case: show something only when a condition is true. Toggle the switch to see the alert appear and disappear.

<ComponentPreview json={{"view":{"cssClass":"gap-3","type":"Column","children":[{"cssClass":"gap-2 items-center","type":"Row","children":[{"name":"outOfStock","value":false,"type":"Switch","size":"default","disabled":false,"required":false},{"content":"Out of stock","type":"Text"}]},{"type":"Condition","cases":[{"when":"{{ outOfStock }}","children":[{"type":"Alert","variant":"destructive","children":[{"type":"AlertTitle","content":"This item is unavailable"}]}]}]}]},"state":{"outOfStock":false}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgQWxlcnQsIEFsZXJ0VGl0bGUsIENvbHVtbiwgUm93LCBTd2l0Y2gsIFRleHQKZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cy5jb250cm9sX2Zsb3cgaW1wb3J0IElmCmZyb20gcHJlZmFiX3VpLnJ4IGltcG9ydCBSeAoKb3V0T2ZTdG9jayA9IFJ4KCJvdXRPZlN0b2NrIikKCndpdGggQ29sdW1uKGdhcD0zKToKICAgIHdpdGggUm93KGdhcD0yLCBhbGlnbj0iY2VudGVyIik6CiAgICAgICAgU3dpdGNoKG5hbWU9Im91dE9mU3RvY2siKQogICAgICAgIFRleHQoIk91dCBvZiBzdG9jayIpCiAgICB3aXRoIElmKG91dE9mU3RvY2spOgogICAgICAgIHdpdGggQWxlcnQodmFyaWFudD0iZGVzdHJ1Y3RpdmUiKToKICAgICAgICAgICAgQWxlcnRUaXRsZSgiVGhpcyBpdGVtIGlzIHVuYXZhaWxhYmxlIikK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import Alert, AlertTitle, Column, Row, Switch, Text
    from prefab_ui.components.control_flow import If
    from prefab_ui.rx import Rx

    outOfStock = Rx("outOfStock")

    with Column(gap=3):
        with Row(gap=2, align="center"):
            Switch(name="outOfStock")
            Text("Out of stock")
        with If(outOfStock):
            with Alert(variant="destructive"):
                AlertTitle("This item is unavailable")
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-3",
        "type": "Column",
        "children": [
          {
            "cssClass": "gap-2 items-center",
            "type": "Row",
            "children": [
              {
                "name": "outOfStock",
                "value": false,
                "type": "Switch",
                "size": "default",
                "disabled": false,
                "required": false
              },
              {"content": "Out of stock", "type": "Text"}
            ]
          },
          {
            "type": "Condition",
            "cases": [
              {
                "when": "{{ outOfStock }}",
                "children": [
                  {
                    "type": "Alert",
                    "variant": "destructive",
                    "children": [{"type": "AlertTitle", "content": "This item is unavailable"}]
                  }
                ]
              }
            ]
          }
        ]
      },
      "state": {"outOfStock": false}
    }
    ```
  </CodeGroup>
</ComponentPreview>

A lone `If` renders its children when the condition is truthy, and renders nothing when it's falsy.

## If / Else

Add an `Else` branch to render fallback content when the condition is false. Toggle the switch to see the two branches swap.

<ComponentPreview json={{"view":{"cssClass":"gap-3","type":"Column","children":[{"cssClass":"gap-2 items-center","type":"Row","children":[{"name":"showDetails","value":false,"type":"Switch","size":"default","disabled":false,"required":false},{"content":"Show details","type":"Text"}]},{"type":"Condition","cases":[{"when":"{{ showDetails }}","children":[{"type":"Card","children":[{"type":"CardHeader","children":[{"type":"CardTitle","content":"Project Details"}]},{"type":"CardContent","children":[{"content":"Heart of Gold \u2014 Infinite Improbability Drive","type":"Text"}]}]}]}],"else":[{"type":"Badge","label":"Details hidden","variant":"secondary"}]}]},"state":{"showDetails":false}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgKAogICAgU1RBVEUgYXMgc3RhdGUsCiAgICBCYWRnZSwKICAgIENhcmQsCiAgICBDYXJkQ29udGVudCwKICAgIENhcmRIZWFkZXIsCiAgICBDYXJkVGl0bGUsCiAgICBDb2x1bW4sCiAgICBSb3csCiAgICBTd2l0Y2gsCiAgICBUZXh0LAopCmZyb20gcHJlZmFiX3VpLmNvbXBvbmVudHMuY29udHJvbF9mbG93IGltcG9ydCBFbHNlLCBJZgoKCndpdGggQ29sdW1uKGdhcD0zKToKICAgIHdpdGggUm93KGdhcD0yLCBhbGlnbj0iY2VudGVyIik6CiAgICAgICAgU3dpdGNoKG5hbWU9InNob3dEZXRhaWxzIikKICAgICAgICBUZXh0KCJTaG93IGRldGFpbHMiKQogICAgd2l0aCBJZihzdGF0ZS5zaG93RGV0YWlscyk6CiAgICAgICAgd2l0aCBDYXJkKCk6CiAgICAgICAgICAgIHdpdGggQ2FyZEhlYWRlcigpOgogICAgICAgICAgICAgICAgQ2FyZFRpdGxlKCJQcm9qZWN0IERldGFpbHMiKQogICAgICAgICAgICB3aXRoIENhcmRDb250ZW50KCk6CiAgICAgICAgICAgICAgICBUZXh0KCJIZWFydCBvZiBHb2xkIOKAlCBJbmZpbml0ZSBJbXByb2JhYmlsaXR5IERyaXZlIikKICAgIHdpdGggRWxzZSgpOgogICAgICAgIEJhZGdlKCJEZXRhaWxzIGhpZGRlbiIsIHZhcmlhbnQ9InNlY29uZGFyeSIpCg">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import (
        STATE as state,
        Badge,
        Card,
        CardContent,
        CardHeader,
        CardTitle,
        Column,
        Row,
        Switch,
        Text,
    )
    from prefab_ui.components.control_flow import Else, If


    with Column(gap=3):
        with Row(gap=2, align="center"):
            Switch(name="showDetails")
            Text("Show details")
        with If(state.showDetails):
            with Card():
                with CardHeader():
                    CardTitle("Project Details")
                with CardContent():
                    Text("Heart of Gold — Infinite Improbability Drive")
        with Else():
            Badge("Details hidden", variant="secondary")
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-3",
        "type": "Column",
        "children": [
          {
            "cssClass": "gap-2 items-center",
            "type": "Row",
            "children": [
              {
                "name": "showDetails",
                "value": false,
                "type": "Switch",
                "size": "default",
                "disabled": false,
                "required": false
              },
              {"content": "Show details", "type": "Text"}
            ]
          },
          {
            "type": "Condition",
            "cases": [
              {
                "when": "{{ showDetails }}",
                "children": [
                  {
                    "type": "Card",
                    "children": [
                      {
                        "type": "CardHeader",
                        "children": [{"type": "CardTitle", "content": "Project Details"}]
                      },
                      {
                        "type": "CardContent",
                        "children": [
                          {"content": "Heart of Gold \u2014 Infinite Improbability Drive", "type": "Text"}
                        ]
                      }
                    ]
                  }
                ]
              }
            ],
            "else": [{"type": "Badge", "label": "Details hidden", "variant": "secondary"}]
          }
        ]
      },
      "state": {"showDetails": false}
    }
    ```
  </CodeGroup>
</ComponentPreview>

## If / Elif / Else

Chain multiple conditions with `Elif`. The renderer evaluates them in order and renders the first match. If nothing matches, the `Else` branch renders. Use the select below to change the status and watch the right badge appear.

<ComponentPreview json={{"view":{"cssClass":"gap-3","type":"Column","children":[{"name":"status","type":"Select","placeholder":"Choose a status...","size":"default","disabled":false,"required":false,"invalid":false,"children":[{"type":"SelectOption","value":"active","label":"Active","selected":false,"disabled":false},{"type":"SelectOption","value":"warning","label":"Warning","selected":false,"disabled":false},{"type":"SelectOption","value":"error","label":"Error","selected":false,"disabled":false},{"type":"SelectOption","value":"other","label":"Something else","selected":false,"disabled":false}]},{"type":"Condition","cases":[{"when":"{{ status == 'error' }}","children":[{"type":"Badge","label":"Error \u2014 system down","variant":"destructive"}]},{"when":"{{ status == 'warning' }}","children":[{"type":"Badge","label":"Warning \u2014 degraded","variant":"warning"}]},{"when":"{{ status == 'active' }}","children":[{"type":"Badge","label":"Active \u2014 all systems go","variant":"success"}]}],"else":[{"type":"Badge","label":"Unknown status: {{ status }}","variant":"secondary"}]}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgKAogICAgU1RBVEUgYXMgc3RhdGUsCiAgICBCYWRnZSwKICAgIENvbHVtbiwKICAgIFNlbGVjdCwKICAgIFNlbGVjdE9wdGlvbiwKKQpmcm9tIHByZWZhYl91aS5jb21wb25lbnRzLmNvbnRyb2xfZmxvdyBpbXBvcnQgRWxpZiwgRWxzZSwgSWYKCgp3aXRoIENvbHVtbihnYXA9Myk6CiAgICB3aXRoIFNlbGVjdChuYW1lPSJzdGF0dXMiLCBwbGFjZWhvbGRlcj0iQ2hvb3NlIGEgc3RhdHVzLi4uIik6CiAgICAgICAgU2VsZWN0T3B0aW9uKCJBY3RpdmUiLCB2YWx1ZT0iYWN0aXZlIikKICAgICAgICBTZWxlY3RPcHRpb24oIldhcm5pbmciLCB2YWx1ZT0id2FybmluZyIpCiAgICAgICAgU2VsZWN0T3B0aW9uKCJFcnJvciIsIHZhbHVlPSJlcnJvciIpCiAgICAgICAgU2VsZWN0T3B0aW9uKCJTb21ldGhpbmcgZWxzZSIsIHZhbHVlPSJvdGhlciIpCiAgICB3aXRoIElmKHN0YXRlLnN0YXR1cyA9PSAiZXJyb3IiKToKICAgICAgICBCYWRnZSgiRXJyb3Ig4oCUIHN5c3RlbSBkb3duIiwgdmFyaWFudD0iZGVzdHJ1Y3RpdmUiKQogICAgd2l0aCBFbGlmKHN0YXRlLnN0YXR1cyA9PSAid2FybmluZyIpOgogICAgICAgIEJhZGdlKCJXYXJuaW5nIOKAlCBkZWdyYWRlZCIsIHZhcmlhbnQ9Indhcm5pbmciKQogICAgd2l0aCBFbGlmKHN0YXRlLnN0YXR1cyA9PSAiYWN0aXZlIik6CiAgICAgICAgQmFkZ2UoIkFjdGl2ZSDigJQgYWxsIHN5c3RlbXMgZ28iLCB2YXJpYW50PSJzdWNjZXNzIikKICAgIHdpdGggRWxzZSgpOgogICAgICAgIEJhZGdlKGYiVW5rbm93biBzdGF0dXM6IHtzdGF0ZS5zdGF0dXN9IiwgdmFyaWFudD0ic2Vjb25kYXJ5IikK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import (
        STATE as state,
        Badge,
        Column,
        Select,
        SelectOption,
    )
    from prefab_ui.components.control_flow import Elif, Else, If


    with Column(gap=3):
        with Select(name="status", placeholder="Choose a status..."):
            SelectOption("Active", value="active")
            SelectOption("Warning", value="warning")
            SelectOption("Error", value="error")
            SelectOption("Something else", value="other")
        with If(state.status == "error"):
            Badge("Error — system down", variant="destructive")
        with Elif(state.status == "warning"):
            Badge("Warning — degraded", variant="warning")
        with Elif(state.status == "active"):
            Badge("Active — all systems go", variant="success")
        with Else():
            Badge(f"Unknown status: {state.status}", variant="secondary")
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-3",
        "type": "Column",
        "children": [
          {
            "name": "status",
            "type": "Select",
            "placeholder": "Choose a status...",
            "size": "default",
            "disabled": false,
            "required": false,
            "invalid": false,
            "children": [
              {
                "type": "SelectOption",
                "value": "active",
                "label": "Active",
                "selected": false,
                "disabled": false
              },
              {
                "type": "SelectOption",
                "value": "warning",
                "label": "Warning",
                "selected": false,
                "disabled": false
              },
              {
                "type": "SelectOption",
                "value": "error",
                "label": "Error",
                "selected": false,
                "disabled": false
              },
              {
                "type": "SelectOption",
                "value": "other",
                "label": "Something else",
                "selected": false,
                "disabled": false
              }
            ]
          },
          {
            "type": "Condition",
            "cases": [
              {
                "when": "{{ status == 'error' }}",
                "children": [
                  {"type": "Badge", "label": "Error \u2014 system down", "variant": "destructive"}
                ]
              },
              {
                "when": "{{ status == 'warning' }}",
                "children": [{"type": "Badge", "label": "Warning \u2014 degraded", "variant": "warning"}]
              },
              {
                "when": "{{ status == 'active' }}",
                "children": [
                  {"type": "Badge", "label": "Active \u2014 all systems go", "variant": "success"}
                ]
              }
            ],
            "else": [
              {
                "type": "Badge",
                "label": "Unknown status: {{ status }}",
                "variant": "secondary"
              }
            ]
          }
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

Select "Error" or "Something else" to see different branches render. The `Else` catches anything that doesn't match the explicit conditions.

## Conditions Are Expressions

The first argument to `If` and `Elif` is a [reactive expression](/concepts/expressions). With `Rx`, you can use Python operators directly:

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
from prefab_ui.rx import Rx

status = Rx("status")
count = Rx("count")
items = Rx("items")

with If(status == "active"):
    ...

with If((count > 0) & items.length()):
    ...
```

Any expression the language supports — comparisons, boolean logic, [pipes](/concepts/expressions#formatting-with-pipes) — works as a condition.

## Chain Rules

Consecutive `If/Elif/Else` siblings in the same parent form a single conditional chain:

* A chain starts with `If` and extends through consecutive `Elif` and `Else` siblings
* `Elif` and `Else` are optional — a lone `If` is valid
* `Else` must be last in a chain
* Any non-conditional sibling breaks the chain — including another `If`, which starts a new independent chain

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
from prefab_ui.rx import Rx

status = Rx("status")
showDetails = Rx("showDetails")
showFooter = Rx("showFooter")

with Column():
    # Chain 1: If / Elif / Else → one Condition node
    with If(status == "error"):
        Badge("Error", variant="destructive")
    with Elif(status == "warning"):
        Badge("Warning", variant="secondary")
    with Else():
        Badge("OK")

    Text("---")  # breaks the chain

    # Chain 2: standalone If → separate Condition node
    with If(showDetails):
        Text("Details here...")

    # Chain 3: another If starts a new chain (not an Elif!)
    with If(showFooter):
        Text("Footer content")
```

This produces three independent `Condition` nodes with a `Text` between the first and second.

## Wire Format

In the Python DSL, you write natural `If/Elif/Else` siblings. During serialization, these are grouped into a single `Condition` node on the wire. The `If` and `Elif` components never appear in the JSON directly — they're purely authoring constructs.

Each `Elif` becomes a `case` entry with a `when` expression. The `Else` branch becomes the `else` field. See the [Condition protocol reference](/protocol/condition) for the full schema.

## API Reference

<Card icon="code" title="If">
  <ParamField body="condition" type="str" required>
    Expression to evaluate. Renders children when truthy. Can be passed as a positional argument.
  </ParamField>
</Card>

<Card icon="code" title="Elif">
  <ParamField body="condition" type="str" required>
    Expression to evaluate. Must follow an `If` or another `Elif`. Can be passed as a positional argument.
  </ParamField>
</Card>

<Card icon="code" title="Else">
  Renders children when no preceding `If` or `Elif` matched. Takes no condition argument.
</Card>

## Protocol Reference

For the wire format schema, see the [Condition protocol definition](/protocol/condition).
