1.0.5 • Published 3 years ago

react-shop-cart v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

react-shop-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: Christian Ballester <ballester_christian@yahoo.com>
  • license: MIT
  • based on Dennis Paler react-cart-component

Features

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

Demo

demo: https://flintstore.herokuapp.com/

Install

npm install --save react-shop-cart

Usage

With Redux.

import React, { Component } from 'react'
import { Provider } from 'react-redux'
import { createStore, combineReducers } from 'redux'


import { CartReducers } from react-cart-components'

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

import React, { Component } from 'react'

import { Cart, AddCartButton } from 'react-shop-cart'

const products = [
  {
    id: 1,
    name: 'Flamboyant Pink Top',
    sku: 'kskskskks',
    price: 200.0,
    image: 'https://colorlib.com/preview/theme/divisima/img/product/6.jpg'
  },
  {
    id: 2,
    name: 'Black and White Stripes Dress',
    sku: 'kskskskks',
    price: 300.0,
    image: 'https://colorlib.com/preview/theme/divisima/img/product/5.jpg'
  },
  {
    id: 3,
    name: 'Flamboyant Pink Top',
    sku: 'kskskskks',
    price: 400.0,
    image: 'https://colorlib.com/preview/theme/divisima/img/product/7.jpg'
  },
  {
    id: 4,
    name: 'Flamboyant Pink Top',
    sku: 'kskskskks',
    price: 400.0,
    image: 'https://colorlib.com/preview/theme/divisima/img/product/8.jpg'
  },
];

class Example extends Component {
  render () {
    return (
      <Cart currency="USD" />
      <div>
      {products.map((product, key) => {
            return (
                <div className="col" key={key}>
                  <div className="product-item">
                    <div className="pi-pic">
                       <img src={product.image} />
                       <div className="pi-links">
                          <AddCartButton
                            product={product}
                            styles={{ backgroundColor: '#009688', color: 'white', border: '0' }}
                          />
                       </div>
                    </div>
                    <div className="pi-text">
                        <p>{product.name}</p>
                        <h6>{formatter.format(product.price)}</h6>
                    </div>
                  </div>
                </div>
              );
      })}
      </div>
    )
  }
}

Props

Cart Component

NameTypeDefaultDescription
currencySymbolstringUSDCurrency symbol to be used
checkoutTextLabelstringCheckoutA checkout button text on the cart
cartTextLabelstringYour CartA cart header title
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
stylesArrayObject | Object[{}]The style 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

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago