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
@@ -0,0 +1,137 @@
1
+ import React, {createContext, useContext} from 'react'
2
+ import Text from './Text'
3
+ import {VStack} from '../patterns'
4
+ import {DefaultFieldVariants, FieldStyles} from '../theme/Field.recipe'
5
+ import {UnistylesVariants} from 'react-native-unistyles'
6
+ import {PalettesWithNestedKeys} from '../style/varia/types'
7
+
8
+ type FieldVariants = UnistylesVariants<typeof FieldStyles>
9
+
10
+ type FieldContextType = {
11
+ error?: string
12
+ variant?: FieldVariants['variant']
13
+ size?: FieldVariants['size']
14
+ colorPalette?: PalettesWithNestedKeys
15
+ }
16
+
17
+ const FieldContext = createContext<FieldContextType | undefined>(undefined)
18
+
19
+ function useField() {
20
+ const context = useContext(FieldContext)
21
+ if (!context) {
22
+ throw new Error(
23
+ 'Field subcomponents (Label, Error) must be used inside Field.Root',
24
+ )
25
+ }
26
+ return context
27
+ }
28
+
29
+ type FieldRootProps = FieldVariants & {
30
+ children: React.ReactNode
31
+ error?: string
32
+ colorPalette?: PalettesWithNestedKeys
33
+ flex?: number
34
+ }
35
+
36
+ const FieldRoot = ({
37
+ children,
38
+ error,
39
+ variant = DefaultFieldVariants.variant,
40
+ size = DefaultFieldVariants.size,
41
+ colorPalette = 'accent',
42
+ flex = 1,
43
+ }: FieldRootProps) => {
44
+ FieldStyles.useVariants({size})
45
+
46
+ const contextValue: FieldContextType = {
47
+ error,
48
+ variant,
49
+ size,
50
+ colorPalette,
51
+ }
52
+
53
+ FieldStyles.useVariants({variant, size})
54
+
55
+ return (
56
+ <VStack
57
+ style={[
58
+ {
59
+ flexShrink: 1,
60
+ flexGrow: flex,
61
+ alignItems: 'stretch',
62
+ alignSelf: 'stretch',
63
+ },
64
+ FieldStyles.root(colorPalette),
65
+ ]}>
66
+ <FieldContext.Provider value={contextValue}>
67
+ {children}
68
+ </FieldContext.Provider>
69
+ </VStack>
70
+ )
71
+ }
72
+
73
+ type FieldLabelProps = {
74
+ children: React.ReactNode
75
+ size?: FieldVariants['size']
76
+ variant?: FieldVariants['variant']
77
+ colorPalette?: PalettesWithNestedKeys
78
+ }
79
+
80
+ const FieldLabel = ({children, ...props}: FieldLabelProps) => {
81
+ const {
82
+ size,
83
+ variant,
84
+ colorPalette = 'accent',
85
+ } = {
86
+ ...useField(),
87
+ ...props,
88
+ }
89
+
90
+ FieldStyles.useVariants({variant, size})
91
+
92
+ return (
93
+ <Text
94
+ size={size}
95
+ // @ts-ignore
96
+ color={FieldStyles.label(colorPalette).color}>
97
+ {children}
98
+ </Text>
99
+ )
100
+ }
101
+
102
+ type FieldErrorProps = {
103
+ size?: FieldVariants['size']
104
+ variant?: FieldVariants['variant']
105
+ colorPalette?: PalettesWithNestedKeys
106
+ }
107
+
108
+ const FieldError = ({...props}: FieldErrorProps) => {
109
+ const {
110
+ error,
111
+ size,
112
+ variant,
113
+ colorPalette = 'accent',
114
+ } = {
115
+ ...useField(),
116
+ ...props,
117
+ }
118
+
119
+ if (!error) return null
120
+
121
+ FieldStyles.useVariants({size, variant})
122
+
123
+ return (
124
+ // @ts-ignore
125
+ <Text size={size} color={FieldStyles.error(colorPalette).color}>
126
+ {error}
127
+ </Text>
128
+ )
129
+ }
130
+
131
+ export const Field = Object.assign(FieldRoot, {
132
+ Root: FieldRoot,
133
+ Label: FieldLabel,
134
+ Error: FieldError,
135
+ })
136
+
137
+ export default Field
@@ -1,37 +1,34 @@
1
- import {View, StyleSheet, type ColorValue} from 'react-native'
1
+ import {View, StyleSheet, StyleProp, ViewStyle} from 'react-native'
2
2
  import Svg, {Defs, LinearGradient, Stop, Rect} from 'react-native-svg'
