@shopify/shop-minis-cli 0.0.83 → 0.0.84

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 (94) hide show
  1. package/build/commands/codemod/releases/index.js +2 -0
  2. package/build/commands/codemod/releases/index.js.map +1 -1
  3. package/build/commands/codemod/releases/v0-0-84.d.ts +3 -0
  4. package/build/commands/codemod/releases/v0-0-84.js +41 -0
  5. package/build/commands/codemod/releases/v0-0-84.js.map +1 -0
  6. package/build/commands/create-mini/index.js +0 -10
  7. package/build/commands/create-mini/index.js.map +1 -1
  8. package/build/commands/generate-graphql-types/index.js +1 -1
  9. package/build/commands/generate-graphql-types/index.js.map +1 -1
  10. package/build/data/types/autogenerated/shop-minis-admin-api/graphql.d.ts +151 -1
  11. package/build/data/types/autogenerated/shop-minis-admin-api/graphql.js +4 -0
  12. package/build/data/types/autogenerated/shop-minis-admin-api/graphql.js.map +1 -1
  13. package/package.json +1 -1
  14. package/templates/__template_common/.eslintrc.js +1 -1
  15. package/templates/__template_hello_world/src/assets/Modal-component-thumbnail.png +0 -0
  16. package/templates/__template_hello_world/src/assets/ProductCard-component-thumbnail.png +0 -0
  17. package/templates/__template_hello_world/src/assets/ProductLink-component-thumbnail.png +0 -0
  18. package/templates/__template_hello_world/src/assets/assets.d.ts +0 -4
  19. package/templates/__template_hello_world/src/assets/figma-logo.svg +0 -14
  20. package/templates/__template_hello_world/src/assets/shop-minis-logo.svg +0 -7
  21. package/templates/__template_hello_world/src/components/ButtonCTA.tsx +0 -31
  22. package/templates/__template_hello_world/src/components/ComponentLink.ts +0 -94
  23. package/templates/__template_hello_world/src/components/ComponentListItem.tsx +0 -39
  24. package/templates/__template_hello_world/src/components/FeaturedComponents.tsx +0 -110
  25. package/templates/__template_hello_world/src/components/Header.tsx +0 -40
  26. package/templates/__template_hello_world/src/components/quiz/ImageCarouselSlide.tsx +0 -54
  27. package/templates/__template_hello_world/src/components/quiz/MultipleChoiceSlide.tsx +0 -77
  28. package/templates/__template_hello_world/src/components/quiz/QuizProvider.tsx +0 -64
  29. package/templates/__template_hello_world/src/components/quiz/QuizSlide.tsx +0 -79
  30. package/templates/__template_hello_world/src/components/quiz/QuizSlideCommander.tsx +0 -35
  31. package/templates/__template_hello_world/src/components/quiz/TextFieldSlide.tsx +0 -84
  32. package/templates/__template_hello_world/src/components/quiz/TextSlide.tsx +0 -6
  33. package/templates/__template_hello_world/src/components/quiz/types.ts +0 -72
  34. package/templates/__template_hello_world/src/data/Test.graphql +0 -33
  35. package/templates/__template_hello_world/src/data/Test.graphql.d.ts +0 -107
  36. package/templates/__template_hello_world/src/data/TestProducts.graphql +0 -64
  37. package/templates/__template_hello_world/src/data/TestProducts.graphql.d.ts +0 -197
  38. package/templates/__template_hello_world/src/fixtures/mocked-products-with-variants.ts +0 -274
  39. package/templates/__template_hello_world/src/hooks/useQuizData.ts +0 -26
  40. package/templates/__template_hello_world/src/hooks/useQuizState.ts +0 -27
  41. package/templates/__template_hello_world/src/index.tsx +0 -10
  42. package/templates/__template_hello_world/src/routes.tsx +0 -149
  43. package/templates/__template_hello_world/src/screens/AccordionScreen.tsx +0 -73
  44. package/templates/__template_hello_world/src/screens/AvatarScreen.tsx +0 -95
  45. package/templates/__template_hello_world/src/screens/BottomSheetScreen.tsx +0 -712
  46. package/templates/__template_hello_world/src/screens/ButtonsScreen.tsx +0 -90
  47. package/templates/__template_hello_world/src/screens/GridScreen.tsx +0 -74
  48. package/templates/__template_hello_world/src/screens/HomeScreen.tsx +0 -81
  49. package/templates/__template_hello_world/src/screens/IconsScreen.tsx +0 -181
  50. package/templates/__template_hello_world/src/screens/ImageMultipleChoiceScreen.tsx +0 -145
  51. package/templates/__template_hello_world/src/screens/InputScreen.tsx +0 -149
  52. package/templates/__template_hello_world/src/screens/MediaScreen.tsx +0 -130
  53. package/templates/__template_hello_world/src/screens/ModalScreen.tsx +0 -379
  54. package/templates/__template_hello_world/src/screens/MultipleChoiceScreen.tsx +0 -75
  55. package/templates/__template_hello_world/src/screens/ProductCardGridScreen.tsx +0 -68
  56. package/templates/__template_hello_world/src/screens/ProductCardScreen.tsx +0 -62
  57. package/templates/__template_hello_world/src/screens/ProductLinkScreen.tsx +0 -215
  58. package/templates/__template_hello_world/src/screens/ProgressIndicatorScreen.tsx +0 -77
  59. package/templates/__template_hello_world/src/screens/QuantityPickerScreen.tsx +0 -76
  60. package/templates/__template_hello_world/src/screens/QuizResultScreen.tsx +0 -82
  61. package/templates/__template_hello_world/src/screens/QuizScreen.tsx +0 -40
  62. package/templates/__template_hello_world/src/screens/QuizSlideScreen.tsx +0 -150
  63. package/templates/__template_hello_world/src/screens/ShopActionsScreen.tsx +0 -48
  64. package/templates/__template_hello_world/src/screens/SpinnerScreen.tsx +0 -63
  65. package/templates/__template_hello_world/src/screens/TypographyScreen.tsx +0 -274
  66. package/templates/__template_hello_world/src/screens/VariantPickerScreen.tsx +0 -120
  67. package/templates/__template_hello_world/src/screens/WebViewScreen.tsx +0 -42
  68. package/templates/__template_hello_world/src/types.ts +0 -31
  69. package/templates/__template_hello_world/src/utils/getFlagEmoji.ts +0 -7
  70. package/templates/__template_hello_world/src/utils/mockQuizData.ts +0 -330
  71. package/templates/__template_hello_world/src/utils/quizUtils.ts +0 -75
  72. package/templates/__template_snowboardz/src/assets/assets.d.ts +0 -4
  73. package/templates/__template_snowboardz/src/assets/circle-blue.svg +0 -9
  74. package/templates/__template_snowboardz/src/assets/circle-green.svg +0 -9
  75. package/templates/__template_snowboardz/src/assets/circle-purple.svg +0 -9
  76. package/templates/__template_snowboardz/src/assets/circle-rainbow.svg +0 -34
  77. package/templates/__template_snowboardz/src/assets/circle-red.svg +0 -9
  78. package/templates/__template_snowboardz/src/assets/circle-yellow.svg +0 -9
  79. package/templates/__template_snowboardz/src/assets/skill-level-icon-advanced.svg +0 -3
  80. package/templates/__template_snowboardz/src/assets/skill-level-icon-beginner.svg +0 -3
  81. package/templates/__template_snowboardz/src/assets/skill-level-icon-intermediate.svg +0 -3
  82. package/templates/__template_snowboardz/src/components/ColorButton.tsx +0 -79
  83. package/templates/__template_snowboardz/src/components/ColorPicker.tsx +0 -40
  84. package/templates/__template_snowboardz/src/components/EmptyResult.tsx +0 -52
  85. package/templates/__template_snowboardz/src/components/SkillLevelIcon.tsx +0 -41
  86. package/templates/__template_snowboardz/src/components/SkillLevelPicker.tsx +0 -92
  87. package/templates/__template_snowboardz/src/data/TestProducts.graphql +0 -34
  88. package/templates/__template_snowboardz/src/data/TestProducts.graphql.d.ts +0 -118
  89. package/templates/__template_snowboardz/src/hooks/useSnowboardData.tsx +0 -37
  90. package/templates/__template_snowboardz/src/index.tsx +0 -10
  91. package/templates/__template_snowboardz/src/routes.tsx +0 -17
  92. package/templates/__template_snowboardz/src/screens/HomeScreen.tsx +0 -126
  93. package/templates/__template_snowboardz/src/types.ts +0 -12
  94. package/templates/__template_snowboardz/src/utils.ts +0 -17
