@lotics/ui 9.0.0 → 11.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.
Files changed (41) hide show
  1. package/AGENTS.md +41 -10
  2. package/examples/tpl_allocate.tsx +2 -2
  3. package/examples/tpl_attendance.tsx +1 -1
  4. package/examples/tpl_calendar.tsx +1 -1
  5. package/examples/tpl_dashboard.tsx +1 -1
  6. package/examples/tpl_documents.tsx +1 -1
  7. package/examples/tpl_item_list.tsx +1 -1
  8. package/examples/tpl_lookup.tsx +1 -1
  9. package/examples/tpl_pick.tsx +3 -3
  10. package/examples/tpl_pivot.tsx +1 -1
  11. package/examples/tpl_record.tsx +24 -30
  12. package/examples/tpl_report.tsx +1 -1
  13. package/examples/tpl_rollup.tsx +1 -1
  14. package/examples/tpl_shifts.tsx +1 -1
  15. package/examples/tpl_statements.tsx +1 -1
  16. package/examples/tpl_stock.tsx +1 -1
  17. package/examples/tpl_task_board.tsx +1 -1
  18. package/examples/tpl_tasks.tsx +1 -1
  19. package/examples/tpl_tower.tsx +1 -1
  20. package/package.json +2 -7
  21. package/src/button.tsx +5 -1
  22. package/src/button_colors.ts +4 -1
  23. package/src/locale.tsx +4 -0
  24. package/src/page_content.tsx +1 -1
  25. package/src/page_header.tsx +2 -4
  26. package/src/popover_nav.tsx +40 -0
  27. package/src/record_summary.tsx +3 -1
  28. package/src/ring_gauge.tsx +1 -1
  29. package/src/section_heading.tsx +70 -9
  30. package/src/section_stack.tsx +67 -0
  31. package/src/text.css +13 -2
  32. package/src/text.tsx +8 -2
  33. package/src/text_utils.ts +6 -1
  34. package/src/trend_footer.tsx +3 -1
  35. package/src/use_screen_size.ts +1 -1
  36. package/src/animation_horizontal_slide.tsx +0 -75
  37. package/src/form_time_picker.tsx +0 -22
  38. package/src/highlighted_text.tsx +0 -92
  39. package/src/menu_title.tsx +0 -15
  40. package/src/pager_view.tsx +0 -167
  41. package/src/popover_header.tsx +0 -38
