react-native-varia 0.5.2 → 0.6.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.
@@ -1,4 +1,10 @@
1
- import {Platform, TouchableWithoutFeedback, View} from 'react-native'
1
+ import {
2
+ Platform,
3
+ StyleProp,
4
+ TouchableWithoutFeedback,
5
+ View,
6
+ ViewStyle,
7
+ } from 'react-native'
2
8
  import Animated, {
3
9
  useAnimatedStyle,
4
10
  useSharedValue,
@@ -31,6 +37,8 @@ type SwitchProps = SwitchVariants & {
31
37
  enabledIcon?: ReactNode
32
38
  disabledIcon?: ReactNode
33
39
  alignSelf?: AlignSelf
40
+ containerStyles?: StyleProp<ViewStyle>
41
+ thumbStyles?: StyleProp<ViewStyle>
34
42
  }
35
43
 
36
44
  const Switch = ({
@@ -44,6 +52,8 @@ const Switch = ({
44
52
  size = SwitchTokens.defaultProps.size,
45
53
  flex = 0,
46
54
  alignSelf = 'flex-start',
55
+ containerStyles,
56
+ thumbStyles,
47
57
  }: SwitchProps) => {
48
58
  const animatedRef = useRef<View>(null)
49
59
 
@@ -166,15 +176,17 @@ const Switch = ({
166
176
  <AnimatedView
167
177
  ref={animatedRef}
168
178
  style={[
179
+ SwitchStyles.container(colorPalette),
180
+ containerStyles,
169
181
  styles.container(flex, alignSelf),
170
182
  animatedStyle,
171
- SwitchStyles.container(colorPalette),
172
183
  ]}>
173
184
  <AnimatedView
174
185
  testID="varia-switch-thumb"
175
186
  style={[
176
- styles.thumb,
177
187
  SwitchStyles.thumb(colorPalette),
188
+ thumbStyles,
189
+ styles.thumb,
178
190
  thumbAnimatedStyle,
179
191
  circleTranslationStyle,
180
192
  ]}>
@@ -11,7 +11,7 @@ type TextProps = TextVariants &
11
11
  colorPalette?: PalettesWithNestedKeys
12
12
  fontSize?: number | undefined
13
13
  color?: ThemeColors
14
- style?: TextStyle
14
+ style?: StyleProp<TextStyle>
15
15
  children?: React.ReactNode
16
16
  mixins?: StyleProp<TextStyle> | StyleProp<TextStyle>[]
17
17
  }
@@ -37,8 +37,8 @@ const Text = ({
37
37
  style={[
38
38
  TextStyles.text(colorPalette),
39
39
  styles.text(color, fontSize),
40
- mixins && mixins,
41
40
  style,
41
+ mixins && mixins,
42
42
  ]}
43
43
  {...props}>
44
44
  {children}
@@ -15,6 +15,7 @@ import {PalettesWithNestedKeys, ZIndex} from '../../style/varia/types'
15
15
  import Text from './Text'
16
16
  import {AnimatedHStack, VStack} from '../../patterns'
17
17
  import {ZINDEXES} from '../../style/varia/constants'
18
+ import {StyleProp, TextStyle, ViewStyle} from 'react-native'
18
19
 
19
20
  type ToastVariants = UnistylesVariants<typeof ToastStyles>
20
21
 
@@ -25,6 +26,8 @@ export type ToastProps = ToastVariants & {
25
26
  onClose?: () => void
26
27
  position?: 'top' | 'bottom'
27
28
  zIndex?: ZIndex
29
+ containerStyles?: StyleProp<ViewStyle>
30
+ textStyles?: StyleProp<TextStyle>
28
31
  }
29
32
 
30
33
  const Toast: React.FC<ToastProps> = ({
@@ -36,6 +39,8 @@ const Toast: React.FC<ToastProps> = ({
36
39
  onClose,
37
40
  position = 'bottom',
38
41
  zIndex,
42
+ containerStyles,
43
+ textStyles,
39
44
  }) => {
40
45
  ToastStyles.useVariants({variant, size})
41
46
 
@@ -91,13 +96,19 @@ const Toast: React.FC<ToastProps> = ({
91
96
  justifyContent:
92
97
  position === 'bottom' || !position ? 'flex-end' : 'flex-start',
93
98
  },
94
- styles.container(zIndex || ZINDEXES.toast),
95
99
  ToastStyles.root,
100
+ styles.container(zIndex || ZINDEXES.toast),
96
101
  ]}>
97
102
  <AnimatedHStack
98
103
  ref={animatedRef}
99
- style={[animatedStyle, ToastStyles.container(colorPalette)]}>
100
- <Text style={ToastStyles.text(colorPalette)}>{message}</Text>
104
+ style={[
105
+ animatedStyle,
106
+ ToastStyles.container(colorPalette),
107
+ containerStyles,
108
+ ]}>
109
+ <Text style={[ToastStyles.text(colorPalette), textStyles]}>
110
+ {message}
111
+ </Text>
101
112
  </AnimatedHStack>
102
113
  </VStack>
103
114
  )
@@ -2,6 +2,7 @@ import {createContext, useContext} from 'react'
2
2
  import {UnistylesVariants} from 'react-native-unistyles'
3
3
  import {FieldStyles} from '../../../theme/Field.recipe'
4
4
  import {PalettesWithNestedKeys} from '../../../style/varia/types'
5
+ import {StyleProp, TextStyle} from 'react-native'
5
6
 
6
7
  export type FieldVariants = UnistylesVariants<typeof FieldStyles>
7
8
 
@@ -10,6 +11,7 @@ export type FieldContextType = {
10
11
  variant?: FieldVariants['variant']
11
12
  size?: FieldVariants['size']
12
13
  colorPalette?: PalettesWithNestedKeys
14
+ labelStyles?: StyleProp<TextStyle>
13
15
  }
14
16
 
15
17
  const FieldContext = createContext<FieldContextType | undefined>(undefined)
@@ -287,3 +287,9 @@ export type rotationDirection = 'clockwise' | 'counterclockwise'
287
287
  export type Flex = ViewStyle['flex']
288
288
  export type MaxWidth = ViewStyle['maxWidth']
289
289
  export type ZIndex = ViewStyle['zIndex']
290
+
291
+ export type Axis = 'x' | 'y'
292
+ export type SizeEntry = {
293
+ x?: Record<string, any>
294
+ y?: Record<string, any>
295
+ }
@@ -37,6 +37,7 @@ import {
37
37
  ColorScheme,
38
38
  CreatePresetDTO,
39
39
  CustomColorScheme,
40
+ SizeEntry,
40
41
  ThemeColors,
41
42
  ThemePresetDTO,
42
43
  } from './types'
@@ -439,3 +440,9 @@ export function getCompoundVariantValue<
439
440
 
440
441
  return match.styles[propName]
441
442
  }
443
+
444
+ export const generateCompoundVariants = (sizes: Record<string, SizeEntry>) =>
445
+ Object.entries(sizes).flatMap(([size, axes]) => [
446
+ {axis: 'x', size, styles: axes.x ?? {}},
447
+ {axis: 'y', size, styles: axes.y ?? {}},
448
+ ])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-varia",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "bin": {
5
5
  "varia": "bin/cli.js"
6
6
  },