React SDK
Open the assistant
Show Cartesian as an adaptive panel over your page, from a button, a search bar or your own code.
The panel
Render CartesianPanel once inside CartesianProvider. It is drawn in a portal on document.body and stays hidden until it is opened.
<CartesianProvider client={cartesian}>
<Shop />
<CartesianPanel />
</CartesianProvider>tsxAdaptive layouts
With layout="auto" (the default) the panel picks a presentation from the window size, and picks again when the window is resized:
| Window | Layout | Behaviour |
|---|---|---|
| Width < 600px, height ≥ 480px | bottomSheet | Slides up and opens full height. Drag the handle down to half height or to close. |
| Width < 600px, height < 480px | fullScreen | Covers the page. |
| 600–1200px | sidePanel | A 440px panel docked on the right, over a dimmed page. |
| ≥ 1200px | floating | A 420 × 720px card in the bottom-right corner. The page stays usable. |
To force a layout, pass layout="sidePanel" (or any other value).
Sheet behaviour
- The sheet opens full height. Use
panel.open(prompt, "half")to start at half height. - Drag the handle to move between full, half and closed. Click the handle, or press Enter or Space on it, to switch between full and half.
- At half height, scrolling up in the conversation, focusing the composer or starting an answer expands the sheet.
- Escape closes the panel. If the cart drawer is open, Escape closes the drawer first.
- While the sheet, side panel or full-screen layout is open, focus stays inside it and returns to the trigger when it closes. Page scrolling is locked for the sheet and full-screen layouts.
Panel state
useCartesianPanel() returns the provider's CartesianPanelState:
const panel = useCartesianPanel();
panel.open(); // open full height
panel.open("Gluten-free pasta under $5"); // open and send a question
panel.open(null, "half");
panel.expand(); // half → full
panel.collapse(); // full → half
panel.hide();
panel.toggle();tsxRead it reactively with usePanelSnapshot(), which returns { isVisible, detent, layout, pendingPrompt }. You can also create a new CartesianPanelState() yourself and pass it as panel to the provider or to each component.
Ready-made triggers
Ask button
A pill button with the assistant orb. It hides itself while the panel is open. Position it yourself:
<CartesianAskButton
label="Ask FreshMart"
expanded={!scrolling} // collapse to the icon while the shopper scrolls
prompt={undefined} // or a question to send straight away
style={{ position: "fixed", right: 20, bottom: 20 }}
/>tsxOther props: icon (any React node), containerColor, contentColor, visible and className.
Ask bar
A search-style field. What the shopper types is sent as the first question.
<CartesianAskBar placeholder="Ask about any product" />tsxYour own trigger
Anything can call open:
const panel = useCartesianPanel();
<PromoBanner onClick={() => panel.open("Plan a week of dinners under $60")} />
<ProductTile product={p} onAsk={() => panel.open(`Is ${p.name} good for kids?`)} />tsxOutside React components
Cartesian.present() opens the panel of the most recently mounted provider. Use it from code that has no access to hooks, such as a menu handler or a deep-link router:
import { Cartesian } from "@cogitx/cartesian-react";
Cartesian.present();
Cartesian.present("Reorder my usual groceries");
Cartesian.hide();tsIt throws if no CartesianProvider is mounted.