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,12 @@
|
|
|
1
1
|
import React, {createContext, useContext, useState, useCallback} from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
Pressable,
|
|
6
|
+
ViewStyle,
|
|
7
|
+
StyleProp,
|
|
8
|
+
TextStyle,
|
|
9
|
+
} from 'react-native'
|
|
3
10
|
import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
|
|
4
11
|
import {
|
|
5
12
|
RadioGroupStyles,
|
|
@@ -28,6 +35,10 @@ type RadioGroupRootProps = RadioGroupVariants & {
|
|
|
28
35
|
justifyContent?: JustifyContent
|
|
29
36
|
alignItems?: AlignItems
|
|
30
37
|
gap?: Gap
|
|
38
|
+
containerStyles?: StyleProp<ViewStyle>
|
|
39
|
+
itemStyles?: StyleProp<ViewStyle>
|
|
40
|
+
indicatorStyles?: StyleProp<ViewStyle>
|
|
41
|
+
itemTextStyles?: StyleProp<TextStyle>
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
type RadioGroupContextProps = {
|
|
@@ -38,6 +49,9 @@ type RadioGroupContextProps = {
|
|
|
38
49
|
size: RadioGroupVariants['size']
|
|
39
50
|
flex: Flex
|
|
40
51
|
alignSelf?: AlignSelf
|
|
52
|
+
itemStyles?: StyleProp<ViewStyle>
|
|
53
|
+
indicatorStyles?: StyleProp<ViewStyle>
|
|
54
|
+
itemTextStyles?: StyleProp<ViewStyle>
|
|
41
55
|
}
|
|
42
56
|
|
|
43
57
|
const RadioGroupContext = createContext<RadioGroupContextProps | null>(null)
|
|
@@ -65,6 +79,10 @@ function Root({
|
|
|
65
79
|
justifyContent = 'space-between',
|
|
66
80
|
alignItems,
|
|
67
81
|
gap,
|
|
82
|
+
containerStyles,
|
|
83
|
+
itemStyles,
|
|
84
|
+
indicatorStyles,
|
|
85
|
+
itemTextStyles,
|
|
68
86
|
}: RadioGroupRootProps) {
|
|
69
87
|
RadioGroupStyles.useVariants({variant, size})
|
|
70
88
|
const [value, setValue] = useState(defaultValue)
|
|
@@ -86,6 +104,9 @@ function Root({
|
|
|
86
104
|
variant,
|
|
87
105
|
size,
|
|
88
106
|
flex,
|
|
107
|
+
itemStyles,
|
|
108
|
+
indicatorStyles,
|
|
109
|
+
itemTextStyles,
|
|
89
110
|
}
|
|
90
111
|
|
|
91
112
|
return (
|
|
@@ -93,6 +114,8 @@ function Root({
|
|
|
93
114
|
<View
|
|
94
115
|
testID="varia-radio-group-root"
|
|
95
116
|
style={[
|
|
117
|
+
RadioGroupStyles.container(colorPalette),
|
|
118
|
+
containerStyles,
|
|
96
119
|
styles.root(
|
|
97
120
|
flex,
|
|
98
121
|
direction,
|
|
@@ -101,7 +124,6 @@ function Root({
|
|
|
101
124
|
alignItems as ViewStyle['alignItems'],
|
|
102
125
|
gap,
|
|
103
126
|
),
|
|
104
|
-
RadioGroupStyles.container(colorPalette),
|
|
105
127
|
]}>
|
|
106
128
|
{children}
|
|
107
129
|
</View>
|
|
@@ -116,7 +138,8 @@ type PublicItemProps = {
|
|
|
116
138
|
|
|
117
139
|
function Item({children, value: itemValue}: PublicItemProps) {
|
|
118
140
|
const context = useRadioGroupContext()
|
|
119
|
-
const {value, onValueChange, colorPalette, variant, size} =
|
|
141
|
+
const {value, onValueChange, colorPalette, variant, size, itemStyles} =
|
|
142
|
+
context
|
|
120
143
|
const isSelected = value === itemValue
|
|
121
144
|
|
|
122
145
|
RadioGroupStyles.useVariants({
|
|
@@ -143,8 +166,9 @@ function Item({children, value: itemValue}: PublicItemProps) {
|
|
|
143
166
|
aria-checked={value === itemValue}
|
|
144
167
|
testID={`varia-radio-group-item-${value}`}
|
|
145
168
|
style={({pressed}) => [
|
|
146
|
-
styles.item,
|
|
147
169
|
RadioGroupStyles.item(colorPalette, pressed),
|
|
170
|
+
itemStyles,
|
|
171
|
+
styles.item,
|
|
148
172
|
]}
|
|
149
173
|
onPress={() => onValueChange(itemValue)}
|
|
150
174
|
accessibilityRole="radio"
|
|
@@ -163,10 +187,12 @@ function Indicator({
|
|
|
163
187
|
variant,
|
|
164
188
|
size,
|
|
165
189
|
colorPalette = 'accent',
|
|
190
|
+
indicatorStyles,
|
|
166
191
|
} = {
|
|
167
192
|
...useRadioGroupContext(),
|
|
168
193
|
...props,
|
|
169
194
|
}
|
|
195
|
+
console.log('🚀 ~ indicatorStyles:', indicatorStyles)
|
|
170
196
|
const isSelected = value === itemValue
|
|
171
197
|
RadioGroupStyles.useVariants({
|
|
172
198
|
variant,
|
|
@@ -177,7 +203,7 @@ function Indicator({
|
|
|
177
203
|
return (
|
|
178
204
|
<View
|
|
179
205
|
testID="varia-radio-group-indicator"
|
|
180
|
-
style={RadioGroupStyles.control(colorPalette)}>
|
|
206
|
+
style={[RadioGroupStyles.control(colorPalette), indicatorStyles]}>
|
|
181
207
|
<View style={RadioGroupStyles.indicator(colorPalette)} />
|
|
182
208
|
</View>
|
|
183
209
|
)
|
|
@@ -196,6 +222,7 @@ function ItemText({
|
|
|
196
222
|
variant,
|
|
197
223
|
size,
|
|
198
224
|
colorPalette = 'accent',
|
|
225
|
+
itemTextStyles,
|
|
199
226
|
} = {
|
|
200
227
|
...useRadioGroupContext(),
|
|
201
228
|
...props,
|
|
@@ -208,7 +235,9 @@ function ItemText({
|
|
|
208
235
|
})
|
|
209
236
|
|
|
210
237
|
return (
|
|
211
|
-
<Text style={[RadioGroupStyles.itemText(colorPalette)]}>
|
|
238
|
+
<Text style={[RadioGroupStyles.itemText(colorPalette), itemTextStyles]}>
|
|
239
|
+
{children}
|
|
240
|
+
</Text>
|
|
212
241
|
)
|
|
213
242
|
}
|
|
214
243
|
|
|
@@ -61,9 +61,9 @@ const ReText = ({
|
|
|
61
61
|
value={initialValue}
|
|
62
62
|
style={[
|
|
63
63
|
TextStyles.text(colorPalette),
|
|
64
|
-
styles.text(fontSize, color),
|
|
65
64
|
style && style,
|
|
66
65
|
mixins && mixins,
|
|
66
|
+
styles.text(fontSize, color),
|
|
67
67
|
]}
|
|
68
68
|
onStartShouldSetResponder={() => true}
|
|
69
69
|
{...rest}
|
|
@@ -12,6 +12,9 @@ import {
|
|
|
12
12
|
ScrollView,
|
|
13
13
|
TouchableWithoutFeedback,
|
|
14
14
|
Pressable,
|
|
15
|
+
ViewStyle,
|
|
16
|
+
StyleProp,
|
|
17
|
+
TextStyle,
|
|
15
18
|
} from 'react-native'
|
|
16
19
|
import {UnistylesVariants} from 'react-native-unistyles'
|
|
17
20
|
import {Portal} from '@gorhom/portal'
|
|
@@ -50,6 +53,11 @@ interface SelectContextType {
|
|
|
50
53
|
size: SelectVariants['size']
|
|
51
54
|
flex: Flex
|
|
52
55
|
zIndex: ZIndex
|
|
56
|
+
triggerStyles?: StyleProp<ViewStyle>
|
|
57
|
+
overlayStyles?: StyleProp<ViewStyle>
|
|
58
|
+
contentStyles?: StyleProp<ViewStyle>
|
|
59
|
+
itemStyles?: StyleProp<ViewStyle>
|
|
60
|
+
itemTextStyles?: StyleProp<TextStyle>
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
const SelectContext = createContext<SelectContextType | undefined>(undefined)
|
|
@@ -74,6 +82,12 @@ type RootProps = SelectVariants & {
|
|
|
74
82
|
stretch?: AlignSelf
|
|
75
83
|
direction?: 'row' | 'column'
|
|
76
84
|
zIndex?: ZIndex
|
|
85
|
+
containerStyles?: StyleProp<ViewStyle>
|
|
86
|
+
triggerStyles?: StyleProp<ViewStyle>
|
|
87
|
+
overlayStyles?: StyleProp<ViewStyle>
|
|
88
|
+
contentStyles?: StyleProp<ViewStyle>
|
|
89
|
+
itemStyles?: StyleProp<ViewStyle>
|
|
90
|
+
itemTextStyles?: StyleProp<ViewStyle>
|
|
77
91
|
}
|
|
78
92
|
|
|
79
93
|
const SelectRoot = ({
|
|
@@ -90,6 +104,12 @@ const SelectRoot = ({
|
|
|
90
104
|
stretch,
|
|
91
105
|
direction = 'column',
|
|
92
106
|
zIndex,
|
|
107
|
+
containerStyles,
|
|
108
|
+
triggerStyles,
|
|
109
|
+
overlayStyles,
|
|
110
|
+
contentStyles,
|
|
111
|
+
itemStyles,
|
|
112
|
+
itemTextStyles,
|
|
93
113
|
}: RootProps) => {
|
|
94
114
|
SelectStyles.useVariants({variant, size})
|
|
95
115
|
const [internalValue, setInternalValue] = useState(defaultValue)
|
|
@@ -121,7 +141,9 @@ const SelectRoot = ({
|
|
|
121
141
|
)
|
|
122
142
|
|
|
123
143
|
return (
|
|
124
|
-
<View
|
|
144
|
+
<View
|
|
145
|
+
style={[containerStyles, styles.container(flex, stretch)]}
|
|
146
|
+
testID="varia-select-root">
|
|
125
147
|
{trigger &&
|
|
126
148
|
React.cloneElement(trigger as ReactElement<TriggerProps>, {
|
|
127
149
|
isOpen,
|
|
@@ -131,6 +153,7 @@ const SelectRoot = ({
|
|
|
131
153
|
flex,
|
|
132
154
|
stretch,
|
|
133
155
|
direction,
|
|
156
|
+
triggerStyles,
|
|
134
157
|
variant:
|
|
135
158
|
(trigger as ReactElement<TriggerProps>).props.variant ?? variant,
|
|
136
159
|
size: (trigger as ReactElement<TriggerProps>).props.size ?? size,
|
|
@@ -153,6 +176,11 @@ const SelectRoot = ({
|
|
|
153
176
|
size,
|
|
154
177
|
flex,
|
|
155
178
|
zIndex,
|
|
179
|
+
triggerStyles,
|
|
180
|
+
overlayStyles,
|
|
181
|
+
contentStyles,
|
|
182
|
+
itemStyles,
|
|
183
|
+
itemTextStyles,
|
|
156
184
|
}}>
|
|
157
185
|
<View style={styles.portalContainer(zIndex || ZINDEXES.select)}>
|
|
158
186
|
{portalChildren}
|
|
@@ -176,6 +204,7 @@ interface TriggerProps {
|
|
|
176
204
|
flex?: Flex
|
|
177
205
|
stretch?: AlignSelf
|
|
178
206
|
direction?: 'row' | 'column'
|
|
207
|
+
triggerStyles?: StyleProp<ViewStyle>
|
|
179
208
|
}
|
|
180
209
|
|
|
181
210
|
const SelectTrigger = ({
|
|
@@ -190,6 +219,7 @@ const SelectTrigger = ({
|
|
|
190
219
|
stretch,
|
|
191
220
|
direction,
|
|
192
221
|
options = [],
|
|
222
|
+
triggerStyles,
|
|
193
223
|
}: TriggerProps) => {
|
|
194
224
|
SelectStyles.useVariants({variant, size})
|
|
195
225
|
const {flex: childFlex} = useMemo(() => {
|
|
@@ -200,8 +230,9 @@ const SelectTrigger = ({
|
|
|
200
230
|
<Pressable
|
|
201
231
|
onPress={() => setIsOpen?.(!isOpen)}
|
|
202
232
|
style={({pressed}) => [
|
|
203
|
-
styles.input(childFlex),
|
|
204
233
|
SelectStyles.trigger(colorPalette, pressed),
|
|
234
|
+
triggerStyles,
|
|
235
|
+
styles.input(childFlex),
|
|
205
236
|
]}
|
|
206
237
|
testID="varia-select-trigger">
|
|
207
238
|
<Text>{selected ? selected.label : placeholder}</Text>
|
|
@@ -220,11 +251,15 @@ const SelectOverlay = ({
|
|
|
220
251
|
colorPalette?: PalettesWithNestedKeys
|
|
221
252
|
}) => {
|
|
222
253
|
SelectStyles.useVariants({variant, size})
|
|
223
|
-
const {setIsOpen} = useSelect()
|
|
254
|
+
const {setIsOpen, overlayStyles} = useSelect()
|
|
224
255
|
return (
|
|
225
256
|
<TouchableWithoutFeedback onPress={() => setIsOpen(false)}>
|
|
226
257
|
<View
|
|
227
|
-
style={[
|
|
258
|
+
style={[
|
|
259
|
+
SelectStyles.overlay(colorPalette),
|
|
260
|
+
overlayStyles,
|
|
261
|
+
styles.backdrop,
|
|
262
|
+
]}
|
|
228
263
|
testID="varia-select-overlay"
|
|
229
264
|
/>
|
|
230
265
|
</TouchableWithoutFeedback>
|
|
@@ -240,11 +275,18 @@ const SelectContent = ({
|
|
|
240
275
|
variant?: SelectVariants['variant']
|
|
241
276
|
size?: SelectVariants['size']
|
|
242
277
|
}) => {
|
|
243
|
-
const {variant, size, colorPalette} = {
|
|
278
|
+
const {variant, size, colorPalette, contentStyles} = {
|
|
279
|
+
...useSelect(),
|
|
280
|
+
...props,
|
|
281
|
+
}
|
|
244
282
|
SelectStyles.useVariants({variant, size})
|
|
245
283
|
return (
|
|
246
284
|
<View
|
|
247
|
-
style={[
|
|
285
|
+
style={[
|
|
286
|
+
SelectStyles.content(colorPalette),
|
|
287
|
+
contentStyles,
|
|
288
|
+
styles.modalContent,
|
|
289
|
+
]}
|
|
248
290
|
testID="varia-select-content">
|
|
249
291
|
<ScrollView>{children}</ScrollView>
|
|
250
292
|
</View>
|
|
@@ -259,6 +301,8 @@ const SelectItem = ({value, label, ...props}: Option) => {
|
|
|
259
301
|
setValue,
|
|
260
302
|
value: selected,
|
|
261
303
|
colorPalette,
|
|
304
|
+
itemStyles,
|
|
305
|
+
itemTextStyles,
|
|
262
306
|
} = {...useSelect(), ...props}
|
|
263
307
|
const isSelected = selected === value
|
|
264
308
|
SelectStyles.useVariants({variant, size})
|
|
@@ -267,8 +311,17 @@ const SelectItem = ({value, label, ...props}: Option) => {
|
|
|
267
311
|
onPress={() => setValue(value)}
|
|
268
312
|
testID="varia-select-item"
|
|
269
313
|
aria-selected={isSelected}>
|
|
270
|
-
<View
|
|
271
|
-
|
|
314
|
+
<View
|
|
315
|
+
style={[
|
|
316
|
+
SelectStyles.item(colorPalette, isSelected),
|
|
317
|
+
itemStyles,
|
|
318
|
+
styles.item,
|
|
319
|
+
]}>
|
|
320
|
+
<Text
|
|
321
|
+
style={[
|
|
322
|
+
SelectStyles.itemText(colorPalette, isSelected),
|
|
323
|
+
itemTextStyles,
|
|
324
|
+
]}>
|
|
272
325
|
{label}
|
|
273
326
|
</Text>
|
|
274
327
|
</View>
|