npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

shopping-cart-mfs

v1.3.5

Published

Simple Shopping cart for mini app

Downloads

6

Readme

Bootcamp Sample of Simple Shopping Cart

Bootcamp Sample of Simple Shopping Cart

repository

Mini App

  • Bootcamp Sample of Simple Shopping Cart - status

For installation

npm install shopping-cart-mfs

Usage

import { ShoppingCart } from "shopping-cart-mfs"

additional config kindly add these to your react-app-env.d.ts to remove type declaration error

and if your are using React 18 kindly downgrade your react and react-dom to 17.0.2 and tweak your index.ts to look like this.

Types

{
dataLoad:{
    api: {
    [key: string]: any    <------- any axios api calls or created axios instance
  }
}
dataIn:{
   addToCartHeader: {
    id: string         // required
    header: string     // required
    accessor: string | { [key: string]: unknown } // required
    withComputation?: { [key: string]: unknown } | boolean | string // required
    hasComponent?: boolean  // optional if need other components
    hasImage?: true  // optional if the components is image
    imageComponent?: any // optional
    sx?: CSSProperties | null // image styles properties
  }[]
  itemListHeader: {
    id: string              // required
    nestedObj?: boolean     // optional if you need to access deeper objects
    mainObj?: string        // optional main object before to access deeper object values
    htmlSign?: JSX.Element  // optional only html signs if needed
    withIcons?: JSX.Element // optional if needed to add icons
    accessor: string | Array<string> // required because it is need to access object value
    imageComponent?: any    // optional if need image component
    hasImage?: boolean      // optional boolean only if has image component
    className?: string      // optional className for styling
  }[]
}
dataOut:{
  snackBarMessage: (value: boolean) => JSX.Element // required you can use any html elements or materil ui
  addToCartSnackBarMessage: (                      // required you can use any html elements or materil ui
    openSnackBar: boolean,
    snackBarMessage: string,
    handleAddTuCart: (data: boolean) => void
  ) => JSX.Element
}

}

Example

import { ShoppingCart } from "shopping-cart-mfs"
import GradeIcon from "@mui/icons-material/Grade";
import InventoryIcon from "@mui/icons-material/Inventory";
import DialogBox from "@mui/material/Dialog";
import Box from "@mui/material/Box";
import Snackbar from "@mui/material/Snackbar";
import axios from "axios"

export default function App() {
  return (
    <ShoppingCart
      dataLoad={{
        api: {
          getAll: getAll: axios.get("https://fakestoreapi.com/products")

        }
      }}

      dataIn={{
        itemListHeader: [
          {
            id: "id",
            accessor: "image",
            hasImage: true,
            imageComponent: (value: unknown) => {
              return (
                <img
                  style={{
                    width: "100px",
                    objectFit: "cover",
                    cursor: "pointer"
                  }}
                  src={`${value}?w=8&h=8&fit=crop&auto=format`}
                  srcSet={`${value}?w=8&h=8&fit=crop&auto=format&dpr=2`}
                  alt={`${value}`}
                  loading="lazy"
                />
              )
            }
          },
          { id: "id", accessor: "title", className: "text-center" },
          {
            id: "id",
            nestedObj: true,
            withIcons: <GradeIcon />,
            accessor: ["rating", "rate"],
            className: "flex gap-x-12"
          },
          {
            id: "id",
            nestedObj: true,
            withIcons: <InventoryIcon />,
            accessor: ["rating", "count"],
            className: "flex gap-x-12"
          },
          {
            id: "id",
            accessor: "price",
            htmlSign: <span>&#8369; </span>,
            className: "flex"
          }
        ],
        addToCartHeader: [
          {
            id: "id",
            header: "Quantity",
            accessor: "quantity",
            hasComponent: true
          },
          {
            id: "id",
            header: "Items",
            accessor: "image",
            hasImage: true,
            imageComponent: (value: unknown) => {
              return (
                <img
                  style={{
                    width: "50px",
                    objectFit: "cover",
                    cursor: "pointer"
                  }}
                  src={`${value}?w=8&h=8&fit=crop&auto=format`}
                  srcSet={`${value}?w=8&h=8&fit=crop&auto=format&dpr=2`}
                  alt={`${value}`}
                  loading="lazy"
                />
              )
            }
          },
          {
            id: "id",
            header: "Title",
            accessor: "title",
            sx: { width: "100px" }
          },
          {
            id: "id",
            header: "Price",
            accessor: "price"
          },
          {
            id: "id",
            header: "Total Price",
            accessor: { price: "price", quantity: "quantity" },
            withComputation: "multiply",
            sx: { width: "100px" }
          },
          {
            id: "id",
            header: "",
            accessor: "cancelIcon",
            sx: { width: "100px" }
          }
        ]
      }}
      dataOut={{
        snackBarMessage: (value: boolean) => {
          return (
            <DialogBox open={value}>
              <Box sx={{ padding: "2em" }}>THANKS FOR YOUR PURCHASE</Box>
            </DialogBox>
          )
        },
        addToCartSnackBarMessage: (
          openSnackBar: boolean,
          snackBarMessage: string,
          handleAddTuCart: (data: boolean) => void
        ) => {
          return (
            <SnackBarMessage
              open={openSnackBar}
              message={snackBarMessage}
              handleClose={handleAddTuCart}
            />
          )
        }
      }}
    />
  )
}

Sample Return value from GetAll Api

Demo

Demo

Peer Dependecies

"node":"v16.14.0"
"react": "^17.0.2",
"react-dom": "^17.0.2"