@bacon-pos/ui 0.2.1 → 0.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.
Files changed (45) hide show
  1. package/lib/commonjs/components/Dialog/Dialog.js +215 -0
  2. package/lib/commonjs/components/Dialog/Dialog.js.map +1 -0
  3. package/lib/commonjs/components/Dialog/Dialog.stories.js +169 -0
  4. package/lib/commonjs/components/Dialog/Dialog.stories.js.map +1 -0
  5. package/lib/commonjs/components/Dialog/Dialog.test.js +71 -0
  6. package/lib/commonjs/components/Dialog/Dialog.test.js.map +1 -0
  7. package/lib/commonjs/components/Dialog/index.js +13 -0
  8. package/lib/commonjs/components/Dialog/index.js.map +1 -0
  9. package/lib/commonjs/components/_internal/ScrollArea.js +96 -0
  10. package/lib/commonjs/components/_internal/ScrollArea.js.map +1 -0
  11. package/lib/commonjs/components/index.js +22 -11
  12. package/lib/commonjs/components/index.js.map +1 -1
  13. package/lib/module/components/Dialog/Dialog.js +211 -0
  14. package/lib/module/components/Dialog/Dialog.js.map +1 -0
  15. package/lib/module/components/Dialog/Dialog.stories.js +165 -0
  16. package/lib/module/components/Dialog/Dialog.stories.js.map +1 -0
  17. package/lib/module/components/Dialog/Dialog.test.js +70 -0
  18. package/lib/module/components/Dialog/Dialog.test.js.map +1 -0
  19. package/lib/module/components/Dialog/index.js +4 -0
  20. package/lib/module/components/Dialog/index.js.map +1 -0
  21. package/lib/module/components/_internal/ScrollArea.js +92 -0
  22. package/lib/module/components/_internal/ScrollArea.js.map +1 -0
  23. package/lib/module/components/index.js +1 -0
  24. package/lib/module/components/index.js.map +1 -1
  25. package/lib/typescript/commonjs/components/Dialog/Dialog.d.ts +75 -0
  26. package/lib/typescript/commonjs/components/Dialog/Dialog.d.ts.map +1 -0
  27. package/lib/typescript/commonjs/components/Dialog/index.d.ts +2 -0
  28. package/lib/typescript/commonjs/components/Dialog/index.d.ts.map +1 -0
  29. package/lib/typescript/commonjs/components/_internal/ScrollArea.d.ts +20 -0
  30. package/lib/typescript/commonjs/components/_internal/ScrollArea.d.ts.map +1 -0
  31. package/lib/typescript/commonjs/components/index.d.ts +1 -0
  32. package/lib/typescript/commonjs/components/index.d.ts.map +1 -1
  33. package/lib/typescript/module/components/Dialog/Dialog.d.ts +75 -0
  34. package/lib/typescript/module/components/Dialog/Dialog.d.ts.map +1 -0
  35. package/lib/typescript/module/components/Dialog/index.d.ts +2 -0
  36. package/lib/typescript/module/components/Dialog/index.d.ts.map +1 -0
  37. package/lib/typescript/module/components/_internal/ScrollArea.d.ts +20 -0
  38. package/lib/typescript/module/components/_internal/ScrollArea.d.ts.map +1 -0
  39. package/lib/typescript/module/components/index.d.ts +1 -0
  40. package/lib/typescript/module/components/index.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/components/Dialog/Dialog.tsx +269 -0
  43. package/src/components/Dialog/index.ts +6 -0
  44. package/src/components/_internal/ScrollArea.tsx +95 -0
  45. package/src/components/index.ts +1 -0
