react-native-varia 0.0.1 → 0.2.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 (86) hide show
  1. package/bin/cli.js +35 -18
  2. package/lib/components/Badge.tsx +31 -32
  3. package/lib/components/Button.tsx +20 -20
  4. package/lib/components/Checkbox.tsx +95 -0
  5. package/lib/components/CircleProgress.tsx +56 -66
  6. package/lib/components/Field.tsx +137 -0
  7. package/lib/components/GradientBackground.tsx +17 -18
  8. package/lib/components/GradientText.tsx +25 -64
  9. package/lib/components/IconWrapper.tsx +32 -25
  10. package/lib/components/Input.tsx +66 -68
  11. package/lib/components/Link.tsx +14 -28
  12. package/lib/components/Modal.tsx +197 -97
  13. package/lib/components/NewSelect.tsx +202 -0
  14. package/lib/components/NumberInput.tsx +226 -0
  15. package/lib/components/RadioGroup.tsx +195 -0
  16. package/lib/components/ReText.tsx +53 -87
  17. package/lib/components/Select.tsx +272 -0
  18. package/lib/components/SelectOld.tsx +153 -0
  19. package/lib/components/Slider.tsx +32 -40
  20. package/lib/components/Slideshow.tsx +174 -261
  21. package/lib/components/SlidingDrawer.tsx +216 -265
  22. package/lib/components/Spinner.tsx +21 -12
  23. package/lib/components/Switch.tsx +133 -180
  24. package/lib/components/Switchold.tsx +174 -0
  25. package/lib/components/Text.tsx +36 -83
  26. package/lib/components/layoutTest.tsx +74 -0
  27. package/lib/patterns/index.tsx +143 -202
  28. package/lib/theme/Badge.recipe.tsx +44 -39
  29. package/lib/theme/Button.recipe.tsx +139 -48
  30. package/lib/theme/Checkbox.recipe.tsx +121 -0
  31. package/lib/theme/CircleProgress.recipe.tsx +16 -22
  32. package/lib/theme/Field.recipe.tsx +66 -0
  33. package/lib/theme/GradientBackground.recipe.tsx +7 -20
  34. package/lib/theme/GradientText.recipe.tsx +42 -28
  35. package/lib/theme/IconWrapper.recipe.tsx +10 -85
  36. package/lib/theme/Input.recipe.tsx +76 -83
  37. package/lib/theme/Link.recipe.tsx +16 -43
  38. package/lib/theme/Modal.recipe.tsx +59 -21
  39. package/lib/theme/NumberInput.recipe.tsx +191 -0
  40. package/lib/theme/RadioGroup.recipe.tsx +163 -0
  41. package/lib/theme/ReText.recipe.tsx +4 -7
  42. package/lib/theme/Select.recipe.tsx +121 -0
  43. package/lib/theme/Slider.recipe.tsx +97 -181
  44. package/lib/theme/Slideshow.recipe.tsx +24 -102
  45. package/lib/theme/SlidingDrawer.recipe.tsx +21 -59
  46. package/lib/theme/Spinner.recipe.tsx +28 -3
  47. package/lib/theme/Switch.recipe.tsx +75 -54
  48. package/lib/theme/Text.recipe.tsx +66 -8
  49. package/lib/theme/animations.tsx +13 -0
  50. package/lib/varia/colorPalettes/amber.ts +54 -0
  51. package/lib/varia/colorPalettes/blue.ts +54 -0
  52. package/lib/varia/colorPalettes/bronze.ts +54 -0
  53. package/lib/varia/colorPalettes/brown.ts +54 -0
  54. package/lib/varia/colorPalettes/crimson.ts +55 -0
  55. package/lib/varia/colorPalettes/cyan.ts +54 -0
  56. package/lib/varia/colorPalettes/gold.ts +54 -0
  57. package/lib/varia/colorPalettes/grass.ts +54 -0
  58. package/lib/varia/colorPalettes/green.ts +54 -0
  59. package/lib/varia/colorPalettes/indigo.ts +54 -0
  60. package/lib/varia/colorPalettes/iris.ts +54 -0
  61. package/lib/varia/colorPalettes/jade.ts +54 -0
  62. package/lib/varia/colorPalettes/lime.ts +55 -0
  63. package/lib/varia/colorPalettes/mauve.ts +54 -0
  64. package/lib/varia/colorPalettes/mint.ts +54 -0
  65. package/lib/varia/colorPalettes/neutral.ts +54 -0
  66. package/lib/varia/colorPalettes/olive.ts +54 -0
  67. package/lib/varia/colorPalettes/orange.ts +54 -0
  68. package/lib/varia/colorPalettes/pink.ts +54 -0
  69. package/lib/varia/colorPalettes/plum.ts +54 -0
  70. package/lib/varia/colorPalettes/purple.ts +56 -0
  71. package/lib/varia/colorPalettes/red.ts +55 -0
  72. package/lib/varia/colorPalettes/ruby.ts +56 -0
  73. package/lib/varia/colorPalettes/sage.ts +56 -0
  74. package/lib/varia/colorPalettes/sand.ts +56 -0
  75. package/lib/varia/colorPalettes/sky.ts +56 -0
  76. package/lib/varia/colorPalettes/slate.ts +56 -0
  77. package/lib/varia/colorPalettes/teal.ts +56 -0
  78. package/lib/varia/colorPalettes/tomato.ts +56 -0
  79. package/lib/varia/colorPalettes/violet.ts +56 -0
  80. package/lib/varia/colorPalettes/yellow.ts +56 -0
  81. package/lib/varia/defaultTheme.ts +174 -0
  82. package/lib/varia/mixins.ts +223 -0
  83. package/lib/varia/textStyles.ts +48 -0
  84. package/lib/varia/types.ts +277 -0
  85. package/lib/varia/utils.ts +283 -0
  86. package/package.json +1 -1
