@butternutbox/pawprint-native 0.3.1 → 0.4.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.
Files changed (32) hide show
  1. package/.turbo/turbo-build.log +16 -16
  2. package/CHANGELOG.md +15 -0
  3. package/dist/index.cjs +1447 -627
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +246 -5
  6. package/dist/index.d.ts +246 -5
  7. package/dist/index.js +1442 -627
  8. package/dist/index.js.map +1 -1
  9. package/package.json +2 -1
  10. package/src/components/atoms/Button/Button.tsx +4 -1
  11. package/src/components/atoms/Hint/Hint.tsx +1 -2
  12. package/src/components/atoms/Input/InputField.tsx +7 -1
  13. package/src/components/molecules/Animated/Animated.tsx +12 -3
  14. package/src/components/molecules/Countdown/Countdown.stories.tsx +218 -0
  15. package/src/components/molecules/Countdown/Countdown.tsx +315 -0
  16. package/src/components/molecules/Countdown/index.ts +2 -0
  17. package/src/components/molecules/Drawer/DrawerBody.tsx +12 -24
  18. package/src/components/molecules/ProductDisplayCard/ProductDisplayCard.stories.tsx +248 -0
  19. package/src/components/molecules/ProductDisplayCard/ProductDisplayCard.test.tsx +198 -0
  20. package/src/components/molecules/ProductDisplayCard/ProductDisplayCard.tsx +243 -0
  21. package/src/components/molecules/ProductDisplayCard/index.ts +5 -0
  22. package/src/components/molecules/ProductListingCard/Badge.tsx +65 -0
  23. package/src/components/molecules/ProductListingCard/Grid.tsx +59 -0
  24. package/src/components/molecules/ProductListingCard/ProductListingCard.stories.tsx +209 -0
  25. package/src/components/molecules/ProductListingCard/ProductListingCard.tsx +235 -0
  26. package/src/components/molecules/ProductListingCard/index.ts +2 -0
  27. package/src/components/molecules/TabNavigation/TabNavigation.stories.tsx +183 -0
  28. package/src/components/molecules/TabNavigation/TabNavigation.tsx +354 -0
  29. package/src/components/molecules/TabNavigation/index.ts +7 -0
  30. package/src/components/molecules/index.ts +4 -0
  31. package/src/utils/index.ts +1 -0
  32. package/src/utils/token.ts +1 -0
@@ -2,9 +2,7 @@ import React from "react"
2
2
  import { ScrollView, ScrollViewProps } from "react-native"
3
3
  import styled from "@emotion/native"
4
4
  import { useTheme } from "@emotion/react"
5
- import { useSafeAreaInsets } from "react-native-safe-area-context"
6
5
  import { useDrawerHeaderContext } from "./DrawerHeaderContext"
7
- import { useDrawerFooterContext } from "./DrawerFooterContext"
8
6
 
9
7
  export type DrawerBodyProps = ScrollViewProps
10
8
 
@@ -14,22 +12,12 @@ const StyledScrollView = styled(ScrollView)<{
14
12
  bodyPaddingHorizontal: number
15
13
  bodyPaddingRight: number
16
14
  bodyGap: number
17
- bodyPaddingVertical: number
18
- }>(
19
- ({
20
- bodyPaddingHorizontal,
21
- bodyPaddingRight,
22
- bodyGap,
23
- bodyPaddingVertical
24
- }) => ({
25
- flexGrow: 1,
26
- flexShrink: 1,
27
- paddingLeft: bodyPaddingHorizontal,
28
- paddingRight: bodyPaddingRight,
29
- gap: bodyGap,
30
- paddingTop: bodyPaddingVertical
31
- })
32
- )
15
+ }>(({ bodyPaddingHorizontal, bodyPaddingRight, bodyGap }) => ({
16
+ flex: 1,
17
+ paddingLeft: bodyPaddingHorizontal,
18
+ paddingRight: bodyPaddingRight,
19
+ gap: bodyGap
20
+ }))
33
21
 