@@ -0,0 +1,6 @@
1
+ export {
2
+ Dialog,
3
+ type DialogProps,
4
+ type DialogAction,
5
+ type DialogCancelConfig,
6
+ } from './Dialog';
@@ -0,0 +1,95 @@
1
+ import { useRef, useState, type ReactNode } from 'react';
2
+ import {
3
+ Animated,
4
+ type NativeScrollEvent,
5
+ type NativeSyntheticEvent,
6
+ type StyleProp,
7
+ type ViewStyle,
8
+ } from 'react-native';
9
+
10
+ export interface ScrollAreaProps {
11
+ children: ReactNode;
12
+ /** Thin indicator color (a design-system color). */
13
+ indicatorColor: string;
14
+ /** Indicator thickness. Defaults to 4. */
15
+ indicatorWidth?: number;
16
+ keyboardShouldPersistTaps?: 'always' | 'never' | 'handled';
17
+ keyboardDismissMode?: 'none' | 'on-drag' | 'interactive';
18
+ style?: StyleProp<ViewStyle>;
19
+ contentContainerStyle?: StyleProp<ViewStyle>;
20
+ }
21
+
22
+ /**
23
+ * ScrollView with an elegant custom vertical indicator: thin, rounded, colored,
24
+ * and only visible while scrolling (fades out when idle). The native indicator
25
+ * is hidden so it looks the same on iOS, Android and web.
26
+ */
27
+ export function ScrollArea({
28
+ children,
29
+ indicatorColor,
30
+ indicatorWidth = 4,
31
+ keyboardShouldPersistTaps,
32
+ keyboardDismissMode,
33
+ style,
34
+ contentContainerStyle,
35
+ }: ScrollAreaProps) {
36
+ const [viewportH, setViewportH] = useState(0);
37
+ const [contentH, setContentH] = useState(0);
38
+ const scrollY = useRef(new Animated.Value(0)).current;
39
+ const opacity = useRef(new Animated.Value(0)).current;
40
+ const hideTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
41
+
42
+ const scrollable = contentH > viewportH + 1;
43
+ const thumbH = scrollable ? Math.max(24, (viewportH / contentH) * viewportH) : 0;
44
+ const maxScroll = Math.max(1, contentH - viewportH);
45
+ const translateY = scrollY.interpolate({
46
+ inputRange: [0, maxScroll],
47
+ outputRange: [0, viewportH - thumbH],
48
+ extrapolate: 'clamp',
49
+ });
50
+
51
+ const reveal = () => {
52
+ Animated.timing(opacity, { toValue: 1, duration: 120, useNativeDriver: true }).start();
53
+ if (hideTimer.current) clearTimeout(hideTimer.current);
54
+ hideTimer.current = setTimeout(() => {
55
+ Animated.timing(opacity, { toValue: 0, duration: 400, useNativeDriver: true }).start();
56
+ }, 900);
57
+ };
58
+
59
+ return (
60
+ <Animated.View style={[{ position: 'relative' }, style]}>
61
+ <Animated.ScrollView
62
+ style={{ flexShrink: 1 }}
63
+ contentContainerStyle={contentContainerStyle}
64
+ showsVerticalScrollIndicator={false}
65
+ scrollEventThrottle={16}
66
+ keyboardShouldPersistTaps={keyboardShouldPersistTaps}
67
+ keyboardDismissMode={keyboardDismissMode}
68
+ onLayout={(e) => setViewportH(e.nativeEvent.layout.height)}
69
+ onContentSizeChange={(_w: number, h: number) => setContentH(h)}
70
+ onScroll={Animated.event([{ nativeEvent: { contentOffset: { y: scrollY } } }], {
71
+ useNativeDriver: true,
72
+ listener: (_e: NativeSyntheticEvent<NativeScrollEvent>) => reveal(),
73
+ })}
74
+ >
75
+ {children}
76
+ </Animated.ScrollView>
77
+ {scrollable ? (
78
+ <Animated.View
79
+ pointerEvents="none"
80
+ style={{
81
+ position: 'absolute',
82
+ top: 0,
83
+ right: 2,
84
+ width: indicatorWidth,
85
+ height: thumbH,
86
+ borderRadius: indicatorWidth / 2,
87
+ backgroundColor: indicatorColor,
88
+ opacity,
89
+ transform: [{ translateY }],
90
+ }}
91
+ />
92
+ ) : null}
93
+ </Animated.View>
94
+ );
95
+ }
@@ -6,6 +6,7 @@ export * from './Checkbox';
6
6
  export * from './Chip';
7
7
  export * from './CodeField';
8
8
  export * from './CodeInput';
9
+ export * from './Dialog';
9
10
  export * from './Icon';
10
11
  export * from './IconButton';
11
12
  export * from './Input';