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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ak2109/cart-library

v0.0.1

Published

A React cart library providing components and hooks to easily integrate cart functionality into your React application.

Downloads

17

Readme

Cart Library

A React cart library providing components and hooks to easily integrate cart functionality into your React application.

Installation

npm install cart-library

or

yarn add cart-library

Peer Dependencies

This library requires the following dependencies:

{
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
  "styled-components": "^5.0.0 || ^6.0.0"
}

Basic Usage

1. Using the useCartContext Hook

import React from 'react';
import { useCart } from 'cart-library';

function Product({ product }) {
  const { addItem } = useCartContext();

  return (
    <div>
      <h3>{product.name}</h3>
      <p>${product.price}</p>
      <button onClick={() => addItem(product)}>
        Add to cart
      </button>
    </div>
  );
}

2. Using the Cart Component

import React from 'react';
import { Cart } from 'cart-library';

function App() {
  return (
    <div>
      <h1>My Application</h1>
      {/* Other components */}
      <Cart />
    </div>
  );
}

4. Other Components

  • CartItem: Displays each product in the cart
  • Button, InputText, Modal, Card: Reusable UI components

Data Types

import type { ICartItem } from 'cart-library'

const item: ICartItem = {
  id: '1',
  name: 'Product A',
  price: 100000,
  quantity: 1,
  image: 'image_link'
}

Cart Hook API

This hook returns an object with the following properties and methods:

  • items: CartItem[] - Array of products in the cart

  • addItem(item: Omit<CartItem, 'quantity'>): void - Add a product to the cart

  • updateQuantity(id: string, quantity: number): void - Update product quantity

  • removeItem(id: string): void - Remove a product from the cart

Cart Component

Displays the full cart interface with add, update, and remove functionality.

Props:

  • showModal?: boolean - Display the cart as a modal (default: false)

  • onClose?: () => void - Function called when closing the modal

CartItem Component

Displays a single product in the cart.

Props:

  • item: CartItem - Product information

  • onUpdateQuantity: (id: string, quantity: number) => void - Update quantity function

  • onRemove: (id: string) => void - Remove product function

Example

import React from 'react';
import { CartProvider, Cart, useCartContext } from 'cart-library';

// Product component
function ProductList() {
  const { addItem } = useCartContext();
  
  const products = [
    { id: '1', name: 'Product 1', price: 100 },
    { id: '2', name: 'Product 2', price: 200 },
    { id: '3', name: 'Product 3', price: 300 },
  ];
  
  return (
    <div>
      <h2>Product List</h2>
      {products.map(product => (
        <div key={product.id}>
          <h3>{product.name}</h3>
          <p>Price: ${product.price}</p>
          <button onClick={() => addItem(product)}>
            Add to cart
          </button>
        </div>
      ))}
    </div>
  );
}

// Main component
function App() {
  const [isCartOpen, setIsCartOpen] = React.useState(false);
  
  return (
    <CartProvider>
      <div>
        <header>
          <h1>My Store</h1>
          <button onClick={() => setIsCartOpen(true)}>
            Open cart
          </button>
        </header>
        
        <ProductList />
        
        {/* Cart as modal */}
        <Cart 
          showModal={isCartOpen} 
          onClose={() => setIsCartOpen(false)} 
        />
      </div>
    </CartProvider>
  );
}

export default App;

Styling Customization

Components use Styled Components, so you can easily customize styles by passing props or extending components:

import styled from 'styled-components';
import { Button } from 'cart-library';

const CustomButton = styled(Button)`
  background-color: #ff5722;
  border-radius: 8px;
  font-weight: bold;
  
  &:hover {
    background-color: #e64a19;
  }
`;

Development

If you want to contribute or develop the library:

  1. Clone the repository

  2. Install dependencies: npm install

  3. Run development mode: npm run dev

  4. Build the library: npm run build

License

MIT