@wasto/cms-components 1.5.10 → 1.5.12

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 (101) hide show
  1. package/README.md +47 -47
  2. package/dist/index.d.mts +181 -51
  3. package/dist/index.d.ts +181 -51
  4. package/dist/index.js +3614 -3015
  5. package/dist/index.mjs +3021 -2418
  6. package/package.json +12 -2
  7. package/src/components/announcement-modal/AnnouncementModal.tsx +183 -183
  8. package/src/components/article/Article.tsx +21 -21
  9. package/src/components/article/ArticleCard.tsx +81 -81
  10. package/src/components/article/ArticleExcerpts.tsx +80 -80
  11. package/src/components/article/ArticleList.tsx +114 -114
  12. package/src/components/article/ArticleMarkdown.tsx +170 -170
  13. package/src/components/article/ArticleReaderModal.tsx +93 -93
  14. package/src/components/article/ArticleSingle.tsx +57 -57
  15. package/src/components/bottom-tab/BottomTab.tsx +392 -392
  16. package/src/components/button/Button.tsx +154 -154
  17. package/src/components/challenge/Badges.tsx +84 -84
  18. package/src/components/challenge/BadgesModal.tsx +166 -166
  19. package/src/components/challenge/Challenge.tsx +380 -380
  20. package/src/components/challenge/ChallengeModal.tsx +231 -231
  21. package/src/components/challenge/ChallengeVignette.tsx +249 -249
  22. package/src/components/challenge/ChallengesModal.tsx +243 -243
  23. package/src/components/challenge/QuizModal.tsx +381 -381
  24. package/src/components/challenge/ResultModal.tsx +144 -144
  25. package/src/components/chat/Chat.tsx +928 -928
  26. package/src/components/collection-calendar/CollectionCalendar.tsx +274 -274
  27. package/src/components/columns/Columns.tsx +33 -33
  28. package/src/components/consignes-modal/ConsignesModal.tsx +267 -267
  29. package/src/components/content-inset/ContentInset.tsx +33 -33
  30. package/src/components/header/Header.tsx +415 -391
  31. package/src/components/image/Image.tsx +15 -15
  32. package/src/components/image/ImageFrame.tsx +102 -102
  33. package/src/components/image/ImageMedia.tsx +31 -31
  34. package/src/components/image/ImageUrl.tsx +30 -30
  35. package/src/components/locations-map/LocationSheet.tsx +417 -417
  36. package/src/components/locations-map/LocationsMap.native.tsx +260 -260
  37. package/src/components/locations-map/LocationsMap.tsx +13 -13
  38. package/src/components/locations-map/LocationsMap.web.tsx +10 -10
  39. package/src/components/locations-map/LocationsMapShell.tsx +546 -527
  40. package/src/components/locations-map/LocationsMapView.tsx +108 -108
  41. package/src/components/locations-map/LocationsMapView.web.tsx +331 -331
  42. package/src/components/nav-button/NavButton.tsx +59 -59
  43. package/src/components/next-collection/NextCollection.tsx +636 -621
  44. package/src/components/notifications/NotificationsScreen.tsx +247 -247
  45. package/src/components/page/Page.tsx +102 -64
  46. package/src/components/parapraph/Paragraph.tsx +67 -67
  47. package/src/components/profile/ProfileScreen.tsx +236 -236
  48. package/src/components/push/PushTokenRegistrar.tsx +47 -0
  49. package/src/components/recycling-info/RecyclingInfo.tsx +189 -189
  50. package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
  51. package/src/components/search/Search.tsx +320 -320
  52. package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
  53. package/src/components/title/Title.tsx +100 -100
  54. package/src/components/vision/Vision.tsx +447 -447
  55. package/src/components/vision/VisionActionCard.tsx +117 -117
  56. package/src/components/vision/VisionCapture.tsx +30 -30
  57. package/src/components/vision/VisionTapOverlay.tsx +122 -122
  58. package/src/contexts/AnnouncementsContext.tsx +171 -171
  59. package/src/contexts/AppDataContext.tsx +458 -0
  60. package/src/contexts/ChallengesContext.tsx +182 -182
  61. package/src/contexts/HeaderConfigContext.tsx +29 -0
  62. package/src/contexts/LocalContext.tsx +227 -227
  63. package/src/contexts/ThemeContext.tsx +37 -37
  64. package/src/contexts/WastoContext.tsx +132 -127
  65. package/src/helpers/blogPost.ts +72 -72
  66. package/src/helpers/generateQuizQuestions.ts +247 -247
  67. package/src/helpers/getContrastColor.ts +18 -18
  68. package/src/helpers/haptics.ts +20 -20
  69. package/src/helpers/hoursSchedule.ts +230 -230
  70. package/src/helpers/htmlContentToMarkdown.ts +114 -114
  71. package/src/helpers/layout.ts +54 -54
  72. package/src/helpers/loadLinearGradient.ts +22 -22
  73. package/src/helpers/mapLocations.ts +170 -0
  74. package/src/helpers/maquetteTheme.ts +76 -76
  75. package/src/helpers/markdownUnderlinePlugin.ts +32 -32
  76. package/src/helpers/nextCollection.ts +122 -0
  77. package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
  78. package/src/helpers/publicMediaUrl.ts +8 -8
  79. package/src/helpers/resolveApiAssetUrl.ts +21 -21
  80. package/src/helpers/systemRoutes.ts +7 -7
  81. package/src/helpers/themeStyles.ts +114 -114
  82. package/src/helpers/ttlCache.ts +41 -0
  83. package/src/helpers/useSafeAreaPadding.ts +14 -14
  84. package/src/hooks/useBadges.ts +100 -100
  85. package/src/hooks/useBlogPosts.ts +109 -105
  86. package/src/hooks/useChallenges.ts +110 -110
  87. package/src/hooks/useCities.ts +56 -56
  88. package/src/hooks/useCityAnnouncements.ts +118 -118
  89. package/src/hooks/useCollectionCalendar.ts +421 -421
  90. package/src/hooks/useColumns.ts +19 -19
  91. package/src/hooks/useConsignes.ts +62 -62
  92. package/src/hooks/useLocations.ts +120 -248
  93. package/src/hooks/useNextCollection.ts +163 -238
  94. package/src/hooks/useRecyclingInfo.ts +90 -90
  95. package/src/hooks/useWastoClient.ts +16 -16
  96. package/src/index.ts +161 -142
  97. package/src/navigation/NavigationContext.tsx +56 -56
  98. package/src/push/registerExpoPushToken.ts +133 -0
  99. package/src/sentry/initSentry.ts +120 -120
  100. package/src/types/Theme.ts +72 -72
  101. package/src/types/css-modules.d.ts +1 -1