@@ -1,52 +1,36 @@
1
- import {
2
- Children,
3
- forwardRef,
4
- type ReactNode,
5
- useImperativeHandle,
6
- useState,
7
- } from 'react';
8
- import { View } from 'react-native';
1
+ import {Children, type ReactNode, useImperativeHandle, useState} from 'react'
2
+ import {View} from 'react-native'
9
3
  import Animated, {
10
4
  useAnimatedReaction,
11
5
  useAnimatedStyle,
12
6
  useSharedValue,
13
7
  withSpring,
14
8
  withTiming,
15
- } from 'react-native-reanimated';
16
- import {runOnJS} from 'react-native-worklets';
17
- import { StyleSheet, UnistylesVariants } from 'react-native-unistyles';
18
- import { Gesture, GestureDetector } from 'react-native-gesture-handler';
19
- import { SlideshowStyles, SlideshowTokens } from '../theme/Slideshow.recipe';
20
- import { SlidingDrawerTokens } from '../theme/SlidingDrawer.recipe';
21
- // import type { SpringConfig } from 'react-native-reanimated/lib/typescript/animation/springUtils';
22
- // import type {
23
- // SlideshowAnimationVariants,
24
- // SlideshowColorSchemeVariants,
25
- // } from '../style/styles/types';
26
- // import { type Tokens } from '../style/tokenManager';
27
- // import { useTokens } from '../style/useTokens';
9
+ } from 'react-native-reanimated'
10
+ import {runOnJS} from 'react-native-worklets'
11
+ import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
12
+ import {Gesture, GestureDetector} from 'react-native-gesture-handler'
13
+ import {SlideshowStyles, SlideshowTokens} from '../theme/Slideshow.recipe'
14
+ import {PalettesWithNestedKeys} from '../style/varia/types'
28
15
 
29
16
  export type SlideshowRef = {
30
- handleNext: () => void | null;
31
- handlePrev: () => void | null;
32
- };
17
+ handleNext: () => void | null
18
+ handlePrev: () => void | null
19
+ }
33
20
 
