> ## 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.

# ChoiceCard

> Bordered, clickable card for toggle controls.

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>;
};

ChoiceCard is a [Field](/components/field) that renders as a bordered card. Clicking anywhere on the card — the title, description, or empty space — toggles the wrapped control. When toggled on, the card highlights with a subtle border and background tint.

## Basic Usage

Place a `FieldContent` (with title and description) alongside a toggle control like Switch or Checkbox.

<ComponentPreview json={{"view":{"cssClass":"gap-4","type":"Column","children":[{"type":"ChoiceCard","invalid":false,"disabled":false,"children":[{"type":"FieldContent","children":[{"type":"FieldTitle","content":"Marketing emails"},{"type":"FieldDescription","content":"Receive emails about new products and features."}]},{"name":"switch_1","value":false,"type":"Switch","size":"default","disabled":false,"required":false}]},{"type":"ChoiceCard","invalid":false,"disabled":false,"children":[{"type":"FieldContent","children":[{"type":"FieldTitle","content":"Security emails"},{"type":"FieldDescription","content":"Receive emails about your account activity."}]},{"name":"switch_2","value":true,"type":"Switch","size":"default","disabled":false,"required":false}]}]},"state":{"switch_1":false,"switch_2":true}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgKAogICAgQ2hvaWNlQ2FyZCwgQ29sdW1uLCBGaWVsZENvbnRlbnQsIEZpZWxkRGVzY3JpcHRpb24sIEZpZWxkVGl0bGUsIFN3aXRjaCwKKQoKd2l0aCBDb2x1bW4oZ2FwPTQpOgogICAgd2l0aCBDaG9pY2VDYXJkKCk6CiAgICAgICAgd2l0aCBGaWVsZENvbnRlbnQoKToKICAgICAgICAgICAgRmllbGRUaXRsZSgiTWFya2V0aW5nIGVtYWlscyIpCiAgICAgICAgICAgIEZpZWxkRGVzY3JpcHRpb24oCiAgICAgICAgICAgICAgICAiUmVjZWl2ZSBlbWFpbHMgYWJvdXQgbmV3IHByb2R1Y3RzIGFuZCBmZWF0dXJlcy4iCiAgICAgICAgICAgICkKICAgICAgICBTd2l0Y2goKQoKICAgIHdpdGggQ2hvaWNlQ2FyZCgpOgogICAgICAgIHdpdGggRmllbGRDb250ZW50KCk6CiAgICAgICAgICAgIEZpZWxkVGl0bGUoIlNlY3VyaXR5IGVtYWlscyIpCiAgICAgICAgICAgIEZpZWxkRGVzY3JpcHRpb24oCiAgICAgICAgICAgICAgICAiUmVjZWl2ZSBlbWFpbHMgYWJvdXQgeW91ciBhY2NvdW50IGFjdGl2aXR5LiIKICAgICAgICAgICAgKQogICAgICAgIFN3aXRjaCh2YWx1ZT1UcnVlKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import (
        ChoiceCard, Column, FieldContent, FieldDescription, FieldTitle, Switch,
    )

    with Column(gap=4):
        with ChoiceCard():
            with FieldContent():
                FieldTitle("Marketing emails")
                FieldDescription(
                    "Receive emails about new products and features."
                )
            Switch()

        with ChoiceCard():
            with FieldContent():
                FieldTitle("Security emails")
                FieldDescription(
                    "Receive emails about your account activity."
                )
            Switch(value=True)
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-4",
        "type": "Column",
        "children": [
          {
            "type": "ChoiceCard",
            "invalid": false,
            "disabled": false,
            "children": [
              {
                "type": "FieldContent",
                "children": [
                  {"type": "FieldTitle", "content": "Marketing emails"},
                  {
                    "type": "FieldDescription",
                    "content": "Receive emails about new products and features."
                  }
                ]
              },
              {
                "name": "switch_1",
                "value": false,
                "type": "Switch",
                "size": "default",
                "disabled": false,
                "required": false
              }
            ]
          },
          {
            "type": "ChoiceCard",
            "invalid": false,
            "disabled": false,
            "children": [
              {
                "type": "FieldContent",
                "children": [
                  {"type": "FieldTitle", "content": "Security emails"},
                  {
                    "type": "FieldDescription",
                    "content": "Receive emails about your account activity."
                  }
                ]
              },
              {
                "name": "switch_2",
                "value": true,
                "type": "Switch",
                "size": "default",
                "disabled": false,
                "required": false
              }
            ]
          }
        ]
      },
      "state": {"switch_1": false, "switch_2": true}
    }
    ```
  </CodeGroup>
</ComponentPreview>

## With Checkbox

ChoiceCard works with any toggle control.

<ComponentPreview json={{"view":{"cssClass":"gap-4","type":"Column","children":[{"type":"ChoiceCard","invalid":false,"disabled":false,"children":[{"type":"FieldContent","children":[{"type":"FieldTitle","content":"Accept terms"},{"type":"FieldDescription","content":"You agree to our Terms of Service and Privacy Policy."}]},{"name":"checkbox_10","value":false,"type":"Checkbox","disabled":false,"required":false}]},{"type":"ChoiceCard","invalid":false,"disabled":false,"children":[{"type":"FieldContent","children":[{"type":"FieldTitle","content":"Subscribe to newsletter"},{"type":"FieldDescription","content":"Get weekly updates on new features."}]},{"name":"checkbox_11","value":true,"type":"Checkbox","disabled":false,"required":false}]}]},"state":{"checkbox_10":false,"checkbox_11":true}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgKAogICAgQ2hlY2tib3gsIENob2ljZUNhcmQsIENvbHVtbiwgRmllbGRDb250ZW50LCBGaWVsZERlc2NyaXB0aW9uLCBGaWVsZFRpdGxlLAopCgp3aXRoIENvbHVtbihnYXA9NCk6CiAgICB3aXRoIENob2ljZUNhcmQoKToKICAgICAgICB3aXRoIEZpZWxkQ29udGVudCgpOgogICAgICAgICAgICBGaWVsZFRpdGxlKCJBY2NlcHQgdGVybXMiKQogICAgICAgICAgICBGaWVsZERlc2NyaXB0aW9uKAogICAgICAgICAgICAgICAgIllvdSBhZ3JlZSB0byBvdXIgVGVybXMgb2YgU2VydmljZSBhbmQgUHJpdmFjeSBQb2xpY3kuIgogICAgICAgICAgICApCiAgICAgICAgQ2hlY2tib3goKQoKICAgIHdpdGggQ2hvaWNlQ2FyZCgpOgogICAgICAgIHdpdGggRmllbGRDb250ZW50KCk6CiAgICAgICAgICAgIEZpZWxkVGl0bGUoIlN1YnNjcmliZSB0byBuZXdzbGV0dGVyIikKICAgICAgICAgICAgRmllbGREZXNjcmlwdGlvbigiR2V0IHdlZWtseSB1cGRhdGVzIG9uIG5ldyBmZWF0dXJlcy4iKQogICAgICAgIENoZWNrYm94KHZhbHVlPVRydWUpCg">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import (
        Checkbox, ChoiceCard, Column, FieldContent, FieldDescription, FieldTitle,
    )

    with Column(gap=4):
        with ChoiceCard():
            with FieldContent():
                FieldTitle("Accept terms")
                FieldDescription(
                    "You agree to our Terms of Service and Privacy Policy."
                )
            Checkbox()

        with ChoiceCard():
            with FieldContent():
                FieldTitle("Subscribe to newsletter")
                FieldDescription("Get weekly updates on new features.")
            Checkbox(value=True)
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-4",
        "type": "Column",
        "children": [
          {
            "type": "ChoiceCard",
            "invalid": false,
            "disabled": false,
            "children": [
              {
                "type": "FieldContent",
                "children": [
                  {"type": "FieldTitle", "content": "Accept terms"},
                  {
                    "type": "FieldDescription",
                    "content": "You agree to our Terms of Service and Privacy Policy."
                  }
                ]
              },
              {
                "name": "checkbox_10",
                "value": false,
                "type": "Checkbox",
                "disabled": false,
                "required": false
              }
            ]
          },
          {
            "type": "ChoiceCard",
            "invalid": false,
            "disabled": false,
            "children": [
              {
                "type": "FieldContent",
                "children": [
                  {"type": "FieldTitle", "content": "Subscribe to newsletter"},
                  {"type": "FieldDescription", "content": "Get weekly updates on new features."}
                ]
              },
              {
                "name": "checkbox_11",
                "value": true,
                "type": "Checkbox",
                "disabled": false,
                "required": false
              }
            ]
          }
        ]
      },
      "state": {"checkbox_10": false, "checkbox_11": true}
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Disabled

A disabled ChoiceCard dims the entire card and prevents interaction.

<ComponentPreview json={{"view":{"cssClass":"gap-4","type":"Column","children":[{"type":"ChoiceCard","invalid":false,"disabled":false,"children":[{"type":"FieldContent","children":[{"type":"FieldTitle","content":"Enabled option"},{"type":"FieldDescription","content":"You can toggle this."}]},{"name":"switch_3","value":true,"type":"Switch","size":"default","disabled":false,"required":false}]},{"type":"ChoiceCard","invalid":false,"disabled":true,"children":[{"type":"FieldContent","children":[{"type":"FieldTitle","content":"Disabled option"},{"type":"FieldDescription","content":"This cannot be changed."}]},{"name":"switch_4","value":false,"type":"Switch","size":"default","disabled":true,"required":false}]}]},"state":{"switch_3":true,"switch_4":false}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgKAogICAgQ2hvaWNlQ2FyZCwgQ29sdW1uLCBGaWVsZENvbnRlbnQsIEZpZWxkRGVzY3JpcHRpb24sIEZpZWxkVGl0bGUsIFN3aXRjaCwKKQoKd2l0aCBDb2x1bW4oZ2FwPTQpOgogICAgd2l0aCBDaG9pY2VDYXJkKCk6CiAgICAgICAgd2l0aCBGaWVsZENvbnRlbnQoKToKICAgICAgICAgICAgRmllbGRUaXRsZSgiRW5hYmxlZCBvcHRpb24iKQogICAgICAgICAgICBGaWVsZERlc2NyaXB0aW9uKCJZb3UgY2FuIHRvZ2dsZSB0aGlzLiIpCiAgICAgICAgU3dpdGNoKHZhbHVlPVRydWUpCgogICAgd2l0aCBDaG9pY2VDYXJkKGRpc2FibGVkPVRydWUpOgogICAgICAgIHdpdGggRmllbGRDb250ZW50KCk6CiAgICAgICAgICAgIEZpZWxkVGl0bGUoIkRpc2FibGVkIG9wdGlvbiIpCiAgICAgICAgICAgIEZpZWxkRGVzY3JpcHRpb24oIlRoaXMgY2Fubm90IGJlIGNoYW5nZWQuIikKICAgICAgICBTd2l0Y2goZGlzYWJsZWQ9VHJ1ZSkK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import (
        ChoiceCard, Column, FieldContent, FieldDescription, FieldTitle, Switch,
    )

    with Column(gap=4):
        with ChoiceCard():
            with FieldContent():
                FieldTitle("Enabled option")
                FieldDescription("You can toggle this.")
            Switch(value=True)

        with ChoiceCard(disabled=True):
            with FieldContent():
                FieldTitle("Disabled option")
                FieldDescription("This cannot be changed.")
            Switch(disabled=True)
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-4",
        "type": "Column",
        "children": [
          {
            "type": "ChoiceCard",
            "invalid": false,
            "disabled": false,
            "children": [
              {
                "type": "FieldContent",
                "children": [
                  {"type": "FieldTitle", "content": "Enabled option"},
                  {"type": "FieldDescription", "content": "You can toggle this."}
                ]
              },
              {
                "name": "switch_3",
                "value": true,
                "type": "Switch",
                "size": "default",
                "disabled": false,
                "required": false
              }
            ]
          },
          {
            "type": "ChoiceCard",
            "invalid": false,
            "disabled": true,
            "children": [
              {
                "type": "FieldContent",
                "children": [
                  {"type": "FieldTitle", "content": "Disabled option"},
                  {"type": "FieldDescription", "content": "This cannot be changed."}
                ]
              },
              {
                "name": "switch_4",
                "value": false,
                "type": "Switch",
                "size": "default",
                "disabled": true,
                "required": false
              }
            ]
          }
        ]
      },
      "state": {"switch_3": true, "switch_4": false}
    }
    ```
  </CodeGroup>
