@klyftig/mobile-ui 1.2.1 → 1.3.1
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
CHANGED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Text,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
StyleProp,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import { MaterialCommunityIcons as Icon } from '@expo/vector-icons';
|
|
10
|
+
import { useTheme } from '../hooks/useTheme';
|
|
11
|
+
|
|
12
|
+
export interface DisclaimerPillProps {
|
|
13
|
+
message: string;
|
|
14
|
+
linkLabel?: string;
|
|
15
|
+
onPress?: () => void;
|
|
16
|
+
iconName?: React.ComponentProps<typeof Icon>['name'];
|
|
17
|
+
style?: StyleProp<ViewStyle>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Compact footer pill with optional inline link. Used for medical/AI disclaimers
|
|
22
|
+
* that link to a sources/citations screen. Consumer wires up navigation via onPress.
|
|
23
|
+
*/
|
|
24
|
+
export function DisclaimerPill({
|
|
25
|
+
message,
|
|
26
|
+
linkLabel,
|
|
27
|
+
onPress,
|
|
28
|
+
iconName = 'information-outline',
|
|
29
|
+
style,
|
|
30
|
+
}: DisclaimerPillProps) {
|
|
31
|
+
const { colors } = useTheme();
|
|
32
|
+
const content = (
|
|
33
|
+
<>
|
|
34
|
+
<Icon name={iconName} size={14} color={colors.text.tertiary} />
|
|
35
|
+
<Text style={[styles.text, { color: colors.text.tertiary }]}>
|
|
36
|
+
{message}
|
|
37
|
+
{linkLabel ? (
|
|
38
|
+
<>
|
|
39
|
+
{' '}
|
|
40
|
+
<Text
|
|
41
|
+
style={[
|
|
42
|
+
styles.link,
|
|
43
|
+
{ color: colors.text.secondary },
|
|
44
|
+
]}
|
|
45
|
+
>
|
|
46
|
+
{linkLabel}
|
|
47
|
+
</Text>
|
|
48
|
+
</>
|
|
49
|
+
) : null}
|
|
50
|
+
</Text>
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (onPress) {
|
|
55
|
+
return (
|
|
56
|
+
<TouchableOpacity
|
|
57
|
+
onPress={onPress}
|
|
58
|
+
activeOpacity={0.7}
|
|
59
|
+
accessibilityRole="button"
|
|
60
|
+
accessibilityLabel={linkLabel ? `${message} Tap to ${linkLabel}.` : message}
|
|
61
|
+
style={[styles.container, style]}
|
|
62
|
+
>
|
|
63
|
+
{content}
|
|
64
|
+
</TouchableOpacity>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
return (
|
|
68
|
+
<TouchableOpacity
|
|
69
|
+
disabled
|
|
70
|
+
accessibilityLabel={message}
|
|
71
|
+
style={[styles.container, style]}
|
|
72
|
+
>
|
|
73
|
+
{content}
|
|
74
|
+
</TouchableOpacity>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const styles = StyleSheet.create({
|
|
79
|
+
container: {
|
|
80
|
+
flexDirection: 'row',
|
|
81
|
+
alignItems: 'center',
|
|
82
|
+
gap: 6,
|
|
83
|
+
paddingVertical: 8,
|
|
84
|
+
paddingHorizontal: 12,
|
|
85
|
+
},
|
|
86
|
+
text: {
|
|
87
|
+
flex: 1,
|
|
88
|
+
fontSize: 11,
|
|
89
|
+
lineHeight: 15,
|
|
90
|
+
},
|
|
91
|
+
link: {
|
|
92
|
+
fontWeight: '600',
|
|
93
|
+
textDecorationLine: 'underline',
|
|
94
|
+
},
|
|
95
|
+
});
|
|
@@ -4,13 +4,15 @@ import { MaterialCommunityIcons as Icon } from '@expo/vector-icons';
|
|
|
4
4
|
import { useTheme } from '../hooks/useTheme';
|
|
5
5
|
|
|
6
6
|
interface GlassInputProps {
|
|
7
|
-
label
|
|
7
|
+
label?: string;
|
|
8
8
|
value: string;
|
|
9
9
|
onChangeText: (text: string) => void;
|
|
10
10
|
placeholder?: string;
|
|
11
11
|
secureTextEntry?: boolean;
|
|
12
|
-
keyboardType?: 'default' | 'email-address' | 'numeric' | 'phone-pad';
|
|
12
|
+
keyboardType?: 'default' | 'email-address' | 'numeric' | 'phone-pad' | 'decimal-pad' | 'number-pad';
|
|
13
13
|
autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters';
|
|
14
|
+
multiline?: boolean;
|
|
15
|
+
numberOfLines?: number;
|
|
14
16
|
// Off by default for fields where iOS would otherwise replace partially-edited
|
|
15
17
|
// multi-word values with its autocorrect suggestion and snap the caret to end.
|
|
16
18
|
autoCorrect?: boolean;
|
|
@@ -45,6 +47,8 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
|
|
|
45
47
|
onFocus,
|
|
46
48
|
onBlur,
|
|
47
49
|
selectTextOnFocus,
|
|
50
|
+
multiline = false,
|
|
51
|
+
numberOfLines,
|
|
48
52
|
}) => {
|
|
49
53
|
const { colors } = useTheme();
|
|
50
54
|
const [isSecure, setIsSecure] = useState(secureTextEntry);
|
|
@@ -66,7 +70,9 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
|
|
|
66
70
|
|
|
67
71
|
return (
|
|
68
72
|
<View style={styles.container}>
|
|
69
|
-
|
|
73
|
+
{label ? (
|
|
74
|
+
<Text style={[styles.label, { color: colors.text.primary }]}>{label}</Text>
|
|
75
|
+
) : null}
|
|
70
76
|
<View
|
|
71
77
|
style={[
|
|
72
78
|
styles.inputContainer,
|
|
@@ -74,7 +80,7 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
|
|
|
74
80
|
disabled && styles.inputContainerDisabled,
|
|
75
81
|
]}
|
|
76
82
|
>
|
|
77
|
-
<View style={styles.inputWrapper}>
|
|
83
|
+
<View style={[styles.inputWrapper, multiline && styles.inputWrapperMultiline]}>
|
|
78
84
|
{icon && (
|
|
79
85
|
<Icon name={icon} size={20} color="#9B9B9B" style={styles.leftIcon} />
|
|
80
86
|
)}
|
|
@@ -92,12 +98,20 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
|
|
|
92
98
|
onFocus={handleFocus}
|
|
93
99
|
onBlur={handleBlur}
|
|
94
100
|
selectTextOnFocus={selectTextOnFocus}
|
|
101
|
+
multiline={multiline}
|
|
102
|
+
numberOfLines={numberOfLines}
|
|
103
|
+
textAlignVertical={multiline ? 'top' : undefined}
|
|
95
104
|
textContentType={textContentType ?? (secureTextEntry ? 'oneTimeCode' : undefined)}
|
|
96
105
|
autoComplete={autoComplete as any}
|
|
97
106
|
accessibilityLabel={label}
|
|
98
|
-
accessibilityHint={placeholder ? `Enter ${label.toLowerCase()}` : undefined}
|
|
107
|
+
accessibilityHint={placeholder && label ? `Enter ${label.toLowerCase()}` : undefined}
|
|
99
108
|
accessibilityState={{ disabled }}
|
|
100
|
-
style={[
|
|
109
|
+
style={[
|
|
110
|
+
styles.input,
|
|
111
|
+
icon && styles.inputWithLeftIcon,
|
|
112
|
+
(rightText || showPasswordToggle) && styles.inputWithRightIcon,
|
|
113
|
+
multiline && styles.inputMultiline,
|
|
114
|
+
]}
|
|
101
115
|
/>
|
|
102
116
|
{rightText && (
|
|
103
117
|
<Text style={styles.rightText}>{rightText}</Text>
|
|
@@ -154,6 +168,17 @@ const styles = StyleSheet.create({
|
|
|
154
168
|
paddingHorizontal: 16,
|
|
155
169
|
height: 56,
|
|
156
170
|
},
|
|
171
|
+
inputWrapperMultiline: {
|
|
172
|
+
height: undefined,
|
|
173
|
+
minHeight: 96,
|
|
174
|
+
paddingVertical: 12,
|
|
175
|
+
alignItems: 'flex-start',
|
|
176
|
+
},
|
|
177
|
+
inputMultiline: {
|
|
178
|
+
height: undefined,
|
|
179
|
+
minHeight: 72,
|
|
180
|
+
paddingTop: 4,
|
|
181
|
+
},
|
|
157
182
|
leftIcon: {
|
|
158
183
|
marginRight: 12,
|
|
159
184
|
},
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ScrollView,
|
|
4
|
+
View,
|
|
5
|
+
Text,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
NativeSyntheticEvent,
|
|
8
|
+
NativeScrollEvent,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { useTheme } from '../hooks/useTheme';
|
|
11
|
+
|
|
12
|
+
export interface WheelPickerProps {
|
|
13
|
+
values: number[];
|
|
14
|
+
selected: number;
|
|
15
|
+
onChange: (value: number) => void;
|
|
16
|
+
formatLabel?: (value: number) => string;
|
|
17
|
+
itemHeight?: number;
|
|
18
|
+
visibleCount?: number;
|
|
19
|
+
width?: number;
|
|
20
|
+
flex?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const DEFAULT_ITEM_HEIGHT = 48;
|
|
24
|
+
const DEFAULT_VISIBLE_COUNT = 5;
|
|
25
|
+
|
|
26
|
+
export function WheelPicker({
|
|
27
|
+
values,
|
|
28
|
+
selected,
|
|
29
|
+
onChange,
|
|
30
|
+
formatLabel,
|
|
31
|
+
itemHeight = DEFAULT_ITEM_HEIGHT,
|
|
32
|
+
visibleCount = DEFAULT_VISIBLE_COUNT,
|
|
33
|
+
width,
|
|
34
|
+
flex,
|
|
35
|
+
}: WheelPickerProps) {
|
|
36
|
+
const { colors } = useTheme();
|
|
37
|
+
const scrollRef = useRef<ScrollView>(null);
|
|
38
|
+
const containerHeight = itemHeight * visibleCount;
|
|
39
|
+
const padding = (containerHeight - itemHeight) / 2;
|
|
40
|
+
const lastIndexRef = useRef<number>(-1);
|
|
41
|
+
|
|
42
|
+
const selectedIndex = useMemo(() => {
|
|
43
|
+
const idx = values.indexOf(selected);
|
|
44
|
+
return idx >= 0 ? idx : 0;
|
|
45
|
+
}, [values, selected]);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (selectedIndex !== lastIndexRef.current) {
|
|
49
|
+
lastIndexRef.current = selectedIndex;
|
|
50
|
+
requestAnimationFrame(() => {
|
|
51
|
+
scrollRef.current?.scrollTo({ y: selectedIndex * itemHeight, animated: false });
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}, [selectedIndex, itemHeight]);
|
|
55
|
+
|
|
56
|
+
const handleMomentumEnd = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
57
|
+
const offsetY = e.nativeEvent.contentOffset.y;
|
|
58
|
+
const index = Math.round(offsetY / itemHeight);
|
|
59
|
+
const clamped = Math.max(0, Math.min(values.length - 1, index));
|
|
60
|
+
if (values[clamped] !== selected) {
|
|
61
|
+
onChange(values[clamped]);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<View style={[styles.wrapper, { height: containerHeight, width, flex }]}>
|
|
67
|
+
<View
|
|
68
|
+
pointerEvents="none"
|
|
69
|
+
style={[
|
|
70
|
+
styles.selectionOverlay,
|
|
71
|
+
{ top: padding, height: itemHeight, backgroundColor: 'rgba(0,0,0,0.06)' },
|
|
72
|
+
]}
|
|
73
|
+
/>
|
|
74
|
+
<ScrollView
|
|
75
|
+
ref={scrollRef}
|
|
76
|
+
showsVerticalScrollIndicator={false}
|
|
77
|
+
snapToInterval={itemHeight}
|
|
78
|
+
decelerationRate="fast"
|
|
79
|
+
contentContainerStyle={{ paddingTop: padding, paddingBottom: padding }}
|
|
80
|
+
onMomentumScrollEnd={handleMomentumEnd}
|
|
81
|
+
nestedScrollEnabled
|
|
82
|
+
contentOffset={{ x: 0, y: selectedIndex * itemHeight }}
|
|
83
|
+
>
|
|
84
|
+
{values.map((item, index) => {
|
|
85
|
+
const isSelected = index === selectedIndex;
|
|
86
|
+
return (
|
|
87
|
+
<View key={item} style={[styles.item, { height: itemHeight }]}>
|
|
88
|
+
<Text
|
|
89
|
+
style={[
|
|
90
|
+
styles.itemText,
|
|
91
|
+
{
|
|
92
|
+
color: isSelected ? colors.text.primary : colors.text.tertiary,
|
|
93
|
+
},
|
|
94
|
+
]}
|
|
95
|
+
>
|
|
96
|
+
{formatLabel ? formatLabel(item) : String(item)}
|
|
97
|
+
</Text>
|
|
98
|
+
</View>
|
|
99
|
+
);
|
|
100
|
+
})}
|
|
101
|
+
</ScrollView>
|
|
102
|
+
</View>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const styles = StyleSheet.create({
|
|
107
|
+
wrapper: {
|
|
108
|
+
position: 'relative',
|
|
109
|
+
overflow: 'hidden',
|
|
110
|
+
},
|
|
111
|
+
selectionOverlay: {
|
|
112
|
+
position: 'absolute',
|
|
113
|
+
left: 8,
|
|
114
|
+
right: 8,
|
|
115
|
+
borderRadius: 12,
|
|
116
|
+
zIndex: 0,
|
|
117
|
+
},
|
|
118
|
+
item: {
|
|
119
|
+
alignItems: 'center',
|
|
120
|
+
justifyContent: 'center',
|
|
121
|
+
},
|
|
122
|
+
itemText: {
|
|
123
|
+
fontSize: 22,
|
|
124
|
+
fontWeight: '600',
|
|
125
|
+
},
|
|
126
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -40,6 +40,10 @@ export { ErrorState } from './components/ErrorState';
|
|
|
40
40
|
export type { ErrorStateProps } from './components/ErrorState';
|
|
41
41
|
export { LoadingState } from './components/LoadingState';
|
|
42
42
|
export type { LoadingStateProps } from './components/LoadingState';
|
|
43
|
+
export { WheelPicker } from './components/WheelPicker';
|
|
44
|
+
export type { WheelPickerProps } from './components/WheelPicker';
|
|
45
|
+
export { DisclaimerPill } from './components/DisclaimerPill';
|
|
46
|
+
export type { DisclaimerPillProps } from './components/DisclaimerPill';
|
|
43
47
|
|
|
44
48
|
// Progress
|
|
45
49
|
export { CircularProgress } from './components/progress/CircularProgress';
|