react-native-varia 0.2.4 → 0.4.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 (43) hide show
  1. package/lib/components/Accordion.tsx +61 -21
  2. package/lib/components/Badge.tsx +9 -0
  3. package/lib/components/Button.tsx +21 -6
  4. package/lib/components/Checkbox.tsx +22 -8
  5. package/lib/components/CircleProgress.tsx +8 -0
  6. package/lib/components/Divider.tsx +11 -4
  7. package/lib/components/Drawer.tsx +34 -25
  8. package/lib/components/Field.tsx +4 -0
  9. package/lib/components/GradientBackground.tsx +3 -0
  10. package/lib/components/GradientText.tsx +37 -11
  11. package/lib/components/IconWrapper.tsx +3 -2
  12. package/lib/components/Input.tsx +47 -20
  13. package/lib/components/Link.tsx +4 -0
  14. package/lib/components/Modal.tsx +21 -14
  15. package/lib/components/NumberInput.tsx +27 -5
  16. package/lib/components/RadioGroup.tsx +19 -6
  17. package/lib/components/ReText.tsx +4 -1
  18. package/lib/components/Select.tsx +20 -0
  19. package/lib/components/Slider.tsx +244 -134
  20. package/lib/components/Slideshow.tsx +19 -3
  21. package/lib/components/Spinner.tsx +12 -2
  22. package/lib/components/Switch.tsx +57 -26
  23. package/lib/components/Text.tsx +3 -0
  24. package/lib/components/Toast.tsx +110 -36
  25. package/lib/patterns/index.tsx +299 -79
  26. package/lib/theme/Accordion.tsx +184 -0
  27. package/lib/theme/Button.recipe.tsx +24 -7
  28. package/lib/theme/{SlidingDrawer.recipe.tsx → Drawer.recipe.tsx} +4 -6
  29. package/lib/theme/Field.recipe.tsx +45 -15
  30. package/lib/theme/GradientText.recipe.tsx +103 -34
  31. package/lib/theme/Input.recipe.tsx +14 -6
  32. package/lib/theme/Select.recipe.tsx +3 -0
  33. package/lib/theme/Slider.recipe.tsx +108 -141
  34. package/lib/theme/Spinner.recipe.tsx +4 -0
  35. package/lib/theme/Switch.recipe.tsx +19 -0
  36. package/lib/theme/Text.recipe.tsx +63 -12
  37. package/lib/theme/Toast.recipe.tsx +40 -7
  38. package/lib/varia/mixins.ts +0 -4
  39. package/lib/varia/types.ts +11 -0
  40. package/lib/varia/utils.ts +172 -14
  41. package/package.json +1 -1
  42. package/lib/components/OldSlider.tsx +0 -327
  43. package/lib/components/SlidingDrawer.tsx +0 -301
@@ -14,7 +14,6 @@ import {
14
14
  NestedColorsType,
15
15
  PalettesWithNestedKeys,
16
16
  ThemeColors,
17
- ThemeType,
18
17
  } from '../style/varia/types'
19
18
  import {resolveColor} from '../style/varia/utils'
20
19
 
@@ -107,7 +106,9 @@ const styles = StyleSheet.create({
107
106
  justifyContent: 'center',
108
107
  alignItems: 'center',
109
108
  ...(rotation && {transform: [{rotate: `${rotation}deg`}]}),
110
- // transform: rotation ? [{rotate: `${rotation}deg`}] : [],
109
+ _web: {
110
+ _classNames: 'icon_wrapper-root-base',
111
+ },
111
112
  }),
112
113
  })
113
114
 
@@ -19,6 +19,7 @@ import {
19
19
  } from '../style/varia/types'
20
20
  import {useState} from 'react'
21
21
  import {IconWrapperProps} from './IconWrapper'
22
+ import {getVariantValue} from '../style/varia/utils'
22
23
 
23
24
  type InputVariants = UnistylesVariants<typeof InputStyles>
24
25
 
@@ -89,17 +90,22 @@ const Input = ({
89
90
  disabled,
90
91
  invalid,
91
92
  })
92
- const iconPosition = icon ? !icon.position && 'left' : null
93
+ const iconPosition = icon ? icon.position || 'left' : null
93
94
 
