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.
- package/bin/cli.js +35 -18
- package/lib/components/Badge.tsx +31 -32
- package/lib/components/Button.tsx +20 -20
- package/lib/components/Checkbox.tsx +95 -0
- package/lib/components/CircleProgress.tsx +56 -66
- package/lib/components/Field.tsx +137 -0
- package/lib/components/GradientBackground.tsx +17 -18
- package/lib/components/GradientText.tsx +25 -64
- package/lib/components/IconWrapper.tsx +32 -25
- package/lib/components/Input.tsx +66 -68
- package/lib/components/Link.tsx +14 -28
- package/lib/components/Modal.tsx +197 -97
- package/lib/components/NewSelect.tsx +202 -0
- package/lib/components/NumberInput.tsx +226 -0
- package/lib/components/RadioGroup.tsx +195 -0
- package/lib/components/ReText.tsx +53 -87
- package/lib/components/Select.tsx +272 -0
- package/lib/components/SelectOld.tsx +153 -0
- package/lib/components/Slider.tsx +32 -40
- package/lib/components/Slideshow.tsx +174 -261
- package/lib/components/SlidingDrawer.tsx +216 -265
- package/lib/components/Spinner.tsx +21 -12
- package/lib/components/Switch.tsx +133 -180
- package/lib/components/Switchold.tsx +174 -0
- package/lib/components/Text.tsx +36 -83
- package/lib/components/layoutTest.tsx +74 -0
- package/lib/patterns/index.tsx +143 -202
- package/lib/theme/Badge.recipe.tsx +44 -39
- package/lib/theme/Button.recipe.tsx +139 -48
- package/lib/theme/Checkbox.recipe.tsx +121 -0
- package/lib/theme/CircleProgress.recipe.tsx +16 -22
- package/lib/theme/Field.recipe.tsx +66 -0
- package/lib/theme/GradientBackground.recipe.tsx +7 -20
- package/lib/theme/GradientText.recipe.tsx +42 -28
- package/lib/theme/IconWrapper.recipe.tsx +10 -85
- package/lib/theme/Input.recipe.tsx +76 -83
- package/lib/theme/Link.recipe.tsx +16 -43
- package/lib/theme/Modal.recipe.tsx +59 -21
- package/lib/theme/NumberInput.recipe.tsx +191 -0
- package/lib/theme/RadioGroup.recipe.tsx +163 -0
- package/lib/theme/ReText.recipe.tsx +4 -7
- package/lib/theme/Select.recipe.tsx +121 -0
- package/lib/theme/Slider.recipe.tsx +97 -181
- package/lib/theme/Slideshow.recipe.tsx +24 -102
- package/lib/theme/SlidingDrawer.recipe.tsx +21 -59
- package/lib/theme/Spinner.recipe.tsx +28 -3
- package/lib/theme/Switch.recipe.tsx +75 -54
- package/lib/theme/Text.recipe.tsx +66 -8
- package/lib/theme/animations.tsx +13 -0
- package/lib/varia/colorPalettes/amber.ts +54 -0
- package/lib/varia/colorPalettes/blue.ts +54 -0
- package/lib/varia/colorPalettes/bronze.ts +54 -0
- package/lib/varia/colorPalettes/brown.ts +54 -0
- package/lib/varia/colorPalettes/crimson.ts +55 -0
- package/lib/varia/colorPalettes/cyan.ts +54 -0
- package/lib/varia/colorPalettes/gold.ts +54 -0
- package/lib/varia/colorPalettes/grass.ts +54 -0
- package/lib/varia/colorPalettes/green.ts +54 -0
- package/lib/varia/colorPalettes/indigo.ts +54 -0
- package/lib/varia/colorPalettes/iris.ts +54 -0
- package/lib/varia/colorPalettes/jade.ts +54 -0
- package/lib/varia/colorPalettes/lime.ts +55 -0
- package/lib/varia/colorPalettes/mauve.ts +54 -0
- package/lib/varia/colorPalettes/mint.ts +54 -0
- package/lib/varia/colorPalettes/neutral.ts +54 -0
- package/lib/varia/colorPalettes/olive.ts +54 -0
- package/lib/varia/colorPalettes/orange.ts +54 -0
- package/lib/varia/colorPalettes/pink.ts +54 -0
- package/lib/varia/colorPalettes/plum.ts +54 -0
- package/lib/varia/colorPalettes/purple.ts +56 -0
- package/lib/varia/colorPalettes/red.ts +55 -0
- package/lib/varia/colorPalettes/ruby.ts +56 -0
- package/lib/varia/colorPalettes/sage.ts +56 -0
- package/lib/varia/colorPalettes/sand.ts +56 -0
- package/lib/varia/colorPalettes/sky.ts +56 -0
- package/lib/varia/colorPalettes/slate.ts +56 -0
- package/lib/varia/colorPalettes/teal.ts +56 -0
- package/lib/varia/colorPalettes/tomato.ts +56 -0
- package/lib/varia/colorPalettes/violet.ts +56 -0
- package/lib/varia/colorPalettes/yellow.ts +56 -0
- package/lib/varia/defaultTheme.ts +174 -0
- package/lib/varia/mixins.ts +223 -0
- package/lib/varia/textStyles.ts +48 -0
- package/lib/varia/types.ts +277 -0
- package/lib/varia/utils.ts +283 -0
- package/package.json +1 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import React, {createContext, useContext, useState} from 'react'
|
|
2
|
+
import {View, TextInput, Pressable} from 'react-native'
|
|
3
|
+
import {
|
|
4
|
+
NumberInputStyles,
|
|
5
|
+
NumberInputDefaultVariants,
|
|
6
|
+
} from '../theme/NumberInput.recipe'
|
|
7
|
+
import {PalettesWithNestedKeys} from '../style/varia/types'
|
|
8
|
+
import {UnistylesVariants, StyleSheet} from 'react-native-unistyles'
|
|
9
|
+
import Arrow from '../icons/Arrow'
|
|
10
|
+
import Plus from '../icons/Plus'
|
|
11
|
+
import Minus from '../icons/Minus'
|
|
12
|
+
|
|
13
|
+
type NumberInputVariants = UnistylesVariants<typeof NumberInputStyles>
|
|
14
|
+
|
|
15
|
+
type PublicInputProps = Omit<NumberInputVariants, 'variant' | 'size'> & {
|
|
16
|
+
placeholder?: string
|
|
17
|
+
}
|
|
18
|
+
type PublicTriggerProps = {
|
|
19
|
+
children?: React.ReactNode
|
|
20
|
+
variant?: NumberInputVariants['variant']
|
|
21
|
+
size?: NumberInputVariants['size']
|
|
22
|
+
colorPalette?: PalettesWithNestedKeys
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type SimpleNumberInputProps = NumberInputVariants & {
|
|
26
|
+
value?: number
|
|
27
|
+
onChange?: (n: number) => void
|
|
28
|
+
onBlur?: () => void
|
|
29
|
+
defaultValue?: number
|
|
30
|
+
colorPalette?: PalettesWithNestedKeys
|
|
31
|
+
flex?: number
|
|
32
|
+
min?: number
|
|
33
|
+
max?: number
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const SimpleNumberInputContext = createContext<{
|
|
37
|
+
value: number
|
|
38
|
+
setValue: (n: number) => void
|
|
39
|
+
onBlur?: () => void
|
|
40
|
+
colorPalette?: PalettesWithNestedKeys
|
|
41
|
+
variant?: NumberInputVariants['variant']
|
|
42
|
+
size?: NumberInputVariants['size']
|
|
43
|
+
distribution?: NumberInputVariants['distribution']
|
|
44
|
+
min?: number
|
|
45
|
+
max?: number
|
|
46
|
+
}>({
|
|
47
|
+
value: 0,
|
|
48
|
+
setValue: () => {},
|
|
49
|
+
onBlur: undefined,
|
|
50
|
+
min: undefined,
|
|
51
|
+
max: undefined,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
function useSimpleNumberInputContext() {
|
|
55
|
+
const ctx = useContext(SimpleNumberInputContext)
|
|
56
|
+
if (!ctx) {
|
|
57
|
+
throw new Error('SimpleNumberInput.* must be inside SimpleNumberInput.Root')
|
|
58
|
+
}
|
|
59
|
+
return ctx
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const NumberInput = {
|
|
63
|
+
Root: ({
|
|
64
|
+
value: propValue,
|
|
65
|
+
onChange: propOnChange,
|
|
66
|
+
onBlur: propOnBlur,
|
|
67
|
+
defaultValue = 0,
|
|
68
|
+
colorPalette = 'accent',
|
|
69
|
+
distribution = NumberInputDefaultVariants.distribution,
|
|
70
|
+
variant = NumberInputDefaultVariants.variant,
|
|
71
|
+
size = NumberInputDefaultVariants.size,
|
|
72
|
+
children,
|
|
73
|
+
flex = 1,
|
|
74
|
+
min,
|
|
75
|
+
max,
|
|
76
|
+
}: React.PropsWithChildren<SimpleNumberInputProps>) => {
|
|
77
|
+
NumberInputStyles.useVariants({variant, size, distribution})
|
|
78
|
+
const [internalValue, setInternalValue] = useState<number>(defaultValue)
|
|
79
|
+
const isControlled = propValue !== undefined && propOnChange !== undefined
|
|
80
|
+
const value = isControlled ? propValue! : internalValue
|
|
81
|
+
|
|
82
|
+
const setValue = (n: number) => {
|
|
83
|
+
if (isControlled) {
|
|
84
|
+
propOnChange!(n)
|
|
85
|
+
} else {
|
|
86
|
+
setInternalValue(n)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<SimpleNumberInputContext.Provider
|
|
92
|
+
value={{
|
|
93
|
+
value,
|
|
94
|
+
setValue,
|
|
95
|
+
onBlur: propOnBlur,
|
|
96
|
+
min,
|
|
97
|
+
max,
|
|
98
|
+
variant,
|
|
99
|
+
size,
|
|
100
|
+
distribution,
|
|
101
|
+
}}>
|
|
102
|
+
<View
|
|
103
|
+
style={[
|
|
104
|
+
simpleNumberInputstyles.rootContainer(flex),
|
|
105
|
+
NumberInputStyles.container(colorPalette),
|
|
106
|
+
]}>
|
|
107
|
+
{children}
|
|
108
|
+
</View>
|
|
109
|
+
</SimpleNumberInputContext.Provider>
|
|
110
|
+
)
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
Input: ({placeholder, ...props}: PublicInputProps) => {
|
|
114
|
+
const {
|
|
115
|
+
value,
|
|
116
|
+
setValue,
|
|
117
|
+
onBlur,
|
|
118
|
+
colorPalette = 'accent',
|
|
119
|
+
variant,
|
|
120
|
+
size,
|
|
121
|
+
distribution,
|
|
122
|
+
min,
|
|
123
|
+
max,
|
|
124
|
+
} = {...useSimpleNumberInputContext(), ...props}
|
|
125
|
+
const handleChangeText = (text: string) => {
|
|
126
|
+
const numeric = text.replace(/[^0-9]/g, '')
|
|
127
|
+
let num = numeric === '' ? 0 : parseInt(numeric, 10)
|
|
128
|
+
if (min !== undefined && num < min) num = min
|
|
129
|
+
if (max !== undefined && num > max) num = max
|
|
130
|
+
setValue(num)
|
|
131
|
+
}
|
|
132
|
+
NumberInputStyles.useVariants({variant, size, distribution})
|
|
133
|
+
return (
|
|
134
|
+
<TextInput
|
|
135
|
+
style={[
|
|
136
|
+
simpleNumberInputstyles.input,
|
|
137
|
+
NumberInputStyles.input(colorPalette),
|
|
138
|
+
]}
|
|
139
|
+
keyboardType="numeric"
|
|
140
|
+
value={value.toString()}
|
|
141
|
+
onChangeText={handleChangeText}
|
|
142
|
+
onBlur={onBlur}
|
|
143
|
+
placeholder={placeholder}
|
|
144
|
+
/>
|
|
145
|
+
)
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
Increment: ({...props}: PublicTriggerProps) => {
|
|
149
|
+
const {
|
|
150
|
+
value,
|
|
151
|
+
setValue,
|
|
152
|
+
variant = NumberInputDefaultVariants.variant,
|
|
153
|
+
size = NumberInputDefaultVariants.size,
|
|
154
|
+
distribution = NumberInputDefaultVariants.distribution,
|
|
155
|
+
colorPalette = 'accent',
|
|
156
|
+
children,
|
|
157
|
+
min,
|
|
158
|
+
max,
|
|
159
|
+
} = {...useSimpleNumberInputContext(), ...props}
|
|
160
|
+
NumberInputStyles.useVariants({variant, size, distribution})
|
|
161
|
+
return (
|
|
162
|
+
<Pressable
|
|
163
|
+
onPress={() => setValue(value + 1)}
|
|
164
|
+
disabled={max !== undefined && value >= max}
|
|
165
|
+
style={[
|
|
166
|
+
simpleNumberInputstyles.button,
|
|
167
|
+
NumberInputStyles.buttons(colorPalette),
|
|
168
|
+
NumberInputStyles.increaseTrigger(colorPalette),
|
|
169
|
+
]}>
|
|
170
|
+
{children || <IncreaseTriggerIcon />}
|
|
171
|
+
</Pressable>
|
|
172
|
+
)
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
Decrement: ({...props}: PublicTriggerProps) => {
|
|
176
|
+
const {
|
|
177
|
+
value,
|
|
178
|
+
setValue,
|
|
179
|
+
variant = NumberInputDefaultVariants.variant,
|
|
180
|
+
size = NumberInputDefaultVariants.size,
|
|
181
|
+
distribution = NumberInputDefaultVariants.distribution,
|
|
182
|
+
colorPalette = 'accent',
|
|
183
|
+
children,
|
|
184
|
+
min,
|
|
185
|
+
max,
|
|
186
|
+
} = {...useSimpleNumberInputContext(), ...props}
|
|
187
|
+
NumberInputStyles.useVariants({variant, size, distribution})
|
|
188
|
+
return (
|
|
189
|
+
<Pressable
|
|
190
|
+
onPress={() => setValue(value - 1)}
|
|
191
|
+
disabled={min !== undefined && value <= min}
|
|
192
|
+
style={[
|
|
193
|
+
simpleNumberInputstyles.button,
|
|
194
|
+
NumberInputStyles.buttons(colorPalette),
|
|
195
|
+
NumberInputStyles.decreaseTrigger(colorPalette),
|
|
196
|
+
]}>
|
|
197
|
+
{children || <DecreaseTriggerIcon />}
|
|
198
|
+
</Pressable>
|
|
199
|
+
)
|
|
200
|
+
},
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const IncreaseTriggerIcon = () => {
|
|
204
|
+
return <Plus scale={0.8} variant="solid" />
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const DecreaseTriggerIcon = () => {
|
|
208
|
+
return <Minus scale={0.8} variant="solid" />
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export default NumberInput
|
|
212
|
+
|
|
213
|
+
const simpleNumberInputstyles = StyleSheet.create({
|
|
214
|
+
rootContainer: (flex: number) => ({
|
|
215
|
+
flexDirection: 'row',
|
|
216
|
+
flexGrow: flex,
|
|
217
|
+
alignSelf: 'flex-start',
|
|
218
|
+
}),
|
|
219
|
+
input: {
|
|
220
|
+
paddingVertical: 0,
|
|
221
|
+
},
|
|
222
|
+
button: {
|
|
223
|
+
justifyContent: 'center',
|
|
224
|
+
alignItems: 'center',
|
|
225
|
+
},
|
|
226
|
+
})
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import React, {createContext, useContext, useState, useCallback} from 'react'
|
|
2
|
+
import {View, Text, Pressable} from 'react-native'
|
|
3
|
+
import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
|
|
4
|
+
import {
|
|
5
|
+
RadioGroupStyles,
|
|
6
|
+
RadioGroupDefaultVariants,
|
|
7
|
+
} from '../theme/RadioGroup.recipe'
|
|
8
|
+
import {PalettesWithNestedKeys} from '../style/varia/types'
|
|
9
|
+
|
|
10
|
+
type RadioGroupVariants = UnistylesVariants<typeof RadioGroupStyles>
|
|
11
|
+
|
|
12
|
+
type RadioGroupRootProps = RadioGroupVariants & {
|
|
13
|
+
children: React.ReactNode
|
|
14
|
+
colorPalette?: PalettesWithNestedKeys
|
|
15
|
+
defaultValue?: string
|
|
16
|
+
onValueChange?: (value: string) => void
|
|
17
|
+
direction?: 'horizontal' | 'vertical'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type RadioGroupContextProps = {
|
|
21
|
+
value?: string
|
|
22
|
+
onValueChange: (newValue: string) => void
|
|
23
|
+
colorPalette: PalettesWithNestedKeys
|
|
24
|
+
variant: RadioGroupVariants['variant']
|
|
25
|
+
size: RadioGroupVariants['size']
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const RadioGroupContext = createContext<RadioGroupContextProps | null>(null)
|
|
29
|
+
|
|
30
|
+
function useRadioGroupContext() {
|
|
31
|
+
const context = useContext(RadioGroupContext)
|
|
32
|
+
if (!context) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
'RadioGroup.* component must be rendered within a RadioGroup.Root',
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
return context
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function Root({
|
|
41
|
+
children,
|
|
42
|
+
defaultValue,
|
|
43
|
+
colorPalette = 'accent',
|
|
44
|
+
variant = RadioGroupDefaultVariants.variant,
|
|
45
|
+
size = RadioGroupDefaultVariants.size,
|
|
46
|
+
onValueChange,
|
|
47
|
+
direction = 'vertical',
|
|
48
|
+
}: RadioGroupRootProps) {
|
|
49
|
+
RadioGroupStyles.useVariants({variant, size})
|
|
50
|
+
const [value, setValue] = useState(defaultValue)
|
|
51
|
+
|
|
52
|
+
const handleValueChange = useCallback(
|
|
53
|
+
(newValue: string) => {
|
|
54
|
+
setValue(newValue)
|
|
55
|
+
if (onValueChange) {
|
|
56
|
+
onValueChange(newValue)
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
[onValueChange],
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const contextValue = {
|
|
63
|
+
value,
|
|
64
|
+
onValueChange: handleValueChange,
|
|
65
|
+
colorPalette,
|
|
66
|
+
variant,
|
|
67
|
+
size,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<RadioGroupContext.Provider value={contextValue}>
|
|
72
|
+
<View
|
|
73
|
+
style={[
|
|
74
|
+
styles.root,
|
|
75
|
+
RadioGroupStyles.container(colorPalette),
|
|
76
|
+
direction === 'horizontal' && styles.rootHorizontal,
|
|
77
|
+
]}>
|
|
78
|
+
{children}
|
|
79
|
+
</View>
|
|
80
|
+
</RadioGroupContext.Provider>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
type PublicItemProps = {
|
|
85
|
+
value: string
|
|
86
|
+
children: React.ReactNode
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function Item({children, value: itemValue}: PublicItemProps) {
|
|
90
|
+
const context = useRadioGroupContext()
|
|
91
|
+
const {value, onValueChange, colorPalette, variant, size} = context
|
|
92
|
+
const isSelected = value === itemValue
|
|
93
|
+
|
|
94
|
+
RadioGroupStyles.useVariants({
|
|
95
|
+
variant,
|
|
96
|
+
size,
|
|
97
|
+
checked: isSelected,
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
const childrenWithValue = React.Children.map(children, child => {
|
|
101
|
+
if (React.isValidElement(child)) {
|
|
102
|
+
return React.cloneElement(child as React.ReactElement<any>, {
|
|
103
|
+
itemValue,
|
|
104
|
+
isSelected,
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
return child
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<Pressable
|
|
112
|
+
style={[styles.item, RadioGroupStyles.item(colorPalette)]}
|
|
113
|
+
onPress={() => onValueChange(itemValue)}
|
|
114
|
+
accessibilityRole="radio"
|
|
115
|
+
accessibilityState={{checked: isSelected}}>
|
|
116
|
+
{childrenWithValue}
|
|
117
|
+
</Pressable>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function Indicator({
|
|
122
|
+
...props
|
|
123
|
+
}: Partial<RadioGroupVariants> & {itemValue?: string}) {
|
|
124
|
+
const {
|
|
125
|
+
itemValue,
|
|
126
|
+
value,
|
|
127
|
+
variant,
|
|
128
|
+
size,
|
|
129
|
+
colorPalette = 'accent',
|
|
130
|
+
} = {
|
|
131
|
+
...useRadioGroupContext(),
|
|
132
|
+
...props,
|
|
133
|
+
}
|
|
134
|
+
const isSelected = value === itemValue
|
|
135
|
+
RadioGroupStyles.useVariants({
|
|
136
|
+
variant,
|
|
137
|
+
size,
|
|
138
|
+
checked: isSelected,
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<View style={RadioGroupStyles.control(colorPalette)}>
|
|
143
|
+
<View style={RadioGroupStyles.indicator(colorPalette)} />
|
|
144
|
+
</View>
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function ItemText({
|
|
149
|
+
children,
|
|
150
|
+
...props
|
|
151
|
+
}: {
|
|
152
|
+
children: React.ReactNode
|
|
153
|
+
itemValue?: string
|
|
154
|
+
}) {
|
|
155
|
+
const {
|
|
156
|
+
value,
|
|
157
|
+
itemValue,
|
|
158
|
+
variant,
|
|
159
|
+
size,
|
|
160
|
+
colorPalette = 'accent',
|
|
161
|
+
} = {
|
|
162
|
+
...useRadioGroupContext(),
|
|
163
|
+
...props,
|
|
164
|
+
}
|
|
165
|
+
const isSelected = value === itemValue
|
|
166
|
+
RadioGroupStyles.useVariants({
|
|
167
|
+
variant,
|
|
168
|
+
size,
|
|
169
|
+
checked: isSelected,
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<Text style={[RadioGroupStyles.itemText(colorPalette)]}>{children}</Text>
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const styles = StyleSheet.create({
|
|
178
|
+
root: {
|
|
179
|
+
flexDirection: 'column',
|
|
180
|
+
},
|
|
181
|
+
rootHorizontal: {
|
|
182
|
+
flexDirection: 'row',
|
|
183
|
+
},
|
|
184
|
+
item: {
|
|
185
|
+
flexDirection: 'row',
|
|
186
|
+
alignItems: 'center',
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
export const RadioGroup = {
|
|
191
|
+
Root,
|
|
192
|
+
Item,
|
|
193
|
+
Indicator,
|
|
194
|
+
ItemText,
|
|
195
|
+
}
|
|
@@ -1,28 +1,38 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import Animated, { useAnimatedProps
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import type {StyleProp, TextInputProps, TextStyle} from 'react-native'
|
|
2
|
+
import {TextInput} from 'react-native'
|
|
3
|
+
import Animated, {SharedValue, useAnimatedProps} from 'react-native-reanimated'
|
|
4
|
+
import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
|
|
5
|
+
import {
|
|
6
|
+
PalettesWithNestedKeys,
|
|
7
|
+
TextSemanticSizes,
|
|
8
|
+
ThemeColors,
|
|
9
|
+
} from '../style/varia/types'
|
|
10
|
+
import {TextStyles, DefaultTextVariants} from '../theme/Text.recipe'
|
|
11
|
+
import {useMemo} from 'react'
|
|
12
|
+
import {extractThemeColor} from '../style/varia/utils'
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
type ReTextVariants = UnistylesVariants<typeof TextStyles>
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
type TextProps = ReTextVariants &
|
|
17
|
+
Omit<TextInputProps, 'value' | 'style'> & {
|
|
18
|
+
colorPalette?: PalettesWithNestedKeys
|
|
19
|
+
text: SharedValue<string>
|
|
20
|
+
as?: TextSemanticSizes
|
|
21
|
+
fontSize?: number | undefined
|
|
22
|
+
color?: ThemeColors
|
|
23
|
+
style?: TextStyle
|
|
24
|
+
children?: React.ReactNode
|
|
25
|
+
numberOfLines?: number
|
|
26
|
+
adjustsFontSizeToFit?: boolean
|
|
27
|
+
mixins?: StyleProp<TextStyle> | StyleProp<TextStyle>[]
|
|
28
|
+
}
|
|
22
29
|
|
|
23
|
-
const AnimatedTextInput = Animated.createAnimatedComponent(TextInput)
|
|
30
|
+
const AnimatedTextInput = Animated.createAnimatedComponent(TextInput)
|
|
24
31
|
|
|
25
32
|
const ReText = ({
|
|
33
|
+
colorPalette = 'accent',
|
|
34
|
+
variant,
|
|
35
|
+
size = DefaultTextVariants.size,
|
|
26
36
|
as = 'body',
|
|
27
37
|
fontSize,
|
|
28
38
|
color,
|
|
@@ -31,94 +41,50 @@ const ReText = ({
|
|
|
31
41
|
mixins,
|
|
32
42
|
...rest
|
|
33
43
|
}: TextProps) => {
|
|
44
|
+
TextStyles.useVariants({
|
|
45
|
+
variant,
|
|
46
|
+
size,
|
|
47
|
+
})
|
|
34
48
|
|
|
35
|
-
|
|
36
|
-
as,
|
|
37
|
-
});
|
|
49
|
+
const initialValue = useMemo(() => text.value, [text])
|
|
38
50
|
|
|
39
51
|
const animatedProps = useAnimatedProps(() => {
|
|
40
52
|
return {
|
|
41
53
|
text: text.value,
|
|
42
|
-
} as any
|
|
43
|
-
})
|
|
54
|
+
} as any
|
|
55
|
+
})
|
|
44
56
|
return (
|
|
45
57
|
<AnimatedTextInput
|
|
46
58
|
underlineColorAndroid="transparent"
|
|
47
59
|
multiline={true}
|
|
48
60
|
editable={false}
|
|
49
|
-
value={
|
|
61
|
+
value={initialValue}
|
|
50
62
|
style={[
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
TextStyles.text(colorPalette),
|
|
64
|
+
styles.text(fontSize, color),
|
|
65
|
+
style && style,
|
|
53
66
|
mixins && mixins,
|
|
54
67
|
]}
|
|
55
68
|
onStartShouldSetResponder={() => true}
|
|
56
69
|
{...rest}
|
|
57
|
-
{...{
|
|
70
|
+
{...{animatedProps}}
|
|
58
71
|
/>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
72
|
+
)
|
|
73
|
+
}
|
|
61
74
|
|
|
62
|
-
const styles = StyleSheet.create(
|
|
63
|
-
text: (
|
|
64
|
-
fontSize: number | undefined,
|
|
65
|
-
color: string | undefined,
|
|
66
|
-
defaultProps
|
|
67
|
-
) => ({
|
|
75
|
+
const styles = StyleSheet.create(theme => ({
|
|
76
|
+
text: (fontSize?: number, color?: string) => ({
|
|
68
77
|
verticalAlign: 'bottom',
|
|
69
78
|
padding: 0,
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
...(color && {
|
|
80
|
+
color: extractThemeColor(color, theme),
|
|
81
|
+
}),
|
|
82
|
+
...(fontSize && {fontSize}),
|
|
72
83
|
textAlign: 'left',
|
|
73
|
-
color: color || defaultProps.color,
|
|
74
|
-
variants: {
|
|
75
|
-
as: {
|
|
76
|
-
h1: {
|
|
77
|
-
//@ts-ignore
|
|
78
|
-
fontSize: fontSize || theme.fontSizes.xxl,
|
|
79
|
-
},
|
|
80
|
-
h2: {
|
|
81
|
-
//@ts-ignore
|
|
82
|
-
fontSize: fontSize || theme.fontSizes.xl,
|
|
83
|
-
},
|
|
84
|
-
h3: {
|
|
85
|
-
//@ts-ignore
|
|
86
|
-
fontSize: fontSize || theme.fontSizes.lg,
|
|
87
|
-
},
|
|
88
|
-
h4: {
|
|
89
|
-
//@ts-ignore
|
|
90
|
-
fontSize: fontSize || theme.fontSizes.md,
|
|
91
|
-
},
|
|
92
|
-
h5: {
|
|
93
|
-
//@ts-ignore
|
|
94
|
-
fontSize: fontSize || theme.fontSizes.sm,
|
|
95
|
-
},
|
|
96
|
-
h6: {
|
|
97
|
-
//@ts-ignore
|
|
98
|
-
fontSize: fontSize || theme.fontSizes.xs,
|
|
99
|
-
},
|
|
100
|
-
h7: {
|
|
101
|
-
//@ts-ignore
|
|
102
|
-
fontSize: fontSize || theme.fontSizes.xs,
|
|
103
|
-
},
|
|
104
|
-
h8: {
|
|
105
|
-
//@ts-ignore
|
|
106
|
-
fontSize: fontSize || theme.fontSizes.xxs,
|
|
107
|
-
},
|
|
108
|
-
h9: {
|
|
109
|
-
//@ts-ignore
|
|
110
|
-
fontSize: fontSize || theme.fontSizes.xxs,
|
|
111
|
-
},
|
|
112
|
-
body: {
|
|
113
|
-
//@ts-ignore
|
|
114
|
-
fontSize: fontSize || theme.fontSizes.md,
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
84
|
}),
|
|
119
|
-
customStyle:
|
|
85
|
+
customStyle: style => ({
|
|
120
86
|
...style,
|
|
121
87
|
}),
|
|
122
|
-
}))
|
|
88
|
+
}))
|
|
123
89
|
|
|
124
|
-
export default ReText
|
|
90
|
+
export default ReText
|