DocsComponentsCommerce
MiniCart
React example follows below.
ts
import { MiniCart, Button } from "@grassroot/ui-react";import * as React from "react"; const items = [ { id: "tee", name: "Heavyweight tee", price: 3200, quantity: 1 }, { id: "cap", name: "Corduroy cap", price: 2400, quantity: 2 },]; const [open, setOpen] = React.useState(false); <Button variant="secondary" onClick={() => setOpen(true)}>Open cart</Button><MiniCart open={open} onClose={() => setOpen(false)} items={items} shipping={800} taxRate={0.2} />ts
<script setup lang="ts">import { ref } from "vue";import { Button, MiniCart } from "@grassroot/ui-vue"; const items = [ { id: "tee", name: "Heavyweight tee", price: 3200, quantity: 1 }, { id: "cap", name: "Corduroy cap", price: 2400, quantity: 2 },]; const open = ref(false);</script> <template> <Button variant="secondary" @click="open = true">Open cart</Button> <MiniCart v-model:open="open" :items="items" :shipping="800" :tax-rate="0.2" /></template>ts
import { Component, signal } from "@angular/core";import { GrassrootButton, GrassrootMiniCart } from "@grassroot/ui-angular"; @Component({ selector: "app-example", standalone: true, imports: [GrassrootButton, GrassrootMiniCart], template: ` <grassroot-button variant="secondary" (click)="open.set(true)" >Open cart</grassroot-button> <grassroot-mini-cart [open]="open()" [items]="items" [shipping]="800" [taxRate]="0.2" /> `,})export class ExampleComponent { readonly items = [ { id: "tee", name: "Heavyweight tee", price: 3200, quantity: 1 }, { id: "cap", name: "Corduroy cap", price: 2400, quantity: 2 }, ]; readonly open = signal(false);}ts
<script lang="ts"> import { Button, MiniCart } from "@grassroot/ui-svelte"; const items = [ { id: "tee", name: "Heavyweight tee", price: 3200, quantity: 1 }, { id: "cap", name: "Corduroy cap", price: 2400, quantity: 2 }, ]; let open = $state(false);</script> <Button variant="secondary" onClick={() => open = true}>Open cart</Button><MiniCart open={open} onClose={() => open = false} items={items} shipping={800} taxRate={0.2}/>ts
import { createSignal } from "solid-js";import { Button, MiniCart } from "@grassroot/ui-solid"; const items = [ { id: "tee", name: "Heavyweight tee", price: 3200, quantity: 1 }, { id: "cap", name: "Corduroy cap", price: 2400, quantity: 2 },]; export function Example() { const [open, setOpen] = createSignal(false); return ( <> <Button variant="secondary" onClick={() => setOpen(true)}>Open cart</Button> <MiniCart open={open()} onClose={() => setOpen(false)} items={items} shipping={800} taxRate={0.2} /> </> );}Installation
bash
pnpm dlx grassroot add ui/mini-cartbash
npx grassroot@latest add ui/mini-cartbash
yarn dlx grassroot add ui/mini-cartbash
bunx grassroot add ui/mini-cartAPI Reference
| Prop | Type | Default |
|---|---|---|
openrequired | boolean | — |
onCloserequired | () => void | — |
itemsrequired | CartItem[] | — |
currency | string | undefined | "USD" |
shipping | number | undefined | — |
taxRate | number | undefined | — |
discount | number | undefined | — |
onQuantityChange | ((id: string, quantity: number) => void) | undefined | — |
onRemove | ((id: string) => void) | undefined | — |
onCheckout | (() => void) | undefined | — |
sideDrawer edge. | "top" | "bottom" | "left" | "right" | undefined | "right" |