react-native-varia 0.3.0 → 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.
- package/lib/components/Accordion.tsx +61 -21
- package/lib/components/Badge.tsx +9 -0
- package/lib/components/Button.tsx +19 -8
- package/lib/components/Checkbox.tsx +21 -12
- package/lib/components/CircleProgress.tsx +8 -0
- package/lib/components/Divider.tsx +6 -0
- package/lib/components/Drawer.tsx +16 -4
- package/lib/components/Field.tsx +4 -0
- package/lib/components/GradientBackground.tsx +3 -0
- package/lib/components/GradientText.tsx +27 -14
- package/lib/components/IconWrapper.tsx +3 -2
- package/lib/components/Input.tsx +47 -21
- package/lib/components/Link.tsx +4 -0
- package/lib/components/Modal.tsx +18 -5
- package/lib/components/NumberInput.tsx +27 -5
- package/lib/components/RadioGroup.tsx +16 -5
- package/lib/components/ReText.tsx +4 -1
- package/lib/components/Select.tsx +20 -0
- package/lib/components/Slider.tsx +59 -23
- package/lib/components/Slideshow.tsx +19 -3
- package/lib/components/Spinner.tsx +9 -3
- package/lib/components/Switch.tsx +57 -26
- package/lib/components/Text.tsx +3 -0
- package/lib/components/Toast.tsx +110 -36
- package/lib/patterns/index.tsx +299 -90
- package/lib/theme/Accordion.tsx +184 -0
- package/lib/theme/Button.recipe.tsx +24 -7
- package/lib/theme/Drawer.recipe.tsx +2 -4
- package/lib/theme/Field.recipe.tsx +45 -15
- package/lib/theme/GradientText.recipe.tsx +103 -34
- package/lib/theme/Input.recipe.tsx +14 -6
- package/lib/theme/Select.recipe.tsx +3 -0
- package/lib/theme/Slider.recipe.tsx +86 -150
- package/lib/theme/Spinner.recipe.tsx +4 -0
- package/lib/theme/Switch.recipe.tsx +19 -0
- package/lib/theme/Text.recipe.tsx +63 -12
- package/lib/theme/Toast.recipe.tsx +40 -7
- package/lib/varia/types.ts +3 -0
- package/lib/varia/utils.ts +110 -18
- package/package.json +1 -1
- package/lib/components/OldSlider.tsx +0 -327
- package/lib/components/SlidingDrawer.tsx +0 -301
- package/lib/patterns/newPatterns.tsx +0 -285
package/lib/components/Input.tsx
CHANGED
|
@@ -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 ?
|
|
93
|
+
const iconPosition = icon ? icon.position || 'left' : null
|
|
93
94
|
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
const resolvedPlaceholderColor = getVariantValue(
|
|
96
|
+
InputStyles.placeholder(colorPalette),
|
|
97
|
+
'variant',
|
|
98
|
+
variant,
|
|
99
|
+
'color',
|
|
100
|
+
)
|
|
98
101
|
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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(
|
|
119
|
+
style: styles.icon(
|
|
120
|
+
iconPosition,
|
|
121
|
+
resolvedPaddingHorizontal,
|
|
122
|
+
textAlignVertical,
|
|
123
|
+
),
|
|
114
124
|
}}
|
|
115
125
|
/>
|
|
116
126
|
) : null
|
|
117
127
|
|
|
118
|
-
|
|
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
|
-
|
|
141
|
+
resolvedPaddingHorizontal,
|
|
136
142
|
textAlignVertical,
|
|
137
|
-
(icon?.size || 0) +
|
|
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={
|
|
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,12 +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,
|
|
193
|
-
outline: 'none'
|
|
212
|
+
outline: 'none',
|
|
213
|
+
flexBasis: 'auto',
|
|
214
|
+
_web: {
|
|
215
|
+
_classNames: 'input-base',
|
|
216
|
+
},
|
|
194
217
|
}),
|
|
195
218
|
icon: (iconPosition, paddingHorizontal, textAlignVertical) => ({
|
|
196
219
|
position: 'absolute',
|
|
@@ -198,6 +221,9 @@ const styles = StyleSheet.create({
|
|
|
198
221
|
...(iconPosition === 'right' && {right: paddingHorizontal}),
|
|
199
222
|
top: textAlignVertical !== 'top' ? 'auto' : 10,
|
|
200
223
|
bottom: textAlignVertical !== 'bottom' ? 'auto' : 10,
|
|
224
|
+
_web: {
|
|
225
|
+
_classNames: 'input-icon-base',
|
|
226
|
+
},
|
|
201
227
|
}),
|
|
202
228
|
})
|
|
203
229
|
|
package/lib/components/Link.tsx
CHANGED
|
@@ -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
|
|
package/lib/components/Modal.tsx
CHANGED
|
@@ -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,7 +90,7 @@ const ModalOverlay = ({children, ...props}: ModalOverlayProps) => {
|
|
|
89
90
|
ModalStyles.useVariants({variant})
|
|
90
91
|
|
|
91
92
|
return (
|
|
92
|
-
<
|
|
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}>
|
|
@@ -97,7 +98,7 @@ const ModalOverlay = ({children, ...props}: ModalOverlayProps) => {
|
|
|
97
98
|
<View style={StyleSheet.absoluteFillObject} />
|
|
98
99
|
</TouchableWithoutFeedback>
|
|
99
100
|
{children}
|
|
100
|
-
</
|
|
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
|
-
<
|
|
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
|
-
</
|
|
132
|
+
</AnimatedView>
|
|
132
133
|
)
|
|
133
134
|
}
|
|
134
135
|
|
|
@@ -217,11 +218,17 @@ const styles = StyleSheet.create(theme => {
|
|
|
217
218
|
zIndex: 1000,
|
|
218
219
|
justifyContent: 'center',
|
|
219
220
|
alignItems: 'center',
|
|
221
|
+
_web: {
|
|
222
|
+
_classNames: 'modal-overlay-base',
|
|
223
|
+
},
|
|
220
224
|
},
|
|
221
225
|
content: () => ({
|
|
222
226
|
justifyContent: 'center',
|
|
223
227
|
alignItems: 'center',
|
|
224
228
|
alignSelf: 'stretch',
|
|
229
|
+
_web: {
|
|
230
|
+
_classNames: 'modal-content-base',
|
|
231
|
+
},
|
|
225
232
|
}),
|
|
226
233
|
header: {
|
|
227
234
|
flexDirection: 'row',
|
|
@@ -229,9 +236,15 @@ const styles = StyleSheet.create(theme => {
|
|
|
229
236
|
alignItems: 'center',
|
|
230
237
|
width: '100%',
|
|
231
238
|
marginBottom: 10,
|
|
239
|
+
_web: {
|
|
240
|
+
_classNames: 'modal-header-base',
|
|
241
|
+
},
|
|
232
242
|
},
|
|
233
243
|
closeButton: {
|
|
234
244
|
color: 'white',
|
|
245
|
+
_web: {
|
|
246
|
+
_classNames: 'modal-close-button-base',
|
|
247
|
+
},
|
|
235
248
|
},
|
|
236
249
|
}
|
|
237
250
|
})
|
|
@@ -246,4 +259,4 @@ const Modal = Object.assign(ModalRoot, {
|
|
|
246
259
|
CloseTrigger: ModalCloseTrigger,
|
|
247
260
|
CloseButton: CloseButton,
|
|
248
261
|
})
|
|
249
|
-
export default Modal
|
|
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
|
-
|
|
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
|
-
|
|
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?:
|
|
25
|
-
alignItems?:
|
|
26
|
-
gap?:
|
|
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:
|
|
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,10 +222,17 @@ 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
|
|
|
@@ -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
|
})
|
|
@@ -9,6 +9,7 @@ import Animated, {
|
|
|
9
9
|
import {runOnJS} from 'react-native-worklets'
|
|
10
10
|
import {SliderStyles, SliderDefaultVariants} from '../theme/Slider.recipe'
|
|
11
11
|
import {PalettesWithNestedKeys} from '../style/varia/types'
|
|
12
|
+
import {getCompoundVariantValue} from '../style/varia/utils'
|
|
12
13
|
|
|
13
14
|
function throttle<T extends (...args: any[]) => any>(
|
|
14
15
|
func: T,
|
|
@@ -28,6 +29,8 @@ function throttle<T extends (...args: any[]) => any>(
|
|
|
28
29
|
|
|
29
30
|
type SliderVariants = UnistylesVariants<typeof SliderStyles>
|
|
30
31
|
|
|
32
|
+
const AnimatedView = Animated.createAnimatedComponent(View)
|
|
33
|
+
|
|
31
34
|
type ThumbStyleExtended = ReturnType<typeof SliderStyles.thumb> & {
|
|
32
35
|
width: number
|
|
33
36
|
height: number
|
|
@@ -38,7 +41,6 @@ type SliderProps = SliderVariants & {
|
|
|
38
41
|
thickness?: number
|
|
39
42
|
minimumTrackThickness?: number
|
|
40
43
|
minimumTrackColor?: string
|
|
41
|
-
displayStepsOnMinimumTrack?: boolean
|
|
42
44
|
thumbSize?: {
|
|
43
45
|
width: number
|
|
44
46
|
height: number
|
|
@@ -56,7 +58,6 @@ const Slider = ({
|
|
|
56
58
|
colorPalette = 'accent',
|
|
57
59
|
variant = SliderDefaultVariants.variant,
|
|
58
60
|
size = SliderDefaultVariants.size,
|
|
59
|
-
displayStepsOnMinimumTrack = false,
|
|
60
61
|
thumbChildren: ThumbChildren,
|
|
61
62
|
axis = 'x',
|
|
62
63
|
value = 0,
|
|
@@ -80,10 +81,21 @@ const Slider = ({
|
|
|
80
81
|
return throttle(onValueChange, 50)
|
|
81
82
|
}, [onValueChange])
|
|
82
83
|
|
|
83
|
-
const thumbStyle = SliderStyles.thumb(colorPalette) as ThumbStyleExtended
|
|
84
|
+
// const thumbStyle = SliderStyles.thumb(colorPalette) as ThumbStyleExtended
|
|
85
|
+
// const thumbWidth = getVariantValue(SliderStyles.thumb(colorPalette), 'size', size, 'width', true)
|
|
86
|
+
const thumbWidth = getCompoundVariantValue(
|
|
87
|
+
SliderStyles.thumb(colorPalette),
|
|
88
|
+
{axis, size},
|
|
89
|
+
'width',
|
|
90
|
+
)
|
|
91
|
+
const thumbHeight = getCompoundVariantValue(
|
|
92
|
+
SliderStyles.thumb(colorPalette),
|
|
93
|
+
{axis, size},
|
|
94
|
+
'height',
|
|
95
|
+
)
|
|
96
|
+
// const thumbHeight = getVariantValue(SliderStyles.thumb(colorPalette), 'size', size, 'height', true)
|
|
84
97
|
|
|
85
|
-
const halfSize =
|
|
86
|
-
axis === 'x' ? (thumbStyle.width ?? 0) / 2 : (thumbStyle.height ?? 0) / 2
|
|
98
|
+
const halfSize = ((axis === 'x' ? thumbWidth : thumbHeight) ?? 0) / 2
|
|
87
99
|
const context = useSharedValue({x: 0})
|
|
88
100
|
const translate = useSharedValue(value)
|
|
89
101
|
const trackLength = useSharedValue(0)
|
|
@@ -240,9 +252,11 @@ const Slider = ({
|
|
|
240
252
|
onSlidingComplete && runOnJS(onSlidingComplete)(snappedValue)
|
|
241
253
|
})
|
|
242
254
|
|
|
243
|
-
const animatedTrack = useAnimatedStyle(() =>
|
|
244
|
-
|
|
245
|
-
|
|
255
|
+
const animatedTrack = useAnimatedStyle(() => {
|
|
256
|
+
return {
|
|
257
|
+
[axis === 'y' ? 'height' : 'width']: translate.value + halfSize,
|
|
258
|
+
}
|
|
259
|
+
})
|
|
246
260
|
|
|
247
261
|
const animatedThumb = useAnimatedStyle(() => {
|
|
248
262
|
if (axis === 'x') {
|
|
@@ -257,8 +271,6 @@ const Slider = ({
|
|
|
257
271
|
}
|
|
258
272
|
})
|
|
259
273
|
|
|
260
|
-
const opacityTrack = steps !== undefined && displayStepsOnMinimumTrack
|
|
261
|
-
|
|
262
274
|
return (
|
|
263
275
|
<View
|
|
264
276
|
style={[
|
|
@@ -273,10 +285,10 @@ const Slider = ({
|
|
|
273
285
|
SliderStyles.maximumTrack(colorPalette),
|
|
274
286
|
]}
|
|
275
287
|
onLayout={handleTrackLayout}>
|
|
276
|
-
<
|
|
288
|
+
<AnimatedView
|
|
277
289
|
style={[
|
|
278
290
|
styles.minimumTrack(halfSize),
|
|
279
|
-
SliderStyles.minimumTrack(colorPalette
|
|
291
|
+
SliderStyles.minimumTrack(colorPalette),
|
|
280
292
|
animatedTrack,
|
|
281
293
|
]}
|
|
282
294
|
/>
|
|
@@ -300,7 +312,7 @@ const Slider = ({
|
|
|
300
312
|
)}
|
|
301
313
|
<GestureDetector gesture={slideGesture}>
|
|
302
314
|
<View style={styles.thumbContainerFull}>
|
|
303
|
-
<
|
|
315
|
+
<AnimatedView style={[animatedThumb, {flex: 1}]}>
|
|
304
316
|
<View
|
|
305
317
|
style={[
|
|
306
318
|
SliderStyles.thumb(colorPalette),
|
|
@@ -308,7 +320,7 @@ const Slider = ({
|
|
|
308
320
|
]}>
|
|
309
321
|
{ThumbChildren || null}
|
|
310
322
|
</View>
|
|
311
|
-
</
|
|
323
|
+
</AnimatedView>
|
|
312
324
|
</View>
|
|
313
325
|
</GestureDetector>
|
|
314
326
|
</View>
|
|
@@ -326,16 +338,18 @@ const styles = StyleSheet.create(theme => ({
|
|
|
326
338
|
) => ({
|
|
327
339
|
flex,
|
|
328
340
|
alignSelf,
|
|
341
|
+
overflow: 'hidden',
|
|
342
|
+
// flexBasis: 'auto',
|
|
329
343
|
variants: {
|
|
330
344
|
axis: {
|
|
331
345
|
x: {
|
|
332
|
-
maxWidth: 'auto',
|
|
346
|
+
// maxWidth: 'auto',
|
|
333
347
|
paddingTop: 0,
|
|
334
348
|
paddingRight: halfSize,
|
|
335
349
|
flexDirection: 'row',
|
|
336
350
|
},
|
|
337
351
|
y: {
|
|
338
|
-
maxHeight: 'auto',
|
|
352
|
+
// maxHeight: 'auto',
|
|
339
353
|
height: '100%',
|
|
340
354
|
paddingTop: halfSize,
|
|
341
355
|
paddingRight: 0,
|
|
@@ -343,11 +357,16 @@ const styles = StyleSheet.create(theme => ({
|
|
|
343
357
|
},
|
|
344
358
|
},
|
|
345
359
|
},
|
|
360
|
+
_web: {
|
|
361
|
+
_classNames: 'slider-container-base',
|
|
362
|
+
flex: flex === 0 ? undefined : flex,
|
|
363
|
+
},
|
|
346
364
|
}),
|
|
347
365
|
maximumTrack: () => ({
|
|
348
366
|
flex: 1,
|
|
349
367
|
position: 'relative',
|
|
350
368
|
overflow: 'visible',
|
|
369
|
+
flexBasis: 'auto',
|
|
351
370
|
variants: {
|
|
352
371
|
axis: {
|
|
353
372
|
x: {
|
|
@@ -358,8 +377,12 @@ const styles = StyleSheet.create(theme => ({
|
|
|
358
377
|
},
|
|
359
378
|
},
|
|
360
379
|
},
|
|
380
|
+
_web: {
|
|
381
|
+
_classNames: 'slider-maximun-track-base',
|
|
382
|
+
},
|
|
361
383
|
}),
|
|
362
384
|
minimumTrack: (halfSize: number) => ({
|
|
385
|
+
flexBasis: 'auto',
|
|
363
386
|
variants: {
|
|
364
387
|
axis: {
|
|
365
388
|
x: {
|
|
@@ -369,9 +392,6 @@ const styles = StyleSheet.create(theme => ({
|
|
|
369
392
|
bottom: 'auto',
|
|
370
393
|
paddingBottom: 0,
|
|
371
394
|
paddingLeft: halfSize,
|
|
372
|
-
borderBottomLeftRadius: 20,
|
|
373
|
-
borderBottomRightRadius: 0,
|
|
374
|
-
borderTopLeftRadius: 20,
|
|
375
395
|
justifyContent: 'center',
|
|
376
396
|
alignItems: 'flex-end',
|
|
377
397
|
},
|
|
@@ -380,13 +400,13 @@ const styles = StyleSheet.create(theme => ({
|
|
|
380
400
|
paddingBottom: halfSize,
|
|
381
401
|
marginBottom: halfSize * -1,
|
|
382
402
|
paddingLeft: 0,
|
|
383
|
-
borderBottomLeftRadius: 20,
|
|
384
|
-
borderBottomRightRadius: 20,
|
|
385
|
-
borderTopLeftRadius: 0,
|
|
386
403
|
alignItems: 'flex-start',
|
|
387
404
|
},
|
|
388
405
|
},
|
|
389
406
|
},
|
|
407
|
+
_web: {
|
|
408
|
+
_classNames: 'slider-minimum-track-base',
|
|
409
|
+
},
|
|
390
410
|
}),
|
|
391
411
|
thumbContainerFull: {
|
|
392
412
|
position: 'absolute',
|
|
@@ -395,21 +415,28 @@ const styles = StyleSheet.create(theme => ({
|
|
|
395
415
|
top: 0,
|
|
396
416
|
bottom: 0,
|
|
397
417
|
zIndex: 2,
|
|
418
|
+
_web: {
|
|
419
|
+
_classNames: 'thumb-container-full-base',
|
|
420
|
+
},
|
|
398
421
|
},
|
|
399
422
|
thumb: halfSize => ({
|
|
400
|
-
borderRadius: 25,
|
|
401
423
|
variants: {
|
|
402
424
|
axis: {
|
|
403
425
|
x: {
|
|
404
426
|
height: '100%',
|
|
405
427
|
justifyContent: 'center',
|
|
428
|
+
alignItems: 'center',
|
|
406
429
|
},
|
|
407
430
|
y: {
|
|
408
431
|
width: '100%',
|
|
432
|
+
justifyContent: 'center',
|
|
409
433
|
alignItems: 'center',
|
|
410
434
|
},
|
|
411
435
|
},
|
|
412
436
|
},
|
|
437
|
+
_web: {
|
|
438
|
+
_classNames: 'slider-thumb-base',
|
|
439
|
+
},
|
|
413
440
|
}),
|
|
414
441
|
|
|
415
442
|
stepsOverlay: {
|
|
@@ -419,6 +446,9 @@ const styles = StyleSheet.create(theme => ({
|
|
|
419
446
|
top: 0,
|
|
420
447
|
bottom: 0,
|
|
421
448
|
zIndex: 1,
|
|
449
|
+
_web: {
|
|
450
|
+
_classNames: 'slider-steps-overlay-base',
|
|
451
|
+
},
|
|
422
452
|
},
|
|
423
453
|
steps: {
|
|
424
454
|
width: '100%',
|
|
@@ -437,6 +467,9 @@ const styles = StyleSheet.create(theme => ({
|
|
|
437
467
|
},
|
|
438
468
|
},
|
|
439
469
|
},
|
|
470
|
+
_web: {
|
|
471
|
+
_classNames: 'slider-steps-base',
|
|
472
|
+
},
|
|
440
473
|
},
|
|
441
474
|
step: (index, length) => ({
|
|
442
475
|
backgroundColor:
|
|
@@ -453,6 +486,9 @@ const styles = StyleSheet.create(theme => ({
|
|
|
453
486
|
},
|
|
454
487
|
},
|
|
455
488
|
},
|
|
489
|
+
_web: {
|
|
490
|
+
_classNames: 'slider-step-base',
|
|
491
|
+
},
|
|
456
492
|
}),
|
|
457
493
|
}))
|
|
458
494
|
|