34
- type SlideshowVariants = UnistylesVariants<typeof SlideshowStyles>;
21
+ type SlideshowVariants = UnistylesVariants<typeof SlideshowStyles>
35
22
 
36
23
  type SlideshowProps = SlideshowVariants & {
37
- animation?: keyof typeof SlidingDrawerTokens.variants.animation;
38
- // spacing?: SlideshowSlideContainerSpacing;
39
- allowGestures?: boolean;
40
- flex?: number;
41
- onSlideChange?: (index: number) => void;
42
- // slideContainerType?: SlideshowSlideContainerColorScheme;
43
- slideContainerType?: any;
44
- children: ReactNode;
45
- ref?: React.RefObject<SlideshowRef>;
24
+ animation?: keyof typeof SlideshowTokens.variants.animation
25
+ colorPalette?: PalettesWithNestedKeys
26
+ allowGestures?: boolean
27
+ flex?: number
28
+ onSlideChange?: (index: number) => void
29
+ slideContainerType?: any
30
+ children: ReactNode
31
+ ref?: React.RefObject<SlideshowRef>
46
32
  }
47
33
 
48
- // const slideshowTokens = getTokens('slideshow');
49
-
50
34
  /**
51
35
  * Flex Wrapper
52
36
  * @param colorScheme ? string: color scheme
@@ -60,228 +44,169 @@ type SlideshowProps = SlideshowVariants & {
60
44
  * @returns Slideshow react component
61
45
  */