94
- const placeholderStyle = InputStyles.placeholder(colorPalette) as {
95
- color: string
96
- }
97
- const placeholderColor = placeholderStyle.color
95
+ const resolvedPlaceholderColor = getVariantValue(
96
+ InputStyles.placeholder(colorPalette),
97
+ 'variant',
98
+ variant,
99
+ 'color',
100
+ )
98
101
 
99
- const inputResolvedVariantStyle = InputStyles.input(colorPalette) as {
100
- paddingHorizontal?: number
101
- }
102
- const paddingHorizontal = inputResolvedVariantStyle.paddingHorizontal ?? 0
102
+ const resolvedPaddingHorizontal =
103
+ getVariantValue(
104
+ InputStyles.input(colorPalette),
105
+ 'size',
106
+ size,
107
+ 'paddingHorizontal',
108
+ ) || 0
103
109
 
104
110
  const IconComponent = icon?.component
105
111
  const IconRendered = IconComponent ? (
@@ -110,16 +116,16 @@ const Input = ({
110
116
  colorPalette,
111
117
  size: icon.size,
112
118
  color: InputStyles.input(colorPalette).color,
113
- style: styles.icon(iconPosition, paddingHorizontal, textAlignVertical),
119
+ style: styles.icon(
120
+ iconPosition,
121
+ resolvedPaddingHorizontal,
122
+ textAlignVertical,
123
+ ),
114
124
  }}
115
125
  />
116
126
  ) : null
117
127
 
118
- console.log(
119
- iconPosition === 'left'
120
- ? (icon?.size || 0) + paddingHorizontal * 2
121
- : paddingHorizontal,
122
- )
128
+ const withIconPadding = (icon?.size || 0) + resolvedPaddingHorizontal * 2
123
129
 
124
130
  return (
125
131
  <View
@@ -132,18 +138,29 @@ const Input = ({
132
138
  flex,
133
139
  maxWidth,
134
140
  iconPosition,
135
- paddingHorizontal,
141
+ resolvedPaddingHorizontal,
136
142
  textAlignVertical,
137
- (icon?.size || 0) + paddingHorizontal * 2,
143
+ (icon?.size || 0) + resolvedPaddingHorizontal * 2,
138
144
  alignSelf,
139
145
  ),
140
146
  InputStyles.input(colorPalette),
141
147
  inputMixins && inputMixins,
142
148
  style && style,
149
+ iconPosition && {
150
+ paddingInline: 0,
151
+ paddingLeft:
152
+ iconPosition === 'left'
153
+ ? withIconPadding - 0.1
154
+ : resolvedPaddingHorizontal,
155
+ paddingRight:
156
+ iconPosition === 'right'
157
+ ? withIconPadding - 0.1
158
+ : resolvedPaddingHorizontal,
159
+ },
143
160
  ]}
144
161
  value={value}
145
162
  placeholder={placeholder}
146
- placeholderTextColor={placeholderColor}
163
+ placeholderTextColor={resolvedPlaceholderColor}
147
164
  inputMode={inputMode}
148
165
  keyboardType={keyboardType}
149
166
  secureTextEntry={password}
@@ -174,6 +191,10 @@ const styles = StyleSheet.create({
174
191
  : textAlignVertical === 'bottom'
175
192
  ? 'flex-end'
176
193
  : 'flex-start',
194
+ flexBasis: 'auto',
195
+ _web: {
196
+ _classNames: 'input-container-base',
197
+ },
177
198
  }),