</ComponentPreview>

## API Reference

<Card icon="code" title="ChoiceCard">
  ChoiceCard inherits all props from [Field](/components/field).

  <ParamField body="invalid" type="bool | str" default="False">
    Whether the card is in an error state. Cascades red text to all children.
  </ParamField>

  <ParamField body="disabled" type="bool | str" default="False">
    Whether the card is dimmed and non-interactive.
  </ParamField>

  <ParamField body="css_class" type="str | None" default="None">
    Additional Tailwind CSS classes.
  </ParamField>
</Card>

<Card icon="code" title="FieldTitle">
  <ParamField body="content" type="str" required>
    Title text.
  </ParamField>
</Card>

<Card icon="code" title="FieldDescription">
  <ParamField body="content" type="str" required>
    Description text.
  </ParamField>
</Card>

<Card icon="code" title="FieldContent">
  Container that groups FieldTitle and FieldDescription on the left side of the card.
</Card>

## Protocol Reference

```json ChoiceCard theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "ChoiceCard",
  "children?": "[Component]",
  "let?": "object",
  "invalid?": false,
  "disabled?": false,
  "cssClass?": "string"
}
```

```json FieldTitle theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "FieldTitle",
  "content": "string (required)"
}
```

```json FieldDescription theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "FieldDescription",
  "content": "string (required)"
}
```

```json FieldContent theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "FieldContent",
  "children?": "[Component]"
}
```

For the complete protocol schema, see [ChoiceCard](/protocol/choice-card).