62
46
  const Slideshow = ({
63
- allowGestures = true,
64
- flex = 1,
65
- onSlideChange,
66
- colorPalette,
67
- animation = SlideshowTokens.defaultProps.animation,
68
- spacing = 'none',
69
- // slideContainerType = 'primary',
70
- children,
71
- ref
72
- } : SlideshowProps,
73
- ) => {
74
- // const slideshowTokens = useTokens('slideshow')();
75
-
76
- // const resolvedColorScheme =
77
- // colorScheme ??
78
- // (slideshowTokens.defaultProps
79
- // .colorScheme as keyof SlideshowColorSchemeVariants);
80
-
81
- // const resolvedAnimation =
82
- // animation ??
83
- // (SlideshowTokens.defaultProps.animation
84
- // // as keyof SlideshowTokens.variants.animation
85
- // );
86
-
87
- // const resolvedSpacing =
88
- // spacing ??
89
- // (slideshowTokens.defaultProps
90
- // .spacing as keyof SlideshowSlideContainerSpacing);
91
-
92
- const slides = Children.toArray(children);
93
- const NUM_PAGES = slides.length; // Total number of slides
94
- const scalingFactor = 1 / NUM_PAGES;
95
-
96
- // styles.useVariants({
97
- // colorScheme: resolvedColorScheme,
98
- // spacing,
99
- // });
100
-
101
- SlideshowStyles.useVariants({
102
- colorPalette,
103
- });
104
-
105
- const [containerWidth, setContainerWidth] = useState(0); // To store the container width
106
-
107
- const slideWidth = 100 / NUM_PAGES; // Each slide's width as a percentage
108
- const translateX = useSharedValue(0); // Tracks the animated X position
109
- const currentSlide = useSharedValue(0); // Tracks the current slide index
110
-
111
- type AnimationType = 'withSpring' | 'withTiming';
112
-
113
- const animations = {
114
- withSpring,
115
- withTiming,
116
- };
117
- const animationVariant =
118
- SlideshowTokens.variants?.animation && animation
119
- ? SlideshowTokens.variants.animation[animation]
120
- : {
121
- type: 'withSpring' as AnimationType, // Type assertion ensures 'withSpring' is a valid value
122
- props: {
123
- damping: 15,
124
- stiffness: 100,
125
- mass: 1,
126
- },
127
- };
128
-
129
- const animateSlide = (destination: number) => {
130
- 'worklet';
131
-
132
- if (
133
- animationVariant &&
134
- animationVariant.type &&
135
- animations[animationVariant.type]
136
- ) {
137
- translateX.value = animations[animationVariant.type](
138
- destination,
139
- animationVariant.props
140
- );
141
-
142
- // Optional callback for onSlideChange
143
- if (onSlideChange) {
144
- runOnJS(onSlideChange)((destination / 100) * NUM_PAGES * -1);
47
+ colorPalette = 'accent',
48
+ variant = 'solid',
49
+ allowGestures = true,
50
+ flex = 1,
51
+ onSlideChange,
52
+ animation = SlideshowTokens.defaultProps.animation,
53
+ children,
54
+ ref,
55
+ }: SlideshowProps) => {
56
+ const slides = Children.toArray(children)
57
+ const NUM_PAGES = slides.length
58
+ const scalingFactor = 1 / NUM_PAGES
59
+
60
+ SlideshowStyles.useVariants({
61
+ variant,
62
+ })
63
+
64
+ const [containerWidth, setContainerWidth] = useState(0)
65
+
66
+ const slideWidth = 100 / NUM_PAGES
67
+ const translateX = useSharedValue(0)
68
+ const currentSlide = useSharedValue(0)
69
+
70
+ type AnimationType = 'withSpring' | 'withTiming'
71
+
72
+ const animations = {
73
+ withSpring,
74
+ withTiming,
75
+ }
76
+ const animationVariant =
77
+ SlideshowTokens.variants?.animation && animation
78
+ ? SlideshowTokens.variants.animation[animation]
79
+ : {
80
+ type: 'withSpring' as AnimationType,
81
+ props: {
82
+ damping: 15,
83
+ stiffness: 100,
84
+ mass: 1,
85
+ },
145
86
  }
146
- }
147
- };
148
87
 
149
- useAnimatedReaction(
150
- () => currentSlide.value,
151
- () => {
152
- animateSlide(-currentSlide.value * slideWidth);
88
+ const animateSlide = (destination: number) => {
89
+ 'worklet'
90
+
91
+ if (
92
+ animationVariant &&
93
+ animationVariant.type &&
94
+ animations[animationVariant.type]
95
+ ) {
96
+ translateX.value = animations[animationVariant.type](
97
+ destination,
98
+ animationVariant.props,
99
+ )
100
+
101
+ if (onSlideChange) {
102
+ runOnJS(onSlideChange)((destination / 100) * NUM_PAGES * -1)
153
103
  }
154
- );
155
-
156
- // Move to the previous slide
157
- const handlePrev = () => {
158
- 'worklet';
159
- if (currentSlide.value > 0) {
160
- currentSlide.value -= 1;
161
- }
162
- };
163
- // Move to the next slide
164
- const handleNext = () => {
165
- 'worklet';
166
- if (currentSlide.value < NUM_PAGES - 1) {
167
- currentSlide.value += 1;
168
- }
169
- };
170
-
171
- const context = useSharedValue({ x: 0, snapPoint: 0 });
172
- const velocityThreshold = 500; // Velocity threshold in px/s
173
-
174
- const slideGesture = Gesture.Pan()
175
- .enabled(allowGestures)
176
- .onBegin(() => {
177
- context.value.x = translateX.value;
178
- })
179
- .onUpdate((e) => {
180
- const pixelToPercentage =
181
- (e.translationX / containerWidth) * 100 * scalingFactor; // Adjusted conversion (px to %)
182
- translateX.value = context.value.x + pixelToPercentage;
183
- })
184
- .onEnd(({ velocityX, translationX }) => {
185
- const pixelToPercentage =
186
- (translationX / containerWidth) * 100 * scalingFactor;
187
- const slideWidthPercentage = 100 / NUM_PAGES;
188
-
189
- // Determine current slide index based on translateX
190
- const currentIndex = Math.round(
191
- -context.value.x / slideWidthPercentage
192
- );
193
-
194
- // Decide snapping based on velocity or distance
195
- let targetIndex;
196
- if (Math.abs(velocityX) > velocityThreshold) {
197
- // Use velocity to decide direction
198
- targetIndex = velocityX > 0 ? currentIndex - 1 : currentIndex + 1;
199
- } else {
200
- // Use the 50% distance rule
201
- const crossedThreshold =
202
- Math.abs(pixelToPercentage) > slideWidthPercentage / 2;
203
- targetIndex =
204
- crossedThreshold && pixelToPercentage < 0
205
- ? currentIndex + 1
206
- : crossedThreshold
207
- ? currentIndex - 1
208
- : currentIndex;
209
- }
210
-
211
- // Clamp to valid range
212
- targetIndex = Math.max(0, Math.min(NUM_PAGES - 1, targetIndex));
213
-
214
- // Animate to the target slide
215
- animateSlide(-targetIndex * slideWidthPercentage);
216
-
217
- // Update the currentSlide shared value
218
- currentSlide.value = targetIndex;
219
- });
220
-
221
- // Animated style for the slides container
222
- const animatedStyle = useAnimatedStyle(() => ({
223
- transform: [{ translateX: `${translateX.value}%` }],
224
- }));
225
-
226
- useImperativeHandle(ref, () => ({
227
- handlePrev,
228
- handleNext,
229
- }));
104
+ }
105
+ }
230
106
 
231
- return (
232
- <View style={styles.flex(flex)}>
233
- <GestureDetector gesture={slideGesture}>
234
- <View
235
- //@ts-ignore
236
- // TODO: fix type
237
- style={[styles.container(
238
- // slideshowTokens.variants
239
- ),
240
- SlideshowStyles.container
241
- ]}
242
- onLayout={(e) => setContainerWidth(e.nativeEvent.layout.width)}
243
- >
244
- <Animated.View
245
- style={[
246
- styles.slidesContainer(`${NUM_PAGES * 100}%`),
247
- animatedStyle,
248
- ]}
249
- >
250
- {slides.map((Slide, index) => (
251
- <View
252
- key={index}
253
- style={[
254
- styles.slide(
255
- `${slideWidth}%`,
256
- // SlideshowTokens.slideContainer.variants
257
- ),
258
- SlideshowStyles.slideContainer
259
- ]}
260
- >
261
- {Slide}
262
- </View>
263
- ))}
264
- </Animated.View>
265
- </View>
266
- </GestureDetector>
267
- </View>
268
- );
107
+ useAnimatedReaction(
108
+ () => currentSlide.value,
109
+ () => {
110
+ animateSlide(-currentSlide.value * slideWidth)
111
+ },
112
+ )
113
+
114
+ const handlePrev = () => {
115
+ 'worklet'
116
+ if (currentSlide.value > 0) {
117
+ currentSlide.value -= 1
118
+ }
119
+ }
120
+ const handleNext = () => {
121
+ 'worklet'
122
+ if (currentSlide.value < NUM_PAGES - 1) {
123
+ currentSlide.value += 1
124
+ }
269
125
  }
270
126
 
271
- export default Slideshow;
127
+ const context = useSharedValue({x: 0, snapPoint: 0})
128
+ const velocityThreshold = 500
129
+
130
+ const slideGesture = Gesture.Pan()
131
+ .enabled(allowGestures)
132
+ .onBegin(() => {
133
+ context.value.x = translateX.value
134
+ })
135
+ .onUpdate(e => {
136
+ const pixelToPercentage =
137
+ (e.translationX / containerWidth) * 100 * scalingFactor
138
+ translateX.value = context.value.x + pixelToPercentage
139
+ })
140
+ .onEnd(({velocityX, translationX}) => {
141
+ const pixelToPercentage =
142
+ (translationX / containerWidth) * 100 * scalingFactor
143
+ const slideWidthPercentage = 100 / NUM_PAGES
144
+
145
+ const currentIndex = Math.round(-context.value.x / slideWidthPercentage)
146
+
147
+ let targetIndex
148
+ if (Math.abs(velocityX) > velocityThreshold) {
149
+ targetIndex = velocityX > 0 ? currentIndex - 1 : currentIndex + 1
150
+ } else {
151
+ const crossedThreshold =
152
+ Math.abs(pixelToPercentage) > slideWidthPercentage / 2
153
+ targetIndex =
154
+ crossedThreshold && pixelToPercentage < 0
155
+ ? currentIndex + 1
156
+ : crossedThreshold
157
+ ? currentIndex - 1
158
+ : currentIndex
159
+ }
160
+ targetIndex = Math.max(0, Math.min(NUM_PAGES - 1, targetIndex))
161
+ animateSlide(-targetIndex * slideWidthPercentage)
162
+ currentSlide.value = targetIndex
163
+ })
164
+
165
+ const animatedStyle = useAnimatedStyle(() => ({
166
+ transform: [{translateX: `${translateX.value}%`}],
167
+ }))
168
+
169
+ useImperativeHandle(ref, () => ({
170
+ handlePrev,
171
+ handleNext,
172
+ }))
173
+
174
+ return (
175
+ <View style={styles.flex(flex)}>
176
+ <GestureDetector gesture={slideGesture}>
177
+ <View
178
+ style={[styles.container(), SlideshowStyles.container(colorPalette)]}
179
+ onLayout={e => setContainerWidth(e.nativeEvent.layout.width)}>
180
+ <Animated.View
181
+ style={[
182
+ styles.slidesContainer(`${NUM_PAGES * 100}%`),
183
+ animatedStyle,
184
+ ]}>
185
+ {slides.map((Slide, index) => (
186
+ <View
187
+ key={index}
188
+ style={[
189
+ styles.slide(`${slideWidth}%`),
190
+ SlideshowStyles.slideContainer(colorPalette),
191
+ ]}>
192
+ {Slide}
193
+ </View>
194
+ ))}
195
+ </Animated.View>
196
+ </View>
197
+ </GestureDetector>
198
+ </View>
199
+ )
200
+ }
272
201
 
273
- // type SlideshowTokenType = ReturnType<Tokens['slideshow']>; // This is the return of the function
274
- // type VariantsType = SlideshowTokenType['variants'];
275
- // type SlideContainerType = SlideshowTokenType['slideContainer']['variants'];
202
+ export default Slideshow
276
203
 
277
204
  const styles = StyleSheet.create({
278
- flex: (flex) => ({
205
+ flex: flex => ({
279
206
  flex,
280
207
  flexDirection: 'row',
281
208
  }),
282
- container: (
283
- // variants: VariantsType
284
- ) => ({
209
+ container: () => ({
285
210
  zIndex: 1,
286
211
  width: '100%',
287
212
  height: '100%',
@@ -290,28 +215,16 @@ const styles = StyleSheet.create({
290
215
  alignItems: 'flex-start',
291
216
  backgroundColor: 'white',
292
217
  borderRadius: 16,
293
- // backgroundColor: slideshowTokens.baseStyles?.backgroundColor?.(theme),
294
- // borderRadius: slideshowTokens.baseStyles?.borderRadius,
295
- // variants: {
296
- // colorScheme: variants.colorScheme as any,
297
- // },
298
218
  }),
299
- slidesContainer: (width) => ({
219
+ slidesContainer: width => ({
300
220
  flexDirection: 'row',
301
221
  width,
302
222
  flex: 1,
303
223
  }),
304
- slide: (width,
305
- // variants: SlideContainerType
306
- ) => ({
224
+ slide: width => ({
307
225
  width,
308
226
  flex: 1,
309
- // height: '100%',
310
227
  justifyContent: 'center',
311
228
  alignItems: 'center',
312
- // variants: {
313
- // colorScheme: variants.colorScheme as any,
314
- // spacing: variants.spacing as any,
315
- // },
316
229
  }),
317
- });
230
+ })