@haus-storefront-react/discounts 0.0.49 → 0.0.52-1

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.
Files changed (5) hide show
  1. package/CHANGELOG.md +44 -4
  2. package/index.js +26 -26
  3. package/index.mjs +3106 -3023
  4. package/package.json +6 -6
  5. package/README.md +0 -247
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-storefront-react/discounts",
3
- "version": "0.0.49",
3
+ "version": "0.0.52-1",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -11,10 +11,10 @@
11
11
  }
12
12
  },
13
13
  "dependencies": {
14
- "@haus-storefront-react/common-ui": "0.0.49",
15
- "@haus-storefront-react/common-utils": "0.0.49",
16
- "@haus-storefront-react/core": "0.0.49",
17
- "@haus-storefront-react/hooks": "0.0.49",
18
- "@haus-storefront-react/shared-types": "0.0.49"
14
+ "@haus-storefront-react/common-ui": "0.0.52-1",
15
+ "@haus-storefront-react/common-utils": "0.0.52-1",
16
+ "@haus-storefront-react/core": "0.0.52-1",
17
+ "@haus-storefront-react/hooks": "0.0.52-1",
18
+ "@haus-storefront-react/shared-types": "0.0.52-1"
19
19
  }
20
20
  }
package/README.md DELETED
@@ -1,247 +0,0 @@
1
- # Discounts Components
2
-
3
- A collection of headless, flexible discount components for e-commerce storefronts. Include coupon code management and active discounts display. Built with TypeScript, accessibility-first design, and works on both web and React Native.
4
-
5
- ## Components
6
-
7
- ### CouponCode Component
8
-
9
- A headless, flexible coupon code component for e-commerce storefronts. Supports applying and removing coupon codes, error handling, and platform-agnostic architecture.
10
-
11
- ## Installation
12
-
13
- ```bash
14
- npm install @haus-storefront-react/discounts
15
- # or
16
- yarn add @haus-storefront-react/discounts
17
- ```
18
-
19
- ## Requirements
20
-
21
- This package requires **@haus-storefront-react/core version 15.0.0 or higher** to function properly. Make sure you have the correct version installed:
22
-
23
- ## Components
24
-
25
- ### CouponCode component
26
-
27
- Supports applying and removing coupon codes, error handling, and platform-agnostic architecture.
28
-
29
- #### Usage Example
30
-
31
- ```tsx
32
- import { CouponCode } from '@haus-storefront-react/discounts'
33
- ;<CouponCode.Root>
34
- {(couponCodeContext) => (
35
- <div>
36
- <CouponCode.Input placeholder="Enter coupon code" />
37
- <CouponCode.ApplyButton>Apply</CouponCode.ApplyButton>
38
- <CouponCode.Error>
39
- <div>Invalid coupon code</div>
40
- </CouponCode.Error>
41
- </div>
42
- )
43
- </div>
44
- )}
45
- </CouponCode.Root>
46
- ```
47
-
48
- ## API Reference
49
-
50
- ### CouponCode.Root
51
-
52
- The main container component that provides the coupon code context.
53
-
54
- **Props:**
55
-
56
- - `children`: Render function that receives the coupon code context
57
-
58
- ### CouponCode.Input
59
-
60
- Text input for entering coupon codes.
61
-
62
- **Props:**
63
-
64
- - `asChild`: Use a custom component instead of the default input
65
- - `placeholder`: Placeholder text
66
- - `disabled`: Disable the input
67
- - All standard HTML input attributes
68
-
69
- **Features:**
70
-
71
- - Enter key applies the coupon code
72
- - Escape key closes the input
73
- - Auto-focus when opened
74
-
75
- ### CouponCode.ApplyButton
76
-
77
- Button to apply the entered coupon code.
78
-
79
- **Props:**
80
-
81
- - `asChild`: Use a custom component instead of the default button
82
- - `disabled`: Disable the button (auto-disabled when no code entered)
83
- - All standard HTML button attributes
84
-
85
- ### CouponCode.RemoveButton
86
-
87
- Button to remove an applied coupon code.
88
-
89
- **Props:**
90
-
91
- - `couponCode`: The coupon code to remove
92
- - `asChild`: Use a custom component instead of the default button
93
- - All standard HTML button attributes
94
-
95
- ## ActiveDiscounts Component
96
-
97
- A headless component for displaying and managing active discounts on an order. Shows applied discounts with their descriptions and amounts, and provides functionality to remove coupon codes.
98
-
99
- ### Usage Example
100
-
101
- ```tsx
102
- import { ActiveDiscounts } from '@haus-storefront-react/discounts'
103
- import { Price } from '@haus-storefront-react/common-ui'
104
- ;<ActiveDiscounts.Root>
105
- {(activeDiscountsContext) => (
106
- <ActiveDiscounts.List>
107
- {({ discounts }) => (
108
- <div>
109
- {discounts?.map((discount, index) => (
110
- <ActiveDiscounts.Item key={index} discount={discount}>
111
- {({ discount }) => (
112
- <div>
113
- <div>
114
- <span>{discount.description}</span>
115
- {discount.promotion?.couponCode && (
116
- <span>({discount.promotion.couponCode})</span>
117
- )}
118
- </div>
119
-
120
- <ActiveDiscounts.RemoveButton discount={discount}>
121
- Remove discount code
122
- </ActiveDiscounts.RemoveButton>
123
-
124
- <Price.Root
125
- price={discount.amount}
126
- priceWithTax={discount.amountWithTax}
127
- currencyCode={discount.currencyCode}
128
- asChild
129
- >
130
- <div>
131
- <Price.Amount withCurrency />
132
- </div>
133
- </Price.Root>
134
- </div>
135
- )}
136
- </ActiveDiscounts.Item>
137
- ))}
138
- </div>
139
- )}
140
- </ActiveDiscounts.List>
141
- )}
142
- </ActiveDiscounts.Root>
143
- ```
144
-
145
- ### API Reference
146
-
147
- #### ActiveDiscounts.Root
148
-
149
- The main container component that provides the active discounts context.
150
-
151
- **Props:**
152
-
153
- - `children`: Render function that receives the active discounts context
154
-
155
- #### ActiveDiscounts.List
156
-
157
- Container for the list of active discounts.
158
-
159
- **Props:**
160
-
161
- - `asChild`: Use a custom component instead of the default div
162
- - `children`: Render function that receives the discounts array
163
-
164
- #### ActiveDiscounts.Item
165
-
166
- Container for individual discount items.
167
-
168
- **Props:**
169
-
170
- - `asChild`: Use a custom component instead of the default div
171
- - `children`: Render function that receives the discount object
172
-
173
- #### ActiveDiscounts.RemoveButton
174
-
175
- Button to remove a coupon code from the order. Only renders if the discount has a promotion with a coupon code.
176
-
177
- **Props:**
178
-
179
- - `discount`: The discount object (required to check if it has a coupon code)
180
- - `asChild`: Use a custom component instead of the default button
181
- - All standard HTML button attributes
182
-
183
- **Features:**
184
-
185
- - Only renders if the discount has a promotion with a coupon code
186
- - Automatically removes the coupon code associated with the discount
187
- - Platform agnostic (works on web and React Native)
188
-
189
- ## Context Value
190
-
191
- The `CouponCode.Root` component provides the following context to its children:
192
-
193
- ```typescript
194
- interface UseCouponCodeReturn {
195
- code: string // Current coupon code input
196
- isLoading: boolean // Loading state for API calls
197
- error: Error | null // Error state
198
- isOpen: boolean // Whether input is visible
199
- setCode: (code: string) => void
200
- setIsOpen: (isOpen: boolean) => void
201
- applyCouponCode: (code: string) => Promise<void>
202
- removeCouponCode: (code: string) => Promise<void>
203
- clearError: () => void
204
- }
205
- ```
206
-
207
- ### React Native Usage
208
-
209
- ```tsx
210
- import { View, Text, TouchableOpacity, TextInput } from 'react-native'
211
- ;<CouponCode.Root>
212
- {(context) => (
213
- <View>
214
- {context.isOpen ? (
215
- <View>
216
- <CouponCode.Input asChild>
217
- <TextInput placeholder="Enter coupon code" />
218
- </CouponCode.Input>
219
- <CouponCode.ApplyButton asChild>
220
- <TouchableOpacity>
221
- <Text>Apply</Text>
222
- </TouchableOpacity>
223
- </CouponCode.ApplyButton>
224
- </View>
225
- ) : (
226
- <CouponCode.ToggleButton asChild>
227
- <TouchableOpacity>
228
- <Text>Add Coupon Code</Text>
229
- </TouchableOpacity>
230
- </CouponCode.ToggleButton>
231
- )}
232
-
233
- <CouponCode.Error asChild>
234
- <View>
235
- <Text>Invalid coupon code</Text>
236
- </View>
237
- </CouponCode.Error>
238
- </View>
239
- )}
240
- </CouponCode.Root>
241
- ```
242
-
243
- ## Dependencies
244
-
245
- - `@haus-storefront-react/core`: Core SDK and platform detection (requires version 15.0.0 or higher)
246
- - `@haus-storefront-react/common-utils`: Platform utilities and context creation
247
- - `@haus-storefront-react/shared-types`: TypeScript type definitions