@@ -1,167 +0,0 @@
1
- import React, { Ref, useCallback, useEffect, useImperativeHandle, useRef } from "react";
2
- import { Animated, View, PanResponder, StyleSheet, NativeSyntheticEvent } from "react-native";
3
- import type RNPagerView from "react-native-pager-view";
4
- import type { PagerViewProps } from "react-native-pager-view";
5
- import { AutoSizer } from "@lotics/ui/auto_sizer";
6
-
7
- type PagerViewHandle = Pick<
8
- RNPagerView,
9
- "setPage" | "setPageWithoutAnimation" | "setScrollEnabled"
10
- >;
11
-
12
- export function PagerView(props: PagerViewProps & { ref?: Ref<PagerViewHandle> }) {
13
- const {
14
- ref,
15
- children,
16
- initialPage = 0,
17
- scrollEnabled = true,
18
- overdrag = false,
19
- onPageSelected,
20
- } = props;
21
- const pageWidthRef = useRef(0);
22
- const pan = useRef(new Animated.Value(0)).current;
23
- const offset = useRef(0);
24
- const pageRef = useRef(initialPage);
25
- const scroll = useRef(!!scrollEnabled);
26
-
27
- const setPage = useCallback(
28
- (newPage: number) => {
29
- if (newPage < 0 || newPage >= React.Children.count(children)) {
30
- return; // Ignore invalid pageRef
31
- }
32
-
33
- pageRef.current = newPage;
34
-
35
- Animated.spring(pan, {
36
- toValue: -newPage * pageWidthRef.current,
37
- useNativeDriver: false,
38
- bounciness: 0,
39
- }).start();
40
- },
41
- [children, pan],
42
- );
43
-
44
- const setPageWithoutAnimation = useCallback(
45
- (newPage: number) => {
46
- if (newPage < 0 || newPage >= React.Children.count(children)) {
47
- return; // Ignore invalid pageRef
48
- }
49
-
50
- pageRef.current = newPage;
51
- pan.setValue(-newPage * pageWidthRef.current);
52
- },
53
- [children, pan],
54
- );
55
-
56
- const setScrollEnabled = useCallback((enabled: boolean) => {
57
- scroll.current = enabled;
58
- }, []);
59
-
60
- useEffect(() => {
61
- // Update the scroll when the scrollEnabled prop changes
62
- scroll.current = !!scrollEnabled;
63
- }, [scrollEnabled]);
64
-
65
- useImperativeHandle(ref, () => ({
66
- setPage,
67
- setPageWithoutAnimation,
68
- setScrollEnabled,
69
- }));
70
-
71
- const panResponder = useRef(
72
- PanResponder.create({
73
- onStartShouldSetPanResponder: () => scroll.current,
74
- onPanResponderMove: (_evt, gestureState) => {
75
- let newOffset = gestureState.dx - pageRef.current * pageWidthRef.current;
76
-
77
- // Prevent overdragging at the start
78
- if (overdrag === false && pageRef.current === 0 && gestureState.dx > 0) {
79
- newOffset = 0;
80
- }
81
-
82
- // Prevent overdragging at the end
83
- if (
84
- overdrag === false &&
85
- pageRef.current === React.Children.count(children) - 1 &&
86
- gestureState.dx < 0
87
- ) {
88
- newOffset = -pageRef.current * pageWidthRef.current;
89
- }
90
-
91
- offset.current = newOffset;
92
- pan.setValue(newOffset);
93
- },
94
- onPanResponderRelease: (evt, gestureState) => {
95
- // Consider both the offset and the swipe velocity for the snap. Adjust according to preference
96
- const swipeVelocityThreshold = 0.5;
97
- const swipeDistanceThreshold = pageWidthRef.current / 4;
98
-
99
- let newPage = pageRef.current;
100
-
101
- if (
102
- Math.abs(gestureState.vx) > swipeVelocityThreshold ||
103
- Math.abs(gestureState.dx) > swipeDistanceThreshold
104
- ) {
105
- newPage =
106
- gestureState.dx > 0
107
- ? Math.max(pageRef.current - 1, 0)
108
- : Math.min(pageRef.current + 1, React.Children.count(children) - 1);
109
- }
110
-
111
- pageRef.current = newPage;
112
-
113
- Animated.spring(pan, {
114
- toValue: -newPage * pageWidthRef.current,
115
- useNativeDriver: false,
116
- bounciness: 0,
117
- }).start(() => {
118
- // Update the offset after the animation completes
119
- offset.current = -newPage * pageWidthRef.current;
120
- });
121
-
122
- onPageSelected?.({
123
- nativeEvent: { position: newPage },
124
- } as NativeSyntheticEvent<Readonly<{ position: number }>>);
125
- },
126
- }),
127
- ).current;
128
-
129
- const handleResize = useCallback(
130
- (size: { width: number; height: number }) => {
131
- const width = size.width;
132
-
133
- pan.setValue(-pageRef.current * width);
134
- offset.current = -pageRef.current * width;
135
- pageWidthRef.current = width;
136
- },
137
- [pan],
138
- );
139
-
140
- return (
141
- <AutoSizer onResize={handleResize}>
142
- {({ width }) => (
143
- <View style={styles.container}>
144
- <Animated.View
145
- style={{
146
- flex: 1,
147
- flexDirection: "row",
148
- transform: [{ translateX: pan }],
149
- }}
150
- {...panResponder.panHandlers}
151
- >
152
- {React.Children.map(children, (child) => (
153
- <View style={{ width }}>{child}</View>
154
- ))}
155
- </Animated.View>
156
- </View>
157
- )}
158
- </AutoSizer>
159
- );
160
- }
161
-
162
- const styles = StyleSheet.create({
163
- container: {
164
- flex: 1,
165
- overflow: "hidden",
166
- },
167
- });
@@ -1,38 +0,0 @@
1
- import { ReactNode } from "react";
2
- import { View, StyleSheet } from "react-native";
3
- import { IconButton } from "./icon_button";
4
- import { Text } from "./text";
5
- import { usePopoverNav } from "./popover_nav";
6
-
7
- interface PopoverHeaderProps {
8
- title: string;
9
- right?: ReactNode;
10
- /** Accessible name for the back button. Default: "Back". Pass a translated string from the consumer. */
11
- backLabel?: string;
12
- }
13
-
14
- export function PopoverHeader(props: PopoverHeaderProps) {
15
- const { title, right, backLabel = "Back" } = props;
16
- const { goBack, canGoBack } = usePopoverNav();
17
-
18
- return (
19
- <View style={styles.container}>
20
- {canGoBack && (
21
- <IconButton icon="chevron-left" size="lg" color="secondary" accessibilityLabel={backLabel} onPress={goBack} />
22
- )}
23
- <Text size="sm" weight="medium" style={{ flex: 1 }}>
24
- {title}
25
- </Text>
26
- {right}
27
- </View>
28
- );
29
- }
30
-
31
- const styles = StyleSheet.create({
32
- container: {
33
- paddingLeft: 8,
34
- flexDirection: "row",
35
- alignItems: "center",
36
- gap: 8,
37
- },
38
- });