1.0.10 • Published 5 years ago

react-purchase-cart v1.0.10

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

react-shopping-cart

A react shopping cart components with redux with instant updates for e-commerce applications

NPM JavaScript Style Guide

This package provides several components:

Meta

  • author: Dennis Paler <dtpaler@gmail.com>
  • license: MIT

Features

  • Add and remove product to the cart
  • Cart Products persist after page reloads

Demo

demo: https://react-cart-components-demo.herokuapp.com/

Install

npm install --save react-cart-components

Usage

With Redux.

import React, { Component } from "react";
import { Cart, AddCartButton, CartReducers } from "react-cart-components";
import { Provider } from "react-redux";
import { createStore, combineReducers } from "redux";

const store = createStore(
  combineReducers({
    cart: CartReducers
    // Your own reducers here,
  })
);

const products = [
  {
    id: 1,
    name: "Flamboyant Pink Top",
    sku: "kskskskks",
    price: 2000,
    thumb: { type: "icon", classes: "fa fa-2x fa-cogs" }
  },
  {
    id: 2,
    name: "Black and White Stripes Dress",
    sku: "kskskskks",
    price: 3000,
    thumb: {
      type: "image",
      src: "https://colorlib.com/preview/theme/divisima/img/product/2.jpg"
    }
  },
  {
    id: 3,
    name: "Flamboyant Pink Top",
    sku: "kskskskks",
    price: 10000
  },
  {
    id: 4,
    name: "Flamboyant Pink Top",
    sku: "kskskskks",
    price: 5000
  }
];

class Example extends Component {
  handleCheckout(data) {
    console.log(data);
  }

  render() {
    return (
      <Provider store={store}>
        <Cart
          currencySymbol="CLP"
          language="es-CL"
          handleCheckout={handleCheckout}
          cartEmptyLabel={"El carrito está vacio"}
          cartTextLabel={"Carrito de compras"}
          checkoutTextLabel={"Ir a pagar"}
          subTotalTextLabel={"Total"}
          quantityTextLabel={"Cantidad"}
        />
        <div>
          {products.map((product, key) => {
            return (
              <div className="col" key={key}>
                <div className="product-item">
                  <div className="pi-pic">
                    <div className="pi-links">
                      <AddCartButton product={product} />
                    </div>
                  </div>
                  <div className="pi-text">
                    <p>{product.name}</p>
                  </div>
                </div>
              </div>
            );
          })}
        </div>
      </Provider>
    );
  }
}

export default ShopingCart;

Props

Cart Component

NameTypeDefaultDescription
currencySymbolstringUSDCurrency symbol to be used
languagestringen-USlanguage to be used in currencies
checkoutTextLabelstringCheckoutA checkout button text on the cart
cartTextLabelstringYour CartCart - Header title
cartEmptyLabelstringAdd some products in the cartCart - Empty message
subTotalTextLabelstringSub TotalCart - Sub Total Text
quantityTextLabelstringQuantityCart - Product Qty Text
handleCheckoutFunctionnullhandleCheckout will be triggered when checkoutLabel button is clicked and return cart products object.

AddCartButton

NameTypeDefaultDescription
productObjectnull(Required) Product object to be added to the cart
styleObject{}The style used for button
classNamestring""Classes used for button
addLabelstringAdd to CartA add cart button text

Type: Object

Properties

  • id string Product's id. Required.
  • name string Product Name to display pattern. Required.
  • price Price {currency: value}. Required
  • image string Path to main image. Required.

License

MIT © Dennis Paler

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago