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

@lamquangho/shopping-cart-library

v1.0.0

Published

A reusable shopping cart component library with standardized UI components

Downloads

10

Readme

🛒 Shopping Cart Library

Một thư viện React component chuẩn hóa cho chức năng giỏ hàng với UI đẹp và dễ sử dụng.

✨ Tính năng

  • 🎨 UI Components chuẩn hóa: Input, Button, Modal, Card
  • 🛍️ Shopping Cart hoàn chỉnh: Thêm, sửa, xóa sản phẩm
  • 📱 Responsive Design: Tối ưu cho mọi thiết bị
  • 🎯 TypeScript Support: Type safety đầy đủ
  • 🔧 Customizable: Dễ dàng tùy chỉnh giao diện
  • 📦 Lightweight: Kích thước nhỏ gọn
  • 🚀 Easy Integration: Dễ dàng tích hợp vào dự án

📦 Cài đặt

npm install shopping-cart-library

🚀 Sử dụng cơ bản

1. Thiết lập CartProvider

import React from 'react';
import { CartProvider } from 'shopping-cart-library';

function App() {
  return (
    <CartProvider>
      <YourApp />
    </CartProvider>
  );
}

2. Sử dụng ShoppingCart component

import React from 'react';
import { ShoppingCart } from 'shopping-cart-library';

function CartPage() {
  const handleCheckout = (items) => {
    console.log('Checkout items:', items);
    // Xử lý thanh toán
  };

  return (
    <ShoppingCart
      onCheckout={handleCheckout}
      showCheckoutButton={true}
      showClearButton={true}
    />
  );
}

3. Thêm sản phẩm vào giỏ hàng

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

function ProductCard({ product }) {
  const { addItem } = useCart();

  const handleAddToCart = () => {
    addItem({
      id: product.id,
      name: product.name,
      price: product.price,
      image: product.image,
      description: product.description,
      category: product.category
    });
  };

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

🎨 Components

Input

import { Input } from 'shopping-cart-library';

<Input
  type="text"
  placeholder="Enter your name"
  value={value}
  onChange={setValue}
  label="Name"
  error={error}
/>

Button

import { Button } from 'shopping-cart-library';

<Button
  variant="primary"
  size="medium"
  onClick={handleClick}
  loading={isLoading}
>
  Click me
</Button>

Modal

import { Modal } from 'shopping-cart-library';

<Modal
  isOpen={isOpen}
  onClose={handleClose}
  title="Confirmation"
  size="medium"
>
  <p>Are you sure you want to delete this item?</p>
</Modal>

Card

import { Card } from 'shopping-cart-library';

<Card
  title="Product Card"
  subtitle="Product description"
  hover={true}
  padding="medium"
>
  <p>Card content</p>
</Card>

CartItem

import { CartItem } from 'shopping-cart-library';

<CartItem
  item={cartItem}
  onUpdateQuantity={handleUpdateQuantity}
  onRemove={handleRemove}
  showImage={true}
  showDescription={true}
/>

🔧 API Reference

ShoppingCart Props

| Prop | Type | Default | Mô tả | |------|------|---------|-------| | onCheckout | (items: CartItem[]) => void | - | Callback khi người dùng checkout | | onItemUpdate | (item: CartItem) => void | - | Callback khi cập nhật sản phẩm | | onItemRemove | (id: string \| number) => void | - | Callback khi xóa sản phẩm | | showCheckoutButton | boolean | true | Hiển thị nút checkout | | showClearButton | boolean | true | Hiển thị nút xóa tất cả | | maxItems | number | - | Số lượng sản phẩm tối đa | | className | string | - | CSS class tùy chỉnh |

CartItem Type

interface CartItem {
  id: string | number;
  name: string;
  price: number;
  quantity: number;
  image?: string;
  description?: string;
  category?: string;
  inStock?: boolean;
  maxQuantity?: number;
}

useCart Hook

const {
  items,              // Danh sách sản phẩm trong giỏ
  addItem,           // Thêm sản phẩm
  removeItem,        // Xóa sản phẩm
  updateQuantity,    // Cập nhật số lượng
  clearCart,         // Xóa tất cả
  getTotalPrice,     // Tính tổng tiền
  getTotalItems,     // Tính tổng số lượng
  getItemQuantity    // Lấy số lượng của sản phẩm
} = useCart();

🎨 Customization

CSS Variables

Bạn có thể tùy chỉnh màu sắc thông qua CSS variables:

:root {
  --primary-color: #3b82f6;
  --secondary-color: #6b7280;
  --danger-color: #ef4444;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --background-color: #ffffff;
  --text-color: #111827;
  --border-color: #e5e7eb;
  --border-radius: 8px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

Custom Styling

<ShoppingCart
  className="my-custom-cart"
  style={{
    '--primary-color': '#your-color',
    '--border-radius': '12px'
  }}
/>

📱 Responsive Design

Thư viện được thiết kế responsive và tối ưu cho:

  • 📱 Mobile (320px+)
  • 📱 Tablet (768px+)
  • 💻 Desktop (1024px+)

🧪 Demo

Chạy demo để xem thư viện hoạt động:

# Mở file example/index.html trong trình duyệt
open example/index.html

🔨 Development

Cài đặt dependencies

npm install

Build thư viện

npm run build

Development mode

npm run dev

Linting

npm run lint

📄 License

MIT License - xem file LICENSE để biết thêm chi tiết.

🤝 Contributing

Mọi đóng góp đều được chào đón! Vui lòng:

  1. Fork repository
  2. Tạo feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Tạo Pull Request

📞 Support

Nếu bạn gặp vấn đề hoặc có câu hỏi, vui lòng tạo issue trên GitHub.


Được tạo với ❤️ bởi [Your Name]