@codeleap/mobile 3.25.0 → 3.25.2
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/package.json +4 -6
- package/src/components/ActionIcon/index.tsx +37 -55
- package/src/components/ActionIcon/styles.ts +4 -2
- package/src/components/ActivityIndicator/index.tsx +64 -42
- package/src/components/ActivityIndicator/styles.ts +10 -1
- package/src/components/Autocomplete/index.tsx +54 -46
- package/src/components/Autocomplete/styles.ts +5 -2
- package/src/components/Autocomplete/types.ts +23 -13
- package/src/components/Avatar/index.tsx +71 -59
- package/src/components/Avatar/styles.ts +9 -1
- package/src/components/AvatarGroup/index.tsx +44 -30
- package/src/components/AvatarGroup/styles.ts +6 -0
- package/src/components/Backdrop/index.tsx +34 -51
- package/src/components/Backdrop/styles.ts +10 -5
- package/src/components/Badge/index.tsx +62 -36
- package/src/components/Badge/styles.ts +11 -3
- package/src/components/Button/index.tsx +82 -55
- package/src/components/Button/styles.ts +14 -13
- package/src/components/Calendar/index.tsx +29 -35
- package/src/components/Calendar/style.ts +6 -0
- package/src/components/Checkbox/index.tsx +64 -43
- package/src/components/Checkbox/styles.ts +6 -1
- package/src/components/ContentView/index.tsx +63 -0
- package/src/components/ContentView/styles.ts +8 -0
- package/src/components/DatePickerModal/index.tsx +65 -50
- package/src/components/DatePickerModal/styles.ts +10 -9
- package/src/components/DatePickerModal/types.ts +54 -36
- package/src/components/Drawer/index.tsx +28 -0
- package/src/components/Drawer/styles.ts +8 -0
- package/src/components/EmptyPlaceholder/index.tsx +63 -40
- package/src/components/EmptyPlaceholder/styles.ts +5 -0
- package/src/components/FileInput/index.tsx +49 -11
- package/src/components/FileInput/styles.ts +8 -0
- package/src/components/Grid/index.tsx +116 -84
- package/src/components/Grid/styles.ts +5 -0
- package/src/components/Icon/index.tsx +79 -44
- package/src/components/Icon/styles.ts +6 -0
- package/src/components/Image/index.tsx +78 -58
- package/src/components/Image/styles.ts +6 -1
- package/src/components/ImageView/Spotlight.tsx +4 -1
- package/src/components/ImageView/component.tsx +2 -1
- package/src/components/InputBase/index.tsx +24 -33
- package/src/components/InputBase/styles.ts +75 -66
- package/src/components/InputBase/types.ts +4 -3
- package/src/components/InputBase/utils.ts +4 -6
- package/src/components/InputLabel/index.tsx +38 -0
- package/src/components/InputLabel/styles.ts +7 -0
- package/src/components/List/PaginationIndicator.tsx +54 -0
- package/src/components/List/index.tsx +151 -99
- package/src/components/List/styles.ts +6 -0
- package/src/components/LoadingOverlay/index.tsx +29 -42
- package/src/components/LoadingOverlay/styles.ts +7 -7
- package/src/components/Modal/index.tsx +127 -80
- package/src/components/Modal/styles.ts +8 -0
- package/src/components/Navigation/Navigation.tsx +0 -1
- package/src/components/Navigation/types.ts +9 -2
- package/src/components/NumberIncrement/index.tsx +60 -50
- package/src/components/NumberIncrement/styles.ts +5 -0
- package/src/components/NumberIncrement/types.ts +39 -32
- package/src/components/Pager/index.tsx +94 -42
- package/src/components/Pager/styles.ts +13 -1
- package/src/components/RadioInput/index.tsx +57 -32
- package/src/components/RadioInput/styles.ts +7 -5
- package/src/components/RefreshControl/index.tsx +19 -39
- package/src/components/RefreshControl/styles.ts +6 -1
- package/src/components/Scroll/index.tsx +105 -89
- package/src/components/Scroll/styles.ts +5 -0
- package/src/components/Sections/index.tsx +161 -111
- package/src/components/Sections/styles.ts +5 -0
- package/src/components/SegmentedControl/Option.tsx +31 -46
- package/src/components/SegmentedControl/index.tsx +121 -86
- package/src/components/SegmentedControl/styles.ts +22 -15
- package/src/components/Select/index.tsx +82 -71
- package/src/components/Select/styles.ts +5 -3
- package/src/components/Select/types.ts +25 -20
- package/src/components/Slider/index.tsx +43 -58
- package/src/components/Slider/styles.ts +6 -15
- package/src/components/Slider/types.ts +14 -9
- package/src/components/Switch/index.tsx +56 -43
- package/src/components/Switch/styles.ts +7 -1
- package/src/components/Text/index.tsx +52 -56
- package/src/components/Text/styles.ts +7 -1
- package/src/components/TextInput/index.tsx +162 -49
- package/src/components/TextInput/styles.ts +8 -2
- package/src/components/Touchable/index.tsx +87 -44
- package/src/components/Touchable/styles.ts +9 -0
- package/src/components/View/index.tsx +92 -23
- package/src/components/View/styles.ts +6 -0
- package/src/components/components.ts +6 -2
- package/src/components/defaultStyles.ts +77 -0
- package/src/index.ts +0 -2
- package/src/modules/PressableRipple/type.ts +0 -1
- package/src/utils/KeyboardAware/context.tsx +2 -0
- package/src/utils/KeyboardAware/keyboardHooks.ts +2 -1
- package/src/utils/ModalManager/components.tsx +30 -1
- package/src/utils/ModalManager/context.tsx +4 -4
- package/src/utils/ModalManager/index.ts +4 -1
- package/src/utils/hooks.ts +1 -12
- package/src/Registry.ts +0 -52
- package/src/components/ActionIcon/types.ts +0 -15
- package/src/components/ActivityIndicator/types.ts +0 -9
- package/src/components/Avatar/types.ts +0 -23
- package/src/components/AvatarGroup/types.ts +0 -10
- package/src/components/Backdrop/types.ts +0 -14
- package/src/components/Badge/types.ts +0 -27
- package/src/components/Button/types.ts +0 -20
- package/src/components/Checkbox/types.ts +0 -13
- package/src/components/EmptyPlaceholder/types.ts +0 -21
- package/src/components/FileInput/types.ts +0 -27
- package/src/components/Grid/types.ts +0 -20
- package/src/components/Icon/types.ts +0 -15
- package/src/components/Image/types.ts +0 -18
- package/src/components/List/types.ts +0 -41
- package/src/components/LoadingOverlay/types.ts +0 -9
- package/src/components/Modal/types.ts +0 -41
- package/src/components/Pager/types.ts +0 -37
- package/src/components/PaginationIndicator/index.tsx +0 -51
- package/src/components/PaginationIndicator/styles.ts +0 -3
- package/src/components/PaginationIndicator/types.ts +0 -10
- package/src/components/RadioInput/types.ts +0 -31
- package/src/components/RefreshControl/types.ts +0 -9
- package/src/components/Scroll/types.ts +0 -21
- package/src/components/SearchInput/index.tsx +0 -90
- package/src/components/Sections/types.ts +0 -39
- package/src/components/SegmentedControl/types.ts +0 -31
- package/src/components/Switch/types.ts +0 -12
- package/src/components/Text/types.ts +0 -18
- package/src/components/TextInput/types.ts +0 -23
- package/src/components/Touchable/types.ts +0 -27
- package/src/components/View/types.ts +0 -13
- package/src/hooks/index.ts +0 -13
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import * as React from 'react'
|
|
2
2
|
import { Slider as RNSlider } from '@miblanchard/react-native-slider'
|
|
3
3
|
import { StyleSheet } from 'react-native'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
TypeGuards,
|
|
6
|
+
useDefaultComponentStyle,
|
|
7
|
+
onUpdate,
|
|
8
|
+
} from '@codeleap/common'
|
|
9
|
+
|
|
5
10
|
import { SliderProps, TrackMarkProps } from './types'
|
|
6
11
|
import { InputBase, selectInputBaseProps } from '../InputBase'
|
|
12
|
+
import { SliderPresets } from './styles'
|
|
7
13
|
import { Text } from '../Text'
|
|
8
14
|
import { View } from '../View'
|
|
9
15
|
import { Touchable } from '../Touchable'
|
|
10
|
-
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
11
|
-
import { MobileStyleRegistry } from '../../Registry'
|
|
12
|
-
import { useStylesFor } from '../../hooks'
|
|
13
16
|
|
|
14
17
|
export * from './styles'
|
|
15
|
-
export * from './types'
|
|
16
18
|
|
|
17
19
|
const DefaultSliderTrackMark = (props: TrackMarkProps) => {
|
|
18
|
-
const { style, onPress } = props
|
|
20
|
+
const { index, content, style, onPress } = props
|
|
19
21
|
|
|
20
22
|
if (!TypeGuards.isString(props.content)) {
|
|
21
23
|
return <>
|
|
@@ -33,14 +35,11 @@ const DefaultSliderTrackMark = (props: TrackMarkProps) => {
|
|
|
33
35
|
const minimumValue = 0
|
|
34
36
|
const maximumValue = 100
|
|
35
37
|
|
|
36
|
-
export const Slider = (props:
|
|
38
|
+
export const Slider = (props:SliderProps) => {
|
|
37
39
|
const {
|
|
38
40
|
inputBaseProps: { label: _label, description: _description, ..._inputBaseProps },
|
|
39
41
|
others,
|
|
40
|
-
} = selectInputBaseProps(
|
|
41
|
-
...Slider.defaultProps,
|
|
42
|
-
...props,
|
|
43
|
-
})
|
|
42
|
+
} = selectInputBaseProps(props)
|
|
44
43
|
|
|
45
44
|
const {
|
|
46
45
|
debounce = null,
|
|
@@ -49,15 +48,17 @@ export const Slider = (props: SliderProps) => {
|
|
|
49
48
|
label,
|
|
50
49
|
description,
|
|
51
50
|
debugName,
|
|
51
|
+
styles = {},
|
|
52
52
|
style,
|
|
53
53
|
disabled,
|
|
54
|
+
variants,
|
|
54
55
|
trackMarks,
|
|
55
|
-
trackMarksClickable,
|
|
56
|
-
labelClickable,
|
|
57
|
-
trackMarkComponent
|
|
56
|
+
trackMarksClickable = false,
|
|
57
|
+
labelClickable = false,
|
|
58
|
+
trackMarkComponent = DefaultSliderTrackMark,
|
|
58
59
|
...sliderProps
|
|
59
60
|
} = others
|
|
60
|
-
|
|
61
|
+
const SliderTrackMark = trackMarkComponent
|
|
61
62
|
const [_value, _setValue] = React.useState(value)
|
|
62
63
|
|
|
63
64
|
onUpdate(() => {
|
|
@@ -66,40 +67,44 @@ export const Slider = (props: SliderProps) => {
|
|
|
66
67
|
}
|
|
67
68
|
}, [value])
|
|
68
69
|
|
|
69
|
-
const
|
|
70
|
+
const variantStyles = useDefaultComponentStyle<'u:Slider', typeof SliderPresets>('u:Slider', {
|
|
71
|
+
variants,
|
|
72
|
+
styles,
|
|
73
|
+
transform: StyleSheet.flatten,
|
|
74
|
+
})
|
|
70
75
|
|
|
71
76
|
const thumbStyle = React.useMemo(() => {
|
|
72
77
|
return StyleSheet.flatten([
|
|
73
|
-
|
|
74
|
-
disabled &&
|
|
78
|
+
variantStyles.thumb,
|
|
79
|
+
disabled && variantStyles['thumb:disabled'],
|
|
75
80
|
])
|
|
76
81
|
}, [])
|
|
77
82
|
|
|
78
83
|
const trackStyle = React.useMemo(() => {
|
|
79
84
|
return StyleSheet.flatten([
|
|
80
|
-
|
|
81
|
-
disabled &&
|
|
85
|
+
variantStyles.track,
|
|
86
|
+
disabled && variantStyles['track:disabled'],
|
|
82
87
|
])
|
|
83
88
|
}, [disabled])
|
|
84
89
|
|
|
85
90
|
const selectedTrackStyle = React.useMemo(() => {
|
|
86
91
|
return StyleSheet.flatten([
|
|
87
|
-
|
|
88
|
-
disabled &&
|
|
92
|
+
variantStyles.selectedTrack,
|
|
93
|
+
disabled && variantStyles['selectedTrack:disabled'],
|
|
89
94
|
])
|
|
90
95
|
}, [disabled])
|
|
91
96
|
|
|
92
97
|
const unselectedTrackStyle = React.useMemo(() => {
|
|
93
98
|
return StyleSheet.flatten([
|
|
94
|
-
|
|
95
|
-
disabled &&
|
|
99
|
+
variantStyles.unselectedTrack,
|
|
100
|
+
disabled && variantStyles['unselectedTrack:disabled'],
|
|
96
101
|
])
|
|
97
102
|
}, [disabled])
|
|
98
103
|
|
|
99
104
|
const containerStyle = React.useMemo(() => {
|
|
100
105
|
return StyleSheet.flatten([
|
|
101
|
-
|
|
102
|
-
disabled &&
|
|
106
|
+
variantStyles.sliderContainer,
|
|
107
|
+
disabled && variantStyles['sliderContainer:disabled'],
|
|
103
108
|
])
|
|
104
109
|
}, [disabled])
|
|
105
110
|
|
|
@@ -114,8 +119,8 @@ export const Slider = (props: SliderProps) => {
|
|
|
114
119
|
|
|
115
120
|
const trackMarkStyle = React.useMemo(() => {
|
|
116
121
|
return StyleSheet.flatten([
|
|
117
|
-
|
|
118
|
-
disabled &&
|
|
122
|
+
variantStyles.trackMark,
|
|
123
|
+
disabled && variantStyles['trackMark:disabled'],
|
|
119
124
|
])
|
|
120
125
|
}, [disabled])
|
|
121
126
|
|
|
@@ -123,32 +128,31 @@ export const Slider = (props: SliderProps) => {
|
|
|
123
128
|
<InputBase
|
|
124
129
|
{..._inputBaseProps}
|
|
125
130
|
disabled={disabled}
|
|
126
|
-
|
|
131
|
+
styles={variantStyles}
|
|
127
132
|
labelAsRow
|
|
128
133
|
>
|
|
129
134
|
{label || description ? (
|
|
130
|
-
<View style={
|
|
135
|
+
<View style={variantStyles.labelRow}>
|
|
131
136
|
{label ? (
|
|
132
137
|
<Touchable
|
|
133
138
|
onPress={() => labelClickable ? onValueChange(sliderProps?.minimumValue || minimumValue) : null}
|
|
134
|
-
|
|
139
|
+
styles={variantStyles.labelBtn}
|
|
135
140
|
debugName='slider title'
|
|
136
141
|
>
|
|
137
|
-
<Text style={
|
|
142
|
+
<Text style={variantStyles.label} text={label}/>
|
|
138
143
|
</Touchable>
|
|
139
144
|
) : null}
|
|
140
145
|
{description ? (
|
|
141
146
|
<Touchable
|
|
142
147
|
onPress={() => labelClickable ? onValueChange(sliderProps?.maximumValue || maximumValue) : null}
|
|
143
|
-
|
|
148
|
+
styles={variantStyles.descriptionBtn}
|
|
144
149
|
debugName='slider description'
|
|
145
150
|
>
|
|
146
|
-
<Text style={
|
|
151
|
+
<Text style={variantStyles.description} text={description}/>
|
|
147
152
|
</Touchable>
|
|
148
153
|
) : null}
|
|
149
154
|
</View>
|
|
150
155
|
) : null}
|
|
151
|
-
|
|
152
156
|
<RNSlider
|
|
153
157
|
value={_value}
|
|
154
158
|
onValueChange={_setValue}
|
|
@@ -170,17 +174,16 @@ export const Slider = (props: SliderProps) => {
|
|
|
170
174
|
/>
|
|
171
175
|
{
|
|
172
176
|
trackMarksProp ? (
|
|
173
|
-
<View style={
|
|
177
|
+
<View style={variantStyles.trackMarkWrapper}>
|
|
174
178
|
{
|
|
175
179
|
trackMarksProp.map((_, idx) => {
|
|
176
180
|
let idxStyle = {}
|
|
177
181
|
|
|
178
182
|
if (idx === 0) {
|
|
179
|
-
idxStyle =
|
|
183
|
+
idxStyle = variantStyles.firstTrackMark
|
|
180
184
|
} else if (idx === trackMarksProp.length - 1) {
|
|
181
|
-
idxStyle =
|
|
185
|
+
idxStyle = variantStyles.lastTrackMark
|
|
182
186
|
}
|
|
183
|
-
|
|
184
187
|
const style = [
|
|
185
188
|
trackMarkStyle,
|
|
186
189
|
idxStyle,
|
|
@@ -214,21 +217,3 @@ export const Slider = (props: SliderProps) => {
|
|
|
214
217
|
)
|
|
215
218
|
}
|
|
216
219
|
|
|
217
|
-
Slider.styleRegistryName = 'Slider'
|
|
218
|
-
Slider.rootElement = 'wrapper'
|
|
219
|
-
Slider.elements = [
|
|
220
|
-
...InputBase.elements,
|
|
221
|
-
'thumb', 'track', 'selectedTrack', 'unselectedTrack', 'firstTrackMark', 'lastTrackMark', 'sliderContainer', 'labelBtn', 'descriptionBtn'
|
|
222
|
-
]
|
|
223
|
-
|
|
224
|
-
Slider.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
225
|
-
return Slider as (props: StyledComponentProps<SliderProps, typeof styles>) => IJSX
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
Slider.defaultProps = {
|
|
229
|
-
trackMarksClickable: false,
|
|
230
|
-
labelClickable: false,
|
|
231
|
-
trackMarkComponent: DefaultSliderTrackMark,
|
|
232
|
-
} as Partial<SliderProps>
|
|
233
|
-
|
|
234
|
-
MobileStyleRegistry.registerComponent(Slider)
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import { PartialComponentStyle } from '@codeleap/common'
|
|
1
|
+
import { PartialComponentStyle, TouchableComposition, createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
2
|
import { IconLessInputBaseParts, InputBaseStates } from '../InputBase'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
type SliderParts =
|
|
6
|
-
'thumb' |
|
|
7
|
-
'track' |
|
|
8
|
-
'selectedTrack' |
|
|
9
|
-
'unselectedTrack' |
|
|
10
|
-
'trackMark' |
|
|
11
|
-
'firstTrackMark' |
|
|
12
|
-
'lastTrackMark' |
|
|
13
|
-
'trackMarkWrapper' |
|
|
14
|
-
'sliderContainer' |
|
|
15
|
-
IconLessInputBaseParts
|
|
3
|
+
import { TouchableStylesGen } from '../Touchable'
|
|
16
4
|
|
|
5
|
+
type SliderParts = 'thumb' | 'track' | 'selectedTrack' | 'unselectedTrack' | 'trackMark' | 'firstTrackMark' | 'lastTrackMark' | 'trackMarkWrapper' | 'sliderContainer' | IconLessInputBaseParts
|
|
17
6
|
type SliderStates = Exclude<InputBaseStates, 'focus'>
|
|
18
7
|
|
|
19
8
|
export type SliderComposition = `${SliderParts}:${SliderStates}` | SliderParts | 'labelBtn' | 'descriptionBtn'
|
|
20
|
-
|
|
21
9
|
export type SliderStylesGen = {
|
|
22
10
|
labelBtn: PartialComponentStyle<TouchableComposition, TouchableStylesGen>
|
|
23
11
|
descriptionBtn: PartialComponentStyle<TouchableComposition, TouchableStylesGen>
|
|
24
12
|
}
|
|
13
|
+
const createSliderStyle = createDefaultVariantFactory<SliderComposition>()
|
|
14
|
+
|
|
15
|
+
export const SliderPresets = includePresets((styles) => createSliderStyle(() => ({ wrapper: styles })))
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentVariants, Form, PropsOf, SliderStyles } from '@codeleap/common'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
SliderComposition,
|
|
5
|
+
} from './styles'
|
|
6
|
+
|
|
2
7
|
import { SliderProps as RNSliderProps } from '@miblanchard/react-native-slider/lib/types'
|
|
8
|
+
import { StylesOf } from '../../types'
|
|
9
|
+
import { View } from '../View'
|
|
3
10
|
import { InputBaseProps } from '../InputBase'
|
|
4
|
-
import { StyledProp } from '@codeleap/styles'
|
|
5
11
|
|
|
6
|
-
export type SliderProps =
|
|
7
|
-
Partial<Omit<RNSliderProps, 'value' | 'onValueChange' | 'style'>> &
|
|
8
|
-
Pick<InputBaseProps, 'disabled' | 'debugName' | 'description' | 'label'> &
|
|
9
|
-
{
|
|
12
|
+
export type SliderProps = Partial<Omit<RNSliderProps, 'value' | 'onValueChange'>> & Pick<InputBaseProps, 'disabled' | 'debugName' | 'description' | 'label'> & {
|
|
10
13
|
debounce?: number | null
|
|
11
14
|
trackMarklabels: string[]
|
|
12
15
|
value: number | number[]
|
|
13
|
-
onValueChange: (val: number
|
|
16
|
+
onValueChange: (val: number| number[]) => void
|
|
17
|
+
variants?: ComponentVariants<typeof SliderStyles>['variants']
|
|
18
|
+
styles?: StylesOf<SliderComposition>
|
|
19
|
+
style?: PropsOf<typeof View>['style']
|
|
14
20
|
trackMarks?: RNSliderProps['trackMarks'] | Record<number, string>
|
|
15
21
|
trackMarksClickable?: boolean
|
|
16
22
|
labelClickable?: boolean
|
|
17
23
|
trackMarkComponent?: React.ComponentType<TrackMarkProps>
|
|
18
|
-
|
|
19
|
-
}
|
|
24
|
+
}
|
|
20
25
|
|
|
21
26
|
export type TrackMarkProps = {
|
|
22
27
|
index: number
|
|
@@ -1,15 +1,35 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
|
|
4
|
+
ComponentVariants,
|
|
5
|
+
useDefaultComponentStyle,
|
|
6
|
+
StylesOf,
|
|
7
|
+
PropsOf,
|
|
8
|
+
} from '@codeleap/common'
|
|
9
|
+
import { StyleSheet } from 'react-native'
|
|
2
10
|
import { View } from '../View'
|
|
3
|
-
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
SwitchPresets,
|
|
14
|
+
SwitchComposition,
|
|
15
|
+
} from './styles'
|
|
16
|
+
import { InputBase, InputBaseDefaultOrder, InputBaseProps, selectInputBaseProps } from '../InputBase'
|
|
4
17
|
import { useAnimatedVariantStyles } from '../..'
|
|
5
18
|
import { Touchable } from '../Touchable'
|
|
6
|
-
import { SwitchProps } from './types'
|
|
7
|
-
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
8
|
-
import { MobileStyleRegistry } from '../../Registry'
|
|
9
|
-
import { useStylesFor } from '../../hooks'
|
|
10
19
|
|
|
11
20
|
export * from './styles'
|
|
12
|
-
|
|
21
|
+
|
|
22
|
+
export type SwitchProps = Pick<
|
|
23
|
+
InputBaseProps,
|
|
24
|
+
'debugName' | 'disabled' | 'label'
|
|
25
|
+
> & {
|
|
26
|
+
variants?: ComponentVariants<typeof SwitchPresets>['variants']
|
|
27
|
+
styles?: StylesOf<SwitchComposition>
|
|
28
|
+
value: boolean
|
|
29
|
+
onValueChange: (value: boolean) => void
|
|
30
|
+
style?: PropsOf<typeof View>['style']
|
|
31
|
+
switchOnLeft?: boolean
|
|
32
|
+
}
|
|
13
33
|
|
|
14
34
|
const reversedOrder = [...InputBaseDefaultOrder].reverse()
|
|
15
35
|
|
|
@@ -17,13 +37,11 @@ export const Switch = (props: SwitchProps) => {
|
|
|
17
37
|
const {
|
|
18
38
|
inputBaseProps,
|
|
19
39
|
others,
|
|
20
|
-
} = selectInputBaseProps(
|
|
21
|
-
...Switch.defaultProps,
|
|
22
|
-
...props,
|
|
23
|
-
})
|
|
24
|
-
|
|
40
|
+
} = selectInputBaseProps(props)
|
|
25
41
|
const {
|
|
26
|
-
|
|
42
|
+
variants = [],
|
|
43
|
+
style = {},
|
|
44
|
+
styles = {},
|
|
27
45
|
value,
|
|
28
46
|
disabled,
|
|
29
47
|
debugName,
|
|
@@ -31,39 +49,45 @@ export const Switch = (props: SwitchProps) => {
|
|
|
31
49
|
switchOnLeft,
|
|
32
50
|
} = others
|
|
33
51
|
|
|
34
|
-
const
|
|
52
|
+
const variantStyles = useDefaultComponentStyle<'u:Switch', typeof SwitchPresets>('u:Switch', {
|
|
53
|
+
variants,
|
|
54
|
+
styles,
|
|
55
|
+
rootElement: 'wrapper',
|
|
56
|
+
transform: StyleSheet.flatten,
|
|
57
|
+
})
|
|
35
58
|
|
|
36
59
|
const trackAnimation = useAnimatedVariantStyles({
|
|
37
|
-
variantStyles
|
|
60
|
+
variantStyles,
|
|
38
61
|
animatedProperties: ['track:off', 'track:disabled', 'track:on', 'track:disabled-on', 'track:disabled-off'],
|
|
39
|
-
transition:
|
|
62
|
+
transition: variantStyles['track:transition'],
|
|
40
63
|
updater: () => {
|
|
41
64
|
'worklet'
|
|
42
65
|
let disabledStyle = {}
|
|
43
66
|
if (disabled) {
|
|
44
|
-
disabledStyle = value ?
|
|
67
|
+
disabledStyle = value ? variantStyles['track:disabled-on'] : variantStyles['track:disabled-off']
|
|
45
68
|
}
|
|
46
|
-
const style = value ?
|
|
69
|
+
const style = value ? variantStyles['track:on'] : variantStyles['track:off']
|
|
47
70
|
|
|
48
71
|
return {
|
|
49
72
|
...style,
|
|
50
73
|
...disabledStyle,
|
|
51
74
|
}
|
|
75
|
+
|
|
52
76
|
},
|
|
53
77
|
dependencies: [value, disabled],
|
|
54
78
|
})
|
|
55
79
|
|
|
56
80
|
const thumbAnimation = useAnimatedVariantStyles({
|
|
57
|
-
variantStyles
|
|
81
|
+
variantStyles,
|
|
58
82
|
animatedProperties: ['thumb:off', 'thumb:disabled', 'thumb:on', 'thumb:disabled-off', 'thumb:disabled-on'],
|
|
59
|
-
transition:
|
|
83
|
+
transition: variantStyles['thumb:transition'],
|
|
60
84
|
updater: () => {
|
|
61
85
|
'worklet'
|
|
62
86
|
let disabledStyle = {}
|
|
63
87
|
if (disabled) {
|
|
64
|
-
disabledStyle = value ?
|
|
88
|
+
disabledStyle = value ? variantStyles['thumb:disabled-on'] : variantStyles['thumb:disabled-off']
|
|
65
89
|
}
|
|
66
|
-
const style = value ?
|
|
90
|
+
const style = value ? variantStyles['thumb:on'] : variantStyles['thumb:off']
|
|
67
91
|
return {
|
|
68
92
|
...style,
|
|
69
93
|
...disabledStyle,
|
|
@@ -73,14 +97,13 @@ export const Switch = (props: SwitchProps) => {
|
|
|
73
97
|
dependencies: [value, disabled],
|
|
74
98
|
})
|
|
75
99
|
|
|
76
|
-
|
|
77
|
-
const _switchOnLeft = switchOnLeft ?? styles?.__props?.switchOnLeft
|
|
100
|
+
const _switchOnLeft = switchOnLeft ?? variantStyles.__props?.switchOnLeft
|
|
78
101
|
|
|
79
102
|
return <InputBase
|
|
80
103
|
{...inputBaseProps}
|
|
81
104
|
debugName={debugName}
|
|
82
105
|
wrapper={Touchable}
|
|
83
|
-
|
|
106
|
+
styles={variantStyles}
|
|
84
107
|
wrapperProps={{
|
|
85
108
|
onPress: () => {
|
|
86
109
|
onValueChange(!value)
|
|
@@ -89,36 +112,26 @@ export const Switch = (props: SwitchProps) => {
|
|
|
89
112
|
rippleDisabled: true,
|
|
90
113
|
}}
|
|
91
114
|
order={_switchOnLeft ? reversedOrder : InputBaseDefaultOrder}
|
|
115
|
+
style={style}
|
|
92
116
|
disabled={disabled}
|
|
117
|
+
|
|
93
118
|
>
|
|
94
119
|
<View
|
|
95
120
|
animated
|
|
96
|
-
animatedStyle={trackAnimation}
|
|
97
121
|
style={[
|
|
98
|
-
|
|
99
|
-
disabled &&
|
|
122
|
+
variantStyles.track,
|
|
123
|
+
disabled && variantStyles['track:disabled'],
|
|
124
|
+
trackAnimation,
|
|
100
125
|
]}
|
|
101
126
|
>
|
|
102
127
|
<View
|
|
103
128
|
animated
|
|
104
|
-
animatedStyle={thumbAnimation}
|
|
105
129
|
style={[
|
|
106
|
-
|
|
107
|
-
disabled &&
|
|
130
|
+
variantStyles.thumb,
|
|
131
|
+
disabled && variantStyles['thumb:disabled'],
|
|
132
|
+
thumbAnimation,
|
|
108
133
|
]}
|
|
109
134
|
/>
|
|
110
135
|
</View>
|
|
111
136
|
</InputBase>
|
|
112
137
|
}
|
|
113
|
-
|
|
114
|
-
Switch.styleRegistryName = 'Switch'
|
|
115
|
-
Switch.elements = [...InputBase.elements, 'track', 'thumb']
|
|
116
|
-
Switch.rootElement = 'wrapper'
|
|
117
|
-
|
|
118
|
-
Switch.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
119
|
-
return Switch as (props: StyledComponentProps<SwitchProps, typeof styles>) => IJSX
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
Switch.defaultProps = {} as Partial<SwitchProps>
|
|
123
|
-
|
|
124
|
-
MobileStyleRegistry.registerComponent(Switch)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
1
2
|
import { InputBaseParts, InputBaseStates } from '../InputBase'
|
|
2
3
|
|
|
3
4
|
type AnimatableParts = 'track' | 'thumb'
|
|
4
|
-
export type SwitchParts = InputBaseParts | AnimatableParts
|
|
5
|
+
export type SwitchParts = InputBaseParts | AnimatableParts
|
|
5
6
|
|
|
6
7
|
export type SwitchAnimationStates = 'on' | 'off' | 'disabled-on' | 'disabled-off'
|
|
7
8
|
|
|
@@ -13,3 +14,8 @@ export type SwitchComposition =
|
|
|
13
14
|
| `${AnimatableParts}:transition`
|
|
14
15
|
| `${AnimatableParts}:${SwitchAnimationStates}`
|
|
15
16
|
| '__props'
|
|
17
|
+
|
|
18
|
+
const createSwitchStyle = createDefaultVariantFactory<SwitchComposition>()
|
|
19
|
+
|
|
20
|
+
export const SwitchPresets = includePresets((styles) => createSwitchStyle(() => ({ wrapper: styles })))
|
|
21
|
+
|
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { forwardRef } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
ComponentVariants,
|
|
5
|
+
useDefaultComponentStyle,
|
|
6
|
+
BaseViewProps,
|
|
7
|
+
TypeGuards,
|
|
8
|
+
useState,
|
|
9
|
+
} from '@codeleap/common'
|
|
10
|
+
import { Animated, Platform, StyleSheet, Text as NativeText, TextProps as RNTextProps } from 'react-native'
|
|
11
|
+
import { usePressableFeedback } from '../../utils'
|
|
12
|
+
import { TextPresets } from './styles'
|
|
13
|
+
import { ComponentWithDefaultProps } from '../../types'
|
|
9
14
|
|
|
10
15
|
export * from './styles'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} = {
|
|
16
|
+
|
|
17
|
+
export type TextProps = RNTextProps & {
|
|
18
|
+
text?: React.ReactNode
|
|
19
|
+
variants?: ComponentVariants<typeof TextPresets>['variants']
|
|
20
|
+
animated?: boolean
|
|
21
|
+
colorChangeConfig?: Partial<Animated.TimingAnimationConfig>
|
|
22
|
+
debugName?: string
|
|
23
|
+
debounce?: number
|
|
24
|
+
pressDisabled?: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const _Text = forwardRef<NativeText, TextProps>((textProps, ref) => {
|
|
28
|
+
const { variants = [], text, children, onPress, style, debounce = 1000, pressDisabled, ...props } = {
|
|
25
29
|
...Text.defaultProps,
|
|
26
30
|
...textProps,
|
|
27
31
|
}
|
|
@@ -34,7 +38,7 @@ export const Text = forwardRef<NativeText, TextProps>((textProps, ref) => {
|
|
|
34
38
|
const [pressed, setPressed] = useState(false)
|
|
35
39
|
const pressedRef = React.useRef(false)
|
|
36
40
|
|
|
37
|
-
const _onPress:
|
|
41
|
+
const _onPress:TextProps['onPress'] = (e) => {
|
|
38
42
|
if (!onPress) return
|
|
39
43
|
|
|
40
44
|
if (TypeGuards.isNumber(debounce)) {
|
|
@@ -61,56 +65,48 @@ export const Text = forwardRef<NativeText, TextProps>((textProps, ref) => {
|
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
67
|
}
|
|
68
|
+
const variantStyles = useDefaultComponentStyle<'u:Text', typeof TextPresets>('u:Text', {
|
|
69
|
+
variants,
|
|
70
|
+
transform: StyleSheet.flatten,
|
|
71
|
+
rootElement: 'text',
|
|
72
|
+
})
|
|
64
73
|
|
|
65
|
-
const styles =
|
|
74
|
+
const styles = StyleSheet.flatten([variantStyles.text, style])
|
|
66
75
|
|
|
67
76
|
if (!!text && !TypeGuards.isString(text)) return <>{text}</>
|
|
68
77
|
|
|
69
|
-
const Component = animated ? Animated.Text : NativeText
|
|
78
|
+
const Component = textProps.animated ? Animated.Text : NativeText
|
|
70
79
|
|
|
71
80
|
const { getFeedbackStyle } = usePressableFeedback(styles, {
|
|
72
81
|
disabled: !pressPolyfillEnabled,
|
|
73
|
-
feedbackConfig:
|
|
82
|
+
feedbackConfig: variantStyles.pressFeedback,
|
|
74
83
|
hightlightPropertyIn: 'color',
|
|
75
84
|
hightlightPropertyOut: 'backgroundColor',
|
|
76
85
|
})
|
|
77
|
-
|
|
78
86
|
const feedbackStyle = pressPolyfillEnabled ? getFeedbackStyle(pressed) : undefined
|
|
79
87
|
|
|
80
88
|
const pressProps = !!onPress ? {
|
|
81
89
|
onPress: pressDisabled ? null : _onPress,
|
|
82
90
|
} : {}
|
|
83
91
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
>
|
|
96
|
-
{text}
|
|
97
|
-
{children}
|
|
98
|
-
</Component>
|
|
99
|
-
)
|
|
100
|
-
}) as StyledComponentWithProps<TextProps>
|
|
101
|
-
|
|
102
|
-
Text.styleRegistryName = 'Text'
|
|
103
|
-
Text.elements = ['text', 'pressFeedback']
|
|
104
|
-
Text.rootElement = 'text'
|
|
105
|
-
|
|
106
|
-
Text.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
107
|
-
return Text as (props: StyledComponentProps<TextProps & { ref?: React.MutableRefObject<NativeText> }, typeof styles>) => IJSX
|
|
108
|
-
}
|
|
92
|
+
return <Component {...props}
|
|
93
|
+
onPressIn={handlePress(true)} onPressOut={handlePress(false)}
|
|
94
|
+
style={[styles, feedbackStyle, !!onPress && pressDisabled ? variantStyles['text:disabled'] : null]}
|
|
95
|
+
allowFontScaling={false}
|
|
96
|
+
{...pressProps}
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
ref={ref}
|
|
99
|
+
>
|
|
100
|
+
{text}
|
|
101
|
+
{children}
|
|
102
|
+
</Component>
|
|
109
103
|
|
|
110
|
-
|
|
111
|
-
debounce: 1000,
|
|
112
|
-
} as Partial<TextProps>
|
|
104
|
+
})
|
|
113
105
|
|
|
114
|
-
|
|
106
|
+
export const Text = _Text as ComponentWithDefaultProps<TextProps & {ref?: React.MutableRefObject<NativeText> }>
|
|
107
|
+
|
|
108
|
+
Text.defaultProps = {
|
|
109
|
+
}
|
|
115
110
|
|
|
116
111
|
export const AnimatedText = Animated.createAnimatedComponent(Text)
|
|
112
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StylesOf } from '@codeleap/common'
|
|
1
|
+
import { createDefaultVariantFactory, includePresets, StylesOf } from '@codeleap/common'
|
|
2
2
|
import { FeedbackConfig } from '../../utils'
|
|
3
3
|
|
|
4
4
|
export type TextComposition = 'text' | 'pressFeedback' | 'text:disabled'
|
|
@@ -6,3 +6,9 @@ export type TextComposition = 'text' | 'pressFeedback' | 'text:disabled'
|
|
|
6
6
|
export type TextStylesGen<TCSS = any> = StylesOf<'text', TCSS> & {
|
|
7
7
|
'pressFeedback'?: FeedbackConfig
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
const createTextStyle = createDefaultVariantFactory<
|
|
11
|
+
TextComposition, TextStylesGen
|
|
12
|
+
>()
|
|
13
|
+
|
|
14
|
+
export const TextPresets = includePresets((styles) => createTextStyle(() => ({ text: styles })))
|