@codeleap/mobile 1.0.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/dist/components/ActivityIndicator.d.ts +13 -0
- package/dist/components/ActivityIndicator.js +49 -0
- package/dist/components/ActivityIndicator.js.map +1 -0
- package/dist/components/Button.d.ts +116 -0
- package/dist/components/Button.js +57 -0
- package/dist/components/Button.js.map +1 -0
- package/dist/components/Checkbox/index.d.ts +14 -0
- package/dist/components/Checkbox/index.js +75 -0
- package/dist/components/Checkbox/index.js.map +1 -0
- package/dist/components/Checkbox/styles.d.ts +48 -0
- package/dist/components/Checkbox/styles.js +49 -0
- package/dist/components/Checkbox/styles.js.map +1 -0
- package/dist/components/Checkbox.d.ts +12 -0
- package/dist/components/Checkbox.js +61 -0
- package/dist/components/Checkbox.js.map +1 -0
- package/dist/components/Drawer.d.ts +23 -0
- package/dist/components/Drawer.js +78 -0
- package/dist/components/Drawer.js.map +1 -0
- package/dist/components/FileInput.d.ts +2 -0
- package/dist/components/FileInput.js +28 -0
- package/dist/components/FileInput.js.map +1 -0
- package/dist/components/Icon.d.ts +13 -0
- package/dist/components/Icon.js +47 -0
- package/dist/components/Icon.js.map +1 -0
- package/dist/components/Image.d.ts +16 -0
- package/dist/components/Image.js +48 -0
- package/dist/components/Image.js.map +1 -0
- package/dist/components/Navigation.d.ts +30 -0
- package/dist/components/Navigation.js +126 -0
- package/dist/components/Navigation.js.map +1 -0
- package/dist/components/RadioInput/index.d.ts +25 -0
- package/dist/components/RadioInput/index.js +75 -0
- package/dist/components/RadioInput/index.js.map +1 -0
- package/dist/components/RadioInput/styles.d.ts +50 -0
- package/dist/components/RadioInput/styles.js +45 -0
- package/dist/components/RadioInput/styles.js.map +1 -0
- package/dist/components/Scroll.d.ts +104 -0
- package/dist/components/Scroll.js +73 -0
- package/dist/components/Scroll.js.map +1 -0
- package/dist/components/Select/index.d.ts +2 -0
- package/dist/components/Select/index.js +31 -0
- package/dist/components/Select/index.js.map +1 -0
- package/dist/components/Slider.d.ts +20 -0
- package/dist/components/Slider.js +130 -0
- package/dist/components/Slider.js.map +1 -0
- package/dist/components/Switch.d.ts +13 -0
- package/dist/components/Switch.js +73 -0
- package/dist/components/Switch.js.map +1 -0
- package/dist/components/Text.d.ts +12 -0
- package/dist/components/Text.js +49 -0
- package/dist/components/Text.js.map +1 -0
- package/dist/components/TextInput.d.ts +146 -0
- package/dist/components/TextInput.js +147 -0
- package/dist/components/TextInput.js.map +1 -0
- package/dist/components/Touchable.d.ts +19 -0
- package/dist/components/Touchable.js +62 -0
- package/dist/components/Touchable.js.map +1 -0
- package/dist/components/View.d.ts +190 -0
- package/dist/components/View.js +53 -0
- package/dist/components/View.js.map +1 -0
- package/dist/components/index.d.ts +16 -0
- package/dist/components/index.js +29 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/fastImage.d.ts +1 -0
- package/dist/modules/fastImage.js +10 -0
- package/dist/modules/fastImage.js.map +1 -0
- package/dist/types/utility.d.ts +2 -0
- package/dist/types/utility.js +3 -0
- package/dist/types/utility.js.map +1 -0
- package/dist/utils/OSAlert.d.ts +31 -0
- package/dist/utils/OSAlert.js +89 -0
- package/dist/utils/OSAlert.js.map +1 -0
- package/dist/utils/styles.d.ts +1 -0
- package/dist/utils/styles.js +13 -0
- package/dist/utils/styles.js.map +1 -0
- package/package.json +32 -0
- package/src/components/ActivityIndicator.tsx +37 -0
- package/src/components/Button.tsx +61 -0
- package/src/components/Checkbox/index.tsx +68 -0
- package/src/components/Checkbox/styles.ts +63 -0
- package/src/components/FileInput.tsx +6 -0
- package/src/components/Icon.tsx +35 -0
- package/src/components/Image.tsx +43 -0
- package/src/components/Navigation.tsx +125 -0
- package/src/components/RadioInput/index.tsx +76 -0
- package/src/components/RadioInput/styles.ts +62 -0
- package/src/components/Scroll.tsx +87 -0
- package/src/components/Select/index.tsx +8 -0
- package/src/components/Slider.tsx +198 -0
- package/src/components/Switch.tsx +73 -0
- package/src/components/Text.tsx +31 -0
- package/src/components/TextInput.tsx +206 -0
- package/src/components/Touchable.tsx +54 -0
- package/src/components/View.tsx +53 -0
- package/src/components/index.ts +16 -0
- package/src/index.ts +2 -0
- package/src/modules/fastImage.ts +2 -0
- package/src/types/utility.ts +3 -0
- package/src/utils/OSAlert.ts +122 -0
- package/src/utils/styles.ts +17 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
Slider as RNSlider
|
|
4
|
+
} from '@miblanchard/react-native-slider'
|
|
5
|
+
import { SliderProps as RNSliderProps} from '@miblanchard/react-native-slider/lib/types'
|
|
6
|
+
import { useRef } from 'react'
|
|
7
|
+
import { StyleProp, StyleSheet } from 'react-native'
|
|
8
|
+
import { Text } from './Text'
|
|
9
|
+
import { View, ViewProps } from './View'
|
|
10
|
+
import { ComponentVariants, Form, SliderComposition, SliderStyles, useComponentStyle, useStyle } from '@codeleap/common'
|
|
11
|
+
import { InputLabel } from './TextInput'
|
|
12
|
+
import { StylesOf } from '../types/utility'
|
|
13
|
+
|
|
14
|
+
type SliderProps = Partial<Omit<RNSliderProps,'value'|'onValueChange'>> & {
|
|
15
|
+
|
|
16
|
+
debounce?: number
|
|
17
|
+
labels: string[]
|
|
18
|
+
value: number
|
|
19
|
+
valueOverThumb?: boolean
|
|
20
|
+
showMarks?: boolean
|
|
21
|
+
onValueChange:(val:number) => void
|
|
22
|
+
label: Form.Label
|
|
23
|
+
formatTooltip?:(val:number) => React.ReactNode
|
|
24
|
+
variants?: ComponentVariants<typeof SliderStyles>['variants']
|
|
25
|
+
styles?: StylesOf<SliderComposition>
|
|
26
|
+
style?: ViewProps['style']
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type SliderMarkProps = {
|
|
30
|
+
sliderProps: SliderProps
|
|
31
|
+
index: number
|
|
32
|
+
styles:SliderProps['styles']
|
|
33
|
+
variantStyles:SliderProps['styles']
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const SliderMark:React.FC<SliderMarkProps> = ({index, sliderProps,styles,variantStyles}) => {
|
|
38
|
+
const { labels = [], showMarks} = sliderProps
|
|
39
|
+
|
|
40
|
+
const l = labels?.[index] || ''
|
|
41
|
+
|
|
42
|
+
const isFirst = index === 0
|
|
43
|
+
const isLast = index === labels.length - 1
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const centerAdjustWord = -(l.length * 2)
|
|
47
|
+
|
|
48
|
+
const markStyles:StyleProp<any> = {}
|
|
49
|
+
|
|
50
|
+
const labelStyles:StyleProp<any> = {}
|
|
51
|
+
|
|
52
|
+
if (!isFirst && !isLast){
|
|
53
|
+
labelStyles.left = centerAdjustWord
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (isLast){
|
|
58
|
+
labelStyles.right = -20
|
|
59
|
+
markStyles.right = -10
|
|
60
|
+
}
|
|
61
|
+
return <>
|
|
62
|
+
{
|
|
63
|
+
showMarks ? (
|
|
64
|
+
|
|
65
|
+
<View style={[
|
|
66
|
+
markStyles,
|
|
67
|
+
variantStyles.mark,
|
|
68
|
+
styles.mark,
|
|
69
|
+
]}/>) : null
|
|
70
|
+
}
|
|
71
|
+
{l ?
|
|
72
|
+
(<Text
|
|
73
|
+
|
|
74
|
+
style={[
|
|
75
|
+
labelStyles,
|
|
76
|
+
variantStyles.trackLabels,
|
|
77
|
+
styles.trackLabels,
|
|
78
|
+
]}
|
|
79
|
+
text={l}
|
|
80
|
+
/>) : null
|
|
81
|
+
}
|
|
82
|
+
</>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const ThumbTooltip = ({children,visible, styles, variantStyles}) => {
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
return <View style={[
|
|
89
|
+
StyleSheet.flatten([variantStyles.tooltip, styles.tooltip ]),
|
|
90
|
+
visible ?
|
|
91
|
+
StyleSheet.flatten([variantStyles['tooltip:visible'], styles['tooltip:visible'] ]) :
|
|
92
|
+
StyleSheet.flatten([variantStyles['tooltip:hidden'], styles['tooltip:hidden'] ])
|
|
93
|
+
]}>
|
|
94
|
+
<Text style={[variantStyles.tooltipText,styles.tooltipText]} text={children} />
|
|
95
|
+
<View style={[variantStyles.tooltipArrow,styles.tooltipArrow,]}/>
|
|
96
|
+
</View>
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const Slider:React.FC<SliderProps> = (sliderProps) => {
|
|
100
|
+
const [tooltipVisible, setTooltipVisible] = React.useState(false)
|
|
101
|
+
|
|
102
|
+
const {
|
|
103
|
+
|
|
104
|
+
debounce,
|
|
105
|
+
onValueChange,
|
|
106
|
+
labels,
|
|
107
|
+
value,
|
|
108
|
+
label,
|
|
109
|
+
valueOverThumb,
|
|
110
|
+
formatTooltip,
|
|
111
|
+
styles = {},
|
|
112
|
+
style,
|
|
113
|
+
variants,
|
|
114
|
+
...props
|
|
115
|
+
} = sliderProps
|
|
116
|
+
|
|
117
|
+
const changeDebounce = typeof debounce === 'number' ? debounce : 100
|
|
118
|
+
|
|
119
|
+
const debounceTimeout = useRef(null)
|
|
120
|
+
const toggleTooltipTimeout = useRef(null)
|
|
121
|
+
const valueRef = useRef(value)
|
|
122
|
+
|
|
123
|
+
const variantStyles = useComponentStyle('Slider', {
|
|
124
|
+
variants
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
function setValue(){
|
|
128
|
+
onValueChange(valueRef.current)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function onChange(val){
|
|
132
|
+
|
|
133
|
+
let eventValue = val
|
|
134
|
+
|
|
135
|
+
if(Array.isArray(val)){
|
|
136
|
+
eventValue = val[0]
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if(eventValue === value) return
|
|
140
|
+
|
|
141
|
+
valueRef.current = eventValue as number
|
|
142
|
+
|
|
143
|
+
if(debounceTimeout.current) clearTimeout(debounceTimeout.current)
|
|
144
|
+
|
|
145
|
+
debounceTimeout.current = setTimeout(() => {
|
|
146
|
+
setValue()
|
|
147
|
+
}, changeDebounce)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return <View style={[variantStyles.wrapper, style]}>
|
|
151
|
+
<InputLabel label={label} style={[variantStyles.label, styles.label]}/>
|
|
152
|
+
<RNSlider
|
|
153
|
+
value={value}
|
|
154
|
+
|
|
155
|
+
onSlidingStart={() => {
|
|
156
|
+
if(toggleTooltipTimeout.current) clearTimeout(toggleTooltipTimeout.current)
|
|
157
|
+
|
|
158
|
+
setTooltipVisible(true)
|
|
159
|
+
}}
|
|
160
|
+
|
|
161
|
+
onSlidingComplete={() => {
|
|
162
|
+
toggleTooltipTimeout.current = setTimeout(() => setTooltipVisible(false),830)
|
|
163
|
+
}}
|
|
164
|
+
|
|
165
|
+
onValueChange={onChange}
|
|
166
|
+
|
|
167
|
+
renderAboveThumbComponent={(idx) => {
|
|
168
|
+
if(!valueOverThumb || typeof value !== 'number') return null
|
|
169
|
+
|
|
170
|
+
return <ThumbTooltip visible={tooltipVisible} variantStyles={variantStyles} styles={styles}>
|
|
171
|
+
{formatTooltip ? formatTooltip(value) : value.toString()}
|
|
172
|
+
</ThumbTooltip>
|
|
173
|
+
}}
|
|
174
|
+
|
|
175
|
+
renderTrackMarkComponent={(idx) => <SliderMark
|
|
176
|
+
index={idx}
|
|
177
|
+
sliderProps={sliderProps}
|
|
178
|
+
styles={styles}
|
|
179
|
+
variantStyles={variantStyles}
|
|
180
|
+
/>}
|
|
181
|
+
|
|
182
|
+
maximumValue={labels ? labels.length - 1 : 10}
|
|
183
|
+
|
|
184
|
+
trackMarks={labels ? Object.keys(labels).map((z) => parseInt(z)) : []}
|
|
185
|
+
|
|
186
|
+
containerStyle={[variantStyles.inputContainer, styles.inputContainer] as any}
|
|
187
|
+
|
|
188
|
+
thumbStyle={StyleSheet.flatten([variantStyles.handle, styles.handle]) as any}
|
|
189
|
+
|
|
190
|
+
trackStyle={[variantStyles.track, styles.track] as any}
|
|
191
|
+
|
|
192
|
+
minimumTrackTintColor={
|
|
193
|
+
StyleSheet.flatten([variantStyles.selectedTrack, styles.selectedTrack])?.backgroundColor
|
|
194
|
+
}
|
|
195
|
+
{...props}
|
|
196
|
+
/>
|
|
197
|
+
</View>
|
|
198
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { SwitchStyles,SwitchComposition, ComponentVariants, useComponentStyle, StylesOf, useStyle, FormTypes, useValidate } from '@codeleap/common'
|
|
3
|
+
import { ComponentPropsWithRef, forwardRef, ReactNode } from 'react'
|
|
4
|
+
import { StyleSheet, Switch as NativeSwitch } from 'react-native'
|
|
5
|
+
import { InputLabel, FormError} from './TextInput'
|
|
6
|
+
import { View } from './View'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
type NativeSwitchProps = Omit<
|
|
10
|
+
ComponentPropsWithRef<typeof NativeSwitch>,
|
|
11
|
+
'thumbColor'|'trackColor'
|
|
12
|
+
>
|
|
13
|
+
type SwitchProps = NativeSwitchProps & {
|
|
14
|
+
variants?: ComponentVariants<typeof SwitchStyles>['variants']
|
|
15
|
+
label?: ReactNode
|
|
16
|
+
styles?: StylesOf<SwitchComposition>
|
|
17
|
+
validate?: FormTypes.ValidatorFunction | string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Switch = forwardRef<NativeSwitch,SwitchProps>((switchProps,ref) => {
|
|
21
|
+
const {
|
|
22
|
+
variants = [],
|
|
23
|
+
style = {},
|
|
24
|
+
styles = {},
|
|
25
|
+
validate,
|
|
26
|
+
label,
|
|
27
|
+
value,
|
|
28
|
+
...props
|
|
29
|
+
} = switchProps
|
|
30
|
+
|
|
31
|
+
const variantStyles = useComponentStyle('Switch', {
|
|
32
|
+
variants,
|
|
33
|
+
|
|
34
|
+
})
|
|
35
|
+
const {error,showError} = useValidate(switchProps.value, validate)
|
|
36
|
+
function getStyles(key:SwitchComposition){
|
|
37
|
+
return [
|
|
38
|
+
variantStyles[key],
|
|
39
|
+
styles[key],
|
|
40
|
+
key === 'wrapper' ? style : {},
|
|
41
|
+
showError ? variantStyles[key + ':error'] : {},
|
|
42
|
+
showError ? styles[key + ':error'] : {},
|
|
43
|
+
value ? variantStyles[key + ':on'] : {},
|
|
44
|
+
value ? styles[key + ':on'] : {},
|
|
45
|
+
switchProps.disabled ? variantStyles[key + ':disabled'] : {},
|
|
46
|
+
switchProps.disabled ? styles[key + ':disabled'] : {},
|
|
47
|
+
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const inputStyles = getStyles('input')
|
|
52
|
+
|
|
53
|
+
const {color,backgroundColor} = StyleSheet.flatten(inputStyles)
|
|
54
|
+
const {Theme} = useStyle()
|
|
55
|
+
|
|
56
|
+
const thumbColor = color || Theme.colors.primary
|
|
57
|
+
const trackColor = backgroundColor || Theme.colors.gray
|
|
58
|
+
return <View style={getStyles('wrapper')}>
|
|
59
|
+
<View style={getStyles('inputWrapper')}>
|
|
60
|
+
|
|
61
|
+
<NativeSwitch
|
|
62
|
+
|
|
63
|
+
thumbColor={thumbColor}
|
|
64
|
+
trackColor={{ false:trackColor, true: trackColor}}
|
|
65
|
+
ios_backgroundColor={trackColor}
|
|
66
|
+
value={value}
|
|
67
|
+
{...props}
|
|
68
|
+
/>
|
|
69
|
+
<InputLabel label={label} style={getStyles('label')}/>
|
|
70
|
+
</View>
|
|
71
|
+
<FormError message={error.message} style={getStyles('error')}/>
|
|
72
|
+
</View>
|
|
73
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ComponentPropsWithoutRef, forwardRef } from 'react'
|
|
3
|
+
import { ComponentVariants, useComponentStyle, BaseViewProps, TextStyles } from '@codeleap/common'
|
|
4
|
+
import { Text as NativeText } from 'react-native'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export type TextProps =
|
|
8
|
+
ComponentPropsWithoutRef<typeof NativeText> &
|
|
9
|
+
{
|
|
10
|
+
text?: string,
|
|
11
|
+
variants?: ComponentVariants <typeof TextStyles>['variants'],
|
|
12
|
+
} & BaseViewProps
|
|
13
|
+
|
|
14
|
+
export const Text = forwardRef<NativeText, TextProps>((textProps, ref) => {
|
|
15
|
+
const {
|
|
16
|
+
variants = [],
|
|
17
|
+
text,
|
|
18
|
+
style,
|
|
19
|
+
...props
|
|
20
|
+
} = textProps
|
|
21
|
+
|
|
22
|
+
const variantStyles = useComponentStyle('Text', {
|
|
23
|
+
variants,
|
|
24
|
+
rootElement : 'text'
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const styles = [variantStyles.text, style]
|
|
28
|
+
return <NativeText {...props} style={styles} ref={ref}>
|
|
29
|
+
{text}
|
|
30
|
+
</NativeText>
|
|
31
|
+
})
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
ComponentVariants,
|
|
4
|
+
FormTypes,
|
|
5
|
+
IconPlaceholder,
|
|
6
|
+
TextInputComposition,
|
|
7
|
+
TextInputStyles,
|
|
8
|
+
useBooleanToggle,
|
|
9
|
+
useComponentStyle,
|
|
10
|
+
useValidate
|
|
11
|
+
} from '@codeleap/common';
|
|
12
|
+
import { ComponentPropsWithoutRef, forwardRef, useImperativeHandle, useRef, useState } from 'react'
|
|
13
|
+
import { Text } from './Text';
|
|
14
|
+
import { View } from './View';
|
|
15
|
+
import { Button } from './Button';
|
|
16
|
+
import { StylesOf } from '../types/utility';
|
|
17
|
+
import { Icon } from './Icon';
|
|
18
|
+
import {NativeSyntheticEvent, TextInput as NativeTextInput, TextInputChangeEventData} from 'react-native'
|
|
19
|
+
|
|
20
|
+
type IconProp = {name: IconPlaceholder, action?:() => void}
|
|
21
|
+
|
|
22
|
+
type NativeProps = ComponentPropsWithoutRef<typeof NativeTextInput>
|
|
23
|
+
|
|
24
|
+
export type TextInputProps =
|
|
25
|
+
ComponentVariants<typeof TextInputStyles> &
|
|
26
|
+
Omit<NativeProps, 'value'> &
|
|
27
|
+
{
|
|
28
|
+
multiline?: boolean;
|
|
29
|
+
onChangeText?: (text: string) => void;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
edited?: boolean;
|
|
32
|
+
type?: string;
|
|
33
|
+
label?:React.ReactNode
|
|
34
|
+
|
|
35
|
+
leftIcon?:IconProp
|
|
36
|
+
rightIcon?:IconProp
|
|
37
|
+
styles?: StylesOf<TextInputComposition>
|
|
38
|
+
validate?: FormTypes.ValidatorFunction | string
|
|
39
|
+
value?:string
|
|
40
|
+
password?:boolean
|
|
41
|
+
visibilityToggle?: boolean
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const TextInput = forwardRef<NativeTextInput, TextInputProps>((rawprops, inputRef) => {
|
|
45
|
+
const {
|
|
46
|
+
onChange,
|
|
47
|
+
type,
|
|
48
|
+
value,
|
|
49
|
+
onChangeText,
|
|
50
|
+
disabled,
|
|
51
|
+
edited,
|
|
52
|
+
onFocus,
|
|
53
|
+
onBlur,
|
|
54
|
+
multiline,
|
|
55
|
+
responsiveVariants,
|
|
56
|
+
variants,
|
|
57
|
+
label,
|
|
58
|
+
leftIcon,
|
|
59
|
+
rightIcon,
|
|
60
|
+
styles,
|
|
61
|
+
validate,
|
|
62
|
+
password,
|
|
63
|
+
visibilityToggle,
|
|
64
|
+
|
|
65
|
+
...props
|
|
66
|
+
} = rawprops
|
|
67
|
+
|
|
68
|
+
const [_ig, setFocus] = useState(false)
|
|
69
|
+
const [editedState, setEdited] = useState(edited)
|
|
70
|
+
|
|
71
|
+
const input = useRef<any>(null)
|
|
72
|
+
const [textIsVisible, setTextVisible] = useBooleanToggle(false)
|
|
73
|
+
const variantStyles =useComponentStyle('TextInput', {
|
|
74
|
+
variants,
|
|
75
|
+
responsiveVariants,
|
|
76
|
+
styles,
|
|
77
|
+
})
|
|
78
|
+
const InputElement = NativeTextInput
|
|
79
|
+
|
|
80
|
+
const handleBlur:TextInputProps['onBlur'] = (e) => {
|
|
81
|
+
if (!editedState && value) setEdited(true)
|
|
82
|
+
setFocus(false)
|
|
83
|
+
|
|
84
|
+
if (onBlur) {
|
|
85
|
+
onBlur(e)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const handleFocus:TextInputProps['onFocus'] = (e) => {
|
|
90
|
+
setFocus(true)
|
|
91
|
+
if (onFocus) {
|
|
92
|
+
onFocus(e)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const handleChange = (event:NativeSyntheticEvent<TextInputChangeEventData>) => {
|
|
97
|
+
const text = event.nativeEvent.text
|
|
98
|
+
|
|
99
|
+
if (onChange) onChange(event)
|
|
100
|
+
if (onChangeText) onChangeText(text)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
useImperativeHandle(inputRef, () => input.current)
|
|
107
|
+
|
|
108
|
+
const {showError, error} = useValidate(value, validate)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
const leftIconStyle = {
|
|
112
|
+
...variantStyles.icon,
|
|
113
|
+
...(showError ? variantStyles['icon:error'] : {} ),
|
|
114
|
+
...variantStyles.leftIcon,
|
|
115
|
+
...(showError ? variantStyles['leftIcon:error'] : {} ),
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const rightIconStyle = {
|
|
119
|
+
...variantStyles.icon,
|
|
120
|
+
...(showError ? variantStyles['icon:error'] : {} ),
|
|
121
|
+
...variantStyles.rightIcon,
|
|
122
|
+
...(showError ? variantStyles['rightIcon:error'] : {} ),
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function getStyles(key:TextInputComposition){
|
|
126
|
+
const requestedStyles = [variantStyles[key], showError ? variantStyles[key + ':error'] : {}]
|
|
127
|
+
return requestedStyles
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<View
|
|
133
|
+
style={getStyles('wrapper')}
|
|
134
|
+
>
|
|
135
|
+
<InputLabel label={label} style={getStyles('label')}/>
|
|
136
|
+
|
|
137
|
+
<View style={getStyles('innerWrapper')}>
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
<InputIcon {...leftIcon} style={leftIconStyle}/>
|
|
141
|
+
<InputElement
|
|
142
|
+
ref={input}
|
|
143
|
+
secureTextEntry={password && !textIsVisible}
|
|
144
|
+
onChange={handleChange}
|
|
145
|
+
value={value}
|
|
146
|
+
editable={disabled}
|
|
147
|
+
onFocus={handleFocus}
|
|
148
|
+
onBlur={handleBlur}
|
|
149
|
+
{...props}
|
|
150
|
+
style={getStyles('textField')}
|
|
151
|
+
/>
|
|
152
|
+
{
|
|
153
|
+
visibilityToggle ?
|
|
154
|
+
<InputIcon name={
|
|
155
|
+
(textIsVisible ? 'input-visiblity:visible' : 'input-visiblity:hidden') as IconPlaceholder
|
|
156
|
+
} action={() => setTextVisible()} style={rightIconStyle}/>
|
|
157
|
+
:
|
|
158
|
+
<InputIcon {...rightIcon} style={rightIconStyle}/>
|
|
159
|
+
}
|
|
160
|
+
</View>
|
|
161
|
+
|
|
162
|
+
<FormError message={error.message} style={{
|
|
163
|
+
...variantStyles.error,
|
|
164
|
+
|
|
165
|
+
}}/>
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
</View>
|
|
169
|
+
)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
export const FormError = ({message, ...props}) => {
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
if (['number', 'string', 'undefined'].includes(typeof message)){
|
|
176
|
+
return <Text text={`${message||' '}`} variants={['p2', 'marginTop:1']} {...props}/>
|
|
177
|
+
}
|
|
178
|
+
return message
|
|
179
|
+
}
|
|
180
|
+
export const InputIcon:React.FC<{style:any} & IconProp> = ({name, style, action}) => {
|
|
181
|
+
if (!name) return null
|
|
182
|
+
|
|
183
|
+
if (action){
|
|
184
|
+
|
|
185
|
+
return <Button icon={name} onPress={() => action()} styles={{
|
|
186
|
+
icon: style,
|
|
187
|
+
}} variants={['icon']}/>
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return <Icon name={name} style={style}/>
|
|
192
|
+
}
|
|
193
|
+
export const InputLabel = ({label, style}) => {
|
|
194
|
+
if (!label) return null
|
|
195
|
+
|
|
196
|
+
switch (typeof label){
|
|
197
|
+
case 'string':
|
|
198
|
+
return <Text variants={['p2']} style={style} text={label}/>
|
|
199
|
+
case 'object':
|
|
200
|
+
|
|
201
|
+
return label
|
|
202
|
+
default:
|
|
203
|
+
return null
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ComponentPropsWithoutRef, forwardRef } from 'react'
|
|
3
|
+
import { ComponentVariants, useComponentStyle, BaseViewProps, ViewStyles, useStyle } from '@codeleap/common'
|
|
4
|
+
import { View } from './View'
|
|
5
|
+
import { Animated, TouchableOpacity as NativeTouchable } from 'react-native'
|
|
6
|
+
|
|
7
|
+
export type TouchableProps =
|
|
8
|
+
ComponentPropsWithoutRef<typeof NativeTouchable> &
|
|
9
|
+
{
|
|
10
|
+
variants?: ComponentVariants <typeof ViewStyles>['variants'],
|
|
11
|
+
component?: any
|
|
12
|
+
} & BaseViewProps
|
|
13
|
+
|
|
14
|
+
export const Touchable = forwardRef<NativeTouchable, TouchableProps>((touchableProps, ref) => {
|
|
15
|
+
const {
|
|
16
|
+
variants = [],
|
|
17
|
+
children,
|
|
18
|
+
onPress,
|
|
19
|
+
style,
|
|
20
|
+
...props
|
|
21
|
+
} = touchableProps
|
|
22
|
+
|
|
23
|
+
const variantStyles = useComponentStyle('View', {
|
|
24
|
+
variants,
|
|
25
|
+
})
|
|
26
|
+
const {logger} = useStyle()
|
|
27
|
+
const press = () => {
|
|
28
|
+
if(!onPress) throw {message: 'No onPress passed to touchable', touchableProps}
|
|
29
|
+
logger.log('<Touchable/> pressed', { style, variants }, 'Component')
|
|
30
|
+
onPress(null)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const styles = [variantStyles.wrapper, style]
|
|
34
|
+
|
|
35
|
+
return <NativeTouchable onPress={press} {...props} ref={ref}>
|
|
36
|
+
<View style={styles}>
|
|
37
|
+
{children}
|
|
38
|
+
</View>
|
|
39
|
+
</NativeTouchable>
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
export type AnimatedTouchableProps =
|
|
43
|
+
ComponentPropsWithoutRef<typeof Animated.View> &
|
|
44
|
+
TouchableProps
|
|
45
|
+
|
|
46
|
+
export const AnimatedTouchable = forwardRef<typeof Animated.View, AnimatedTouchableProps>((viewProps, ref) => {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
return <Touchable
|
|
49
|
+
component={Animated.View}
|
|
50
|
+
|
|
51
|
+
{...viewProps}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
})
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef, forwardRef } from 'react'
|
|
3
|
+
import { ComponentVariants, useComponentStyle, ViewStyles, BaseViewProps } from '@codeleap/common'
|
|
4
|
+
import { Animated, View as NativeView } from 'react-native'
|
|
5
|
+
|
|
6
|
+
export type ViewProps =
|
|
7
|
+
ComponentPropsWithoutRef<typeof NativeView> &
|
|
8
|
+
ComponentVariants<typeof ViewStyles> & {
|
|
9
|
+
|
|
10
|
+
component?: any
|
|
11
|
+
} & BaseViewProps
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export const View = forwardRef<NativeView, ViewProps>((viewProps, ref) => {
|
|
15
|
+
const {
|
|
16
|
+
responsiveVariants = {},
|
|
17
|
+
variants = [],
|
|
18
|
+
children,
|
|
19
|
+
style,
|
|
20
|
+
onHover,
|
|
21
|
+
component,
|
|
22
|
+
...props
|
|
23
|
+
} = viewProps;
|
|
24
|
+
|
|
25
|
+
const variantStyles = useComponentStyle('View', {
|
|
26
|
+
responsiveVariants,
|
|
27
|
+
variants,
|
|
28
|
+
});
|
|
29
|
+
const Component = component|| NativeView
|
|
30
|
+
|
|
31
|
+
return <Component
|
|
32
|
+
|
|
33
|
+
style={[variantStyles.wrapper, style]}
|
|
34
|
+
ref={ref}
|
|
35
|
+
{...props}
|
|
36
|
+
>
|
|
37
|
+
{children}
|
|
38
|
+
</Component>
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
export type AnimatedViewProps =
|
|
42
|
+
ComponentPropsWithoutRef<typeof Animated.View> &
|
|
43
|
+
ComponentVariants<typeof ViewStyles> & BaseViewProps
|
|
44
|
+
|
|
45
|
+
export const AnimatedView = forwardRef<typeof Animated.View, AnimatedViewProps>((viewProps, ref) => {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
return <View
|
|
48
|
+
component={Animated.View}
|
|
49
|
+
|
|
50
|
+
{...viewProps}
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './View'
|
|
2
|
+
export * from './Icon'
|
|
3
|
+
export * from './Touchable'
|
|
4
|
+
export * from './Text'
|
|
5
|
+
export * from './Image'
|
|
6
|
+
export * from './Checkbox'
|
|
7
|
+
export * from './TextInput'
|
|
8
|
+
export * from './RadioInput'
|
|
9
|
+
export * from './Switch'
|
|
10
|
+
export * from './Select'
|
|
11
|
+
export * from './FileInput'
|
|
12
|
+
export * from './Slider'
|
|
13
|
+
export * from './Navigation'
|
|
14
|
+
export * from './Scroll'
|
|
15
|
+
export * from './ActivityIndicator'
|
|
16
|
+
export * from './Button'
|
package/src/index.ts
ADDED