@@ -1,274 +1,274 @@
1
- import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react-native";
2
- import { useCollectionCalendar, type WasteTypeInfoForDay } from "../../hooks/useCollectionCalendar";
3
- import { StyleSheet, Text, View } from "react-native";
4
- import Animated, { FadeIn, FadeOut } from "react-native-reanimated";
5
- import { NavButton } from "../nav-button/NavButton";
6
- import { ContentInset } from "../content-inset/ContentInset";
7
- import { Theme } from "../../types/Theme";
8
- import { useTheme } from "../../contexts/ThemeContext";
9
- import { resolveTheme } from "../../helpers/themeStyles";
10
- import { NextCollection } from "../next-collection/NextCollection";
11
- import { hapticSelection } from "../../helpers/haptics";
12
- import { SPACE } from "../../helpers/layout";
13
- import { useState, type ReactNode } from "react";
14
-
15
- export type CollectionCalendarProps = {};
16
-
17
- const PIN_H = 6;
18
- const CELL_INSET = 4;
19
-
20
- function colorAlpha(hex: string, alphaHex: string): string {
21
- const h = hex.replace("#", "").trim();
22
- if (h.length === 3) {
23
- return `#${h[0]}${h[0]}${h[1]}${h[1]}${h[2]}${h[2]}${alphaHex}`;
24
- }
25
- if (h.length === 6) return `#${h}${alphaHex}`;
26
- if (h.length === 8) return `#${h.slice(0, 6)}${alphaHex}`;
27
- return hex;
28
- }
29
-
30
- function WasteTypePins({ types }: { types: WasteTypeInfoForDay[] }) {
31
- if (types.length === 0) return null;
32
-
33
- return (
34
- <View style={styles.wasteTypes}>
35
- {types.map((wasteType) => (
36
- <View
37
- key={wasteType.wasteTypeId}
38
- style={[styles.wasteType, { backgroundColor: wasteType.color }]}
39
- />
40
- ))}
41
- </View>
42
- );
43
- }
44
-
45
- export function CollectionCalendar({}: CollectionCalendarProps): ReactNode {
46
- const {
47
- weekDays,
48
- weeks,
49
- monthLabel,
50
- goToNextMonth,
51
- goToPrevMonth,
52
- } = useCollectionCalendar();
53
- const { theme } = useTheme();
54
- const t = resolveTheme(theme);
55
- const themedStyles = createThemedStyles(theme);
56
- const [monthKey, setMonthKey] = useState(0);
57
- const today = new Date();
58
- const todayDay = today.getDate();
59
- const todayMonth = today.getMonth();
60
- const todayYear = today.getFullYear();
61
- const exceptionFill = colorAlpha(theme.colors.error, "33");
62
-
63
- const prev = async () => {
64
- await hapticSelection();
65
- goToPrevMonth();
66
- setMonthKey((k) => k - 1);
67
- };
68
- const next = async () => {
69
- await hapticSelection();
70
- goToNextMonth();
71
- setMonthKey((k) => k + 1);
72
- };
73
-
74
- return (
75
- <View style={styles.collectionCalendar}>
76
- <ContentInset>
77
- <View style={styles.header}>
78
- <Text style={[styles.monthLabel, { color: t.colors.muted }]}>
79
- {monthLabel.toUpperCase()}
80
- </Text>
81
- <View style={styles.navRow}>
82
- <NavButton
83
- icon={ChevronLeftIcon}
84
- onPress={prev}
85
- style={styles.navCircle}
86
- />
87
- <NavButton
88
- icon={ChevronRightIcon}
89
- onPress={next}
90
- style={styles.navCircle}
91
- />
92
- </View>
93
- </View>
94
- </ContentInset>
95
-
96
- <Animated.View
97
- key={monthKey}
98
- entering={FadeIn.duration(220)}
99
- exiting={FadeOut.duration(160)}
100
- style={styles.grid}
101
- >
102
- <View style={[styles.calendarHeader, { backgroundColor: theme.colors.background }]}>
103
- {weekDays.map((weekDay) => (
104
- <View key={weekDay} style={styles.calendarHeaderCell}>
105
- <Text style={themedStyles.mutedText}>{weekDay}</Text>
106
- </View>
107
- ))}
108
- </View>
109
- <View style={styles.calendarBody}>
110
- {weeks.map((week, index) => (
111
- <View
112
- key={index}
113
- style={[
114
- styles.calendarBodyRow,
115
- {
116
- backgroundColor:
117
- index % 2 === 0
118
- ? theme.colors.surface
119
- : theme.colors.background,
120
- },
121
- ]}
122
- >
123
- {week.map((day, cellIndex) => {
124
- const isToday =
125
- day.inCurrentMonth &&
126
- day.day === todayDay &&
127
- day.month === todayMonth &&
128
- day.year === todayYear;
129
- const isException = day.exceptions.length > 0;
130
-
131
- return (
132
- <View
133
- key={cellIndex}
134
- style={[
135
- styles.calendarBodyCell,
136
- !day.inCurrentMonth && styles.notCurrentMonth,
137
- ]}
138
- >
139
- {isToday || isException ? (
140
- <View
141
- pointerEvents="none"
142
- style={[
143
- styles.dayHighlight,
144
- {
145
- backgroundColor: isToday
146
- ? theme.colors.primary
147
- : exceptionFill,
148
- borderRadius: t.radii.sm,
149
- },
150
- ]}
151
- />
152
- ) : null}
153
- <Text
154
- style={[
155
- styles.dayNumber,
156
- isToday
157
- ? {
158
- color: theme.colors.onPrimary,
159
- fontWeight: "700",
160
- }
161
- : isException
162
- ? {
163
- color: theme.colors.error,
164
- fontWeight: "700",
165
- }
166
- : themedStyles.dayNumber,
167
- ]}
168
- >
169
- {day.day}
170
- </Text>
171
- <WasteTypePins types={day.wasteTypesForDay} />
172
- </View>
173
- );
174
- })}
175
- </View>
176
- ))}
177
- </View>
178
- </Animated.View>
179
-
180
- <NextCollection showCalendarCta={false} />
181
- </View>
182
- );
183
- }
184
-
185
- const createThemedStyles = (theme: Theme) =>
186
- StyleSheet.create({
187
- dayNumber: {
188
- color: theme.colors.muted ?? theme.colors.onSurface,
189
- },
190
- mutedText: {
191
- color: theme.colors.muted ?? theme.colors.onSurface,
192
- fontSize: 12,
193
- fontWeight: "600",
194
- },
195
- });
196
-
197
- const styles = StyleSheet.create({
198
- collectionCalendar: {
199
- gap: SPACE.sectionY,
200
- width: "100%",
201
- },
202
- header: {
203
- flexDirection: "row",
204
- justifyContent: "space-between",
205
- alignItems: "center",
206
- paddingVertical: 12,
207
- },
208
- monthLabel: {
209
- fontSize: 13,
210
- fontWeight: "700",
211
- letterSpacing: 0.6,
212
- },
213
- navRow: {
214
- flexDirection: "row",
215
- gap: 8,
216
- },
217
- navCircle: {
218
- width: SPACE.iconHit,
219
- height: SPACE.iconHit,
220
- },
221
- grid: {
222
- width: "100%",
223
- overflow: "hidden",
224
- },
225
- calendarHeader: {
226
- flexDirection: "row",
227
- },
228
- calendarHeaderCell: {
229
- flex: 1,
230
- paddingVertical: 10,
231
- alignItems: "center",
232
- },
233
- calendarBody: {
234
- width: "100%",
235
- },
236
- calendarBodyRow: {
237
- flexDirection: "row",
238
- },
239
- calendarBodyCell: {
240
- flex: 1,
241
- aspectRatio: 1,
242
- position: "relative",
243
- alignItems: "center",
244
- justifyContent: "center",
245
- },
246
- dayHighlight: {
247
- ...StyleSheet.absoluteFillObject,
248
- margin: CELL_INSET,
249
- zIndex: 0,
250
- },
251
- dayNumber: {
252
- fontSize: 14,
253
- fontWeight: "600",
254
- zIndex: 1,
255
- },
256
- notCurrentMonth: {
257
- opacity: 0.32,
258
- },
259
- wasteTypes: {
260
- position: "absolute",
261
- left: CELL_INSET,
262
- right: CELL_INSET,
263
- bottom: CELL_INSET + 2,
264
- height: PIN_H,
265
- flexDirection: "row",
266
- borderRadius: PIN_H / 2,
267
- overflow: "hidden",
268
- zIndex: 2,
269
- },
270
- wasteType: {
271
- flex: 1,
272
- height: PIN_H,
273
- },
274
- });
1
+ import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react-native";
2
+ import { useCollectionCalendar, type WasteTypeInfoForDay } from "../../hooks/useCollectionCalendar";
3
+ import { StyleSheet, Text, View } from "react-native";
4
+ import Animated, { FadeIn, FadeOut } from "react-native-reanimated";
5
+ import { NavButton } from "../nav-button/NavButton";
6
+ import { ContentInset } from "../content-inset/ContentInset";
7
+ import { Theme } from "../../types/Theme";
8
+ import { useTheme } from "../../contexts/ThemeContext";
9
+ import { resolveTheme } from "../../helpers/themeStyles";
10
+ import { NextCollection } from "../next-collection/NextCollection";
11
+ import { hapticSelection } from "../../helpers/haptics";
12
+ import { SPACE } from "../../helpers/layout";
13
+ import { useState, type ReactNode } from "react";
14
+
15
+ export type CollectionCalendarProps = {};
16
+
17
+ const PIN_H = 6;
18
+ const CELL_INSET = 4;
19
+
20
+ function colorAlpha(hex: string, alphaHex: string): string {
21
+ const h = hex.replace("#", "").trim();
22
+ if (h.length === 3) {
23
+ return `#${h[0]}${h[0]}${h[1]}${h[1]}${h[2]}${h[2]}${alphaHex}`;
24
+ }
25
+ if (h.length === 6) return `#${h}${alphaHex}`;
26
+ if (h.length === 8) return `#${h.slice(0, 6)}${alphaHex}`;
27
+ return hex;
28
+ }
29
+
30
+ function WasteTypePins({ types }: { types: WasteTypeInfoForDay[] }) {
31
+ if (types.length === 0) return null;
32
+
33
+ return (
34
+ <View style={styles.wasteTypes}>
35
+ {types.map((wasteType) => (
36
+ <View
37
+ key={wasteType.wasteTypeId}
38
+ style={[styles.wasteType, { backgroundColor: wasteType.color }]}
39
+ />
40
+ ))}
41
+ </View>
42
+ );
43
+ }
44
+
45
+ export function CollectionCalendar({}: CollectionCalendarProps): ReactNode {
46
+ const {
47
+ weekDays,
48
+ weeks,
49
+ monthLabel,
50
+ goToNextMonth,
51
+ goToPrevMonth,
52
+ } = useCollectionCalendar();
53
+ const { theme } = useTheme();
54
+ const t = resolveTheme(theme);
55
+ const themedStyles = createThemedStyles(theme);
56
+ const [monthKey, setMonthKey] = useState(0);
57
+ const today = new Date();
58
+ const todayDay = today.getDate();
59
+ const todayMonth = today.getMonth();
60
+ const todayYear = today.getFullYear();
61
+ const exceptionFill = colorAlpha(theme.colors.error, "33");
62
+
63
+ const prev = async () => {
64
+ await hapticSelection();
65
+ goToPrevMonth();
66
+ setMonthKey((k) => k - 1);
67
+ };
68
+ const next = async () => {
69
+ await hapticSelection();
70
+ goToNextMonth();
71
+ setMonthKey((k) => k + 1);
72
+ };
73
+
74
+ return (
75
+ <View style={styles.collectionCalendar}>
76
+ <ContentInset>
77
+ <View style={styles.header}>
78
+ <Text style={[styles.monthLabel, { color: t.colors.muted }]}>
79
+ {monthLabel.toUpperCase()}
80
+ </Text>
81
+ <View style={styles.navRow}>
82
+ <NavButton
83
+ icon={ChevronLeftIcon}
84
+ onPress={prev}
85
+ style={styles.navCircle}
86
+ />
87
+ <NavButton
88
+ icon={ChevronRightIcon}
89
+ onPress={next}
90
+ style={styles.navCircle}
91
+ />
92
+ </View>
93
+ </View>
94
+ </ContentInset>
95
+
96
+ <Animated.View
97
+ key={monthKey}
98
+ entering={FadeIn.duration(220)}
99
+ exiting={FadeOut.duration(160)}
100
+ style={styles.grid}
101
+ >
102
+ <View style={[styles.calendarHeader, { backgroundColor: theme.colors.background }]}>
103
+ {weekDays.map((weekDay) => (
104
+ <View key={weekDay} style={styles.calendarHeaderCell}>
105
+ <Text style={themedStyles.mutedText}>{weekDay}</Text>
106
+ </View>
107
+ ))}
108
+ </View>
109
+ <View style={styles.calendarBody}>
110
+ {weeks.map((week, index) => (
111
+ <View
112
+ key={index}
113
+ style={[
114
+ styles.calendarBodyRow,
115
+ {
116
+ backgroundColor:
117
+ index % 2 === 0
118
+ ? theme.colors.surface
119
+ : theme.colors.background,
120
+ },
121
+ ]}
122
+ >
123
+ {week.map((day, cellIndex) => {
124
+ const isToday =
125
+ day.inCurrentMonth &&
126
+ day.day === todayDay &&
127
+ day.month === todayMonth &&
128
+ day.year === todayYear;
129
+ const isException = day.exceptions.length > 0;
130
+
131
+ return (
132
+ <View
133
+ key={cellIndex}
134
+ style={[
135
+ styles.calendarBodyCell,
136
+ !day.inCurrentMonth && styles.notCurrentMonth,
137
+ ]}
138
+ >
139
+ {isToday || isException ? (
140
+ <View
141
+ pointerEvents="none"
142
+ style={[
143
+ styles.dayHighlight,
144
+ {
145
+ backgroundColor: isToday
146
+ ? theme.colors.primary
147
+ : exceptionFill,
148
+ borderRadius: t.radii.sm,
149
+ },
150
+ ]}
151
+ />
152
+ ) : null}
153
+ <Text
154
+ style={[
155
+ styles.dayNumber,
156
+ isToday
157
+ ? {
158
+ color: theme.colors.onPrimary,
159
+ fontWeight: "700",
160
+ }
161
+ : isException
162
+ ? {
163
+ color: theme.colors.error,
164
+ fontWeight: "700",
165
+ }
166
+ : themedStyles.dayNumber,
167
+ ]}
168
+ >
169
+ {day.day}
170
+ </Text>
171
+ <WasteTypePins types={day.wasteTypesForDay} />
172
+ </View>
173
+ );
174
+ })}
175
+ </View>
176
+ ))}
177
+ </View>
178
+ </Animated.View>
179
+
180
+ <NextCollection showCalendarCta={false} />
181
+ </View>
182
+ );
183
+ }
184
+
185
+ const createThemedStyles = (theme: Theme) =>
186
+ StyleSheet.create({
187
+ dayNumber: {
188
+ color: theme.colors.muted ?? theme.colors.onSurface,
189
+ },
190
+ mutedText: {
191
+ color: theme.colors.muted ?? theme.colors.onSurface,
192
+ fontSize: 12,
193
+ fontWeight: "600",
194
+ },
195
+ });
196
+
197
+ const styles = StyleSheet.create({
198
+ collectionCalendar: {
199
+ gap: SPACE.sectionY,
200
+ width: "100%",
201
+ },
202
+ header: {
203
+ flexDirection: "row",
204
+ justifyContent: "space-between",
205
+ alignItems: "center",
206
+ paddingVertical: 12,
207
+ },
208
+ monthLabel: {
209
+ fontSize: 13,
210
+ fontWeight: "700",
211
+ letterSpacing: 0.6,
212
+ },
213
+ navRow: {
214
+ flexDirection: "row",
215
+ gap: 8,
216
+ },
217
+ navCircle: {
218
+ width: SPACE.iconHit,
219
+ height: SPACE.iconHit,
220
+ },
221
+ grid: {
222
+ width: "100%",
223
+ overflow: "hidden",
224
+ },
225
+ calendarHeader: {
226
+ flexDirection: "row",
227
+ },
228
+ calendarHeaderCell: {
229
+ flex: 1,
230
+ paddingVertical: 10,
231
+ alignItems: "center",
232
+ },
233
+ calendarBody: {
234
+ width: "100%",
235
+ },
236
+ calendarBodyRow: {
237
+ flexDirection: "row",
238
+ },
239
+ calendarBodyCell: {
240
+ flex: 1,
241
+ aspectRatio: 1,
242
+ position: "relative",
243
+ alignItems: "center",
244
+ justifyContent: "center",
245
+ },
246
+ dayHighlight: {
247
+ ...StyleSheet.absoluteFillObject,
248
+ margin: CELL_INSET,
249
+ zIndex: 0,
250
+ },
251
+ dayNumber: {
252
+ fontSize: 14,
253
+ fontWeight: "600",
254
+ zIndex: 1,
255
+ },
256
+ notCurrentMonth: {
257
+ opacity: 0.32,
258
+ },
259
+ wasteTypes: {
260
+ position: "absolute",
261
+ left: CELL_INSET,
262
+ right: CELL_INSET,
263
+ bottom: CELL_INSET + 2,
264
+ height: PIN_H,
265
+ flexDirection: "row",
266
+ borderRadius: PIN_H / 2,
267
+ overflow: "hidden",
268
+ zIndex: 2,
269
+ },
270
+ wasteType: {
271
+ flex: 1,
272
+ height: PIN_H,
273
+ },
274
+ });
@@ -1,34 +1,34 @@
1
- import { Children, PropsWithChildren, type ReactNode } from "react"
2
- import { StyleSheet, View } from "react-native";
3
-
4
- export type ColumnsColumnCount = 2 | 3;
5
-
6
- export type ColumnsProps = PropsWithChildren & {
7
- columnCount: ColumnsColumnCount
8
- }
9
-
10
- export function Columns({
11
- columnCount,
12
- children
13
- }: ColumnsProps): ReactNode {
14
- if (Children.count(children) > columnCount) {
15
- throw new Error(`Columns must have ${columnCount} (columnCount) children.`);
16
- }
17
-
18
- return <View style={styles.columns}>
19
- {Children.map(children, (child) => (
20
- <View style={styles.column}>{child}</View>
21
- ))}
22
- </View>
23
- }
24
-
25
- const styles = StyleSheet.create({
26
- columns: {
27
- flexDirection: "row",
28
- width: "100%"
29
- },
30
- column: {
31
- padding: 5,
32
- flex: 1
33
- },
1
+ import { Children, PropsWithChildren, type ReactNode } from "react"
2
+ import { StyleSheet, View } from "react-native";
3
+
4
+ export type ColumnsColumnCount = 2 | 3;
5
+
6
+ export type ColumnsProps = PropsWithChildren & {
7
+ columnCount: ColumnsColumnCount
8
+ }
9
+
10
+ export function Columns({
11
+ columnCount,
12
+ children
13
+ }: ColumnsProps): ReactNode {
14
+ if (Children.count(children) > columnCount) {
15
+ throw new Error(`Columns must have ${columnCount} (columnCount) children.`);
16
+ }
17
+
18
+ return <View style={styles.columns}>
19
+ {Children.map(children, (child) => (
20
+ <View style={styles.column}>{child}</View>
21
+ ))}
22
+ </View>
23
+ }
24
+
25
+ const styles = StyleSheet.create({
26
+ columns: {
27
+ flexDirection: "row",
28
+ width: "100%"
29
+ },
30
+ column: {
31
+ padding: 5,
32
+ flex: 1
33
+ },
34
34
  });