@klyftig/mobile-ui 1.2.1 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@klyftig/mobile-ui",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "scripts": {
5
5
  "pack-install": "npm pack && mv klyftig-ui-*.tgz /tmp/klyftig-ui-local.tgz && cd ../../mobile && npm install /tmp/klyftig-ui-local.tgz"
6
6
  },
@@ -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
+ });
@@ -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';