34
22
  /**
35
23
  * Scrollable content area of the drawer. Grows to fill available space
@@ -42,13 +30,10 @@ export const DrawerBody = React.forwardRef<ScrollView, DrawerBodyProps>(
42
30
  const { buttons } = theme.tokens.components
43
31
  const { content } = spacing
44
32
  const headerContext = useDrawerHeaderContext()
45
- const hasFooter = useDrawerFooterContext()
46
- const insets = useSafeAreaInsets()
47
33
 
48
34
  const gap = parseTokenValue(content.slot.gap)
49
- const verticalPadding = parseTokenValue(content.slot.verticalPadding)
50
- const bottomPadding = verticalPadding + (hasFooter ? 0 : insets.bottom)
51
35
  const horizontalPadding = parseTokenValue(content.slot.horizontalPadding)
36
+ const topPadding = parseTokenValue(content.slot.verticalPadding)
52
37
 
53
38
  // When there's no header the close button floats in the top-right corner.
54
39
  // Reserve space on the right so body content doesn't slide under it.
@@ -64,9 +49,12 @@ export const DrawerBody = React.forwardRef<ScrollView, DrawerBodyProps>(
64
49
  bodyPaddingHorizontal={horizontalPadding}
65
50
  bodyPaddingRight={paddingRight}
66
51
  bodyGap={gap}
67
- bodyPaddingVertical={verticalPadding}
68
52
  contentContainerStyle={[
69
- { gap, paddingBottom: bottomPadding },
53
+ {
54
+ gap,
55
+ paddingTop: topPadding,
56
+ paddingBottom: 0
57
+ },
70
58
  contentContainerStyle
71
59
  ]}
72
60
  {...props}
@@ -0,0 +1,248 @@
1
+ import React from "react"
2
+ import { View, StyleSheet, Image } from "react-native"
3
+ import { ProductDisplayCard } from "./ProductDisplayCard"
4
+ import type { ProductDisplayCardProps } from "./ProductDisplayCard"
5
+
6
+ const PlaceholderImage = () => (
7
+ <Image
8
+ source={{ uri: "https://placeholder.co/148x148?text=Recipe" }}
9
+ style={{ width: "100%", height: "100%" }}
10
+ />
11
+ )
12
+
13
+ const styles = StyleSheet.create({
14
+ column: { flexDirection: "column", gap: 24, padding: 16 }
15
+ })
16
+
17
+ export default {
18
+ title: "Molecules/ProductDisplayCard",
19
+ component: ProductDisplayCard,
20
+ argTypes: {
21
+ device: {
22
+ control: { type: "select" },
23
+ options: ["desktop", "mobile"],
24
+ description: "Device variant affecting sizing and typography"
25
+ },
26
+ title: {
27
+ control: { type: "text" },
28
+ description: "Product title"
29
+ },
30
+ subtext: {
31
+ control: { type: "text" },
32
+ description: "Secondary text (e.g. price)"
33
+ },
34
+ showSubtext: {
35
+ control: { type: "boolean" },
36
+ description: "Show/hide subtext"
37
+ },
38
+ quantity: {
39
+ control: { type: "number", min: 1 },
40
+ description: "Current quantity"
41
+ },
42
+ showQuantityPicker: {
43
+ control: { type: "boolean" },
44
+ description: "Show/hide quantity picker"
45
+ },
46
+ disableQuantityButtons: {
47
+ control: { type: "boolean" },
48
+ description: "Disable quantity buttons"
49
+ },
50
+ hideQuantityButtons: {
51
+ control: { type: "boolean" },
52
+ description: "Hide quantity buttons"
53
+ },
54
+ showIncrementButton: {
55
+ control: { type: "boolean" },
56
+ description: "Show/hide increment button"
57
+ },
58
+ showDecrementButton: {
59
+ control: { type: "boolean" },
60
+ description: "Show/hide decrement button"
61
+ },
62
+ incrementDisabled: {
63
+ control: { type: "boolean" },
64
+ description: "Disable increment button"
65
+ },
66
+ decrementDisabled: {
67
+ control: { type: "boolean" },
68
+ description: "Disable decrement button"
69
+ },
70
+ showBanner: {
71
+ control: { type: "boolean" },
72
+ description: "Show/hide banner below card"
73
+ },
74
+ onQuantityChange: {
75
+ control: false,
76
+ description: "Callback when quantity changes"
77
+ },
78
+ image: {
79
+ control: false,
80
+ description: "Image element or content"
81
+ },
82
+ banner: {
83
+ control: { type: "text" },
84
+ description: "Banner content to show below card"
85
+ },
86
+ bannerType: {
87
+ control: { type: "select" },
88
+ options: ["error", "success", "warning", "info"],
89
+ description: "Banner notification type"
90
+ },
91
+ showBannerIcon: {
92
+ control: { type: "boolean" },
93
+ description: "Show/hide banner notification icon"
94
+ }
95
+ }
96
+ }
97
+
98
+ export const Playground = (args: ProductDisplayCardProps) => (
99
+ <View style={styles.column}>
100
+ <ProductDisplayCard {...args} />
101
+ </View>
102
+ )
103
+ Playground.args = {
104
+ device: "mobile",
105
+ title: "Recipe Name",
106
+ subtext: "+£0.00/pouch",
107
+ showSubtext: true,
108
+ quantity: 1,
109
+ showQuantityPicker: true,
110
+ showBanner: true,
111
+ bannerType: "info",
112
+ showBannerIcon: false,
113
+ banner: " High in protein • Natural ingredients • Vet approved",
114
+ image: <PlaceholderImage />
115
+ }
116
+
117
+ export const Default = () => (
118
+ <View style={styles.column}>
119
+ <ProductDisplayCard
120
+ device="mobile"
121
+ title="Recipe Name"
122
+ subtext="+£0.00/pouch"
123
+ showSubtext
124
+ quantity={1}
125
+ showQuantityPicker={false}
126
+ showBanner={false}
127
+ image={<PlaceholderImage />}
128
+ />
129
+ </View>
130
+ )
131
+
132
+ export const Desktop = () => (
133
+ <View style={styles.column}>
134
+ <ProductDisplayCard
135
+ device="desktop"
136
+ title="Recipe Name"
137
+ subtext="+£0.00/pouch"
138
+ showSubtext
139
+ quantity={1}
140
+ showQuantityPicker
141
+ showBanner={false}
142
+ image={<PlaceholderImage />}
143
+ />
144
+ </View>
145
+ )
146
+
147
+ export const Mobile = () => (
148
+ <View style={styles.column}>
149
+ <ProductDisplayCard
150
+ device="mobile"
151
+ title="Recipe Name"
152
+ subtext="+£0.50/pouch"
153
+ showSubtext
154
+ quantity={1}
155
+ showQuantityPicker
156
+ showBanner={false}
157
+ image={<PlaceholderImage />}
158
+ />
159
+ </View>
160
+ )
161
+
162
+ export const WithBanner = () => (
163
+ <View style={styles.column}>
164
+ <ProductDisplayCard
165
+ device="mobile"
166
+ title="Recipe Name"
167
+ subtext="+£0.00/pouch"
168
+ showSubtext
169
+ quantity={1}
170
+ showQuantityPicker
171
+ showBanner
172
+ bannerType="success"
173
+ showBannerIcon={false}
174
+ banner="High in protein • Natural ingredients • Vet approved"
175
+ image={<PlaceholderImage />}
176
+ />
177
+ </View>
178
+ )
179
+
180
+ export const WithBannerIcon = () => (
181
+ <View style={styles.column}>
182
+ <ProductDisplayCard
183
+ device="mobile"
184
+ title="Recipe Name"
185
+ subtext="+£0.00/pouch"
186
+ showSubtext
187
+ quantity={1}
188
+ showQuantityPicker
189
+ showBanner
190
+ bannerType="success"
191
+ showBannerIcon
192
+ banner="High in protein • Natural ingredients • Vet approved"
193
+ image={<PlaceholderImage />}
194
+ />
195
+ </View>
196
+ )
197
+
198
+ export const NoSubtext = () => (
199
+ <View style={styles.column}>
200
+ <ProductDisplayCard
201
+ device="mobile"
202
+ title="Recipe Name"
203
+ showSubtext={false}
204
+ quantity={1}
205
+ showQuantityPicker
206
+ showBanner={false}
207
+ image={<PlaceholderImage />}
208
+ />
209
+ </View>
210
+ )
211
+
212
+ export const AllVariants = () => (
213
+ <View style={styles.column}>
214
+ <ProductDisplayCard
215
+ device="desktop"
216
+ title="Recipe Name"
217
+ subtext="+£0.00/pouch"
218
+ showSubtext
219
+ quantity={1}
220
+ showQuantityPicker
221
+ showBanner={false}
222
+ image={<PlaceholderImage />}
223
+ />
224
+
225
+ <ProductDisplayCard
226
+ device="mobile"
227
+ title="Recipe Name"
228
+ subtext="+£0.50/pouch"
229
+ showSubtext
230
+ quantity={2}
231
+ showQuantityPicker
232
+ showBanner={false}
233
+ image={<PlaceholderImage />}
234
+ />
235
+
236
+ <ProductDisplayCard
237
+ device="mobile"
238
+ title="Recipe Name"
239
+ subtext="+£0.00/pouch"
240
+ showSubtext
241
+ quantity={1}
242
+ showQuantityPicker
243
+ showBanner
244
+ banner=" High in protein • Natural ingredients"
245
+ image={<PlaceholderImage />}
246
+ />
247
+ </View>
248
+ )
@@ -0,0 +1,198 @@
1
+ import { describe, it, expect } from "vitest"
2
+ import { screen } from "@testing-library/react"
3
+ import { View, Text } from "react-native"
4
+ import { ProductDisplayCard } from "./ProductDisplayCard"
5
+ import { renderWithTheme } from "../../../test-utils"
6
+
7
+ describe("ProductDisplayCard (Native)", () => {
8
+ it("renders with required title prop", () => {
9
+ renderWithTheme(<ProductDisplayCard title="Test Product" />)
10
+
11
+ expect(screen.getByText("Test Product")).toBeTruthy()
12
+ })
13
+
14
+ it("renders subtext when provided and showSubtext is true", () => {
15
+ renderWithTheme(
16
+ <ProductDisplayCard
17
+ title="Test Product"
18
+ subtext="£9.99"
19
+ showSubtext={true}
20
+ />
21
+ )
22
+
23
+ expect(screen.getByText("£9.99")).toBeTruthy()
24
+ })
25
+
26
+ it("hides subtext when showSubtext is false", () => {
27
+ renderWithTheme(
28
+ <ProductDisplayCard
29
+ title="Test Product"
30
+ subtext="£9.99"
31
+ showSubtext={false}
32
+ />
33
+ )
34
+
35
+ expect(screen.queryByText("£9.99")).toBeFalsy()
36
+ })
37
+
38
+ it("renders image when provided", () => {
39
+ renderWithTheme(
40
+ <ProductDisplayCard
41
+ title="Test Product"
42
+ image={
43
+ <View>
44
+ <Text>Image</Text>
45
+ </View>
46
+ }
47
+ />
48
+ )
49
+
50
+ expect(screen.getByText("Image")).toBeTruthy()
51
+ })
52
+
53
+ it("shows quantity picker when showQuantityPicker is true", () => {
54
+ renderWithTheme(
55
+ <ProductDisplayCard
56
+ title="Test Product"
57
+ showQuantityPicker={true}
58
+ quantity={1}
59
+ />
60
+ )
61
+
62
+ const numberInput = screen.getByDisplayValue("1")
63
+ expect(numberInput).toBeTruthy()
64
+ })
65
+
66
+ it("does not show quantity picker when showQuantityPicker is false", () => {
67
+ renderWithTheme(
68
+ <ProductDisplayCard title="Test Product" showQuantityPicker={false} />
69
+ )
70
+
71
+ expect(screen.queryByDisplayValue("1")).toBeFalsy()
72
+ })
73
+
74
+ it("renders banner when showBanner is true", () => {
75
+ renderWithTheme(
76
+ <ProductDisplayCard
77
+ title="Test Product"
78
+ showBanner={true}
79
+ banner={<Text>Test Banner</Text>}
80
+ />
81
+ )
82
+
83
+ expect(screen.getByText("Test Banner")).toBeTruthy()
84
+ })
85
+
86
+ it("does not render banner when showBanner is false", () => {
87
+ renderWithTheme(
88
+ <ProductDisplayCard
89
+ title="Test Product"
90
+ showBanner={false}
91
+ banner={<Text>Test Banner</Text>}
92
+ />
93
+ )
94
+
95
+ expect(screen.queryByText("Test Banner")).toBeFalsy()
96
+ })
97
+
98
+ it("renders with desktop device variant by default", () => {
99
+ renderWithTheme(<ProductDisplayCard title="Test Product" />)
100
+
101
+ expect(screen.getByText("Test Product")).toBeTruthy()
102
+ })
103
+
104
+ it("renders with mobile device variant when specified", () => {
105
+ renderWithTheme(<ProductDisplayCard title="Test Product" device="mobile" />)
106
+
107
+ expect(screen.getByText("Test Product")).toBeTruthy()
108
+ })
109
+
110
+ it("forwards ref correctly", () => {
111
+ const ref = { current: null as any }
112
+
113
+ renderWithTheme(<ProductDisplayCard ref={ref} title="Test Product" />)
114
+
115
+ expect(ref.current).toBeTruthy()
116
+ })
117
+
118
+ it("renders title and subtext together", () => {
119
+ renderWithTheme(
120
+ <ProductDisplayCard
121
+ title="Premium Recipe"
122
+ subtext="+£0.00/pouch"
123
+ showSubtext={true}
124
+ />
125
+ )
126
+
127
+ expect(screen.getByText("Premium Recipe")).toBeTruthy()
128
+ expect(screen.getByText("+£0.00/pouch")).toBeTruthy()
129
+ })
130
+
131
+ it("accepts React element as image", () => {
132
+ renderWithTheme(
133
+ <ProductDisplayCard
134
+ title="Test Product"
135
+ image={
136
+ <View>
137
+ <Text>Custom Image</Text>
138
+ </View>
139
+ }
140
+ />
141
+ )
142
+
143
+ expect(screen.getByText("Custom Image")).toBeTruthy()
144
+ })
145
+
146
+ it("accepts React element as banner", () => {
147
+ renderWithTheme(
148
+ <ProductDisplayCard
149
+ title="Test Product"
150
+ showBanner={true}
151
+ banner={
152
+ <View>
153
+ <Text>Custom Banner</Text>
154
+ </View>
155
+ }
156
+ />
157
+ )
158
+
159
+ expect(screen.getByText("Custom Banner")).toBeTruthy()
160
+ })
161
+
162
+ it("renders banner with different types", () => {
163
+ const { rerender } = renderWithTheme(
164
+ <ProductDisplayCard
165
+ title="Test Product"
166
+ showBanner={true}
167
+ banner={<Text>Test Banner</Text>}
168
+ bannerType="success"
169
+ />
170
+ )
171
+
172
+ expect(screen.getByText("Test Banner")).toBeTruthy()
173
+
174
+ rerender(
175
+ <ProductDisplayCard
176
+ title="Test Product"
177
+ showBanner={true}
178
+ banner={<Text>Error Banner</Text>}
179
+ bannerType="error"
180
+ />
181
+ )
182
+
183
+ expect(screen.getByText("Error Banner")).toBeTruthy()
184
+ })
185
+
186
+ it("displays banner with icon when showBannerIcon is true", () => {
187
+ renderWithTheme(
188
+ <ProductDisplayCard
189
+ title="Test Product"
190
+ showBanner={true}
191
+ banner={<Text>Test Banner</Text>}
192
+ showBannerIcon={true}
193
+ />
194
+ )
195
+
196
+ expect(screen.getByText("Test Banner")).toBeTruthy()
197
+ })
198
+ })