react-native-varia 0.2.4 → 0.3.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.
@@ -5,6 +5,7 @@ import {useMemo} from 'react'
5
5
  import {IconWrapperProps} from './IconWrapper'
6
6
  import Spinner, {SpinnerProps} from './Spinner'
7
7
  import {PalettesWithNestedKeys} from '../style/varia/types'
8
+ import { getVariantValue } from '../style/varia/utils'
8
9
 
9
10
  type TextAdjustment = 'singleLine' | 'multiline' | 'adjustToFit'
10
11
 
@@ -56,6 +57,7 @@ const Button = ({
56
57
  variant,
57
58
  disabled,
58
59
  })
60
+ console.log("🚀 ~ size:", size)
59
61
 
60
62
  const getTextProps = useMemo(
61
63
  () => (): TextAdjustmentProps => {
@@ -76,6 +78,8 @@ const Button = ({
76
78
  [textAdjustment],
77
79
  )
78
80
 
81
+ const resolvedColor = getVariantValue(ButtonStyles.text(colorPalette), 'variant', variant, 'color')
82
+
79
83
  const IconComponent = icon?.component
80
84
  const IconRendered = IconComponent ? (
81
85
  <IconComponent
@@ -84,7 +88,7 @@ const Button = ({
84
88
  scale: icon.scale,
85
89
  colorPalette,
86
90
  size: icon.size,
87
- color: ButtonStyles.text(colorPalette).color,
91
+ color: resolvedColor,
88
92
  }}
89
93
  />
90
94
  ) : null
@@ -102,7 +106,7 @@ const Button = ({
102
106
  {loading ? (
103
107
  <Spinner
104
108
  size={size as SpinnerProps['size']}
105
- color={ButtonStyles.text(colorPalette).color}
109
+ color={resolvedColor}
106
110
  />
107
111
  ) : (
108
112
  <>
@@ -4,6 +4,7 @@ import {UnistylesVariants} from 'react-native-unistyles'
4
4
  import {CheckboxDefaultVariants, CheckboxStyles} from '../theme/Checkbox.recipe'
5
5
  import {PalettesWithNestedKeys} from '../style/varia/types'
6
6
  import Svg, {Line} from 'react-native-svg'
7
+ import { getVariantValue } from '../style/varia/utils'
7
8
 
8
9
  type CheckboxVariants = UnistylesVariants<typeof CheckboxStyles>
9
10
 
@@ -31,12 +32,16 @@ function Checkbox({
31
32
 
32
33
  const isChecked = checked
33
34
 
34
- const checkStyle = CheckboxStyles.check(colorPalette) as {
35
- width: string
36
- color: string
37
- }
38
- const checkSize = checkStyle.width
39
- const checkColor = checkStyle.color
35
+ // const checkStyle = CheckboxStyles.check(colorPalette) as {
36
+ // width: string
37
+ // color: string
38
+ // }
39
+ // const checkSize = checkStyle.width
40
+ // const checkColor = checkStyle.color
41
+
42
+ const checkColor = getVariantValue(CheckboxStyles.check(colorPalette), 'variant', variant, 'color')
43
+ const checkSize = getVariantValue(CheckboxStyles.check(colorPalette), 'size', size, 'width')
44
+
40
45
 
41
46
  return (
42
47
  <Pressable
@@ -65,7 +70,7 @@ const styles = StyleSheet.create({
65
70
  },
66
71
  })
67
72
 
68
- export {Checkbox}
73
+ export default Checkbox
69
74
 
70
75
  const Check = ({size, color}: {size: string; color: string}) => {
71
76
  return (
@@ -26,17 +26,18 @@ const Divider = ({
26
26
  const styles = StyleSheet.create(theme => ({
27
27
  container: (size, axis, margin) => ({
28
28
  flex: 1,
29
+ alignSelf: 'stretch',
29
30
  flexDirection: 'row',
30
31
  alignItems: 'center',
31
32
  justifyContent: 'center',
32
- maxHeight: axis === 'y' ? size : '100%',
33
- maxWidth: axis === 'x' ? size : '100%',
33
+ maxWidth: axis === 'y' ? size : '100%',
34
+ maxHeight: axis === 'x' ? size : '100%',
34
35
  marginHorizontal: axis === 'x' ? margin : 0,
35
36
  marginVertical: axis === 'y' ? margin : 0,
36
37
  }),
37
38
  divider: (color, colorPalette, size, axis) => ({
38
- width: axis === 'x' ? size : '100%',
39
- height: axis === 'y' ? size : '100%',
39
+ width: axis === 'y' ? size : '100%',
40
+ height: axis === 'x' ? size : '100%',
40
41
  backgroundColor: color
41
42
  ? resolveColor(color, theme.colors, colorPalette)
42
43
  : theme.colors.fg.default,
@@ -16,11 +16,8 @@ import Animated, {
16
16
  withSpring,
17
17
  withTiming,
18
18
  } from 'react-native-reanimated'
19
- import {runOnUI, scheduleOnRN, scheduleOnUI} from 'react-native-worklets'
20
- import {
21
- SlidingDrawerTokens,
22
- SlidingDrawerStyles,
23
- } from '../theme/SlidingDrawer.recipe'
19
+ import {scheduleOnRN, scheduleOnUI} from 'react-native-worklets'
20
+ import {DrawerTokens, DrawerStyles} from '../theme/Drawer.recipe'
24
21
  import {PalettesWithNestedKeys} from '../style/varia/types'
25
22
  import {
26
23
  StyleSheet,
@@ -33,21 +30,21 @@ import {HStack} from '../patterns'
33
30
  * Types
34
31
  * ----------------------------*/
35
32
 
36
- export type SlidingDrawerRef = {
33
+ export type DrawerRef = {
37
34
  expand: () => void | null
38
35
  collapse: () => void | null
39
36
  snapTo: (point: number) => void | null
40
37
  isCollapsed: () => boolean
41
38
  }
42
39
 
43
- type SlidingDrawerVariants = UnistylesVariants<typeof SlidingDrawerStyles>
40
+ type DrawerVariants = UnistylesVariants<typeof DrawerStyles>
44
41
 
45
- type DrawerContextType = SlidingDrawerVariants & {
42
+ type DrawerContextType = DrawerVariants & {
46
43
  colorPalette: PalettesWithNestedKeys
47
44
  overlayOpacity: SharedValue<number>
48
45
  }
49
46
 
50
- type DrawerRootProps = SlidingDrawerVariants & {
47
+ type DrawerRootProps = DrawerVariants & {
51
48
  colorPalette?: PalettesWithNestedKeys
52
49
  children?: React.ReactNode
53
50
  }
@@ -70,10 +67,10 @@ const useDrawer = () => {
70
67
 
71
68
  const DrawerRoot = ({
72
69
  colorPalette = 'accent',
73
- variant = SlidingDrawerTokens.defaultProps.variant,
70
+ variant = DrawerTokens.defaultProps.variant,
74
71
  children,
75
72
  }: DrawerRootProps) => {
76
- SlidingDrawerStyles.useVariants({variant})
73
+ DrawerStyles.useVariants({variant})
77
74
 
78
75
  const overlayOpacity = useSharedValue(0)
79
76
  const value = useMemo(
@@ -103,7 +100,7 @@ const DrawerPositioner = ({
103
100
  axis: 'x' | 'y'
104
101
  }) => {
105
102
  const {variant} = useDrawer()
106
- SlidingDrawerStyles.useVariants({variant})
103
+ DrawerStyles.useVariants({variant})
107
104
 
108
105
  type WithDirection = {direction?: 1 | -1; axis?: 'x' | 'y'}
109
106
 
@@ -121,7 +118,7 @@ const DrawerPositioner = ({
121
118
  <HStack
122
119
  style={[
123
120
  styles.positioner,
124
- SlidingDrawerStyles.positioner,
121
+ DrawerStyles.positioner,
125
122
  {
126
123
  justifyContent:
127
124
  axis === 'y'
@@ -151,7 +148,7 @@ const AnimatedTouchable = Animated.createAnimatedComponent(
151
148
 
152
149
  const DrawerOverlay = ({onPress}: {onPress?: () => void}) => {
153
150
  const {colorPalette, overlayOpacity, variant} = useDrawer()
154
- SlidingDrawerStyles.useVariants({variant})
151
+ DrawerStyles.useVariants({variant})
155
152
  const visible = useSharedValue(0)
156
153
 
157
154
  useAnimatedReaction(
@@ -176,7 +173,7 @@ const DrawerOverlay = ({onPress}: {onPress?: () => void}) => {
176
173
  style={[
177
174
  StyleSheet.absoluteFillObject,
178
175
  displayOverlayStyle,
179
- SlidingDrawerStyles.overlay(colorPalette),
176
+ DrawerStyles.overlay(colorPalette),
180
177
  ]}
181
178
  />
182
179
  </AnimatedTouchable>
@@ -192,13 +189,13 @@ type InternalDrawerSliderProps = {
192
189
  direction: 1 | -1
193
190
  lockAtEdges?: boolean
194
191
  snapPoints?: number[] | ('hidden' | 'content')[]
195
- animation?: keyof typeof SlidingDrawerTokens.variants.animation
192
+ animation?: keyof typeof DrawerTokens.variants.animation
196
193
  onExpand?: () => void
197
194
  onCollapse?: () => void
198
195
  onSnap?: (point: number) => void
199
196
  allowGestures?: boolean
200
197
  children?: React.ReactNode
201
- ref?: React.RefObject<SlidingDrawerRef | null>
198
+ ref?: React.RefObject<DrawerRef | null>
202
199
  externalTranslate?: SharedValue<number>
203
200
  }
204
201
 
@@ -216,7 +213,7 @@ const DrawerSliderInternal = ({
216
213
  direction,
217
214
  lockAtEdges = false,
218
215
  snapPoints = ['hidden', 'content'],
219
- animation = SlidingDrawerTokens.defaultProps.animation,
216
+ animation = DrawerTokens.defaultProps.animation,
220
217
  onExpand,
221
218
  onCollapse,
222
219
  onSnap,
@@ -227,14 +224,14 @@ const DrawerSliderInternal = ({
227
224
  }: InternalDrawerSliderProps) => {
228
225
  const {variant, colorPalette, overlayOpacity} = useDrawer()
229
226
 
230
- SlidingDrawerStyles.useVariants({variant})
227
+ DrawerStyles.useVariants({variant})
231
228
 
232
229
  const screenHeight =
233
230
  UnistylesRuntime.screen.height - UnistylesRuntime.insets.top
234
231
  const screenWidth = UnistylesRuntime.screen.width
235
232
 
236
233
  const animations = {withSpring, withTiming}
237
- const animationVariant = SlidingDrawerTokens.variants.animation[animation]
234
+ const animationVariant = DrawerTokens.variants.animation[animation]
238
235
  const VELOCITY_THRESHOLD = 2000
239
236
 
240
237
  const viewRef = useAnimatedRef<Animated.View>()
@@ -461,7 +458,7 @@ const DrawerSliderInternal = ({
461
458
  style={[
462
459
  styles.slider,
463
460
  blockAnimatedStyle,
464
- SlidingDrawerStyles.slider(colorPalette),
461
+ DrawerStyles.slider(colorPalette),
465
462
  ]}>
466
463
  {children}
467
464
  </Animated.View>
@@ -6,17 +6,21 @@ import Svg, {
6
6
  Text,
7
7
  type NumberProp,
8
8
  } from 'react-native-svg'
9
- import {withUnistyles} from 'react-native-unistyles'
9
+ import {UnistylesVariants, withUnistyles} from 'react-native-unistyles'
10
10
  import {gradientTextTokens} from '../theme/GradientText.recipe'
11
11
  import {
12
12
  NestedColorsType,
13
13
  PalettesWithNestedKeys,
14
14
  ThemeType,
15
15
  } from '../style/varia/types'
16
- import {resolveColor, resolveFontSize} from '../style/varia/utils'
16
+ import {getVariantValue, resolveColor, resolveFontSize} from '../style/varia/utils'
17
17
  import {ThemeColors} from '../style/varia/types'
18
+ import { TextStyles } from '../theme/Text.recipe'
18
19
 
19
- interface GradientTextProps {
20
+ type AllTextVariants = UnistylesVariants<typeof TextStyles>
21
+ type TextVariantsWithoutVariant = Omit<AllTextVariants, "variant">;
22
+
23
+ type GradientTextProps = TextVariantsWithoutVariant & {
20
24
  colorPalette: PalettesWithNestedKeys
21
25
  variant?: keyof typeof gradientTextTokens.variants.variant
22
26
  direction?: keyof typeof gradientTextTokens.variants.direction
@@ -26,7 +30,7 @@ interface GradientTextProps {
26
30
  fontSizes: ThemeType['fontSizes']
27
31
  fontSize?: TextStyle['fontSize']
28
32
  children?: React.ReactNode
29
- size?: keyof typeof gradientTextTokens.variants.size
33
+ // size?: keyof typeof gradientTextTokens.variants.size
30
34
  }
31
35
 
32
36
  const BaseGradientText = ({
@@ -41,6 +45,10 @@ const BaseGradientText = ({
41
45
  children,
42
46
  size = gradientTextTokens.defaultProps.size,
43
47
  }: GradientTextProps) => {
48
+ TextStyles.useVariants({
49
+ size
50
+ })
51
+
44
52
  const colorValue = gradientTextTokens.variants.variant[variant]
45
53
 
46
54
  const resolvedStartColor = resolveColor(
@@ -54,8 +62,12 @@ const BaseGradientText = ({
54
62
  colorPalette,
55
63
  )
56
64
 
57
- const fontSizeValue = gradientTextTokens.variants.size[size].fontSize
58
- const resolvedFontSize = fontSize || resolveFontSize(fontSizeValue, fontSizes)
65
+ // const fontSizeValue = gradientTextTokens.variants.size[size].fontSize
66
+ // const resolvedFontSize = fontSize || resolveFontSize(fontSizeValue, fontSizes)
67
+
68
+ const resolvedFontSize = fontSize || getVariantValue(TextStyles.text(colorPalette), 'size', size, 'fontSize')
69
+ const resolvedFontWeight = getVariantValue(TextStyles.text(colorPalette), 'size', size, 'fontWeight') || 400
70
+
59
71
 
60
72
  const directionVariant = gradientTextTokens.variants.direction[direction]
61
73
 
@@ -77,10 +89,11 @@ const BaseGradientText = ({
77
89
  <Text
78
90
  fill="url(#gradient)"
79
91
  fontSize={resolvedFontSize}
80
- fontWeight={
81
- (gradientTextTokens.variants.size[size] as {fontWeight?: number})
82
- .fontWeight ?? 400
83
- }
92
+ // fontWeight={
93
+ // (gradientTextTokens.variants.size[size] as {fontWeight?: number})
94
+ // .fontWeight ?? 400
95
+ // }
96
+ fontWeight={resolvedFontWeight}
84
97
  x="50%"
85
98
  y={resolvedFontSize}
86
99
  textAnchor="middle">
@@ -190,6 +190,7 @@ const styles = StyleSheet.create({
190
190
  textAlignVertical,
191
191
  maxWidth,
192
192
  alignSelf,
193
+ outline: 'none'
193
194
  }),
194
195
  icon: (iconPosition, paddingHorizontal, textAlignVertical) => ({
195
196
  position: 'absolute',
@@ -94,7 +94,7 @@ const ModalOverlay = ({children, ...props}: ModalOverlayProps) => {
94
94
  entering={ModalTokens.animations.variants[animation]?.enteringOverlay}
95
95
  exiting={ModalTokens.animations.variants[animation]?.exitingOverlay}>
96
96
  <TouchableWithoutFeedback onPress={() => setIsOpen(false)}>
97
- <View style={RNStyleSheet.absoluteFillObject} />
97
+ <View style={StyleSheet.absoluteFillObject} />
98
98
  </TouchableWithoutFeedback>
99
99
  {children}
100
100
  </Animated.View>
@@ -151,14 +151,7 @@ type ModalBodyProps = Omit<ModalVariants, 'variant'> & {
151
151
  customStyle?: any
152
152
  }
153
153
 
154
- const ModalBody = ({children, ...props}: ModalBodyProps) => {
155
- const context = useModalContext()
156
- const {colorPalette = 'accent', variant} = {
157
- ...context,
158
- ...props,
159
- }
160
-
161
- ModalStyles.useVariants({variant})
154
+ const ModalBody = ({children}: ModalBodyProps) => {
162
155
  return <View>{children}</View>
163
156
  }
164
157
 
@@ -243,7 +236,7 @@ const styles = StyleSheet.create(theme => {
243
236
  }
244
237
  })
245
238
 
246
- export const Modal = Object.assign(ModalRoot, {
239
+ const Modal = Object.assign(ModalRoot, {
247
240
  Root: ModalRoot,
248
241
  Overlay: ModalOverlay,
249
242
  Content: ModalContent,
@@ -253,3 +246,4 @@ export const Modal = Object.assign(ModalRoot, {
253
246
  CloseTrigger: ModalCloseTrigger,
254
247
  CloseButton: CloseButton,
255
248
  })
249
+ export default Modal
@@ -225,9 +225,11 @@ const styles = StyleSheet.create({
225
225
  },
226
226
  })
227
227
 
228
- export const RadioGroup = {
228
+ const RadioGroup = {
229
229
  Root,
230
230
  Item,
231
231
  Indicator,
232
232
  ItemText,
233
233
  }
234
+
235
+ export default RadioGroup