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.
- package/lib/components/Accordion.tsx +55 -27
- package/lib/components/Badge.tsx +12 -6
- package/lib/components/Button.tsx +18 -6
- package/lib/components/Checkbox.tsx +22 -4
- package/lib/components/CircleProgress.tsx +7 -3
- package/lib/components/Divider.tsx +7 -3
- package/lib/components/Drawer.tsx +73 -25
- package/lib/components/Field.tsx +12 -6
- package/lib/components/FloatingAction.tsx +15 -4
- package/lib/components/GradientBackground.tsx +1 -1
- package/lib/components/GradientText.tsx +15 -5
- package/lib/components/IconWrapper.tsx +2 -2
- package/lib/components/Input.tsx +11 -6
- package/lib/components/Link.tsx +7 -7
- package/lib/components/Modal.tsx +42 -13
- package/lib/components/NumberInput.tsx +44 -23
- package/lib/components/RadioGroup.tsx +35 -6
- package/lib/components/ReText.tsx +1 -1
- package/lib/components/Select.tsx +61 -8
- package/lib/components/Slider.tsx +202 -200
- package/lib/components/Slideshow.tsx +12 -3
- package/lib/components/Switch.tsx +15 -3
- package/lib/components/Text.tsx +2 -2
- package/lib/components/Toast.tsx +14 -3
- package/lib/components/context/Field.tsx +2 -0
- package/lib/varia/types.ts +6 -0
- package/lib/varia/utils.ts +7 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, {createContext, useContext} from 'react'
|
|
2
|
-
import {View, Pressable} from 'react-native'
|
|
2
|
+
import {View, Pressable, StyleProp} from 'react-native'
|
|
3
3
|
import Animated, {
|
|
4
4
|
withDelay,
|
|
5
5
|
useAnimatedStyle,
|
|
@@ -48,6 +48,7 @@ function Item({children, onPress, ...props}: ItemProps) {
|
|
|
48
48
|
variant,
|
|
49
49
|
size,
|
|
50
50
|
colorPalette = 'accent',
|
|
51
|
+
itemStyles,
|
|
51
52
|
} = {...useFloatingContext(), ...props}
|
|
52
53
|
FloatingActionStyles.useVariants({
|
|
53
54
|
variant,
|
|
@@ -91,9 +92,10 @@ function Item({children, onPress, ...props}: ItemProps) {
|
|
|
91
92
|
<AnimatedPressable
|
|
92
93
|
testID="varia-floating-action-item"
|
|
93
94
|
style={[
|
|
95
|
+
FloatingActionStyles.item(colorPalette),
|
|
94
96
|
animatedStyles,
|
|
97
|
+
itemStyles,
|
|
95
98
|
styles.itemButton,
|
|
96
|
-
FloatingActionStyles.item(colorPalette),
|
|
97
99
|
]}
|
|
98
100
|
onPress={onPress}>
|
|
99
101
|
{children}
|
|
@@ -112,6 +114,9 @@ type FloatingActionProps = FloatingActionVariants & {
|
|
|
112
114
|
right?: ViewStyle['right']
|
|
113
115
|
left?: ViewStyle['left']
|
|
114
116
|
children: React.ReactNode
|
|
117
|
+
buttonContainerStyles?: StyleProp<ViewStyle>
|
|
118
|
+
buttonStyles?: StyleProp<ViewStyle>
|
|
119
|
+
itemStyles?: StyleProp<ViewStyle>
|
|
115
120
|
}
|
|
116
121
|
|
|
117
122
|
function Root({
|
|
@@ -125,6 +130,9 @@ function Root({
|
|
|
125
130
|
bottom = null,
|
|
126
131
|
right = null,
|
|
127
132
|
left = null,
|
|
133
|
+
buttonContainerStyles,
|
|
134
|
+
buttonStyles,
|
|
135
|
+
itemStyles,
|
|
128
136
|
}: FloatingActionProps) {
|
|
129
137
|
FloatingActionStyles.useVariants({
|
|
130
138
|
variant,
|
|
@@ -155,16 +163,18 @@ function Root({
|
|
|
155
163
|
<View
|
|
156
164
|
testID="varia-floating-action-container"
|
|
157
165
|
style={[
|
|
158
|
-
styles.buttonContainer(top, bottom, left, right),
|
|
159
166
|
FloatingActionStyles.buttonContainer(colorPalette),
|
|
167
|
+
buttonContainerStyles,
|
|
168
|
+
styles.buttonContainer(top, bottom, left, right),
|
|
160
169
|
]}>
|
|
161
170
|
<AnimatedPressable
|
|
162
171
|
testID="varia-floating-action-button"
|
|
163
172
|
onPress={() => (isExpanded.value = !isExpanded.value)}
|
|
164
173
|
style={[
|
|
174
|
+
FloatingActionStyles.button(colorPalette),
|
|
175
|
+
buttonStyles,
|
|
165
176
|
plusIconStyle,
|
|
166
177
|
styles.button,
|
|
167
|
-
FloatingActionStyles.button(colorPalette),
|
|
168
178
|
]}>
|
|
169
179
|
<Plus size={iconHeight - 20} color={iconColor} />
|
|
170
180
|
</AnimatedPressable>
|
|
@@ -179,6 +189,7 @@ function Root({
|
|
|
179
189
|
variant,
|
|
180
190
|
size,
|
|
181
191
|
colorPalette,
|
|
192
|
+
itemStyles,
|
|
182
193
|
}}>
|
|
183
194
|
{child}
|
|
184
195
|
</FloatingActionContext.Provider>
|
|
@@ -45,7 +45,7 @@ const BaseGradientBackground = ({
|
|
|
45
45
|
gradientBackgroundTokens.variants.direction[direction]
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
|
-
<View style={[
|
|
48
|
+
<View style={[containerStyles && containerStyles, styles.container]}>
|
|
49
49
|
<Svg
|
|
50
50
|
width="100%"
|
|
51
51
|
height="100%"
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
StyleProp,
|
|
3
|
+
TextStyle,
|
|
4
|
+
View,
|
|
5
|
+
ViewStyle,
|
|
6
|
+
type ColorValue,
|
|
7
|
+
} from 'react-native'
|
|
2
8
|
import Svg, {
|
|
3
9
|
Defs,
|
|
4
10
|
LinearGradient,
|
|
@@ -34,6 +40,7 @@ type GradientTextProps = TextVariantsWithoutVariant & {
|
|
|
34
40
|
fontSizes: ThemeType['fontSizes']
|
|
35
41
|
fontSize?: TextStyle['fontSize']
|
|
36
42
|
children?: React.ReactNode
|
|
43
|
+
containerStyles?: StyleProp<ViewStyle>
|
|
37
44
|
// size?: keyof typeof gradientTextTokens.variants.size
|
|
38
45
|
}
|
|
39
46
|
|
|
@@ -48,6 +55,7 @@ const BaseGradientText = ({
|
|
|
48
55
|
fontSizes,
|
|
49
56
|
children,
|
|
50
57
|
size = gradientTextTokens.defaultProps.size,
|
|
58
|
+
containerStyles,
|
|
51
59
|
}: GradientTextProps) => {
|
|
52
60
|
TextStyles.useVariants({
|
|
53
61
|
size,
|
|
@@ -83,9 +91,9 @@ const BaseGradientText = ({
|
|
|
83
91
|
const directionVariant = gradientTextTokens.variants.direction[direction]
|
|
84
92
|
|
|
85
93
|
return (
|
|
86
|
-
<View style={styles.
|
|
94
|
+
<View style={[containerStyles, styles.container]}>
|
|
87
95
|
<View style={styles.innerContainer}>
|
|
88
|
-
<Svg height={resolvedFontSize
|
|
96
|
+
<Svg height={resolvedFontSize} width="100%">
|
|
89
97
|
<Defs>
|
|
90
98
|
<LinearGradient
|
|
91
99
|
id="gradient"
|
|
@@ -102,7 +110,8 @@ const BaseGradientText = ({
|
|
|
102
110
|
fontSize={resolvedFontSize}
|
|
103
111
|
fontWeight={resolvedFontWeight}
|
|
104
112
|
x="50%"
|
|
105
|
-
y={resolvedFontSize}
|
|
113
|
+
y={resolvedFontSize / 2}
|
|
114
|
+
alignmentBaseline="middle"
|
|
106
115
|
textAnchor="middle">
|
|
107
116
|
{children}
|
|
108
117
|
</Text>
|
|
@@ -113,8 +122,9 @@ const BaseGradientText = ({
|
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
const styles = StyleSheet.create({
|
|
116
|
-
|
|
125
|
+
container: {
|
|
117
126
|
flexDirection: 'row',
|
|
127
|
+
alignItems: 'center',
|
|
118
128
|
_web: {
|
|
119
129
|
_classNames: 'gradient_text-root-base',
|
|
120
130
|
},
|
|
@@ -64,7 +64,7 @@ const Icon = ({
|
|
|
64
64
|
// const viewBoxHeight = IconTokens.variants.size[size].viewBoxHeight ?? 0
|
|
65
65
|
|
|
66
66
|
return (
|
|
67
|
-
<View style={[styles.
|
|
67
|
+
<View style={[styles.container(size, width, height, rotation), style]}>
|
|
68
68
|
<Svg
|
|
69
69
|
width={size || width}
|
|
70
70
|
height={size || height}
|
|
@@ -100,7 +100,7 @@ const Icon = ({
|
|
|
100
100
|
export default Icon
|
|
101
101
|
|
|
102
102
|
const styles = StyleSheet.create({
|
|
103
|
-
|
|
103
|
+
container: (size, width, height, rotation) => ({
|
|
104
104
|
width: size || width,
|
|
105
105
|
height: size || height,
|
|
106
106
|
justifyContent: 'center',
|
package/lib/components/Input.tsx
CHANGED
|
@@ -52,7 +52,8 @@ type InputProps = InputVariants &
|
|
|
52
52
|
rotation?: number
|
|
53
53
|
size?: number
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
containerStyles?: StyleProp<ViewStyle>
|
|
56
|
+
textInputStyles?: StyleProp<ViewStyle | TextStyle>
|
|
56
57
|
direction?: StackDirection
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -76,7 +77,8 @@ const Input = ({
|
|
|
76
77
|
inputMixins,
|
|
77
78
|
disabled,
|
|
78
79
|
invalid,
|
|
79
|
-
|
|
80
|
+
textInputStyles,
|
|
81
|
+
containerStyles,
|
|
80
82
|
icon,
|
|
81
83
|
textAlignVertical = 'center',
|
|
82
84
|
direction = 'column',
|
|
@@ -130,12 +132,18 @@ const Input = ({
|
|
|
130
132
|
return (
|
|
131
133
|
<View
|
|
132
134
|
testID="varia-input-container"
|
|
133
|
-
style={
|
|
135
|
+
style={[
|
|
136
|
+
containerStyles,
|
|
137
|
+
styles.container(flex, direction, alignSelf, textAlignVertical),
|
|
138
|
+
]}>
|
|
134
139
|
{IconRendered}
|
|
135
140
|
<TextInput
|
|
136
141
|
testID="varia-input"
|
|
137
142
|
editable={!disabled}
|
|
138
143
|
style={[
|
|
144
|
+
InputStyles.input(colorPalette),
|
|
145
|
+
inputMixins && inputMixins,
|
|
146
|
+
textInputStyles && textInputStyles,
|
|
139
147
|
styles.input(
|
|
140
148
|
flex,
|
|
141
149
|
maxWidth,
|
|
@@ -145,9 +153,6 @@ const Input = ({
|
|
|
145
153
|
(icon?.size || 0) + resolvedPaddingHorizontal * 2,
|
|
146
154
|
alignSelf,
|
|
147
155
|
),
|
|
148
|
-
InputStyles.input(colorPalette),
|
|
149
|
-
inputMixins && inputMixins,
|
|
150
|
-
style && style,
|
|
151
156
|
iconPosition && {
|
|
152
157
|
paddingInline: 0,
|
|
153
158
|
paddingLeft:
|
package/lib/components/Link.tsx
CHANGED
|
@@ -18,7 +18,7 @@ type LinkProps = TextVariants & {
|
|
|
18
18
|
underline?: boolean
|
|
19
19
|
fontSize?: number
|
|
20
20
|
color?: ThemeColors
|
|
21
|
-
|
|
21
|
+
textStyles?: StyleProp<TextStyle>
|
|
22
22
|
mixins?:
|
|
23
23
|
| StyleProp<ViewStyle>
|
|
24
24
|
| StyleProp<ViewStyle>[]
|
|
@@ -35,6 +35,7 @@ const Link = ({
|
|
|
35
35
|
underline,
|
|
36
36
|
fontSize,
|
|
37
37
|
color,
|
|
38
|
+
textStyles,
|
|
38
39
|
mixins,
|
|
39
40
|
}: LinkProps) => {
|
|
40
41
|
console.log(color)
|
|
@@ -55,12 +56,11 @@ const Link = ({
|
|
|
55
56
|
fontSize={fontSize}
|
|
56
57
|
color={color}
|
|
57
58
|
colorPalette={colorPalette}
|
|
58
|
-
style={
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}>
|
|
59
|
+
style={[
|
|
60
|
+
textStyles,
|
|
61
|
+
mixins && mixins,
|
|
62
|
+
styles.link(underline ? 'underline' : 'none'),
|
|
63
|
+
]}>
|
|
64
64
|
{text}
|
|
65
65
|
</Text>
|
|
66
66
|
</TouchableOpacity>
|
package/lib/components/Modal.tsx
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import React, {createContext, useContext} from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
StyleProp,
|
|
4
|
+
TextStyle,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
TouchableWithoutFeedback,
|
|
7
|
+
View,
|
|
8
|
+
ViewStyle,
|
|
9
|
+
} from 'react-native'
|
|
3
10
|
import Animated from 'react-native-reanimated'
|
|
4
11
|
import {Portal} from '@gorhom/portal'
|
|
5
12
|
import Svg, {Path} from 'react-native-svg'
|
|
@@ -22,6 +29,11 @@ type ModalRootProps = ModalVariants & {
|
|
|
22
29
|
setIsOpen: (isOpen: boolean) => void
|
|
23
30
|
zIndex?: ZIndex
|
|
24
31
|
children: React.ReactNode
|
|
32
|
+
overlayStyles?: StyleProp<ViewStyle>
|
|
33
|
+
contentStyles?: StyleProp<ViewStyle>
|
|
34
|
+
headerStyles?: StyleProp<ViewStyle>
|
|
35
|
+
titleStyles?: StyleProp<TextStyle>
|
|
36
|
+
closeTriggerStyles?: StyleProp<ViewStyle>
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
type ModalContextProps = Omit<ModalRootProps, 'children' | 'isOpen'>
|
|
@@ -45,6 +57,11 @@ const ModalRoot = ({
|
|
|
45
57
|
setIsOpen,
|
|
46
58
|
zIndex,
|
|
47
59
|
children,
|
|
60
|
+
overlayStyles,
|
|
61
|
+
contentStyles,
|
|
62
|
+
headerStyles,
|
|
63
|
+
titleStyles,
|
|
64
|
+
closeTriggerStyles,
|
|
48
65
|
}: ModalRootProps) => {
|
|
49
66
|
ModalStyles.useVariants({
|
|
50
67
|
variant,
|
|
@@ -58,6 +75,11 @@ const ModalRoot = ({
|
|
|
58
75
|
animation,
|
|
59
76
|
setIsOpen,
|
|
60
77
|
zIndex,
|
|
78
|
+
overlayStyles,
|
|
79
|
+
contentStyles,
|
|
80
|
+
headerStyles,
|
|
81
|
+
titleStyles,
|
|
82
|
+
closeTriggerStyles,
|
|
61
83
|
}
|
|
62
84
|
|
|
63
85
|
return (
|
|
@@ -74,7 +96,6 @@ type ModalOverlayProps = {
|
|
|
74
96
|
variant?: ModalVariants['variant']
|
|
75
97
|
animation?: keyof typeof ModalTokens.animations.variants
|
|
76
98
|
colorPalette?: PalettesWithNestedKeys
|
|
77
|
-
customStyle?: any
|
|
78
99
|
}
|
|
79
100
|
|
|
80
101
|
const ModalOverlay = ({children, ...props}: ModalOverlayProps) => {
|
|
@@ -85,6 +106,7 @@ const ModalOverlay = ({children, ...props}: ModalOverlayProps) => {
|
|
|
85
106
|
animation,
|
|
86
107
|
setIsOpen,
|
|
87
108
|
zIndex,
|
|
109
|
+
overlayStyles,
|
|
88
110
|
} = {...context, ...props}
|
|
89
111
|
|
|
90
112
|
ModalStyles.useVariants({variant})
|
|
@@ -93,8 +115,9 @@ const ModalOverlay = ({children, ...props}: ModalOverlayProps) => {
|
|
|
93
115
|
<AnimatedView
|
|
94
116
|
testID="varia-modal-overlay"
|
|
95
117
|
style={[
|
|
96
|
-
styles.overlay(zIndex || ZINDEXES.modal),
|
|
97
118
|
ModalStyles.overlay(colorPalette),
|
|
119
|
+
overlayStyles,
|
|
120
|
+
styles.overlay(zIndex || ZINDEXES.modal),
|
|
98
121
|
]}
|
|
99
122
|
entering={ModalTokens.animations.variants[animation]?.enteringOverlay}
|
|
100
123
|
exiting={ModalTokens.animations.variants[animation]?.exitingOverlay}>
|
|
@@ -114,7 +137,6 @@ type ModalContentProps = Omit<ModalVariants, 'variant'> & {
|
|
|
114
137
|
variant?: ModalVariants['variant']
|
|
115
138
|
animation?: keyof typeof ModalTokens.animations.variants
|
|
116
139
|
colorPalette?: PalettesWithNestedKeys
|
|
117
|
-
customStyle?: any
|
|
118
140
|
}
|
|
119
141
|
|
|
120
142
|
const ModalContent = ({children, ...props}: ModalContentProps) => {
|
|
@@ -123,6 +145,7 @@ const ModalContent = ({children, ...props}: ModalContentProps) => {
|
|
|
123
145
|
colorPalette = 'accent',
|
|
124
146
|
variant,
|
|
125
147
|
animation,
|
|
148
|
+
contentStyles,
|
|
126
149
|
} = {
|
|
127
150
|
...context,
|
|
128
151
|
...props,
|
|
@@ -133,7 +156,11 @@ const ModalContent = ({children, ...props}: ModalContentProps) => {
|
|
|
133
156
|
return (
|
|
134
157
|
<AnimatedView
|
|
135
158
|
testID="varia-modal-content"
|
|
136
|
-
style={[
|
|
159
|
+
style={[
|
|
160
|
+
ModalStyles.content(colorPalette),
|
|
161
|
+
contentStyles,
|
|
162
|
+
styles.content(),
|
|
163
|
+
]}
|
|
137
164
|
entering={ModalTokens.animations.variants[animation]?.enteringContent}
|
|
138
165
|
exiting={ModalTokens.animations.variants[animation]?.exitingContent}>
|
|
139
166
|
{children}
|
|
@@ -141,9 +168,10 @@ const ModalContent = ({children, ...props}: ModalContentProps) => {
|
|
|
141
168
|
)
|
|
142
169
|
}
|
|
143
170
|
|
|
144
|
-
const ModalHeader = ({children}: {children: React.ReactNode}) => {
|
|
171
|
+
const ModalHeader = ({children, ...props}: {children: React.ReactNode}) => {
|
|
172
|
+
const {headerStyles} = {...useModalContext(), ...props}
|
|
145
173
|
return (
|
|
146
|
-
<View testID="varia-modal-header" style={styles.header}>
|
|
174
|
+
<View testID="varia-modal-header" style={[headerStyles, styles.header]}>
|
|
147
175
|
{children}
|
|
148
176
|
</View>
|
|
149
177
|
)
|
|
@@ -151,11 +179,13 @@ const ModalHeader = ({children}: {children: React.ReactNode}) => {
|
|
|
151
179
|
|
|
152
180
|
const ModalTitle = ({children, ...props}: {children: React.ReactNode}) => {
|
|
153
181
|
const context = useModalContext()
|
|
154
|
-
const {variant, colorPalette = 'accent'} = {...context, ...props}
|
|
182
|
+
const {variant, colorPalette = 'accent', titleStyles} = {...context, ...props}
|
|
155
183
|
|
|
156
184
|
ModalStyles.useVariants({variant})
|
|
157
185
|
return (
|
|
158
|
-
<Text
|
|
186
|
+
<Text
|
|
187
|
+
testID="varia-modal-title"
|
|
188
|
+
style={[titleStyles, ModalStyles.title(colorPalette)]}>
|
|
159
189
|
{children}
|
|
160
190
|
</Text>
|
|
161
191
|
)
|
|
@@ -165,7 +195,6 @@ type ModalBodyProps = Omit<ModalVariants, 'variant'> & {
|
|
|
165
195
|
children: React.ReactNode
|
|
166
196
|
variant?: ModalVariants['variant']
|
|
167
197
|
colorPalette?: PalettesWithNestedKeys
|
|
168
|
-
customStyle?: any
|
|
169
198
|
}
|
|
170
199
|
|
|
171
200
|
const ModalBody = ({children}: ModalBodyProps) => {
|
|
@@ -207,20 +236,20 @@ type ModalCloseTriggerProps = {
|
|
|
207
236
|
style?: any
|
|
208
237
|
}
|
|
209
238
|
|
|
210
|
-
const ModalCloseTrigger = ({children
|
|
211
|
-
const {setIsOpen} = useModalContext()
|
|
239
|
+
const ModalCloseTrigger = ({children}: ModalCloseTriggerProps) => {
|
|
240
|
+
const {setIsOpen, closeTriggerStyles} = useModalContext()
|
|
212
241
|
|
|
213
242
|
const onClose = () => setIsOpen(false)
|
|
214
243
|
|
|
215
244
|
return (
|
|
216
245
|
<View
|
|
217
246
|
style={[
|
|
247
|
+
closeTriggerStyles,
|
|
218
248
|
{
|
|
219
249
|
position: 'absolute',
|
|
220
250
|
right: 0,
|
|
221
251
|
top: 0,
|
|
222
252
|
},
|
|
223
|
-
style,
|
|
224
253
|
]}>
|
|
225
254
|
{children({onClose})}
|
|
226
255
|
</View>
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
ReactNode,
|
|
4
|
+
useContext,
|
|
5
|
+
useMemo,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react'
|
|
2
8
|
import {View, TextInput, Pressable, StyleProp, ViewStyle} from 'react-native'
|
|
3
9
|
import {UnistylesVariants, StyleSheet} from 'react-native-unistyles'
|
|
4
10
|
import {
|
|
@@ -19,7 +25,6 @@ type NumberInputVariants = UnistylesVariants<typeof NumberInputStyles>
|
|
|
19
25
|
type PublicInputProps = Omit<NumberInputVariants, 'variant' | 'size'> & {
|
|
20
26
|
placeholder?: string
|
|
21
27
|
flex?: number
|
|
22
|
-
style?: StyleProp<ViewStyle>
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
interface IconProps {
|
|
@@ -34,7 +39,7 @@ type PublicTriggerProps = {
|
|
|
34
39
|
colorPalette?: PalettesWithNestedKeys
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
type
|
|
42
|
+
type NumberInputProps = NumberInputVariants & {
|
|
38
43
|
value?: number
|
|
39
44
|
onChange?: (n: number) => void
|
|
40
45
|
onBlur?: () => void
|
|
@@ -46,9 +51,14 @@ type SimpleNumberInputProps = NumberInputVariants & {
|
|
|
46
51
|
alignSelf?: AlignSelf
|
|
47
52
|
style?: StyleProp<ViewStyle>
|
|
48
53
|
direction?: 'row' | 'column'
|
|
54
|
+
containerStyles?: StyleProp<ViewStyle>
|
|
55
|
+
inputStyles?: StyleProp<ViewStyle>
|
|
56
|
+
increaseTriggerStyles?: StyleProp<ViewStyle>
|
|
57
|
+
decreaseTriggerStyles?: StyleProp<ViewStyle>
|
|
58
|
+
children: ReactNode
|
|
49
59
|
}
|
|
50
60
|
|
|
51
|
-
export const
|
|
61
|
+
export const NumberInputContext = createContext<{
|
|
52
62
|
value: number
|
|
53
63
|
setValue: (n: number) => void
|
|
54
64
|
onBlur?: () => void
|
|
@@ -61,6 +71,9 @@ export const SimpleNumberInputContext = createContext<{
|
|
|
61
71
|
flex?: number
|
|
62
72
|
alignSelf?: AlignSelf
|
|
63
73
|
direction?: StackDirection
|
|
74
|
+
inputStyles?: StyleProp<ViewStyle>
|
|
75
|
+
increaseTriggerStyles?: StyleProp<ViewStyle>
|
|
76
|
+
decreaseTriggerStyles?: StyleProp<ViewStyle>
|
|
64
77
|
}>({
|
|
65
78
|
value: 0,
|
|
66
79
|
setValue: () => {},
|
|
@@ -70,8 +83,8 @@ export const SimpleNumberInputContext = createContext<{
|
|
|
70
83
|
flex: 0,
|
|
71
84
|
})
|
|
72
85
|
|
|
73
|
-
function
|
|
74
|
-
const ctx = useContext(
|
|
86
|
+
function useNumberInputContext() {
|
|
87
|
+
const ctx = useContext(NumberInputContext)
|
|
75
88
|
if (!ctx) {
|
|
76
89
|
throw new Error('SimpleNumberInput.* must be inside SimpleNumberInput.Root')
|
|
77
90
|
}
|
|
@@ -94,8 +107,11 @@ const NumberInput = {
|
|
|
94
107
|
max,
|
|
95
108
|
alignSelf = 'auto',
|
|
96
109
|
direction = 'column',
|
|
97
|
-
|
|
98
|
-
|
|
110
|
+
containerStyles,
|
|
111
|
+
inputStyles,
|
|
112
|
+
increaseTriggerStyles,
|
|
113
|
+
decreaseTriggerStyles,
|
|
114
|
+
}: NumberInputProps) => {
|
|
99
115
|
NumberInputStyles.useVariants({variant, size, distribution})
|
|
100
116
|
const [internalValue, setInternalValue] = useState<number>(defaultValue)
|
|
101
117
|
const isControlled = propValue !== undefined && propOnChange !== undefined
|
|
@@ -110,7 +126,7 @@ const NumberInput = {
|
|
|
110
126
|
}
|
|
111
127
|
|
|
112
128
|
return (
|
|
113
|
-
<
|
|
129
|
+
<NumberInputContext.Provider
|
|
114
130
|
value={{
|
|
115
131
|
value,
|
|
116
132
|
setValue,
|
|
@@ -123,17 +139,20 @@ const NumberInput = {
|
|
|
123
139
|
flex,
|
|
124
140
|
alignSelf,
|
|
125
141
|
direction,
|
|
142
|
+
inputStyles,
|
|
143
|
+
increaseTriggerStyles,
|
|
144
|
+
decreaseTriggerStyles,
|
|
126
145
|
}}>
|
|
127
146
|
<View
|
|
128
147
|
testID="varia-select-root"
|
|
129
148
|
style={[
|
|
130
|
-
simpleNumberInputstyles.rootContainer(flex, alignSelf),
|
|
131
149
|
NumberInputStyles.container(colorPalette),
|
|
132
|
-
|
|
150
|
+
containerStyles,
|
|
151
|
+
styles.rootContainer(flex, alignSelf),
|
|
133
152
|
]}>
|
|
134
153
|
{children}
|
|
135
154
|
</View>
|
|
136
|
-
</
|
|
155
|
+
</NumberInputContext.Provider>
|
|
137
156
|
)
|
|
138
157
|
},
|
|
139
158
|
|
|
@@ -148,11 +167,11 @@ const NumberInput = {
|
|
|
148
167
|
distribution,
|
|
149
168
|
min,
|
|
150
169
|
max,
|
|
151
|
-
|
|
170
|
+
inputStyles,
|
|
152
171
|
flex,
|
|
153
172
|
alignSelf,
|
|
154
173
|
direction,
|
|
155
|
-
} = {...
|
|
174
|
+
} = {...useNumberInputContext(), ...props}
|
|
156
175
|
const resolvedDirection =
|
|
157
176
|
direction === 'row'
|
|
158
177
|
? distribution === 'horizontal'
|
|
@@ -180,9 +199,9 @@ const NumberInput = {
|
|
|
180
199
|
<TextInput
|
|
181
200
|
testID="varia-select-input"
|
|
182
201
|
style={[
|
|
183
|
-
simpleNumberInputstyles.input(childFlex as number),
|
|
184
202
|
NumberInputStyles.input(colorPalette),
|
|
185
|
-
|
|
203
|
+
inputStyles,
|
|
204
|
+
styles.input(childFlex as number),
|
|
186
205
|
]}
|
|
187
206
|
keyboardType="numeric"
|
|
188
207
|
value={value.toString()}
|
|
@@ -203,11 +222,10 @@ const NumberInput = {
|
|
|
203
222
|
colorPalette = 'accent',
|
|
204
223
|
children,
|
|
205
224
|
max,
|
|
206
|
-
|
|
225
|
+
increaseTriggerStyles,
|
|
226
|
+
} = {...useNumberInputContext(), ...props}
|
|
207
227
|
NumberInputStyles.useVariants({variant, size, distribution})
|
|
208
228
|
|
|
209
|
-
// const color = (NumberInputStyles.buttons(colorPalette) as {color: string})
|
|
210
|
-
// .color
|
|
211
229
|
const color = getVariantValue(
|
|
212
230
|
NumberInputStyles.buttons(colorPalette),
|
|
213
231
|
'variant',
|
|
@@ -228,9 +246,10 @@ const NumberInput = {
|
|
|
228
246
|
onPress={() => setValue(value + 1)}
|
|
229
247
|
disabled={max !== undefined && value >= max}
|
|
230
248
|
style={[
|
|
231
|
-
simpleNumberInputstyles.button,
|
|
232
249
|
NumberInputStyles.buttons(colorPalette),
|
|
233
250
|
NumberInputStyles.increaseTrigger(colorPalette),
|
|
251
|
+
increaseTriggerStyles,
|
|
252
|
+
styles.button,
|
|
234
253
|
]}>
|
|
235
254
|
{iconWithProps}
|
|
236
255
|
</Pressable>
|
|
@@ -247,7 +266,8 @@ const NumberInput = {
|
|
|
247
266
|
colorPalette = 'accent',
|
|
248
267
|
children,
|
|
249
268
|
min,
|
|
250
|
-
|
|
269
|
+
decreaseTriggerStyles,
|
|
270
|
+
} = {...useNumberInputContext(), ...props}
|
|
251
271
|
NumberInputStyles.useVariants({variant, size, distribution})
|
|
252
272
|
|
|
253
273
|
// const color = (NumberInputStyles.buttons(colorPalette) as {color: string})
|
|
@@ -272,9 +292,10 @@ const NumberInput = {
|
|
|
272
292
|
onPress={() => setValue(value - 1)}
|
|
273
293
|
disabled={min !== undefined && value <= min}
|
|
274
294
|
style={[
|
|
275
|
-
simpleNumberInputstyles.button,
|
|
276
295
|
NumberInputStyles.buttons(colorPalette),
|
|
277
296
|
NumberInputStyles.decreaseTrigger(colorPalette),
|
|
297
|
+
decreaseTriggerStyles,
|
|
298
|
+
styles.button,
|
|
278
299
|
]}>
|
|
279
300
|
{iconWithProps}
|
|
280
301
|
</Pressable>
|
|
@@ -292,7 +313,7 @@ const DecreaseTriggerIcon = ({color}: {color?: string}) => {
|
|
|
292
313
|
|
|
293
314
|
export default NumberInput
|
|
294
315
|
|
|
295
|
-
const
|
|
316
|
+
const styles = StyleSheet.create({
|
|
296
317
|
rootContainer: (flex: number, alignSelf?: AlignSelf) => ({
|
|
297
318
|
flexDirection: 'row',
|
|
298
319
|
flex,
|