@@ -1,712 +0,0 @@
1
- import {ComponentProps, useCallback, useState} from 'react'
2
- import {SafeAreaView, ScrollView, TouchableOpacity} from 'react-native'
3
- import Animated from 'react-native-reanimated'
4
- import {
5
- Button,
6
- Box,
7
- Text,
8
- FlatListBottomSheet,
9
- ProductCardGridBottomSheet,
10
- ScrollViewBottomSheet,
11
- SectionListBottomSheet,
12
- useTheme,
13
- useMinisQuery,
14
- TouchableProduct,
15
- ProductCard,
16
- Avatar,
17
- useBottomSheet,
18
- GridBottomSheet,
19
- useScrollViewBottomSheet,
20
- useGridBottomSheet,
21
- useFlatListBottomSheet,
22
- useProductCardGridBottomSheet,
23
- useSectionListBottomSheet,
24
- } from '@shopify/shop-minis-platform-sdk'
25
-
26
- import {Header} from '../components/Header'
27
- import TestProductsQuery from '../data/TestProducts.graphql'
28
-
29
- const SHOP_GID = 'gid://shopify/Shop/68822335510'
30
- const PRODUCT_GIDS = [
31
- 'gid://shopify/Product/7982542651414',
32
- 'gid://shopify/Product/7982528397334',
33
- 'gid://shopify/Product/7982535704598',
34
- 'gid://shopify/Product/7982577352726',
35
- 'gid://shopify/Product/7982564245526',
36
- 'gid://shopify/Product/7982547763222',
37
- 'gid://shopify/Product/7982499495958',
38
- 'gid://shopify/Product/7982540521494',
39
- 'gid://shopify/Product/7982554710038',
40
- 'gid://shopify/Product/7982557200406',
41
- 'gid://shopify/Product/7982571257878',
42
- 'gid://shopify/Product/7982372388886',
43
- ]
44
-
45
- const DemoContent = ({length = 50}: {length?: number}) => (
46
- <>
47
- {Array.from({length}, (_, index) => (
48
- <Box key={`item-${index}`} marginBottom="s" marginHorizontal="gutter">
49
- <Text>item {index + 1}</Text>
50
- </Box>
51
- ))}
52
- </>
53
- )
54
-
55
- const ExampleFlatList = ({
56
- onDismiss,
57
- }: {
58
- onDismiss: ComponentProps<typeof ScrollViewBottomSheet>['onDismiss']
59
- }) => {
60
- return (
61
- <FlatListBottomSheet
62
- onDismiss={onDismiss}
63
- data={Array.from({length: 50}, (_, index) => ({
64
- key: index,
65
- title: `Thing ${index + 1}`,
66
- }))}
67
- renderItem={({item}) => {
68
- return (
69
- <Box key={item.key} marginBottom="s" marginHorizontal="gutter">
70
- <Text>{item.title}</Text>
71
- </Box>
72
- )
73
- }}
74
- />
75
- )
76
- }
77
-
78
- const ExampleGrid = ({
79
- onDismiss,
80
- }: {
81
- onDismiss: ComponentProps<typeof ScrollViewBottomSheet>['onDismiss']
82
- }) => {
83
- const theme = useTheme()
84
- const data = Array.from({length: 50}, (_, index) => ({
85
- text: `Item ${index + 1}`,
86
- }))
87
-
88
- return (
89
- <GridBottomSheet
90
- onDismiss={onDismiss}
91
- data={data}
92
- renderItem={({item}) => (
93
- <Box
94
- minHeight={200}
95
- backgroundColor="backgrounds-success"
96
- justifyContent="center"
97
- alignItems="center"
98
- >
99
- <Text>{item.text}</Text>
100
- </Box>
101
- )}
102
- contentContainerStyle={{
103
- paddingHorizontal: theme.spacing.gutter,
104
- paddingBottom: theme.spacing.m,
105
- }}
106
- />
107
- )
108
- }
109
-
110
- const ExampleProductCardGrid = ({
111
- onDismiss,
112
- }: {
113
- onDismiss: ComponentProps<typeof ScrollViewBottomSheet>['onDismiss']
114
- }) => {
115
- const theme = useTheme()
116
-
117
- const {loading, data} = useMinisQuery(TestProductsQuery, {
118
- variables: {
119
- shopId: SHOP_GID,
120
- productIds: PRODUCT_GIDS,
121
- },
122
- })
123
-
124
- const products = data?.shop?.productsByIds ?? []
125
-
126
- // TODO: It would be nice to handle this inside the bottomsheet with a spinner
127
- if (loading || !data) return null
128
-
129
- return (
130
- <ProductCardGridBottomSheet
131
- onDismiss={onDismiss}
132
- products={products}
133
- renderItem={({product}) => (
134
- <TouchableProduct product={product} key={product.id}>
135
- <ProductCard shopId={SHOP_GID} product={product} />
136
- </TouchableProduct>
137
- )}
138
- contentContainerStyle={{
139
- paddingHorizontal: theme.spacing.gutter,
140
- paddingBottom: theme.spacing.m,
141
- }}
142
- />
143
- )
144
- }
145
-
146
- const ExampleScrollView1 = ({
147
- onDismiss,
148
- }: {
149
- onDismiss: ComponentProps<typeof ScrollViewBottomSheet>['onDismiss']
150
- }) => {
151
- return (
152
- <ScrollViewBottomSheet onDismiss={onDismiss}>
153
- <DemoContent />
154
- </ScrollViewBottomSheet>
155
- )
156
- }
157
-
158
- const ExampleScrollView2 = ({
159
- onDismiss,
160
- }: {
161
- onDismiss: ComponentProps<typeof ScrollViewBottomSheet>['onDismiss']
162
- }) => {
163
- const [answer, setAnswer] = useState<number | null>(null)
164
-
165
- return (
166
- <ScrollViewBottomSheet
167
- onDismiss={onDismiss}
168
- variant="header"
169
- headerText="Poll"
170
- >
171
- <Box marginBottom="m" marginHorizontal="gutter">
172
- <Avatar
173
- color="foregrounds-regular"
174
- title="Mother Goose"
175
- source={{uri: 'https://picsum.photos/150/150'}}
176
- />
177
- </Box>
178
-
179
- <Box marginBottom="m" marginHorizontal="gutter">
180
- <Text>
181
- How much wood could a woodchuck chuck if a woodchuck could chuck wood?
182
- </Text>
183
- </Box>
184
-
185
- <Box marginBottom="s" marginHorizontal="gutter">
186
- <Button
187
- text="5"
188
- variant={answer === 5 ? 'primary' : 'outlined'}
189
- onPress={() => setAnswer(5)}
190
- />
191
- </Box>
192
- <Box marginBottom="s" marginHorizontal="gutter">
193
- <Button
194
- text="10"
195
- variant={answer === 10 ? 'primary' : 'outlined'}
196
- onPress={() => setAnswer(10)}
197
- />
198
- </Box>
199
- <Box marginBottom="s" marginHorizontal="gutter">
200
- <Button
201
- text="500"
202
- variant={answer === 500 ? 'primary' : 'outlined'}
203
- onPress={() => setAnswer(500)}
204
- />
205
- </Box>
206
- <Box marginBottom="s" marginHorizontal="gutter">
207
- <Button
208
- text="10000"
209
- variant={answer === 10000 ? 'primary' : 'outlined'}
210
- onPress={() => setAnswer(10000)}
211
- />
212
- </Box>
213
- </ScrollViewBottomSheet>
214
- )
215
- }
216
-
217
- const ExampleSectionList = ({
218
- onDismiss,
219
- }: {
220
- onDismiss: ComponentProps<typeof ScrollViewBottomSheet>['onDismiss']
221
- }) => {
222
- return (
223
- <SectionListBottomSheet
224
- onDismiss={onDismiss}
225
- sections={Array.from({length: 50}, (_, index) => ({
226
- title: `Section ${index + 1}`,
227
- data: ['1', '2', '3', '4', '5'],
228
- }))}
229
- renderSectionHeader={({section: {title}}) => (
230
- <Box padding="s" backgroundColor="backgrounds-success">
231
- <Text variant="heroBold">{title}</Text>
232
- </Box>
233
- )}
234
- renderItem={({item}) => (
235
- <Box padding="s">
236
- <Text>{item}</Text>
237
- </Box>
238
- )}
239
- />
240
- )
241
- }
242
-
243
- const ExampleSnapPoints = ({
244
- onDismiss,
245
- }: {
246
- onDismiss: ComponentProps<typeof ScrollViewBottomSheet>['onDismiss']
247
- }) => {
248
- return (
249
- <FlatListBottomSheet
250
- onDismiss={onDismiss}
251
- snapPoints={{
252
- positionOne: 200,
253
- positionTwo: 500,
254
- }}
255
- data={Array.from({length: 50}, (_, index) => ({
256
- key: index,
257
- title: `Thing ${index + 1}`,
258
- }))}
259
- renderItem={({item}) => {
260
- return (
261
- <Box key={item.key} marginBottom="s" marginHorizontal="gutter">
262
- <Text>{item.title}</Text>
263
- </Box>
264
- )
265
- }}
266
- />
267
- )
268
- }
269
-
270
- const ExampleVariants = ({
271
- onDismiss,
272
- }: {
273
- onDismiss: ComponentProps<typeof ScrollViewBottomSheet>['onDismiss']
274
- }) => {
275
- return (
276
- <FlatListBottomSheet
277
- onDismiss={onDismiss}
278
- variant="handle"
279
- data={Array.from({length: 50}, (_, index) => ({
280
- key: index,
281
- title: `Thing ${index + 1}`,
282
- }))}
283
- renderItem={({item}) => {
284
- return (
285
- <Box key={item.key} paddingBottom="s" paddingHorizontal="m">
286
- <Text>{item.title}</Text>
287
- </Box>
288
- )
289
- }}
290
- />
291
- )
292
- }
293
-
294
- const ExampleUseBottomSheet = ({
295
- onDismiss,
296
- }: {
297
- onDismiss: ComponentProps<typeof ScrollViewBottomSheet>['onDismiss']
298
- }) => {
299
- const theme = useTheme()
300
-
301
- const scrollToTop = useCallback((ref?: Animated.ScrollView) => {
302
- ref?.scrollTo({y: 0, animated: false})
303
- }, [])
304
-
305
- const {BottomSheet, scrollRef, onScroll, dismissBottomSheet} = useBottomSheet<
306
- typeof Animated.ScrollView
307
- >({
308
- onDismiss,
309
- scrollToTop,
310
- })
311
-
312
- return (
313
- <BottomSheet>
314
- <Animated.ScrollView
315
- ref={scrollRef}
316
- style={[
317
- {
318
- flex: 1,
319
- elevation: 10,
320
- backgroundColor: theme.colors['backgrounds-regular'],
321
- },
322
- ]}
323
- indicatorStyle={theme.type === 'dark' ? 'white' : 'black'}
324
- onScrollBeginDrag={onScroll}
325
- onScroll={onScroll}
326
- scrollEventThrottle={1}
327
- >
328
- <Box marginBottom="s" marginHorizontal="gutter">
329
- <Text>
330
- When using useBottomSheet directly you can programmatically close
331
- the bottomsheet
332
- </Text>
333
- </Box>
334
-
335
- <Box marginBottom="s" marginHorizontal="gutter">
336
- <Button text="Close" onPress={dismissBottomSheet} />
337
- </Box>
338
-
339
- <DemoContent />
340
- </Animated.ScrollView>
341
- </BottomSheet>
342
- )
343
- }
344
-
345
- const ExampleUseScrollViewBottomSheet = ({
346
- onDismiss,
347
- }: {
348
- onDismiss: ComponentProps<typeof ScrollViewBottomSheet>['onDismiss']
349
- }) => {
350
- // Aliasing because we already have `ScrollViewBottomSheet` imported
351
- const {
352
- ScrollViewBottomSheet: ScrollViewBottomSheetComponent,
353
- dismissBottomSheet,
354
- } = useScrollViewBottomSheet({
355
- onDismiss,
356
- })
357
-
358
- return (
359
- <ScrollViewBottomSheetComponent>
360
- <Box marginBottom="s" marginHorizontal="gutter">
361
- <Text>
362
- When using useScrollViewBottomSheet directly you can programmatically
363
- close the bottomsheet
364
- </Text>
365
- </Box>
366
-
367
- <Box marginBottom="s" marginHorizontal="gutter">
368
- <Button text="Close" onPress={dismissBottomSheet} />
369
- </Box>
370
-
371
- <DemoContent />
372
- </ScrollViewBottomSheetComponent>
373
- )
374
- }
375
-
376
- const ExampleUseGridBottomSheet = ({
377
- onDismiss,
378
- }: {
379
- onDismiss: ComponentProps<typeof GridBottomSheet>['onDismiss']
380
- }) => {
381
- const theme = useTheme()
382
-
383
- // Aliasing because we already have `GridBottomSheet` imported
384
- const {GridBottomSheet: GridBottomSheetComponent, dismissBottomSheet} =
385
- useGridBottomSheet({
386
- onDismiss,
387
- })
388
-
389
- const data = Array.from({length: 50}, (_, index) => ({
390
- text: `Item ${index + 1}`,
391
- }))
392
-
393
- return (
394
- <GridBottomSheetComponent
395
- data={data}
396
- renderItem={({item}) => (
397
- <TouchableOpacity onPress={dismissBottomSheet}>
398
- <Box
399
- minHeight={200}
400
- backgroundColor="backgrounds-subdued"
401
- justifyContent="center"
402
- alignItems="center"
403
- >
404
- <Text>{item.text}</Text>
405
- <Text>Press to close</Text>
406
- </Box>
407
- </TouchableOpacity>
408
- )}
409
- contentContainerStyle={{
410
- paddingHorizontal: theme.spacing.gutter,
411
- paddingBottom: theme.spacing.m,
412
- }}
413
- />
414
- )
415
- }
416
-
417
- const ExampleUseProductCardGridBottomSheet = ({
418
- onDismiss,
419
- }: {
420
- onDismiss: ComponentProps<typeof ProductCardGridBottomSheet>['onDismiss']
421
- }) => {
422
- const theme = useTheme()
423
-
424
- // Aliasing because we already have `ProductCardGridBottomSheet` imported
425
- const {
426
- ProductCardGridBottomSheet: ProductCardGridBottomSheetComponent,
427
- dismissBottomSheet,
428
- } = useProductCardGridBottomSheet({
429
- onDismiss,
430
- })
431
-
432
- const {loading, data} = useMinisQuery(TestProductsQuery, {
433
- variables: {
434
- shopId: SHOP_GID,
435
- productIds: PRODUCT_GIDS,
436
- },
437
- })
438
-
439
- const products = data?.shop?.productsByIds ?? []
440
-
441
- // TODO: It would be nice to handle this inside the bottomsheet with a spinner
442
- if (loading || !data) return null
443
-
444
- return (
445
- <ProductCardGridBottomSheetComponent
446
- products={products}
447
- ListHeaderComponent={
448
- <Box paddingBottom="s" paddingHorizontal="gutter">
449
- <Button text="Close" onPress={dismissBottomSheet} />
450
- </Box>
451
- }
452
- renderItem={({product}) => (
453
- <TouchableProduct product={product} key={product.id}>
454
- <ProductCard shopId={SHOP_GID} product={product} />
455
- </TouchableProduct>
456
- )}
457
- contentContainerStyle={{
458
- paddingHorizontal: theme.spacing.gutter,
459
- paddingBottom: theme.spacing.m,
460
- }}
461
- />
462
- )
463
- }
464
-
465
- const ExampleUseFlatListBottomSheet = ({
466
- onDismiss,
467
- }: {
468
- onDismiss: ComponentProps<typeof FlatListBottomSheet>['onDismiss']
469
- }) => {
470
- // Aliasing because we already have `FlatListBottomSheet` imported
471
- const {
472
- FlatListBottomSheet: FlatListBottomSheetComponent,
473
- dismissBottomSheet,
474
- } = useFlatListBottomSheet({
475
- onDismiss,
476
- })
477
-
478
- return (
479
- <FlatListBottomSheetComponent
480
- data={Array.from({length: 50}, (_, index) => ({
481
- key: index,
482
- title: `Thing ${index + 1}`,
483
- }))}
484
- renderItem={({item}) => {
485
- return (
486
- <TouchableOpacity onPress={dismissBottomSheet}>
487
- <Box
488
- key={item.key}
489
- marginBottom="s"
490
- padding="s"
491
- marginHorizontal="gutter"
492
- backgroundColor="backgrounds-dangerous"
493
- >
494
- <Text>{item.title}</Text>
495
- <Text>Touch to close</Text>
496
- </Box>
497
- </TouchableOpacity>
498
- )
499
- }}
500
- />
501
- )
502
- }
503
-
504
- const ExampleUseSectionListBottomSheet = ({
505
- onDismiss,
506
- }: {
507
- onDismiss: ComponentProps<typeof SectionListBottomSheet>['onDismiss']
508
- }) => {
509
- // Aliasing because we already have `SectionListBottomSheet` imported
510
- const {
511
- SectionListBottomSheet: SectionListBottomSheetComponent,
512
- dismissBottomSheet,
513
- } = useSectionListBottomSheet({
514
- onDismiss,
515
- })
516
-
517
- return (
518
- <SectionListBottomSheetComponent
519
- sections={Array.from({length: 50}, (_, index) => ({
520
- title: `Section ${index + 1}`,
521
- data: ['1', '2', '3', '4', '5'],
522
- }))}
523
- renderSectionHeader={({section: {title}}) => (
524
- <Box padding="s" backgroundColor="foregrounds-primary">
525
- <Text variant="heroBold" color="foregrounds-contrasting">
526
- {title}
527
- </Text>
528
- </Box>
529
- )}
530
- renderItem={({item}) => (
531
- <Box padding="s">
532
- <Text>{item}</Text>
533
- </Box>
534
- )}
535
- ListHeaderComponent={
536
- <Box paddingBottom="s" paddingHorizontal="gutter">
537
- <Button text="Close" onPress={dismissBottomSheet} />
538
- </Box>
539
- }
540
- />
541
- )
542
- }
543
-
544
- export const BottomSheetScreen = () => {
545
- const theme = useTheme()
546
- const [examples, setExamples] = useState([
547
- {
548
- Component: ExampleScrollView1,
549
- title: 'ScrollView',
550
- description:
551
- 'The simplest bottomsheet. This is a good starting point although for a large amount of content it will be best to use one of the more optimised options such as the FlatList',
552
- cta: 'scrolling example',
553
- isVisible: false,
554
- },
555
- {
556
- Component: ExampleScrollView2,
557
- cta: 'non-scrolling example',
558
- isVisible: false,
559
- },
560
- {
561
- Component: ExampleFlatList,
562
- title: 'FlatList',
563
- isVisible: false,
564
- },
565
- {
566
- Component: ExampleGrid,
567
- title: 'Grid',
568
- isVisible: false,
569
- },
570
- {
571
- Component: ExampleProductCardGrid,
572
- title: 'ProductCardGrid',
573
- isVisible: false,
574
- },
575
- {
576
- Component: ExampleSectionList,
577
- title: 'SectionList',
578
- isVisible: false,
579
- },
580
- {
581
- Component: ExampleSnapPoints,
582
- title: 'Configuring snapPoints',
583
- description:
584
- 'You can configure snap points for all of the bottomsheets. This allows you to control the initial, smaller, point ' +
585
- ' (positionTwo) as well as the top-most position (positionOne). These are measurements in screen units from the top ' +
586
- 'of the container.',
587
- isVisible: false,
588
- },
589
- {
590
- Component: ExampleVariants,
591
- title: 'Header Variants',
592
- description:
593
- "There's a variant called handle that replaces the top of the bottomsheet with an iOS-style handle",
594
- isVisible: false,
595
- },
596
- {
597
- Component: ExampleUseScrollViewBottomSheet,
598
- title: 'hooks',
599
- description:
600
- 'If you need to programmatically close the bottomsheet or want low-level control of the bottomsheet you can one of the hooks such as useScrollViewBottomSheet directly',
601
- cta: 'with useScrollViewBottomSheet',
602
- isVisible: false,
603
- },
604
- {
605
- Component: ExampleUseGridBottomSheet,
606
- title: 'useGridBottomSheet hook',
607
- isVisible: false,
608
- },
609
- {
610
- Component: ExampleUseProductCardGridBottomSheet,
611
- title: 'useProductCardGridBottomSheet hook',
612
- isVisible: false,
613
- },
614
- {
615
- Component: ExampleUseFlatListBottomSheet,
616
- title: 'useFlatListBottomSheet hook',
617
- isVisible: false,
618
- },
619
- {
620
- Component: ExampleUseSectionListBottomSheet,
621
- title: 'useSectionListBottomSheet hook',
622
- isVisible: false,
623
- },
624
- {
625
- Component: ExampleUseBottomSheet,
626
- description:
627
- 'If you have an advanced use-case you can use useBottomSheet directly but you will need to wire up the scroll handlers manually',
628
- cta: 'with useBottomSheet',
629
- isVisible: false,
630
- },
631
- ])
632
-
633
- const openExample = useCallback((index: number) => {
634
- setExamples(existingExamples =>
635
- existingExamples.map((existingExample, i) => {
636
- if (i !== index) return existingExample
637
-
638
- return {
639
- ...existingExample,
640
- isVisible: true,
641
- }
642
- })
643
- )
644
- }, [])
645
-
646
- const closeExample = useCallback((index: number) => {
647
- setExamples(existingExamples =>
648
- existingExamples.map((existingExample, i) => {
649
- if (i !== index) return existingExample
650
-
651
- return {
652
- ...existingExample,
653
- isVisible: false,
654
- }
655
- })
656
- )
657
- }, [])
658
-
659
- return (
660
- <>
661
- <SafeAreaView
662
- style={{flex: 1, backgroundColor: theme.colors['backgrounds-regular']}}
663
- >
664
- <ScrollView
665
- style={{
666
- flex: 1,
667
- backgroundColor: theme.colors['backgrounds-regular'],
668
- }}
669
- >
670
- <Header />
671
- <Box px="gutter">
672
- <Box marginBottom="m">
673
- <Text variant="headerBold">BottomSheet</Text>
674
- </Box>
675
-
676
- {examples.map(({title, cta, isVisible, description}, i) => (
677
- <Box key={title || cta} marginBottom="s">
678
- {title ? (
679
- <Box marginBottom="xs">
680
- <Text variant="label" style={{textTransform: 'none'}}>
681
- {title}
682
- </Text>
683
- </Box>
684
- ) : null}
685
-
686
- {description ? (
687
- <Box marginBottom="s">
688
- <Text>{description}</Text>
689
- </Box>
690
- ) : null}
691
-
692
- <Button
693
- text={`Launch ${cta ?? 'example'}`}
694
- disabled={isVisible}
695
- onPress={() => openExample(i)}
696
- />
697
- </Box>
698
- ))}
699
- </Box>
700
- </ScrollView>
701
- </SafeAreaView>
702
-
703
- {/* Notice that the bottomsheet component itself lives outside the SafeAreaView */}
704
-
705
- {examples.map(({Component, title, isVisible}, i) => {
706
- if (!isVisible) return null
707
-
708
- return <Component key={title} onDismiss={() => closeExample(i)} />
709
- })}
710
- </>
711
- )
712
- }