3
3
  import {withUnistyles} from 'react-native-unistyles'
4
4
  import {gradientBackgroundTokens} from '../theme/GradientBackground.recipe'
5
+ import {PalettesWithNestedKeys} from '../style/varia/types'
6
+ import {resolveColor} from '../style/varia/utils'
5
7
 
6
8
  interface GradientBackgroundProps {
7
- colorPalette?: keyof typeof gradientBackgroundTokens.variants.colorPalette
9
+ colorPalette?: PalettesWithNestedKeys
10
+ variant?: keyof typeof gradientBackgroundTokens.variants.variant
8
11
  direction?: keyof typeof gradientBackgroundTokens.variants.direction
9
- // colors: Record<string, ColorValue>;
10
- colors: Record<string, ColorValue>
12
+ containerStyles?: StyleProp<ViewStyle>
13
+ colors: any
11
14
  }
12
15
 
13
16
  const BaseGradientBackground = ({
14
- colorPalette = gradientBackgroundTokens.defaultProps.colorPalette,
17
+ colorPalette = 'accent',
18
+ variant = gradientBackgroundTokens.defaultProps.variant,
15
19
  direction = gradientBackgroundTokens.defaultProps.direction,
20
+ containerStyles,
16
21
  colors,
17
22
  }: GradientBackgroundProps) => {
18
- const tokenColorKey =
19
- gradientBackgroundTokens.variants.colorPalette[colorPalette]
20
- const startColor =
21
- tokenColorKey.startColor in colors
22
- ? colors[tokenColorKey.startColor]
23
- : tokenColorKey.startColor
24
-
25
- const endColor =
26
- tokenColorKey.endColor in colors
27
- ? colors[tokenColorKey.endColor]
28
- : tokenColorKey.endColor
23
+ const colorValue = gradientBackgroundTokens.variants.variant[variant]
24
+ const startColor = resolveColor(colorValue.startColor, colors, colorPalette)
25
+ const endColor = resolveColor(colorValue.endColor, colors, colorPalette)
29
26
 
30
27
  const directionVariant =
31
28
  gradientBackgroundTokens.variants.direction[direction]
32
29
 
33
30
  return (
34
- <View style={styles.container}>
31
+ <View style={[styles.container, containerStyles && containerStyles]}>
35
32
  <Svg
36
33
  width="100%"
37
34
  height="100%"
@@ -57,10 +54,12 @@ const BaseGradientBackground = ({
57
54
  const styles = StyleSheet.create({
58
55
  container: {
59
56
  ...StyleSheet.absoluteFillObject,
57
+ borderWidth: 0,
58
+ overflow: 'hidden',
59
+ borderColor: 'transparent',
60
60
  },
61
61
  })
62
62
 
63
- // export default GradientBackground;
64
63
  const GradientBackground = withUnistyles(BaseGradientBackground, theme => ({
65
64
  colors: theme.colors,
66
65
  }))
@@ -6,45 +6,45 @@ import Svg, {
6
6
  Text,
7
7
  type NumberProp,
8
8
  } from 'react-native-svg'
9
- import {StyleSheet, withUnistyles} from 'react-native-unistyles'
9
+ import {withUnistyles} from 'react-native-unistyles'
10
10
  import {gradientTextTokens} from '../theme/GradientText.recipe'
11
- import {TextSemanticSizes} from '../style/types'
11
+ import {PalettesWithNestedKeys} from '../style/varia/types'
12
+ import {resolveColor, resolveFontSize} from '../style/varia/utils'
12
13
 
13
14
  interface GradientTextProps {
14
- colorPalette?: keyof typeof gradientTextTokens.variants.colorPalette
15
+ colorPalette: PalettesWithNestedKeys
16
+ variant?: keyof typeof gradientTextTokens.variants.variant
15
17
  direction?: keyof typeof gradientTextTokens.variants.direction
16
- // colors: Record<string, ColorValue>;
17
- colors: Record<string, ColorValue>
18
- as?: TextSemanticSizes
18
+ colors: any
19
+ fontSizes: any
19
20
  fontSize?: number | undefined
20
21
  children?: React.ReactNode
22
+ size?: keyof typeof gradientTextTokens.variants.size
21
23
  }
22
24
 
23
25
  const BaseGradientText = ({
24
- as = 'body',
25
26
  fontSize,
26
- colorPalette = gradientTextTokens.defaultProps.colorPalette,
27
+ variant = gradientTextTokens.defaultProps.variant,
28
+ colorPalette = 'accent',
27
29
  direction = gradientTextTokens.defaultProps.direction,
28
30
  colors,
31
+ fontSizes,
29
32
  children,
33
+ size = gradientTextTokens.defaultProps.size,
30
34
  }: GradientTextProps) => {
31
- const tokenColorKey = gradientTextTokens.variants.colorPalette[colorPalette]
32
- const startColor =
33
- tokenColorKey.startColor in colors
34
- ? colors[tokenColorKey.startColor]
35
- : tokenColorKey.startColor
35
+ const colorValue = gradientTextTokens.variants.variant[variant]
36
+ const startColor = resolveColor(colorValue.startColor, colors, colorPalette)
37
+ const endColor = resolveColor(colorValue.endColor, colors, colorPalette)
36
38
 
37
- const endColor =
38
- tokenColorKey.endColor in colors
39
- ? colors[tokenColorKey.endColor]
40
- : tokenColorKey.endColor
39
+ const fontSizeValue = gradientTextTokens.variants.size[size].fontSize
40
+ const resolvedFontSize = fontSize || resolveFontSize(fontSizeValue, fontSizes)
41
41
 
42
42
  const directionVariant = gradientTextTokens.variants.direction[direction]
43
43
 
44
44
  return (
45
45
  <View style={{flexDirection: 'row'}}>
46
46
  <View style={{width: '100%'}}>
47
- <Svg height={styles[as](fontSize).fontSize + 20} width="100%">
47
+ <Svg height={resolvedFontSize + 20} width="100%">
48
48
  <Defs>
49
49
  <LinearGradient
50
50
  id="gradient"
@@ -58,10 +58,13 @@ const BaseGradientText = ({
58
58
  </Defs>
59
59
  <Text
60
60
  fill="url(#gradient)"
61
- fontSize={styles[as](fontSize).fontSize}
62
- fontWeight={400}
61
+ fontSize={resolvedFontSize}
62
+ fontWeight={
63
+ (gradientTextTokens.variants.size[size] as {fontWeight?: number})
64
+ .fontWeight ?? 400
65
+ }
63
66
  x="50%"
64
- y={styles[as](fontSize).fontSize}
67
+ y={resolvedFontSize}
65
68
  textAnchor="middle">
66
69
  {children}
67
70
  </Text>
@@ -71,51 +74,9 @@ const BaseGradientText = ({
71
74
  )
72
75
  }
73
76
 
74
- const styles = StyleSheet.create(theme => ({
75
- h1: fontSize => ({
76
- //@ts-ignore
77
- fontSize: fontSize || theme.fontSizes.xxl,
78
- }),
79
- h2: fontSize => ({
80
- //@ts-ignore
81
- fontSize: fontSize || theme.fontSizes.xl,
82
- }),
83
- h3: fontSize => ({
84
- //@ts-ignore
85
- fontSize: fontSize || theme.fontSizes.lg,
86
- }),
87
- h4: fontSize => ({
88
- //@ts-ignore
89
- fontSize: fontSize || theme.fontSizes.md,
90
- }),
91
- h5: fontSize => ({
92
- //@ts-ignore
93
- fontSize: fontSize || theme.fontSizes.sm,
94
- }),
95
- h6: fontSize => ({
96
- //@ts-ignore
97
- fontSize: fontSize || theme.fontSizes.xs,
98
- }),
99
- h7: fontSize => ({
100
- //@ts-ignore
101
- fontSize: fontSize || theme.fontSizes.xs,
102
- }),
103
- h8: fontSize => ({
104
- //@ts-ignore
105
- fontSize: fontSize || theme.fontSizes.xxs,
106
- }),
107
- h9: fontSize => ({
108
- //@ts-ignore
109
- fontSize: fontSize || theme.fontSizes.xxs,
110
- }),
111
- body: fontSize => ({
112
- //@ts-ignore
113
- fontSize: fontSize || theme.fontSizes.md,
114
- }),
115
- }))
116
-
117
77
  const GradientText = withUnistyles(BaseGradientText, theme => ({
118
78
  colors: theme.colors,
79
+ fontSizes: theme.fontSizes,
119
80
  }))
120
81
 
121
82
  export default GradientText
@@ -10,14 +10,22 @@ import Svg from 'react-native-svg'
10
10
  import {View} from 'react-native'
11
11
  import {withUnistyles} from 'react-native-unistyles'
12
12
  import {IconTokens} from '../theme/IconWrapper.recipe'
13
- import {ThemeColors} from '../style/types'
13
+ import {
14
+ NestedColorsType,
15
+ PalettesWithNestedKeys,
16
+ ThemeColors,
17
+ } from '../style/varia/types'
18
+ import {resolveColor} from '../style/varia/utils'
14
19
 
15
20
  interface SVGChildProps {
16
21
  color?: string
17
22
  }
23
+
18
24
  export type IconWrapperProps = {
19
- size?: keyof typeof IconTokens.variants.size
20
- colorPalette?: keyof typeof IconTokens.variants.colorPalette
25
+ variant?: keyof typeof IconTokens.variants.variant
26
+ size?: number
27
+ sizeVariant?: keyof typeof IconTokens.variants.sizeVariant
28
+ colorPalette?: PalettesWithNestedKeys
21
29
  children?: ReactElement<SVGChildProps>
22
30
  scale?: number
23
31
  color?: ThemeColors
@@ -33,8 +41,10 @@ export type IconWrapperProps = {
33
41
  * @returns Icon react component
34
42
  */
35
43
  const Icon = ({
36
- size = IconTokens.defaultProps.size,
37
- colorPalette = IconTokens.defaultProps.colorPalette,
44
+ size,
45
+ colorPalette = 'accent',
46
+ variant = IconTokens.defaultProps.variant,
47
+ sizeVariant = IconTokens.defaultProps.sizeVariant,
38
48
  children,
39
49
  scale = IconTokens.defaultProps.scale,
40
50
  color,
@@ -42,33 +52,30 @@ const Icon = ({
42
52
  colors,
43
53
  ...rest
44
54
  }: IconWrapperProps) => {
45
- const colorPaletteKey = IconTokens.variants.colorPalette[colorPalette]
46
- const colorScheme =
47
- colorPaletteKey.color in colors
48
- ? colors[colorPaletteKey.color]
49
- : colorPaletteKey.color
55
+ const colorValue = IconTokens.variants.variant[variant].color
50
56
  const resolvedColor = color
51
- ? color in colors
52
- ? colors[color]
53
- : color
54
- : colorScheme
57
+ ? resolveColor(color, colors, colorPalette)
58
+ : resolveColor(colorValue, colors, colorPalette)
55
59
 
56
- const width = IconTokens.variants.size[size].width ?? 0
57
- const height = IconTokens.variants.size[size].height ?? 0
58
- const viewBoxWidth = IconTokens.variants.size[size].viewBoxWidth ?? 0
59
- const viewBoxHeight = IconTokens.variants.size[size].viewBoxHeight ?? 0
60
+ const width = IconTokens.variants.sizeVariant[sizeVariant].width ?? 0
61
+ const height = IconTokens.variants.sizeVariant[sizeVariant].height ?? 0
62
+ // const viewBoxWidth = IconTokens.variants.size[size].viewBoxWidth ?? 0
63
+ // const viewBoxHeight = IconTokens.variants.size[size].viewBoxHeight ?? 0
60
64
 
61
65
  return (
62
66
  <View
63
67
  style={{
64
- width: scale * width,
65
- height: scale * height,
68
+ width: size || width,
69
+ height: size || height,
70
+ justifyContent: 'center',
71
+ alignItems: 'center',
66
72
  transform: rotation ? [{rotate: `${rotation}deg`}] : [],
67
73
  }}>
68
74
  <Svg
69
- width={scale * width}
70
- height={scale * height}
71
- viewBox={`0 0 ${viewBoxWidth} ${viewBoxHeight}`}
75
+ width={size || width}
76
+ height={size || height}
77
+ viewBox="0 0 24 24"
78
+ // viewBox={`0 0 ${viewBoxWidth} ${viewBoxHeight}`}
72
79
  fill="none"
73
80
  {...rest}>
74
81
  {Children.map(children, child => {
@@ -81,7 +88,7 @@ const Icon = ({
81
88
  return cloneElement(
82
89
  pathChild as React.ReactElement<{stroke?: string}>,
83
90
  {
84
- stroke: resolvedColor ?? colorScheme,
91
+ stroke: resolvedColor,
85
92
  },
86
93
  )
87
94
  }
@@ -98,7 +105,7 @@ const Icon = ({
98
105
 
99
106
  export default Icon
100
107
 
101
- export const ThemedIcon = withUnistyles(Icon, (theme, rt) => ({
108
+ export const ThemedIcon = withUnistyles(Icon, theme => ({
102
109
  colors: theme.colors,
103
110
  }))
104
111
 
@@ -3,46 +3,44 @@ import {
3
3
  type KeyboardTypeOptions,
4
4
  type StyleProp,
5
5
  TextInput,
6
+ TextInputProps,
6
7
  TextStyle,
7
- View,
8
8
  type ViewStyle,
9
9
  } from 'react-native'
10
- // import Text from './Text';
11
10
  import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
12
- // import Text from './Text';
13
- import {InputTokens, InputStyles} from '../theme/Input.recipe'
14
- import Text from './Text'
11
+ import {InputStyles, InputDefaultVariants} from '../theme/Input.recipe'
12
+ import {PalettesWithNestedKeys} from '../style/varia/types'
13
+ import {useState} from 'react'
14
+ import {HStack} from '../patterns'
15
15
 
16
16
  type InputVariants = UnistylesVariants<typeof InputStyles>
17
17
 
18
- type InputProps = InputVariants & {
19
- label?: string
20
- onChange?: (value: string) => void
21
- placeholder: string
22
- inputMode?: InputModeOptions
23
- keyboardType?: KeyboardTypeOptions
24
- flex?: number
25
- maxWidth?: number | string
26
- password?: boolean
27
- onFocus?: () => void
28
- value: any
29
- containerMixins?: StyleProp<ViewStyle> | StyleProp<ViewStyle>[]
30
- labelMixins?:
31
- | StyleProp<ViewStyle>
32
- | StyleProp<ViewStyle>[]
33
- | StyleProp<TextStyle>
34
- | StyleProp<TextStyle>[]
35
- inputMixins?: StyleProp<ViewStyle> | StyleProp<ViewStyle>[]
36
- // containerStyle?: StyleProp<ViewStyle>;
37
- // labelStyle?: StyleProp<ViewStyle>;
38
- // inputStyle?: StyleProp<ViewStyle>;
39
- }
18
+ type InputProps = InputVariants &
19
+ TextInputProps & {
20
+ colorPalette?: PalettesWithNestedKeys
21
+ onChange?: (value: string) => void
22
+ placeholder: string
23
+ inputMode?: InputModeOptions
24
+ keyboardType?: KeyboardTypeOptions
25
+ flex?: number
26
+ maxWidth?: number | string
27
+ password?: boolean
28
+ onFocus?: () => void
29
+ onBlur?: () => void
30
+ value: any
31
+ disabled?: boolean
32
+ containerMixins?: StyleProp<ViewStyle> | StyleProp<ViewStyle>[]
33
+ labelMixins?:
34
+ | StyleProp<ViewStyle>
35
+ | StyleProp<ViewStyle>[]
36
+ | StyleProp<TextStyle>
37
+ | StyleProp<TextStyle>[]
38
+ inputMixins?: StyleProp<ViewStyle> | StyleProp<ViewStyle>[]
39
+ }
40
40
 
41
41
  const Input = ({
42
- colorPalette = InputTokens.defaultProps.colorPalette,
43
- size = InputTokens.defaultProps.size,
44
- spacing = InputTokens.defaultProps.spacing,
45
- label,
42
+ colorPalette = 'accent',
43
+ size = InputDefaultVariants.size,
46
44
  placeholder,
47
45
  onChange,
48
46
  inputMode,
@@ -51,70 +49,70 @@ const Input = ({
51
49
  maxWidth = '100%',
52
50
  password = false,
53
51
  onFocus = () => {},
52
+ onBlur = () => {},
54
53
  value,
55
54
  containerMixins,
56
55
  labelMixins,
57
56
  inputMixins,
58
- }: // containerStyle,
59
- // labelStyle,
60
- // inputStyle,
61
- InputProps) => {
57
+ disabled,
58
+ invalid,
59
+ ...props
60
+ }: InputProps) => {
61
+ const [focused, setFocused] = useState(false)
62
62
  InputStyles.useVariants({
63
- colorPalette,
64
63
  size,
65
- spacing,
64
+ focused,
65
+ disabled,
66
+ invalid,
66
67
  })
67
68
 
68
69
  return (
69
- <View
70
- style={[
71
- styles.container(flex, maxWidth),
72
- // containerStyle && styles.customStyle(containerStyle),
73
- containerMixins && containerMixins,
74
- ]}>
75
- {label && (
76
- <Text
77
- as="h5"
78
- style={
79
- [
80
- // styles.label,
81
- InputStyles.label,
82
- // labelStyle && styles.customStyle(labelStyle),
83
- labelMixins && labelMixins,
84
- ] as any
85
- }>
86
- {label}
87
- </Text>
88
- )}
70
+ <HStack
71
+ style={{
72
+ flexGrow: flex,
73
+ flexShrink: 0,
74
+ alignSelf: 'stretch',
75
+ }}>
89
76
  <TextInput
77
+ editable={!disabled}
90
78
  style={[
91
- // styles.input,
92
- InputStyles.input,
93
- // inputStyle && styles.customStyle(inputStyle),
79
+ styles.input(flex, maxWidth),
80
+ InputStyles.input(colorPalette),
94
81
  inputMixins && inputMixins,
95
82
  ]}
96
83
  value={value}
97
84
  placeholder={placeholder}
85
+ // @ts-ignore
86
+ placeholderTextColor={InputStyles.placeholder(colorPalette).color}
98
87
  inputMode={inputMode}
99
88
  keyboardType={keyboardType}
100
89
  secureTextEntry={password}
101
- onFocus={onFocus}
90
+ onFocus={() => {
91
+ onFocus()
92
+ setFocused(true)
93
+ }}
94
+ onBlur={() => {
95
+ onBlur()
96
+ setFocused(false)
97
+ }}
102
98
  onChangeText={onChange}
99
+ multiline={false}
100
+ {...props}
103
101
  />
104
- </View>
102
+ </HStack>
105
103
  )
106
104
  }
107
105
 
108
106
  const styles = StyleSheet.create({
109
- container: (flex, maxWidth) => ({
107
+ input: (flex, maxWidth) => ({
110
108
  flex,
111
- width: '100%',
109
+ paddingVertical: 0,
110
+ flexDirection: 'row',
111
+ flexGrow: 1,
112
+ flexShrink: 0,
113
+ alignSelf: 'stretch',
112
114
  maxWidth,
113
- gap: 5,
114
115
  }),
115
- // customStyle: style => ({
116
- // ...style,
117
- // }),
118
116
  })
119
117
 
120
118
  export default Input