0.5.16 • Published 2 months ago

@springmicro/cart v0.5.16

Weekly downloads
-
License
-
Repository
-
Last release
2 months ago

@springmicro/cart

A package for eCommerce sites that provides shopping cart functionality.

Exports

Components

CartProvider

Provides and handles all the data for the cart. Requires a ReactNode child. apiUrl will be modified to end with /api/ecommerce/cart. If the user object changes, the provider automatically logs in and out of the cart.

Required props:

user={({ id: number | string } & any) | undefined}
apiUrl={string}

CartContext

Allows all scopes under the CartProvider to read from the cart data and the functions to modify the cart.

Provisions:

  • cart: Cart
    • Provides cart and authentication data.
  • addToCart: (product: CartProduct) => void
    • Adds a product to the cart.
  • removeFromCart: (i: number) => void
    • Removes an item from the cart at the given index.
  • clearCart: () => void
    • Clears the cart.

CartButton

A frontend-facing component to display the cart contents in a Modal. This component is designed to go in a top navbar, ideally on the right-hand side. This component is required to be in a CartProvider scope.

Types

Cart

The type of the cart in CartContext.cart.

{
  cart: CartProducts[],
  authentication: {loggedIn: boolean, user_id: string | number}
}

CartProduct

The type of the products listed in Cart.cart.

{
  id: number | string,
  name: string,
  quantity: number | undefined
}
0.5.10

3 months ago

0.5.11

3 months ago

0.5.8

3 months ago

0.5.7

3 months ago

0.5.9

3 months ago

0.5.16

2 months ago

0.5.14

2 months ago

0.5.15

2 months ago

0.5.12

3 months ago

0.5.13

2 months ago

0.3.0

7 months ago

0.5.4

4 months ago

0.5.3

4 months ago

0.3.5

6 months ago

0.5.6

3 months ago

0.5.5

3 months ago

0.5.0

4 months ago

0.4.1

4 months ago

0.3.2

7 months ago

0.4.0

5 months ago

0.5.2

4 months ago

0.3.4

6 months ago

0.5.1

4 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.2.0-alpha.4

11 months ago

0.2.0-alpha.3

12 months ago

0.2.0-alpha.2

12 months ago

0.2.0-alpha.1

12 months ago