@butternutbox/pawprint-native 1.0.0 → 1.1.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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +10 -0
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -3
- package/dist/index.d.ts +34 -3
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/molecules/ProductDisplayCard/ProductDisplayCard.stories.tsx +40 -5
- package/src/components/molecules/ProductDisplayCard/ProductDisplayCard.test.tsx +55 -0
- package/src/components/molecules/ProductDisplayCard/ProductDisplayCard.tsx +35 -9
package/package.json
CHANGED
|
@@ -38,7 +38,12 @@ export default {
|
|
|
38
38
|
quantityBadge: {
|
|
39
39
|
control: { type: "boolean" },
|
|
40
40
|
description:
|
|
41
|
-
"Show a quantity badge over the image instead of the picker
|
|
41
|
+
"@deprecated — use `thumbnailBadge`. Show a legacy quantity badge over the image instead of the picker."
|
|
42
|
+
},
|
|
43
|
+
thumbnailBadge: {
|
|
44
|
+
control: false,
|
|
45
|
+
description:
|
|
46
|
+
"Render a Badge over the image (accepts any BadgeProps). Mutually exclusive with the quantity picker."
|
|
42
47
|
},
|
|
43
48
|
disableQuantityButtons: {
|
|
44
49
|
control: { type: "boolean" },
|
|
@@ -277,10 +282,42 @@ export const WithCustomBanner = () => (
|
|
|
277
282
|
</View>
|
|
278
283
|
)
|
|
279
284
|
|
|
285
|
+
export const WithThumbnailBadge = () => (
|
|
286
|
+
<View style={styles.column}>
|
|
287
|
+
{/* Consumer controls the badge content and variant. */}
|
|
288
|
+
<ProductDisplayCard
|
|
289
|
+
title="Recipe Name"
|
|
290
|
+
subtext="+£0.00/pouch"
|
|
291
|
+
showSubtext
|
|
292
|
+
thumbnailBadge={{ variant: "primary", size: "large", children: "New" }}
|
|
293
|
+
image={placeholderImageUrl}
|
|
294
|
+
/>
|
|
295
|
+
<ProductDisplayCard
|
|
296
|
+
title="Recipe Name"
|
|
297
|
+
subtext="+£0.00/pouch"
|
|
298
|
+
showSubtext
|
|
299
|
+
thumbnailBadge={{ variant: "promo", size: "large", children: "Popular" }}
|
|
300
|
+
image={placeholderImageUrl}
|
|
301
|
+
/>
|
|
302
|
+
{/* Suppresses the picker even when showQuantityPicker is set. */}
|
|
303
|
+
<ProductDisplayCard
|
|
304
|
+
title="Recipe Name"
|
|
305
|
+
subtext="+£0.00/pouch"
|
|
306
|
+
showSubtext
|
|
307
|
+
quantity={2}
|
|
308
|
+
showQuantityPicker
|
|
309
|
+
thumbnailBadge={{ variant: "primary", size: "large", children: "2" }}
|
|
310
|
+
image={placeholderImageUrl}
|
|
311
|
+
/>
|
|
312
|
+
</View>
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* @deprecated Prefer `thumbnailBadge`. This story documents the legacy
|
|
317
|
+
* `quantityBadge` prop behaviour during the deprecation window.
|
|
318
|
+
*/
|
|
280
319
|
export const WithQuantityBadge = () => (
|
|
281
320
|
<View style={styles.column}>
|
|
282
|
-
{/* OOB recipe / Extras card: quantity shown as a badge over the image
|
|
283
|
-
instead of the picker. The two are mutually exclusive. */}
|
|
284
321
|
<ProductDisplayCard
|
|
285
322
|
title="Recipe Name"
|
|
286
323
|
subtext="+£0.00/pouch"
|
|
@@ -289,8 +326,6 @@ export const WithQuantityBadge = () => (
|
|
|
289
326
|
quantityBadge
|
|
290
327
|
image={placeholderImageUrl}
|
|
291
328
|
/>
|
|
292
|
-
{/* Even with showQuantityPicker set, the badge wins and the picker is
|
|
293
|
-
suppressed. */}
|
|
294
329
|
<ProductDisplayCard
|
|
295
330
|
title="Recipe Name"
|
|
296
331
|
subtext="+£0.00/pouch"
|
|
@@ -242,4 +242,59 @@ describe("ProductDisplayCard (Native)", () => {
|
|
|
242
242
|
// ...and the picker input is not rendered.
|
|
243
243
|
expect(screen.queryByDisplayValue("3")).toBeFalsy()
|
|
244
244
|
})
|
|
245
|
+
|
|
246
|
+
it("renders a thumbnailBadge from BadgeProps", () => {
|
|
247
|
+
renderWithTheme(
|
|
248
|
+
<ProductDisplayCard
|
|
249
|
+
title="Test Product"
|
|
250
|
+
thumbnailBadge={{ variant: "primary", size: "large", children: "New" }}
|
|
251
|
+
image={
|
|
252
|
+
<View>
|
|
253
|
+
<Text>Image</Text>
|
|
254
|
+
</View>
|
|
255
|
+
}
|
|
256
|
+
/>
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
expect(screen.getByText("New")).toBeTruthy()
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it("suppresses the quantity picker when thumbnailBadge is set", () => {
|
|
263
|
+
renderWithTheme(
|
|
264
|
+
<ProductDisplayCard
|
|
265
|
+
title="Test Product"
|
|
266
|
+
quantity={2}
|
|
267
|
+
thumbnailBadge={{ children: "New" }}
|
|
268
|
+
showQuantityPicker
|
|
269
|
+
image={
|
|
270
|
+
<View>
|
|
271
|
+
<Text>Image</Text>
|
|
272
|
+
</View>
|
|
273
|
+
}
|
|
274
|
+
/>
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
expect(screen.getByText("New")).toBeTruthy()
|
|
278
|
+
expect(screen.queryByDisplayValue("2")).toBeFalsy()
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
it("prefers thumbnailBadge over the deprecated quantityBadge when both are set", () => {
|
|
282
|
+
renderWithTheme(
|
|
283
|
+
<ProductDisplayCard
|
|
284
|
+
title="Test Product"
|
|
285
|
+
quantity={9}
|
|
286
|
+
quantityBadge
|
|
287
|
+
thumbnailBadge={{ children: "Popular" }}
|
|
288
|
+
image={
|
|
289
|
+
<View>
|
|
290
|
+
<Text>Image</Text>
|
|
291
|
+
</View>
|
|
292
|
+
}
|
|
293
|
+
/>
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
expect(screen.getByText("Popular")).toBeTruthy()
|
|
297
|
+
// The legacy quantity badge should not render alongside it.
|
|
298
|
+
expect(screen.queryByText("9")).toBeFalsy()
|
|
299
|
+
})
|
|
245
300
|
})
|
|
@@ -3,7 +3,7 @@ import { View, ViewProps, Image, Pressable } from "react-native"
|
|
|
3
3
|
import styled from "@emotion/native"
|
|
4
4
|
import { useTheme } from "@emotion/react"
|
|
5
5
|
import { Typography } from "../../atoms/Typography"
|
|
6
|
-
import { Badge } from "../../atoms/Badge"
|
|
6
|
+
import { Badge, type BadgeProps } from "../../atoms/Badge"
|
|
7
7
|
import { NumberField } from "../../molecules/NumberField"
|
|
8
8
|
import { Notification } from "../Notification"
|
|
9
9
|
import { parseTokenValue } from "../../../utils"
|
|
@@ -16,12 +16,25 @@ export type ProductDisplayCardProps = ViewProps & {
|
|
|
16
16
|
onQuantityChange?: (quantity: number) => void
|
|
17
17
|
showQuantityPicker?: boolean
|
|
18
18
|
/**
|
|
19
|
+
* @deprecated Use `thumbnailBadge` instead. When both are set, `thumbnailBadge`
|
|
20
|
+
* wins. This prop will be removed in a future major release.
|
|
21
|
+
*
|
|
19
22
|
* Show a quantity badge overlaid on the top-right of the image (rendering the
|
|
20
23
|
* current `quantity`) instead of the quantity picker. Defaults to `false`.
|
|
21
24
|
* The badge and the quantity picker are mutually exclusive — only one shows
|
|
22
25
|
* at a time; when `quantityBadge` is true the picker is never rendered.
|
|
23
26
|
*/
|
|
24
27
|
quantityBadge?: boolean
|
|
28
|
+
/**
|
|
29
|
+
* Render a `Badge` overlaid on the top-right of the image. Accepts any
|
|
30
|
+
* `BadgeProps` (variant, size, icon, children, etc.) — pass them as an object.
|
|
31
|
+
* Mutually exclusive with the quantity picker: when set, the picker is never
|
|
32
|
+
* rendered.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* thumbnailBadge={{ variant: "primary", size: "large", children: "New" }}
|
|
36
|
+
*/
|
|
37
|
+
thumbnailBadge?: BadgeProps
|
|
25
38
|
disableQuantityButtons?: boolean
|
|
26
39
|
hideQuantityButtons?: boolean
|
|
27
40
|
incrementDisabled?: boolean
|
|
@@ -194,9 +207,14 @@ const StyledNoneBanner = styled(View)(({ theme }) => {
|
|
|
194
207
|
* @param quantity - *(optional)* Current quantity value
|
|
195
208
|
* @param onQuantityChange - *(optional)* Callback when quantity changes
|
|
196
209
|
* @param showQuantityPicker - *(optional)* Show/hide quantity picker
|
|
197
|
-
* @param quantityBadge - *(optional)*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
210
|
+
* @param quantityBadge - *(optional)* **@deprecated** — use `thumbnailBadge` instead.
|
|
211
|
+
* Show a legacy quantity badge over the image (renders the current `quantity`
|
|
212
|
+
* as a primary/large Badge). Mutually exclusive with the picker; defaults to
|
|
213
|
+
* `false`. When both `thumbnailBadge` and `quantityBadge` are set, `thumbnailBadge`
|
|
214
|
+
* wins.
|
|
215
|
+
* @param thumbnailBadge - *(optional)* Render a `Badge` overlaid on the top-right
|
|
216
|
+
* of the image. Accepts any `BadgeProps` (`variant`, `size`, `icon`, `children`, …).
|
|
217
|
+
* Mutually exclusive with the quantity picker.
|
|
200
218
|
* @param quantityStep - *(optional)* Increment/decrement amount (default: 1)
|
|
201
219
|
* @param image - *(optional)* Image URL string or React element
|
|
202
220
|
* @param banner - *(optional)* Banner content string or React element to show below card
|
|
@@ -217,6 +235,7 @@ export const ProductDisplayCard = React.forwardRef<
|
|
|
217
235
|
onQuantityChange,
|
|
218
236
|
showQuantityPicker = false,
|
|
219
237
|
quantityBadge = false,
|
|
238
|
+
thumbnailBadge,
|
|
220
239
|
disableQuantityButtons = false,
|
|
221
240
|
hideQuantityButtons = false,
|
|
222
241
|
incrementDisabled = false,
|
|
@@ -241,6 +260,15 @@ export const ProductDisplayCard = React.forwardRef<
|
|
|
241
260
|
}
|
|
242
261
|
}
|
|
243
262
|
|
|
263
|
+
// `thumbnailBadge` supersedes the deprecated `quantityBadge`. When set,
|
|
264
|
+
// consumers control the entire badge; when unset, the legacy `quantityBadge`
|
|
265
|
+
// boolean falls back to the previous hardcoded quantity chip.
|
|
266
|
+
const resolvedBadgeProps: BadgeProps | undefined =
|
|
267
|
+
thumbnailBadge ??
|
|
268
|
+
(quantityBadge
|
|
269
|
+
? { variant: "primary", size: "large", children: String(quantity) }
|
|
270
|
+
: undefined)
|
|
271
|
+
|
|
244
272
|
const cardContent = (
|
|
245
273
|
<StyledCardContainer
|
|
246
274
|
ref={ref}
|
|
@@ -262,11 +290,9 @@ export const ProductDisplayCard = React.forwardRef<
|
|
|
262
290
|
) : (
|
|
263
291
|
image
|
|
264
292
|
)}
|
|
265
|
-
{
|
|
293
|
+
{resolvedBadgeProps && (
|
|
266
294
|
<StyledBadgeOverlay pointerEvents="none">
|
|
267
|
-
<Badge
|
|
268
|
-
{String(quantity)}
|
|
269
|
-
</Badge>
|
|
295
|
+
<Badge {...resolvedBadgeProps} />
|
|
270
296
|
</StyledBadgeOverlay>
|
|
271
297
|
)}
|
|
272
298
|
</StyledImage>
|
|
@@ -286,7 +312,7 @@ export const ProductDisplayCard = React.forwardRef<
|
|
|
286
312
|
)}
|
|
287
313
|
</StyledTextContainer>
|
|
288
314
|
|
|
289
|
-
{showQuantityPicker && !
|
|
315
|
+
{showQuantityPicker && !resolvedBadgeProps && (
|
|
290
316
|
<View style={{ marginLeft: "auto" }}>
|
|
291
317
|
<NumberField
|
|
292
318
|
size="sm"
|