178
199
  input: (
179
200
  flex,
@@ -185,11 +206,14 @@ const styles = StyleSheet.create({
185
206
  alignSelf,
186
207
  ) => ({
187
208
  flex,
188
- paddingLeft: iconPosition === 'left' ? padding : paddingHorizontal,
189
- paddingRight: iconPosition === 'right' ? padding : paddingHorizontal,
190
209
  textAlignVertical,
191
210
  maxWidth,
192
211
  alignSelf,
212
+ outline: 'none',
213
+ flexBasis: 'auto',
214
+ _web: {
215
+ _classNames: 'input-base',
216
+ },
193
217
  }),
194
218
  icon: (iconPosition, paddingHorizontal, textAlignVertical) => ({
195
219
  position: 'absolute',
@@ -197,6 +221,9 @@ const styles = StyleSheet.create({
197
221
  ...(iconPosition === 'right' && {right: paddingHorizontal}),
198
222
  top: textAlignVertical !== 'top' ? 'auto' : 10,
199
223
  bottom: textAlignVertical !== 'bottom' ? 'auto' : 10,
224
+ _web: {
225
+ _classNames: 'input-icon-base',
226
+ },
200
227
  }),
201
228
  })
202
229
 
@@ -37,6 +37,7 @@ const Link = ({
37
37
  color,
38
38
  mixins,
39
39
  }: LinkProps) => {
40
+ console.log(color)
40
41
  return (
41
42
  <TouchableOpacity
42
43
  onPress={async () => {
@@ -67,6 +68,9 @@ const Link = ({
67
68
  const styles = StyleSheet.create({
68
69
  link: (underline): any => ({
69
70
  textDecorationLine: underline,
71
+ _web: {
72
+ _classNames: 'link-base',
73
+ },
70
74
  }),
71
75
  })
72
76
 
@@ -13,6 +13,7 @@ import Text from './Text'
13
13
  import {ModalStyles, ModalTokens} from '../theme/Modal.recipe'
14
14
  import {PalettesWithNestedKeys} from '../style/varia/types'
15
15
 
16
+ const AnimatedView = Animated.createAnimatedComponent(View)
16
17
  type ModalVariants = UnistylesVariants<typeof ModalStyles>
17
18
  type AnimationKey = keyof typeof ModalTokens.animations.variants
18
19
  type ColorPaletteKey = PalettesWithNestedKeys
@@ -89,15 +90,15 @@ const ModalOverlay = ({children, ...props}: ModalOverlayProps) => {
89
90
  ModalStyles.useVariants({variant})
90
91
 
91
92
  return (
92
- <Animated.View
93
+ <AnimatedView
93
94
  style={[styles.overlay, ModalStyles.overlay(colorPalette)]}
94
95
  entering={ModalTokens.animations.variants[animation]?.enteringOverlay}
95
96
  exiting={ModalTokens.animations.variants[animation]?.exitingOverlay}>
96
97
  <TouchableWithoutFeedback onPress={() => setIsOpen(false)}>
97
- <View style={RNStyleSheet.absoluteFillObject} />
98
+ <View style={StyleSheet.absoluteFillObject} />
98
99
  </TouchableWithoutFeedback>
99
100
  {children}
100
- </Animated.View>
101
+ </AnimatedView>
101
102
  )
102
103
  }
103
104
 
@@ -123,12 +124,12 @@ const ModalContent = ({children, ...props}: ModalContentProps) => {
123
124
  ModalStyles.useVariants({variant})
124
125
 
125
126
  return (
126
- <Animated.View
127
+ <AnimatedView
127
128
  style={[styles.content(), ModalStyles.content(colorPalette)]}
128
129
  entering={ModalTokens.animations.variants[animation]?.enteringContent}
129
130
  exiting={ModalTokens.animations.variants[animation]?.exitingContent}>
130
131
  {children}
131
- </Animated.View>
132
+ </AnimatedView>
132
133
  )
133
134
  }
134
135
 
@@ -151,14 +152,7 @@ type ModalBodyProps = Omit<ModalVariants, 'variant'> & {
151
152
  customStyle?: any
152
153
  }
153
154
 
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})
155
+ const ModalBody = ({children}: ModalBodyProps) => {
162
156
  return <View>{children}</View>
163
157
  }
164
158
 
@@ -224,11 +218,17 @@ const styles = StyleSheet.create(theme => {
224
218
  zIndex: 1000,
225
219
  justifyContent: 'center',
226
220
  alignItems: 'center',
221
+ _web: {
222
+ _classNames: 'modal-overlay-base',
223
+ },
227
224
  },
228
225
  content: () => ({
229
226
  justifyContent: 'center',
230
227
  alignItems: 'center',
231
228
  alignSelf: 'stretch',
229
+ _web: {
230
+ _classNames: 'modal-content-base',
231
+ },
232
232
  }),
233
233
  header: {
234
234
  flexDirection: 'row',
@@ -236,14 +236,20 @@ const styles = StyleSheet.create(theme => {
236
236
  alignItems: 'center',
237
237
  width: '100%',
238
238
  marginBottom: 10,
239
+ _web: {
240
+ _classNames: 'modal-header-base',
241
+ },
239
242
  },
240
243
  closeButton: {
241
244
  color: 'white',
245
+ _web: {
246
+ _classNames: 'modal-close-button-base',
247
+ },
242
248
  },
243
249
  }
244
250
  })
245
251
 
246
- export const Modal = Object.assign(ModalRoot, {
252
+ const Modal = Object.assign(ModalRoot, {
247
253
  Root: ModalRoot,
248
254
  Overlay: ModalOverlay,
249
255
  Content: ModalContent,
@@ -253,3 +259,4 @@ export const Modal = Object.assign(ModalRoot, {
253
259
  CloseTrigger: ModalCloseTrigger,
254
260
  CloseButton: CloseButton,
255
261
  })
262
+ export default Modal
@@ -12,7 +12,7 @@ import {
12
12
  } from '../style/varia/types'
13
13
  import Plus from '../icons/Plus'
14
14
  import Minus from '../icons/Minus'
15
- import {computeFlexSync} from '../style/varia/utils'
15
+ import {computeFlexSync, getVariantValue} from '../style/varia/utils'
16
16
 
17
17
  type NumberInputVariants = UnistylesVariants<typeof NumberInputStyles>
18
18
 
@@ -204,8 +204,14 @@ const NumberInput = {
204
204
  } = {...useSimpleNumberInputContext(), ...props}
205
205
  NumberInputStyles.useVariants({variant, size, distribution})
206
206
 
207
- const color = (NumberInputStyles.buttons(colorPalette) as {color: string})
208
- .color
207
+ // const color = (NumberInputStyles.buttons(colorPalette) as {color: string})
208
+ // .color
209
+ const color = getVariantValue(
210
+ NumberInputStyles.buttons(colorPalette),
211
+ 'variant',
212
+ variant,
213
+ 'color',
214
+ )
209
215
 
210
216
  const iconElement = children || <IncreaseTriggerIcon />
211
217
  const iconWithProps = React.isValidElement<IconProps>(iconElement)
@@ -241,8 +247,14 @@ const NumberInput = {
241
247
  } = {...useSimpleNumberInputContext(), ...props}
242
248
  NumberInputStyles.useVariants({variant, size, distribution})
243
249
 
244
- const color = (NumberInputStyles.buttons(colorPalette) as {color: string})
245
- .color
250
+ // const color = (NumberInputStyles.buttons(colorPalette) as {color: string})
251
+ // .color
252
+ const color = getVariantValue(
253
+ NumberInputStyles.buttons(colorPalette),
254
+ 'variant',
255
+ variant,
256
+ 'color',
257
+ )
246
258
 
247
259
  const iconElement = children || <DecreaseTriggerIcon />
248
260
  const iconWithProps = React.isValidElement<IconProps>(iconElement)
@@ -282,13 +294,23 @@ const simpleNumberInputstyles = StyleSheet.create({
282
294
  flex,
283
295
  alignSelf,
284
296
  alignItems: 'stretch',
297
+ flexBasis: 'auto',
298
+ _web: {
299
+ _classNames: 'number-input-root-base',
300
+ },
285
301
  }),
286
302
  input: (flex: number) => ({
287
303
  paddingVertical: 0,
288
304
  flex,
305
+ _web: {
306
+ _classNames: 'number-input-base',
307
+ },
289
308
  }),
290
309
  button: {
291
310
  justifyContent: 'center',
292
311
  alignItems: 'center',
312
+ _web: {
313
+ _classNames: 'number-input-button-base',
314
+ },
293
315
  },
294
316
  })
@@ -6,7 +6,11 @@ import {
6
6
  RadioGroupDefaultVariants,
7
7
  } from '../theme/RadioGroup.recipe'
8
8
  import {
9
+ AlignItems,
9
10
  AlignSelf,
11
+ Flex,
12
+ Gap,
13
+ JustifyContent,
10
14
  PalettesWithNestedKeys,
11
15
  StackDirection,
12
16
  } from '../style/varia/types'
@@ -21,9 +25,9 @@ type RadioGroupRootProps = RadioGroupVariants & {
21
25
  direction?: StackDirection
22
26
  flex?: number
23
27
  alignSelf?: AlignSelf
24
- justifyContent?: string
25
- alignItems?: string
26
- gap?: number
28
+ justifyContent?: JustifyContent
29
+ alignItems?: AlignItems
30
+ gap?: Gap
27
31
  }
28
32
 
29
33
  type RadioGroupContextProps = {
@@ -32,7 +36,7 @@ type RadioGroupContextProps = {
32
36
  colorPalette: PalettesWithNestedKeys
33
37
  variant: RadioGroupVariants['variant']
34
38
  size: RadioGroupVariants['size']
35
- flex: number
39
+ flex: Flex
36
40
  alignSelf?: AlignSelf
37
41
  }
38
42
 
@@ -58,7 +62,7 @@ function Root({
58
62
  flex = 0,
59
63
  alignSelf = 'auto',
60
64
  direction = 'column',
61
- justifyContent,
65
+ justifyContent = 'space-between',
62
66
  alignItems,
63
67
  gap,
64
68
  }: RadioGroupRootProps) {
@@ -218,16 +222,25 @@ const styles = StyleSheet.create({
218
222
  alignItems,
219
223
  gap,
220
224
  justifyContent,
225
+ flexBasis: 'auto',
226
+ _web: {
227
+ _classNames: 'radio-root',
228
+ },
221
229
  }),
222
230
  item: {
223
231
  flexDirection: 'row',
224
232
  alignItems: 'center',
233
+ _web: {
234
+ _classNames: 'radio-item',
235
+ },
225
236
  },
226
237
  })
227
238
 
228
- export const RadioGroup = {
239
+ const RadioGroup = {
229
240
  Root,
230
241
  Item,
231
242
  Indicator,
232
243
  ItemText,
233
244
  }
245
+
246
+ export default RadioGroup
@@ -52,7 +52,7 @@ const ReText = ({
52
52
  return {
53
53
  text: text.value,
54
54
  } as TextInputProps
55
- })
55
+ }, [text])
56
56
  return (
57
57
  <AnimatedTextInput
58
58
  underlineColorAndroid="transparent"
@@ -81,6 +81,9 @@ const styles = StyleSheet.create(theme => ({
81
81
  }),
82
82
  ...(fontSize && {fontSize}),
83
83
  textAlign: 'left',
84
+ _web: {
85
+ _classNames: 'retext-text-base',
86
+ },
84
87
  }),
85
88
  customStyle: style => ({
86
89
  ...style,
@@ -277,24 +277,41 @@ const styles = StyleSheet.create({
277
277
  justifyContent: 'center',
278
278
  ...(stretch ? {alignSelf: stretch} : {}),
279
279
  alignItems: 'stretch',
280
+ flexBasis: 'auto',
281
+ _web: {
282
+ _classNames: 'select-container-base',
283
+ },
280
284
  }),
281
285
  input: (flex: Flex) => ({
282
286
  flex,
283
287
  flexDirection: 'row',
284
288
  alignItems: 'center',
285
289
  justifyContent: 'center',
290
+ flexBasis: 'auto',
291
+ _web: {
292
+ _classNames: 'select-input-base',
293
+ },
286
294
  }),
287
295
  item: {
288
296
  alignItems: 'center',
289
297
  flexDirection: 'row',
298
+ _web: {
299
+ _classNames: 'select-item-base',
300
+ },
290
301
  },
291
302
  backdrop: {
292
303
  ...StyleSheet.absoluteFillObject,
293
304
  backgroundColor: 'rgba(0,0,0,0.3)',
305
+ _web: {
306
+ _classNames: 'select-backdrop-base',
307
+ },
294
308
  },
295
309
  modalContent: {
296
310
  overflow: 'hidden',
297
311
  alignSelf: 'stretch',
312
+ _web: {
313
+ _classNames: 'select-modal-content-base',
314
+ },
298
315
  },
299
316
  portalContainer: {
300
317
  position: 'absolute',
@@ -304,5 +321,8 @@ const styles = StyleSheet.create({
304
321
  bottom: 0,
305
322
  justifyContent: 'center',
306
323
  alignItems: 'center',
324
+ _web: {
325
+ _classNames: 'select-portal-container-base',
326
+ },
307
327
  },
308
328
  })