react-native-varia 0.4.3 → 0.4.5

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.
@@ -169,6 +169,11 @@ const styles = StyleSheet.create({
169
169
  },
170
170
  }),
171
171
  childContainer: {
172
+ position: 'absolute',
173
+ top: 0,
174
+ left: 0,
175
+ right: 0,
176
+ bottom: 0,
172
177
  flexBasis: 'auto',
173
178
  justifyContent: 'center',
174
179
  alignItems: 'center',
@@ -9,7 +9,6 @@ import React, {
9
9
  import {
10
10
  Dimensions,
11
11
  Keyboard,
12
- Platform,
13
12
  TouchableWithoutFeedback,
14
13
  View,
15
14
  } from 'react-native'
@@ -26,17 +25,14 @@ import Animated, {
26
25
  } from 'react-native-reanimated'
27
26
  import {scheduleOnRN, scheduleOnUI} from 'react-native-worklets'
28
27
  import {DrawerTokens, DrawerStyles} from '../theme/Drawer.recipe'
29
- import {PalettesWithNestedKeys} from '../style/varia/types'
28
+ import {PalettesWithNestedKeys, ZIndex} from '../style/varia/types'
30
29
  import {
31
30
  StyleSheet,
32
31
  UnistylesRuntime,
33
32
  UnistylesVariants,
34
33
  } from 'react-native-unistyles'
35
34
  import {HStack} from '../patterns'
36
-
37
- /* -----------------------------
38
- * Types
39
- * ----------------------------*/
35
+ import {ZINDEXES} from '../style/varia/constants'
40
36
 
41
37
  export type DrawerRef = {
42
38
  expand: () => void | null
@@ -55,12 +51,9 @@ type DrawerContextType = DrawerVariants & {
55
51
  type DrawerRootProps = DrawerVariants & {
56
52
  colorPalette?: PalettesWithNestedKeys
57
53
  children?: React.ReactNode
54
+ zIndex?: ZIndex
58
55
  }
59
56
 
60
- /* -----------------------------
61
- * Context
62
- * ----------------------------*/
63
-
64
57
  const DrawerContext = createContext<DrawerContextType | null>(null)
65
58
  const useDrawer = () => {
66
59
  const ctx = useContext(DrawerContext)
@@ -69,13 +62,10 @@ const useDrawer = () => {
69
62
  return ctx
70
63
  }
71
64
 
72
- /* -----------------------------
73
- * Root
74
- * ----------------------------*/
75
-
76
65
  const DrawerRoot = ({
77
66
  colorPalette = 'accent',
78
67
  variant = DrawerTokens.defaultProps.variant,
68
+ zIndex,
79
69
  children,
80
70
  }: DrawerRootProps) => {
81
71
  DrawerStyles.useVariants({variant})
@@ -86,8 +76,9 @@ const DrawerRoot = ({
86
76
  colorPalette,
87
77
  variant,
88
78
  overlayOpacity,
79
+ zIndex,
89
80
  }),
90
- [colorPalette, variant],
81
+ [colorPalette, variant, zIndex],
91
82
  )
92
83
 
93
84
  return (
@@ -95,9 +86,6 @@ const DrawerRoot = ({
95
86
  )
96
87
  }
97
88
 
98
- /* -----------------------------
99
- * Positioner
100
- * ----------------------------*/
101
89
  const DrawerPositioner = ({
102
90
  children,
103
91
  direction,
@@ -147,9 +135,6 @@ const DrawerPositioner = ({
147
135
  )
148
136
  }
149
137
 
150
- /* -----------------------------
151
- * Overlay
152
- * ----------------------------*/
153
138
  const AnimatedTouchable = Animated.createAnimatedComponent(
154
139
  TouchableWithoutFeedback,
155
140
  )
@@ -190,10 +175,6 @@ const DrawerOverlay = ({onPress}: {onPress?: () => void}) => {
190
175
  )
191
176
  }
192
177
 
193
- /* -----------------------------
194
- * Slider (gestión independiente)
195
- * ----------------------------*/
196
-
197
178
  type InternalDrawerSliderProps = {
198
179
  axis: 'x' | 'y'
199
180
  direction: 1 | -1
@@ -207,6 +188,7 @@ type InternalDrawerSliderProps = {
207
188
  children?: React.ReactNode
208
189
  ref?: React.RefObject<DrawerRef | null>
209
190
  externalTranslate?: SharedValue<number>
191
+ zIndex?: ZIndex
210
192
  }
211
193
 
212
194
  export type DrawerSliderProps = Omit<
@@ -231,6 +213,7 @@ const DrawerSliderInternal = ({
231
213
  children,
232
214
  externalTranslate,
233
215
  ref,
216
+ zIndex,
234
217
  }: InternalDrawerSliderProps) => {
235
218
  const {variant, colorPalette, overlayOpacity} = useDrawer()
236
219
 
@@ -489,7 +472,7 @@ const DrawerSliderInternal = ({
489
472
  ref={viewRef}
490
473
  onLayout={onLayout}
491
474
  style={[
492
- styles.slider,
475
+ styles.slider(zIndex || ZINDEXES.drawer),
493
476
  blockAnimatedStyle,
494
477
  DrawerStyles.slider(colorPalette),
495
478
  {pointerEvents: 'auto'},
@@ -523,14 +506,14 @@ const styles = StyleSheet.create((theme, rt) => ({
523
506
  _classNames: 'drawer-positioner-base',
524
507
  },
525
508
  },
526
- slider: {
509
+ slider: (zIndex: ZIndex) => ({
527
510
  flex: 1,
528
511
  alignSelf: 'stretch',
529
512
  alignItems: 'center',
530
513
  justifyContent: 'flex-start',
531
- zIndex: 100,
514
+ zIndex,
532
515
  _web: {
533
516
  _classNames: 'drawer-slider-base',
534
517
  },
535
- },
518
+ }),
536
519
  }))
@@ -40,14 +40,16 @@ const Link = ({
40
40
  console.log(color)
41
41
  return (
42
42
  <TouchableOpacity
43
+ testID="varia-link"
43
44
  onPress={async () => {
44
45
  try {
45
46
  await Linking.openURL(url)
46
47
  } catch {
47
- Alert.alert('No se pudo abrir este enlace')
48
+ Alert.alert('Could not open this link')
48
49
  }
49
50
  }}>
50
51
  <Text
52
+ testID="varia-link-text"
51
53
  size={size}
52
54
  variant={variant}
53
55
  fontSize={fontSize}
@@ -1,17 +1,13 @@
1
1
  import React, {createContext, useContext} from 'react'
2
- import {
3
- TouchableOpacity,
4
- TouchableWithoutFeedback,
5
- View,
6
- StyleSheet as RNStyleSheet,
7
- } from 'react-native'
2
+ import {TouchableOpacity, TouchableWithoutFeedback, View} from 'react-native'
8
3
  import Animated from 'react-native-reanimated'
9
4
  import {Portal} from '@gorhom/portal'
10
5
  import Svg, {Path} from 'react-native-svg'
11
6
  import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
12
7
  import Text from './Text'
13
8
  import {ModalStyles, ModalTokens} from '../theme/Modal.recipe'
14
- import {PalettesWithNestedKeys} from '../style/varia/types'
9
+ import {PalettesWithNestedKeys, ZIndex} from '../style/varia/types'
10
+ import {ZINDEXES} from '../style/varia/constants'
15
11
 
16
12
  const AnimatedView = Animated.createAnimatedComponent(View)
17
13
  type ModalVariants = UnistylesVariants<typeof ModalStyles>
@@ -24,6 +20,7 @@ type ModalRootProps = ModalVariants & {
24
20
  portalHostName?: string
25
21
  isOpen: boolean
26
22
  setIsOpen: (isOpen: boolean) => void
23
+ zIndex?: ZIndex
27
24
  children: React.ReactNode
28
25
  }
29
26
 
@@ -46,6 +43,7 @@ const ModalRoot = ({
46
43
  portalHostName = 'modal',
47
44
  isOpen,
48
45
  setIsOpen,
46
+ zIndex,
49
47
  children,
50
48
  }: ModalRootProps) => {
51
49
  ModalStyles.useVariants({
@@ -59,6 +57,7 @@ const ModalRoot = ({
59
57
  variant,
60
58
  animation,
61
59
  setIsOpen,
60
+ zIndex,
62
61
  }
63
62
 
64
63
  return (
@@ -85,17 +84,25 @@ const ModalOverlay = ({children, ...props}: ModalOverlayProps) => {
85
84
  variant,
86
85
  animation,
87
86
  setIsOpen,
87
+ zIndex,
88
88
  } = {...context, ...props}
89
89
 
90
90
  ModalStyles.useVariants({variant})
91
91
 
92
92
  return (
93
93
  <AnimatedView
94
- style={[styles.overlay, ModalStyles.overlay(colorPalette)]}
94
+ testID="varia-modal-overlay"
95
+ style={[
96
+ styles.overlay(zIndex || ZINDEXES.modal),
97
+ ModalStyles.overlay(colorPalette),
98
+ ]}
95
99
  entering={ModalTokens.animations.variants[animation]?.enteringOverlay}
96
100
  exiting={ModalTokens.animations.variants[animation]?.exitingOverlay}>
97
101
  <TouchableWithoutFeedback onPress={() => setIsOpen(false)}>
98
- <View style={StyleSheet.absoluteFillObject} />
102
+ <View
103
+ testID="varia-modal-backdrop"
104
+ style={StyleSheet.absoluteFillObject}
105
+ />
99
106
  </TouchableWithoutFeedback>
100
107
  {children}
101
108
  </AnimatedView>
@@ -125,6 +132,7 @@ const ModalContent = ({children, ...props}: ModalContentProps) => {
125
132
 
126
133
  return (
127
134
  <AnimatedView
135
+ testID="varia-modal-content"
128
136
  style={[styles.content(), ModalStyles.content(colorPalette)]}
129
137
  entering={ModalTokens.animations.variants[animation]?.enteringContent}
130
138
  exiting={ModalTokens.animations.variants[animation]?.exitingContent}>
@@ -134,7 +142,11 @@ const ModalContent = ({children, ...props}: ModalContentProps) => {
134
142
  }
135
143
 
136
144
  const ModalHeader = ({children}: {children: React.ReactNode}) => {
137
- return <View style={styles.header}>{children}</View>
145
+ return (
146
+ <View testID="varia-modal-header" style={styles.header}>
147
+ {children}
148
+ </View>
149
+ )
138
150
  }
139
151
 
140
152
  const ModalTitle = ({children, ...props}: {children: React.ReactNode}) => {
@@ -142,7 +154,11 @@ const ModalTitle = ({children, ...props}: {children: React.ReactNode}) => {
142
154
  const {variant, colorPalette = 'accent'} = {...context, ...props}
143
155
 
144
156
  ModalStyles.useVariants({variant})
145
- return <Text style={ModalStyles.title(colorPalette)}>{children}</Text>
157
+ return (
158
+ <Text testID="varia-modal-title" style={ModalStyles.title(colorPalette)}>
159
+ {children}
160
+ </Text>
161
+ )
146
162
  }
147
163
 
148
164
  type ModalBodyProps = Omit<ModalVariants, 'variant'> & {
@@ -153,7 +169,7 @@ type ModalBodyProps = Omit<ModalVariants, 'variant'> & {
153
169
  }
154
170
 
155
171
  const ModalBody = ({children}: ModalBodyProps) => {
156
- return <View>{children}</View>
172
+ return <View testID="varia-modal-body">{children}</View>
157
173
  }
158
174
 
159
175
  type CloseButtonProps = {
@@ -168,7 +184,7 @@ const CloseButton = ({
168
184
  color,
169
185
  ...rest
170
186
  }: CloseButtonProps) => (
171
- <TouchableOpacity onPress={onClose}>
187
+ <TouchableOpacity testID="varia-modal-close-button" onPress={onClose}>
172
188
  <Svg
173
189
  width={scale * 24}
174
190
  height={scale * 24}
@@ -213,15 +229,15 @@ const ModalCloseTrigger = ({children, style}: ModalCloseTriggerProps) => {
213
229
 
214
230
  const styles = StyleSheet.create(theme => {
215
231
  return {
216
- overlay: {
217
- ...RNStyleSheet.absoluteFillObject,
218
- zIndex: 1000,
232
+ overlay: (zIndex: ZIndex) => ({
233
+ ...StyleSheet.absoluteFillObject,
234
+ zIndex,
219
235
  justifyContent: 'center',
220
236
  alignItems: 'center',
221
237
  _web: {
222
238
  _classNames: 'modal-overlay-base',
223
239
  },
224
- },
240
+ }),
225
241
  content: () => ({
226
242
  justifyContent: 'center',
227
243
  alignItems: 'center',
@@ -125,6 +125,7 @@ const NumberInput = {
125
125
  direction,
126
126
  }}>
127
127
  <View
128
+ testID="varia-select-root"
128
129
  style={[
129
130
  simpleNumberInputstyles.rootContainer(flex, alignSelf),
130
131
  NumberInputStyles.container(colorPalette),
@@ -177,6 +178,7 @@ const NumberInput = {
177
178
  NumberInputStyles.useVariants({variant, size, distribution})
178
179
  return (
179
180
  <TextInput
181
+ testID="varia-select-input"
180
182
  style={[
181
183
  simpleNumberInputstyles.input(childFlex as number),
182
184
  NumberInputStyles.input(colorPalette),
@@ -222,6 +224,7 @@ const NumberInput = {
222
224
 
223
225
  return (
224
226
  <Pressable
227
+ testID="varia-select-increment"
225
228
  onPress={() => setValue(value + 1)}
226
229
  disabled={max !== undefined && value >= max}
227
230
  style={[
@@ -265,6 +268,7 @@ const NumberInput = {
265
268
 
266
269
  return (
267
270
  <Pressable
271
+ testID="varia-select-decrement"
268
272
  onPress={() => setValue(value - 1)}
269
273
  disabled={min !== undefined && value <= min}
270
274
  style={[
@@ -91,6 +91,7 @@ function Root({
91
91
  return (
92
92
  <RadioGroupContext.Provider value={contextValue}>
93
93
  <View
94
+ testID="varia-radio-group-root"
94
95
  style={[
95
96
  styles.root(
96
97
  flex,
@@ -139,6 +140,8 @@ function Item({children, value: itemValue}: PublicItemProps) {
139
140
 
140
141
  return (
141
142
  <Pressable
143
+ aria-checked={value === itemValue}
144
+ testID={`varia-radio-group-item-${value}`}
142
145
  style={({pressed}) => [
143
146
  styles.item,
144
147
  RadioGroupStyles.item(colorPalette, pressed),
@@ -172,7 +175,9 @@ function Indicator({
172
175
  })
173
176
 
174
177
  return (
175
- <View style={RadioGroupStyles.control(colorPalette)}>
178
+ <View
179
+ testID="varia-radio-group-indicator"
180
+ style={RadioGroupStyles.control(colorPalette)}>
176
181
  <View style={RadioGroupStyles.indicator(colorPalette)} />
177
182
  </View>
178
183
  )
@@ -214,7 +219,7 @@ const styles = StyleSheet.create({
214
219
  alignSelf?: AlignSelf,
215
220
  justifyContent?: ViewStyle['justifyContent'],
216
221
  alignItems?: ViewStyle['alignItems'],
217
- gap?: number,
222
+ gap?: Gap,
218
223
  ) => ({
219
224
  flex,
220
225
  flexDirection: direction,
@@ -23,8 +23,10 @@ import {
23
23
  Flex,
24
24
  PalettesWithNestedKeys,
25
25
  StackDirection,
26
+ ZIndex,
26
27
  } from '../style/varia/types'
27
28
  import {computeFlexSync} from '../style/varia/utils'
29
+ import {ZINDEXES} from '../style/varia/constants'
28
30
 
29
31
  type SelectVariants = UnistylesVariants<typeof SelectStyles>
30
32
 
@@ -47,6 +49,7 @@ interface SelectContextType {
47
49
  variant: SelectVariants['variant']
48
50
  size: SelectVariants['size']
49
51
  flex: Flex
52
+ zIndex: ZIndex
50
53
  }
51
54
 
52
55
  const SelectContext = createContext<SelectContextType | undefined>(undefined)
@@ -70,6 +73,7 @@ type RootProps = SelectVariants & {
70
73
  flex?: Flex
71
74
  stretch?: AlignSelf
72
75
  direction?: 'row' | 'column'
76
+ zIndex?: ZIndex
73
77
  }
74
78
 
75
79
  const SelectRoot = ({
@@ -85,6 +89,7 @@ const SelectRoot = ({
85
89
  flex = 0,
86
90
  stretch,
87
91
  direction = 'column',
92
+ zIndex,
88
93
  }: RootProps) => {
89
94
  SelectStyles.useVariants({variant, size})
90
95
  const [internalValue, setInternalValue] = useState(defaultValue)
@@ -116,7 +121,7 @@ const SelectRoot = ({
116
121
  )
117
122
 
118
123
  return (
119
- <View style={[styles.container(flex, stretch)]}>
124
+ <View style={[styles.container(flex, stretch)]} testID="varia-select-root">
120
125
  {trigger &&
121
126
  React.cloneElement(trigger as ReactElement<TriggerProps>, {
122
127
  isOpen,
@@ -147,8 +152,11 @@ const SelectRoot = ({
147
152
  variant,
148
153
  size,
149
154
  flex,
155
+ zIndex,
150
156
  }}>
151
- <View style={styles.portalContainer}>{portalChildren}</View>
157
+ <View style={styles.portalContainer(zIndex || ZINDEXES.select)}>
158
+ {portalChildren}
159
+ </View>
152
160
  </SelectContext.Provider>
153
161
  </Portal>
154
162
  )}
@@ -194,7 +202,8 @@ const SelectTrigger = ({
194
202
  style={({pressed}) => [
195
203
  styles.input(childFlex),
196
204
  SelectStyles.trigger(colorPalette, pressed),
197
- ]}>
205
+ ]}
206
+ testID="varia-select-trigger">
198
207
  <Text>{selected ? selected.label : placeholder}</Text>
199
208
  </Pressable>
200
209
  )
@@ -214,7 +223,10 @@ const SelectOverlay = ({
214
223
  const {setIsOpen} = useSelect()
215
224
  return (
216
225
  <TouchableWithoutFeedback onPress={() => setIsOpen(false)}>
217
- <View style={[styles.backdrop, SelectStyles.overlay(colorPalette)]} />
226
+ <View
227
+ style={[styles.backdrop, SelectStyles.overlay(colorPalette)]}
228
+ testID="varia-select-overlay"
229
+ />
218
230
  </TouchableWithoutFeedback>
219
231
  )
220
232
  }
@@ -231,7 +243,9 @@ const SelectContent = ({
231
243
  const {variant, size, colorPalette} = {...useSelect(), ...props}
232
244
  SelectStyles.useVariants({variant, size})
233
245
  return (
234
- <View style={[styles.modalContent, SelectStyles.content(colorPalette)]}>
246
+ <View
247
+ style={[styles.modalContent, SelectStyles.content(colorPalette)]}
248
+ testID="varia-select-content">
235
249
  <ScrollView>{children}</ScrollView>
236
250
  </View>
237
251
  )
@@ -249,7 +263,10 @@ const SelectItem = ({value, label, ...props}: Option) => {
249
263
  const isSelected = selected === value
250
264
  SelectStyles.useVariants({variant, size})
251
265
  return (
252
- <TouchableOpacity onPress={() => setValue(value)}>
266
+ <TouchableOpacity
267
+ onPress={() => setValue(value)}
268
+ testID="varia-select-item"
269
+ aria-selected={isSelected}>
253
270
  <View style={[styles.item, SelectStyles.item(colorPalette, isSelected)]}>
254
271
  <Text style={SelectStyles.itemText(colorPalette, isSelected)}>
255
272
  {label}
@@ -300,6 +317,7 @@ const styles = StyleSheet.create({
300
317
  },
301
318
  },
302
319
  backdrop: {
320
+ zIndex: 1001,
303
321
  ...StyleSheet.absoluteFillObject,
304
322
  backgroundColor: 'rgba(0,0,0,0.3)',
305
323
  _web: {
@@ -313,7 +331,8 @@ const styles = StyleSheet.create({
313
331
  _classNames: 'select-modal-content-base',
314
332
  },
315
333
  },
316
- portalContainer: {
334
+ portalContainer: (zIndex: ZIndex) => ({
335
+ zIndex,
317
336
  position: 'absolute',
318
337
  top: 0,
319
338
  left: 0,
@@ -324,5 +343,5 @@ const styles = StyleSheet.create({
324
343
  _web: {
325
344
  _classNames: 'select-portal-container-base',
326
345
  },
327
- },
346
+ }),
328
347
  })
@@ -273,6 +273,7 @@ const Slider = ({
273
273
 
274
274
  return (
275
275
  <View
276
+ testID="varia-slider-container"
276
277
  style={[
277
278
  styles.container(halfSize, flex, alignSelf),
278
279
  SliderStyles.container(colorPalette),
@@ -280,12 +281,14 @@ const Slider = ({
280
281
  {axis === 'x' && <View style={{width: halfSize}} />}
281
282
  <GestureDetector gesture={Gesture.Simultaneous(trackPan, tapGesture)}>
282
283
  <View
284
+ testID="varia-slider-maximun-track"
283
285
  style={[
284
286
  styles.maximumTrack(),
285
287
  SliderStyles.maximumTrack(colorPalette),
286
288
  ]}
287
289
  onLayout={handleTrackLayout}>
288
290
  <AnimatedView
291
+ testID="varia-slider-minimum-track"
289
292
  style={[
290
293
  styles.minimumTrack(halfSize),
291
294
  SliderStyles.minimumTrack(colorPalette),
@@ -295,7 +298,7 @@ const Slider = ({
295
298
 
296
299
  {steps && (
297
300
  <View style={[styles.stepsOverlay]} pointerEvents="none">
298
- <View style={styles.steps}>
301
+ <View style={styles.steps} testID="varia-slider-steps">
299
302
  {Array.from({length: steps + 1}, (_, index) => index).map(
300
303
  (_, i) => (
301
304
  <View
@@ -311,7 +314,7 @@ const Slider = ({
311
314
  </View>
312
315
  )}
313
316
  <GestureDetector gesture={slideGesture}>
314
- <View style={styles.thumbContainerFull}>
317
+ <View style={styles.thumbContainerFull} testID="varia-slider-tumb">
315
318
  <AnimatedView style={[animatedThumb, {flex: 1}]}>
316
319
  <View
317
320
  style={[
@@ -350,7 +353,7 @@ const styles = StyleSheet.create(theme => ({
350
353
  },
351
354
  y: {
352
355
  // maxHeight: 'auto',
353
- height: '100%',
356
+ // height: '100%',
354
357
  paddingTop: halfSize,
355
358
  paddingRight: 0,
356
359
  flexDirection: 'column',
@@ -170,6 +170,7 @@ const Slideshow = ({
170
170
  <View style={styles.flex(flex)}>
171
171
  <GestureDetector gesture={slideGesture}>
172
172
  <View
173
+ testID="varia-slideshow"
173
174
  style={[styles.container(), SlideshowStyles.container(colorPalette)]}
174
175
  onLayout={e => {
175
176
  setContainerWidth(e.nativeEvent.layout.width)
@@ -182,6 +183,7 @@ const Slideshow = ({
182
183
  ]}>
183
184
  {slides.map((Slide, index) => (
184
185
  <View
186
+ testID={`varia-slides-slide-${index}`}
185
187
  key={index}
186
188
  style={[
187
189
  styles.slide(`${slideSize}%`, isHorizontal),
@@ -87,24 +87,30 @@ const Switch = ({
87
87
  useLayoutEffect(() => {
88
88
  animatedRef.current?.measure((x, y, width) => {
89
89
  containerWidth.value = width
90
- // const thumbWidth = SwitchStyles.thumb(colorPalette).width
91
90
  const thumbWidth = getVariantValue(
92
91
  SwitchStyles.thumb(colorPalette),
93
92
  'size',
94
93
  size,
95
94
  'width',
96
95
  )
97
- // const padding = SwitchStyles.container(colorPalette).padding || 0
98
96
  const padding =
99
97
  getVariantValue(
100
98
  SwitchStyles.container(colorPalette),
101
99
  'size',
102
100
  size,
103
101
  'padding',
104
- ) || 0
105
- // const trackBorderWidth =
106
- // SwitchStyles.container(colorPalette).borderWidth || 0
107
- const trackBorderWidth = 1
102
+ ) ||
103
+ SwitchStyles.container(colorPalette).padding ||
104
+ 0
105
+ const trackBorderWidth =
106
+ getVariantValue(
107
+ SwitchStyles.container(colorPalette),
108
+ 'size',
109
+ size,
110
+ 'borderWidth',
111
+ ) ||
112
+ SwitchStyles.container(colorPalette).borderWidth ||
113
+ 0
108
114
  thumbEnabledPosition.value =
109
115
  width - thumbWidth - trackBorderWidth * 2 - padding * 2
110
116
  })
@@ -141,6 +147,7 @@ const Switch = ({
141
147
 
142
148
  return (
143
149
  <TouchableWithoutFeedback
150
+ testID="varia-switch"
144
151
  onPress={() => {
145
152
  if (isAnimating.value) return
146
153
  isAnimating.value = true
@@ -164,6 +171,7 @@ const Switch = ({
164
171
  SwitchStyles.container(colorPalette),
165
172
  ]}>
166
173
  <AnimatedView
174
+ testID="varia-switch-thumb"
167
175
  style={[
168
176
  styles.thumb,
169
177
  SwitchStyles.thumb(colorPalette),
@@ -48,7 +48,7 @@ const Text = ({
48
48
 
49
49
  const styles = StyleSheet.create(theme => ({
50
50
  text: (color?: string, fontSize?: number) => ({
51
- verticalAlign: 'bottom',
51
+ verticalAlign: 'middle',
52
52
  textAlign: 'left',
53
53
  ...(color && {
54
54
  color: extractThemeColor(color, theme),
@@ -11,9 +11,10 @@ import Animated, {
11
11
  import {scheduleOnRN, scheduleOnUI} from 'react-native-worklets'
12
12
  import {ToastStyles, ToastDefaultVariants} from '../theme/Toast.recipe'
13
13
  import {UnistylesVariants} from 'react-native-unistyles'
14
- import {PalettesWithNestedKeys} from '../style/varia/types'
14
+ import {PalettesWithNestedKeys, ZIndex} from '../style/varia/types'
15
15
  import Text from './Text'
16
- import {AnimatedHStack, VStack} from '../patterns/newPatterns'
16
+ import {AnimatedHStack, VStack} from '../patterns'
17
+ import {ZINDEXES} from '../style/varia/constants'
17
18
 
18
19
  type ToastVariants = UnistylesVariants<typeof ToastStyles>
19
20
 
@@ -23,6 +24,7 @@ export type ToastProps = ToastVariants & {
23
24
  duration?: number
24
25
  onClose?: () => void
25
26
  position?: 'top' | 'bottom'
27
+ zIndex?: ZIndex
26
28
  }
27
29
 
28
30
  const Toast: React.FC<ToastProps> = ({
@@ -33,6 +35,7 @@ const Toast: React.FC<ToastProps> = ({
33
35
  duration = 5000,
34
36
  onClose,
35
37
  position = 'bottom',
38
+ zIndex,
36
39
  }) => {
37
40
  ToastStyles.useVariants({variant, size})
38
41
 
@@ -81,13 +84,14 @@ const Toast: React.FC<ToastProps> = ({
81
84
 
82
85
  return (
83
86
  <VStack
87
+ testID="varia-toast"
84
88
  style={[
85
89
  {
86
90
  ...StyleSheet.absoluteFill,
87
91
  justifyContent:
88
92
  position === 'bottom' || !position ? 'flex-end' : 'flex-start',
89
93
  },
90
- styles.container,
94
+ styles.container(zIndex || ZINDEXES.toast),
91
95
  ToastStyles.root,
92
96
  ]}>
93
97
  <AnimatedHStack
@@ -100,16 +104,16 @@ const Toast: React.FC<ToastProps> = ({
100
104
  }
101
105
 
102
106
  const styles = StyleSheet.create({
103
- container: {
107
+ container: (zIndex: ZIndex) => ({
104
108
  alignItems: 'center',
105
109
  overflow: 'hidden',
106
- zIndex: 100,
110
+ zIndex,
107
111
  pointerEvents: 'box-none',
108
112
  _web: {
109
113
  pointerEvents: 'none',
110
114
  _classNames: 'toast-container-base',
111
115
  },
112
- },
116
+ }),
113
117
  })
114
118
 
115
119
  export default Toast
@@ -6,7 +6,7 @@ import type {StyleProp, ViewProps, ViewStyle} from 'react-native'
6
6
  import Animated, {AnimatedRef} from 'react-native-reanimated'
7
7
  import {StyleSheet, UnistylesRuntime} from 'react-native-unistyles'
8
8
 
9
- interface StackProps {
9
+ interface StackProps extends ViewProps {
10
10
  backgroundColor?: ViewStyle['backgroundColor']
11
11
  bg?: ViewStyle['backgroundColor']
12
12
  width?: ViewStyle['width']
@@ -85,7 +85,9 @@ const VStack = ({children, style, align, ...props}: StackProps) => {
85
85
  const styleArr = useMemo(() => mapProps(props), [props])
86
86
 
87
87
  return (
88
- <View style={[stackStyles.stack, stackStyles.vstack, styleArr, style]}>
88
+ <View
89
+ style={[stackStyles.stack, stackStyles.vstack, styleArr, style]}
90
+ {...props}>
89
91
  {children}
90
92
  </View>
91
93
  )
@@ -96,7 +98,9 @@ const HStack = ({children, style, align, ...props}: StackProps) => {
96
98
  const styleArr = useMemo(() => mapProps(props), [props])
97
99
 
98
100
  return (
99
- <View style={[stackStyles.stack, stackStyles.hstack, styleArr, style]}>
101
+ <View
102
+ style={[stackStyles.stack, stackStyles.hstack, styleArr, style]}
103
+ {...props}>
100
104
  {children}
101
105
  </View>
102
106
  )
@@ -24,15 +24,15 @@ export const SelectStyles = StyleSheet.create((theme, rt) => ({
24
24
  size: {
25
25
  sm: {
26
26
  height: theme.sizes[9],
27
- padding: theme.spacing[1],
27
+ paddingHorizontal: theme.spacing[1],
28
28
  },
29
29
  md: {
30
30
  height: theme.sizes[10],
31
- padding: theme.spacing[2],
31
+ paddingHorizontal: theme.spacing[2],
32
32
  },
33
33
  lg: {
34
- height: theme.sizes[11],
35
- padding: theme.spacing[3],
34
+ height: theme.sizes[12],
35
+ paddingHorizontal: theme.spacing[3],
36
36
  },
37
37
  nosize: {},
38
38
  },
@@ -26,15 +26,41 @@ export const SliderStyles = StyleSheet.create(theme => ({
26
26
  },
27
27
  },
28
28
  size: {
29
- sm: {},
30
- md: {},
31
- lg: {},
32
- xl: {},
29
+ sm: {
30
+ borderRadius: theme.radii.lg,
31
+ },
32
+ md: {
33
+ borderRadius: theme.radii.xl,
34
+ },
35
+ lg: {
36
+ borderRadius: theme.radii['2xl'],
37
+ },
33
38
  flex: {},
34
39
  minimal: {},
35
40
  },
36
41
  },
37
42
  compoundVariants: [
43
+ {
44
+ size: 'sm',
45
+ variant: 'outline',
46
+ styles: {
47
+ borderRadius: theme.radii.sm,
48
+ },
49
+ },
50
+ {
51
+ size: 'md',
52
+ variant: 'outline',
53
+ styles: {
54
+ borderRadius: theme.radii.sm,
55
+ },
56
+ },
57
+ {
58
+ size: 'lg',
59
+ variant: 'outline',
60
+ styles: {
61
+ borderRadius: theme.radii.sm,
62
+ },
63
+ },
38
64
  {
39
65
  axis: 'x',
40
66
  size: 'sm',
@@ -56,13 +82,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
56
82
  height: theme.sizes[8],
57
83
  },
58
84
  },
59
- {
60
- axis: 'x',
61
- size: 'xl',
62
- styles: {
63
- height: theme.sizes[10],
64
- },
65
- },
66
85
  {
67
86
  axis: 'x',
68
87
  size: 'flex',
@@ -91,13 +110,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
91
110
  width: theme.sizes[8],
92
111
  },
93
112
  },
94
- {
95
- axis: 'y',
96
- size: 'xl',
97
- styles: {
98
- width: theme.sizes[10],
99
- },
100
- },
101
113
  {
102
114
  axis: 'y',
103
115
  size: 'flex',
@@ -125,7 +137,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
125
137
  sm: {},
126
138
  md: {},
127
139
  lg: {},
128
- xl: {},
129
140
  flex: {},
130
141
  minimal: {},
131
142
  },
@@ -152,13 +163,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
152
163
  height: theme.sizes[8],
153
164
  },
154
165
  },
155
- {
156
- axis: 'x',
157
- size: 'xl',
158
- styles: {
159
- height: theme.sizes[10],
160
- },
161
- },
162
166
  {
163
167
  axis: 'x',
164
168
  size: 'flex',
@@ -185,13 +189,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
185
189
  width: theme.sizes[8],
186
190
  },
187
191
  },
188
- {
189
- axis: 'y',
190
- size: 'xl',
191
- styles: {
192
- width: theme.sizes[10],
193
- },
194
- },
195
192
  ],
196
193
  }),
197
194
  minimumTrack: (colorPalette: PalettesWithNestedKeys) => ({
@@ -199,14 +196,14 @@ export const SliderStyles = StyleSheet.create(theme => ({
199
196
  variants: {
200
197
  axis: {
201
198
  x: {
202
- borderBottomLeftRadius: theme.radii.xl,
203
- borderBottomRightRadius: 0,
204
- borderTopLeftRadius: theme.radii.xl,
199
+ // borderBottomLeftRadius: theme.radii.xl,
200
+ // borderBottomRightRadius: 0,
201
+ // borderTopLeftRadius: theme.radii.xl,
205
202
  },
206
203
  y: {
207
- borderBottomLeftRadius: theme.radii.xl,
208
- borderBottomRightRadius: theme.radii.xl,
209
- borderTopLeftRadius: 0,
204
+ // borderBottomLeftRadius: theme.radii.xl,
205
+ // borderBottomRightRadius: theme.radii.xl,
206
+ // borderTopLeftRadius: 0,
210
207
  },
211
208
  },
212
209
  variant: {
@@ -218,10 +215,9 @@ export const SliderStyles = StyleSheet.create(theme => ({
218
215
  sm: {},
219
216
  md: {},
220
217
  lg: {},
221
- xl: {},
222
218
  flex: {},
223
219
  minimal: {
224
- borderRadius: theme.radii.sm,
220
+ // borderRadius: theme.radii.sm,
225
221
  },
226
222
  },
227
223
  },
@@ -247,13 +243,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
247
243
  height: theme.sizes[8],
248
244
  },
249
245
  },
250
- {
251
- axis: 'x',
252
- size: 'xl',
253
- styles: {
254
- height: theme.sizes[10],
255
- },
256
- },
257
246
  {
258
247
  axis: 'x',
259
248
  size: 'flex',
@@ -280,13 +269,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
280
269
  width: theme.sizes[8],
281
270
  },
282
271
  },
283
- {
284
- axis: 'y',
285
- size: 'xl',
286
- styles: {
287
- width: theme.sizes[10],
288
- },
289
- },
290
272
  {
291
273
  axis: 'y',
292
274
  size: 'flex',
@@ -318,7 +300,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
318
300
  sm: {},
319
301
  md: {},
320
302
  lg: {},
321
- xl: {},
322
303
  flex: {},
323
304
  minimal: {},
324
305
  },
@@ -328,16 +309,16 @@ export const SliderStyles = StyleSheet.create(theme => ({
328
309
  axis: 'x',
329
310
  size: 'sm',
330
311
  styles: {
331
- width: theme.sizes[6],
332
- height: theme.sizes[6],
312
+ width: theme.sizes[4],
313
+ height: theme.sizes[4],
333
314
  },
334
315
  },
335
316
  {
336
317
  axis: 'x',
337
318
  size: 'md',
338
319
  styles: {
339
- width: theme.sizes[7],
340
- height: theme.sizes[7],
320
+ width: theme.sizes[5],
321
+ height: theme.sizes[5],
341
322
  },
342
323
  },
343
324
  {
@@ -348,22 +329,11 @@ export const SliderStyles = StyleSheet.create(theme => ({
348
329
  height: theme.sizes[8],
349
330
  },
350
331
  },
351
- {
352
- axis: 'x',
353
- size: 'xl',
354
- styles: {
355
- width: theme.sizes[11],
356
- height: theme.sizes[11],
357
- },
358
- },
359
332
  {
360
333
  axis: 'x',
361
334
  size: 'flex',
362
335
  styles: {
363
336
  width: 30,
364
- // height: 50,
365
- // alignSel: 'stretch',
366
- // flex: 1,
367
337
  },
368
338
  },
369
339
  {
@@ -371,9 +341,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
371
341
  size: 'minimal',
372
342
  styles: {
373
343
  width: 0,
374
- // height: 50,
375
- // alignSel: 'stretch',
376
- // flex: 1,
377
344
  },
378
345
  },
379
346
  {
@@ -400,14 +367,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
400
367
  height: theme.sizes[8],
401
368
  },
402
369
  },
403
- {
404
- axis: 'y',
405
- size: 'xl',
406
- styles: {
407
- width: theme.sizes[11],
408
- height: theme.sizes[11],
409
- },
410
- },
411
370
  {
412
371
  axis: 'y',
413
372
  size: 'flex',
@@ -444,7 +403,6 @@ export const SliderStyles = StyleSheet.create(theme => ({
444
403
  sm: {},
445
404
  md: {},
446
405
  lg: {},
447
- xl: {},
448
406
  flex: {},
449
407
  minimal: {},
450
408
  },
@@ -30,8 +30,6 @@ export const SwitchTokens = {
30
30
 
31
31
  export const SwitchStyles = StyleSheet.create(theme => ({
32
32
  container: (colorPalette: PalettesWithNestedKeys) => ({
33
- // width: theme.sizes[16],
34
- // height: theme.sizes[16],
35
33
  borderRadius: theme.radii.full,
36
34
  padding: theme.spacing['0.5'],
37
35
  borderWidth: 0,
@@ -57,7 +55,6 @@ export const SwitchStyles = StyleSheet.create(theme => ({
57
55
  },
58
56
  flex: {
59
57
  borderRadius: theme.radii.md,
60
- // alignSelf: 'stretch',
61
58
  },
62
59
  },
63
60
  enabled: {
@@ -81,8 +78,6 @@ export const SwitchStyles = StyleSheet.create(theme => ({
81
78
  thumb: (colorPalette: PalettesWithNestedKeys) => ({
82
79
  backgroundColor: theme.colors.bg.default,
83
80
  borderRadius: theme.radii.full,
84
- // width: theme.sizes[6],
85
- // height: theme.sizes[6],
86
81
  variants: {
87
82
  variant: {
88
83
  solid: {},
@@ -0,0 +1,6 @@
1
+ export const ZINDEXES = {
2
+ drawer: 1000,
3
+ modal: 1001,
4
+ select: 1002,
5
+ toast: 1003,
6
+ }
@@ -0,0 +1,12 @@
1
+ import {useRef, useCallback} from 'react'
2
+
3
+ export function useZIndexGenerator(base = 0) {
4
+ const counterRef = useRef(base)
5
+
6
+ const next = useCallback(() => {
7
+ counterRef.current += 1
8
+ return counterRef.current
9
+ }, [])
10
+
11
+ return next
12
+ }
@@ -286,3 +286,4 @@ export type progressDirection = 'forward' | 'reverse'
286
286
  export type rotationDirection = 'clockwise' | 'counterclockwise'
287
287
  export type Flex = ViewStyle['flex']
288
288
  export type MaxWidth = ViewStyle['maxWidth']
289
+ export type ZIndex = ViewStyle['zIndex']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-varia",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "bin": {
5
5
  "varia": "bin/cli.js"
6
6
  },