react-shopping-cart-kit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Razan Aboushi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,429 @@
1
+ # React Shopping Cart 🛒
2
+
3
+ A modern, lightweight React shopping cart library with beautiful UI components. Perfect for e-commerce websites and marketplaces.
4
+
5
+ ## Features
6
+
7
+ - **Multi-Currency Support** - Dynamic currency switching with real-time conversion
8
+ - **Shipping Methods** - Configurable shipping options with costs
9
+ - **Discount Codes** - Percentage or fixed amount discounts
10
+ - **Internationalization** - English and Arabic with RTL support
11
+ - **TypeScript** - Fully typed with generic product types
12
+ - **Pre-built Components** - Beautiful, customizable UI components
13
+ - **State Management** - Built with Zustand for optimal performance
14
+ - **LocalStorage Persistence** - Cart saves automatically
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install react-shopping-cart
20
+ # or
21
+ yarn add react-shopping-cart
22
+ ```
23
+
24
+ ### Requirements
25
+ - React 18.0.0+
26
+ - React DOM 18.0.0+
27
+ - TypeScript 5.0+ (optional but recommended)
28
+
29
+ ## Quick Start
30
+
31
+ ### 1. Import Styles
32
+
33
+ ```tsx
34
+ // main.tsx or App.tsx
35
+ import 'react-shopping-cart/styles';
36
+ ```
37
+
38
+ ### 2. Wrap Your App with CartProvider
39
+
40
+ ```tsx
41
+ import { CartProvider } from 'react-shopping-cart';
42
+
43
+ const cartConfig = {
44
+ taxRate: 0.08, // 8% tax rate
45
+ currency: 'USD', // Default currency
46
+ availableCurrencies: [ // Multi-currency support
47
+ { code: 'USD', symbol: '$', name: 'US Dollar', conversionRate: 1.0 },
48
+ { code: 'EUR', symbol: '€', name: 'Euro', conversionRate: 0.92 },
49
+ ],
50
+ shippingMethods: [ // Shipping options
51
+ { id: 'standard', name: 'Standard Shipping', cost: 0, estimatedDays: '5-7 days' },
52
+ { id: 'express', name: 'Express Shipping', cost: 15, estimatedDays: '2-3 days' },
53
+ ],
54
+ discountCodes: [ // Discount codes
55
+ { code: 'SAVE10', amount: 10, type: 'percentage' },
56
+ ],
57
+ showTax: true,
58
+ showDiscount: true,
59
+ showShipping: true,
60
+ };
61
+
62
+ function App() {
63
+ return (
64
+ <CartProvider config={cartConfig} language="en">
65
+ <YourApp />
66
+ </CartProvider>
67
+ );
68
+ }
69
+ ```
70
+
71
+ ### 3. Use the Hook in Your Components
72
+
73
+ ```tsx
74
+ import { useShoppingCart } from 'react-shopping-cart';
75
+
76
+ function ProductCard({ product }) {
77
+ const { addItem, formatCurrency } = useShoppingCart();
78
+
79
+ return (
80
+ <div>
81
+ <h3>{product.name}</h3>
82
+ <p>{formatCurrency(product.price)}</p>
83
+ <button onClick={() => addItem(product)}>
84
+ Add to Cart
85
+ </button>
86
+ </div>
87
+ );
88
+ }
89
+ ```
90
+
91
+ ### 4. Add Pre-built Components (Optional)
92
+
93
+ ```tsx
94
+ import { CartButton, CartDrawer, CartSummary, CurrencySelector } from 'react-shopping-cart';
95
+
96
+ function Header() {
97
+ return (
98
+ <header>
99
+ <CurrencySelector compact />
100
+ <CartButton showBadge badgePosition="top-right" />
101
+ </header>
102
+ );
103
+ }
104
+
105
+ function App() {
106
+ return (
107
+ <CartProvider config={cartConfig}>
108
+ <Header />
109
+ <CartDrawer position="right" />
110
+ <CartSummary showTax={true} showDiscount={true} />
111
+ <YourProductList />
112
+ </CartProvider>
113
+ );
114
+ }
115
+ ```
116
+
117
+ ## Components
118
+
119
+ ### CartProvider
120
+
121
+ Wraps your app to provide cart context.
122
+
123
+ ```tsx
124
+ <CartProvider config={cartConfig} language="en">
125
+ <YourApp />
126
+ </CartProvider>
127
+ ```
128
+
129
+ **Props:**
130
+ - `config` - Configuration object (see Configuration section)
131
+ - `language` - Language code: `'en'` or `'ar'` (default: `'en'`)
132
+
133
+ ### CartButton
134
+
135
+ Shopping cart icon with badge showing item count.
136
+
137
+ ```tsx
138
+ <CartButton showBadge badgePosition="top-right" />
139
+ ```
140
+
141
+ **Props:**
142
+ - `showBadge` - Show item count badge (default: `true`)
143
+ - `badgePosition` - `'top-right'` or `'top-left'` (default: `'top-right'`)
144
+ - `className` - Additional CSS classes
145
+ - `onClick` - Click handler
146
+
147
+ ### CartDrawer
148
+
149
+ Side cart with smooth animation. Can be positioned as side drawer or centered popup.
150
+
151
+ ```tsx
152
+ <CartDrawer position="right" showCheckoutButton onCheckout={() => {}} />
153
+ ```
154
+
155
+ **Props:**
156
+ - `position` - `'right'`, `'left'`, or `'center'` (default: `'right'`)
157
+ - `showCheckoutButton` - Show checkout button (default: `true`)
158
+ - `onCheckout` - Checkout handler function
159
+ - `className` - Additional CSS classes
160
+
161
+ ### CartSummary
162
+
163
+ Displays subtotal, discount, taxes, shipping, and total.
164
+
165
+ ```tsx
166
+ <CartSummary showTax={true} showDiscount={true} showShipping={true} />
167
+ ```
168
+
169
+ **Props:**
170
+ - `showTax` - Show tax line (default: `true`)
171
+ - `showDiscount` - Show discount line (default: `true`)
172
+ - `showShipping` - Show shipping selection (default: `true`)
173
+
174
+ ### CurrencySelector
175
+
176
+ Currency dropdown for switching between currencies.
177
+
178
+ ```tsx
179
+ <CurrencySelector compact />
180
+ ```
181
+
182
+ **Props:**
183
+ - `compact` - Use compact dropdown style (default: `false`)
184
+ - `showCurrencyName` - Show full currency name (default: `true`)
185
+
186
+ ### CartItems
187
+
188
+ Renders all items in the cart.
189
+
190
+ ```tsx
191
+ <CartItems emptyMessage="Your cart is empty" />
192
+ ```
193
+
194
+ **Props:**
195
+ - `emptyMessage` - Message when cart is empty (default: `'Your cart is empty'`)
196
+ - `showRemoveButton` - Show remove button on items (default: `true`)
197
+
198
+ ### CartItem
199
+
200
+ Individual cart item component.
201
+
202
+ ```tsx
203
+ <CartItem item={product} showRemoveButton={true} />
204
+ ```
205
+
206
+ **Props:**
207
+ - `item` - Cart item data (required)
208
+ - `showRemoveButton` - Show remove button (default: `true`)
209
+
210
+ ### CheckoutButton
211
+
212
+ Primary checkout button with loading state.
213
+
214
+ ```tsx
215
+ <CheckoutButton loading={false} onClick={() => {}}>
216
+ Checkout
217
+ </CheckoutButton>
218
+ ```
219
+
220
+ **Props:**
221
+ - `loading` - Show loading state (default: `false`)
222
+ - `disabled` - Disable button (default: `false`)
223
+ - `onClick` - Click handler
224
+
225
+ ## useShoppingCart Hook
226
+
227
+ The main hook for accessing cart state and actions.
228
+
229
+ ```tsx
230
+ const {
231
+ // State
232
+ items,
233
+ subtotal,
234
+ tax,
235
+ shippingCost,
236
+ discountAmount,
237
+ total,
238
+ selectedCurrency,
239
+
240
+ // Actions
241
+ addItem,
242
+ removeItem,
243
+ updateItemQuantity,
244
+ clearCart,
245
+ applyDiscount,
246
+ removeDiscount,
247
+ setSelectedShippingMethod,
248
+ setSelectedCurrency,
249
+ formatCurrency,
250
+ } = useShoppingCart();
251
+ ```
252
+
253
+ ### State Properties
254
+
255
+ - `items` - Array of cart items
256
+ - `subtotal` - Subtotal in selected currency
257
+ - `tax` - Tax amount in selected currency
258
+ - `shippingCost` - Shipping cost in selected currency
259
+ - `discountAmount` - Discount amount in selected currency
260
+ - `total` - Total amount in selected currency
261
+ - `selectedCurrency` - Currently selected currency code
262
+
263
+ ### Action Methods
264
+
265
+ - `addItem(product)` - Add product to cart
266
+ - `removeItem(id)` - Remove item from cart
267
+ - `updateItemQuantity(id, quantity)` - Update item quantity
268
+ - `clearCart()` - Clear all items from cart
269
+ - `applyDiscount(code)` - Apply discount by code
270
+ - `removeDiscount()` - Remove applied discount
271
+ - `setSelectedShippingMethod(methodId)` - Select shipping method
272
+ - `setSelectedCurrency(currencyCode)` - Switch currency
273
+ - `formatCurrency(amount)` - Format amount with current currency
274
+
275
+ ## Configuration
276
+
277
+ ### CartConfig Object
278
+
279
+ ```typescript
280
+ {
281
+ // Basic Settings
282
+ taxRate: 0.08, // Tax rate as decimal (0.08 = 8%)
283
+ currency: 'USD', // Default currency code
284
+ storageKey: 'react-shopping-cart', // localStorage key
285
+ persistToLocalStorage: true, // Enable localStorage persistence
286
+
287
+ // Currency Configuration
288
+ availableCurrencies: [...], // Array of Currency objects
289
+ showCurrencySelector: true, // Show currency selector
290
+ decimalPlaces: 2, // Number of decimal places
291
+
292
+ // Shipping Configuration
293
+ shippingMethods: [...], // Array of ShippingMethod objects
294
+ showShipping: true, // Show shipping section
295
+
296
+ // Discount Configuration
297
+ discountCodes: [...], // Array of DiscountCode objects
298
+ showDiscount: true, // Show discount input
299
+
300
+ // Display Options
301
+ showTax: true, // Show tax line
302
+ theme: 'light', // 'light', 'dark', or 'auto'
303
+ }
304
+ ```
305
+
306
+ ### Currency Object
307
+
308
+ ```typescript
309
+ {
310
+ code: 'USD', // Currency code
311
+ symbol: '$', // Currency symbol
312
+ name: 'US Dollar', // Display name
313
+ conversionRate: 1.0, // Conversion rate from base currency
314
+ }
315
+ ```
316
+
317
+ ### ShippingMethod Object
318
+
319
+ ```typescript
320
+ {
321
+ id: 'standard', // Unique ID
322
+ name: 'Standard Shipping', // Display name
323
+ description: '5-7 business days', // Description
324
+ cost: 0, // Cost in base currency
325
+ estimatedDays: '5-7 days', // Estimated delivery
326
+ isDefault: false, // Is default option
327
+ }
328
+ ```
329
+
330
+ ### DiscountCode Object
331
+
332
+ ```typescript
333
+ {
334
+ code: 'SAVE10', // Discount code
335
+ amount: 10, // Discount amount
336
+ type: 'percentage', // 'percentage' or 'fixed'
337
+ expiryDate?: '2024-12-31', // Optional expiry date
338
+ usageLimit?: 100, // Optional usage limit
339
+ }
340
+ ```
341
+
342
+ ## Multi-Currency Support
343
+
344
+ All calculations (subtotal, tax, discount, shipping, total) are performed in the selected currency.
345
+
346
+ **Example:**
347
+ ```tsx
348
+ // Base: USD, User selects EUR (rate: 0.92)
349
+ // $100 product → €92
350
+ // Subtotal: €92 (converted)
351
+ // Tax (8%): €7.36 (calculated on converted amount)
352
+ // Total: €99.36 (all in EUR)
353
+ ```
354
+
355
+ ## Internationalization
356
+
357
+ Built-in support for English and Arabic with automatic RTL layout for Arabic.
358
+
359
+ **Set language:**
360
+ ```tsx
361
+ <CartProvider config={cartConfig} language="ar">
362
+ <YourApp />
363
+ </CartProvider>
364
+ ```
365
+
366
+ **Available languages:**
367
+ - `en` - English (default)
368
+ - `ar` - Arabic (with RTL support)
369
+
370
+ ## TypeScript Support
371
+
372
+ Fully typed with TypeScript. Extend the base product type for type safety:
373
+
374
+ ```tsx
375
+ import { BaseProduct, useShoppingCart } from 'react-shopping-cart';
376
+
377
+ interface MyProduct extends BaseProduct {
378
+ sku: string;
379
+ category: string;
380
+ }
381
+
382
+ function ProductPage() {
383
+ const { addItem, items } = useShoppingCart<MyProduct>();
384
+
385
+ const handleAdd = () => {
386
+ addItem({
387
+ id: '1',
388
+ name: 'Product',
389
+ price: 29.99,
390
+ sku: 'SKU-001',
391
+ category: 'Electronics',
392
+ });
393
+ };
394
+ }
395
+ ```
396
+
397
+ ## Customization
398
+
399
+ ### CSS Variables
400
+
401
+ Override CSS variables to customize the appearance:
402
+
403
+ ```css
404
+ :root {
405
+ --rsc-primary-color: #3b82f6;
406
+ --rsc-primary-hover: #2563eb;
407
+ --rsc-accent-color: #10b981;
408
+ --rsc-danger-color: #ef4444;
409
+ }
410
+ ```
411
+
412
+ ### Custom Styling
413
+
414
+ ```tsx
415
+ <CartButton
416
+ className="bg-purple-600 hover:bg-purple-700 text-white"
417
+ badgeClassName="bg-pink-500 text-white"
418
+ />
419
+ ```
420
+
421
+ ## License
422
+
423
+ MIT © [Razan Aboushi](https://github.com/razan-aboushi)
424
+
425
+ ## Support
426
+
427
+ - 📧 Email: razanalqaddoumi@gmail.com
428
+ - 🐛 GitHub: https://github.com/razan-aboushi/react-shopping-cart
429
+ - 💼 LinkedIn: https://www.linkedin.com/in/razan-aboushi/