The language
Links & actions
Buttons take an action in onPressed. Anything else becomes clickable by wrapping it in a Link.
Button actions
onPressed is an object whose type says what happens. It works on every button: FilledButton, ElevatedButton, OutlinedButton, TextButton and IconButton.
| Type | Does | Fields |
|---|---|---|
"page" | Opens a page of this store | route |
"url" | Opens any address | url, newTab (optional) |
"addToCart" | Adds a product to the cart, without leaving the page | product, variant |
Open a page
<FilledButton label="Shop the sale" onPressed={{ type: "page", route: "/collection/sale" }} />Routes are paths on the storefront: /products, /category/shoes, /collection/sale, or the slug of a page you built.
Open a link
<OutlinedButton label="Size guide" onPressed={{ type: "url", url: "https://example.com/sizes", newTab: true }} />url also takes data, so a button inside a list can open each item's page: { type: "url", url: item.url }.
Add to cart
Pass the product and the variant to add. A product with options (size, colour) needs the shopper to choose first, so test hasOptions and send those products to their page instead:
<GridView className="grid-cols-2 md:grid-cols-4 gap-4">
{products({ limit: 4 }).map((item) => (
<Column className="gap-2">
<Text>{item.name}</Text>
{item.hasOptions ? (
<OutlinedButton label="Choose options" onPressed={{ type: "url", url: item.url }} />
) : (
<FilledButton label="Add to cart" onPressed={{ type: "addToCart", product: item.id, variant: item.variantId }} />
)}
</Column>
))}
</GridView>Making anything clickable
Link wraps any widget (a card, an image, a whole row) and opens href when it's clicked. Use it for cards; use buttons for calls to action.
<Link href="/brand/nike">
<Column className="items-center gap-2">
<Image src={brand("nike").image} height={64} />
<Text>Shop Nike</Text>
</Column>
</Link>