@thanhphi/unistyles-ui 0.0.0-stage → 0.2.7

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 (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +384 -2
  3. package/dist/choices.d.ts +52 -0
  4. package/dist/choices.js +143 -0
  5. package/dist/colors/index.d.ts +79 -0
  6. package/dist/colors/index.js +2 -0
  7. package/dist/date.d.ts +40 -0
  8. package/dist/date.js +153 -0
  9. package/dist/fields.d.ts +140 -0
  10. package/dist/fields.js +233 -0
  11. package/dist/form/index.d.ts +14 -0
  12. package/dist/form/index.js +68 -0
  13. package/dist/icons.d.ts +10 -0
  14. package/dist/icons.js +52 -0
  15. package/dist/image.d.ts +20 -0
  16. package/dist/image.js +34 -0
  17. package/dist/index.d.ts +15 -0
  18. package/dist/index.js +33 -0
  19. package/dist/list-picker.d.ts +45 -0
  20. package/dist/list-picker.js +76 -0
  21. package/dist/module/choices.js +135 -0
  22. package/dist/module/colors/index.js +1 -0
  23. package/dist/module/colors/package.json +1 -0
  24. package/dist/module/date.js +145 -0
  25. package/dist/module/fields.js +225 -0
  26. package/dist/module/form/index.js +62 -0
  27. package/dist/module/form/package.json +1 -0
  28. package/dist/module/icons.js +16 -0
  29. package/dist/module/image.js +31 -0
  30. package/dist/module/index.js +13 -0
  31. package/dist/module/list-picker.js +70 -0
  32. package/dist/module/overlays.js +138 -0
  33. package/dist/module/package.json +1 -0
  34. package/dist/module/primitives.js +432 -0
  35. package/dist/module/process-graph.js +125 -0
  36. package/dist/module/rich-html/html-styles.js +55 -0
  37. package/dist/module/rich-html/image-renderers.js +141 -0
  38. package/dist/module/rich-html/index.js +54 -0
  39. package/dist/module/rich-html/normalize-inline-colors.js +93 -0
  40. package/dist/module/rich-html/package.json +1 -0
  41. package/dist/module/rich-html/rich-html.js +118 -0
  42. package/dist/module/search.js +88 -0
  43. package/dist/module/theme.js +62 -0
  44. package/dist/module/toast.js +30 -0
  45. package/dist/module/ui-modal.js +145 -0
  46. package/dist/overlays.d.ts +72 -0
  47. package/dist/overlays.js +146 -0
  48. package/dist/primitives.d.ts +157 -0
  49. package/dist/primitives.js +480 -0
  50. package/dist/process-graph.d.ts +33 -0
  51. package/dist/process-graph.js +161 -0
  52. package/dist/rich-html/html-styles.d.ts +23 -0
  53. package/dist/rich-html/html-styles.js +63 -0
  54. package/dist/rich-html/image-renderers.d.ts +12 -0
  55. package/dist/rich-html/image-renderers.js +144 -0
  56. package/dist/rich-html/index.d.ts +18 -0
  57. package/dist/rich-html/index.js +92 -0
  58. package/dist/rich-html/normalize-inline-colors.d.ts +8 -0
  59. package/dist/rich-html/normalize-inline-colors.js +99 -0
  60. package/dist/rich-html/rich-html.d.ts +7 -0
  61. package/dist/rich-html/rich-html.js +123 -0
  62. package/dist/search.d.ts +27 -0
  63. package/dist/search.js +91 -0
  64. package/dist/theme.d.ts +67 -0
  65. package/dist/theme.js +68 -0
  66. package/dist/toast.d.ts +3 -0
  67. package/dist/toast.js +69 -0
  68. package/dist/ui-modal.d.ts +17 -0
  69. package/dist/ui-modal.js +151 -0
  70. package/package.json +35 -4
@@ -0,0 +1,88 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState } from "react";
3
+ import { Pressable, StyleSheet, TextInput, View, } from "react-native";
4
+ import { UIIcon } from "./icons.js";
5
+ import { UIText } from "./primitives.js";
6
+ import { useUITheme } from "./theme.js";
7
+ export function SearchBar({ value, onChangeText, onSubmit, onClear, onPress, autoFocus, placeholder = "Search", clearAccessibilityLabel = "Clear search", searchIcon, clearIcon, filter, style, fieldStyle, textStyle, }) {
8
+ const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
9
+ const [input, setInput] = useState("");
10
+ const inputRef = useRef(null);
11
+ const keyword = value ?? input;
12
+ const height = s.xxl + s.xl;
13
+ const filterCount = filter?.count ?? 0;
14
+ const hasFilters = filterCount > 0;
15
+ const badgeLabel = filterCount > 99 ? "99+" : String(filterCount);
16
+ const badgeHeight = s.lg;
17
+ const badgeWidth = badgeHeight + (badgeLabel.length - 1) * s.sm;
18
+ // Keep the badge center on the button's top-right arc at 45 degrees.
19
+ const badgeCenterInset = (height / 2) * (1 - Math.SQRT1_2);
20
+ const changeText = (text) => {
21
+ if (value === undefined)
22
+ setInput(text);
23
+ onChangeText?.(text);
24
+ };
25
+ const field = [
26
+ styles.field,
27
+ {
28
+ height,
29
+ paddingHorizontal: s.md,
30
+ gap: s.sm,
31
+ borderRadius: r.full,
32
+ backgroundColor: c.base3,
33
+ },
34
+ fieldStyle,
35
+ ];
36
+ const icon = searchIcon ?? (_jsx(UIIcon, { name: "search", size: s.xxl, color: c.content2 }));
37
+ return (_jsxs(View, { style: [styles.row, { gap: s.md }, style], children: [onPress ? (_jsxs(Pressable, { accessibilityRole: "button", onPress: onPress, style: ({ pressed }) => [field, pressed && styles.pressed], children: [icon, _jsx(UIText, { color: "content2", numberOfLines: 1, style: [styles.input, textStyle], children: placeholder })] })) : (_jsxs(View, { style: field, children: [icon, _jsx(TextInput, { ref: inputRef, autoFocus: autoFocus, value: keyword, placeholder: placeholder, placeholderTextColor: c.content2, onChangeText: changeText, onSubmitEditing: () => onSubmit?.(keyword), returnKeyType: "search", style: [
38
+ styles.input,
39
+ {
40
+ color: c.content1,
41
+ fontFamily: t.fontFamily,
42
+ fontSize: t.body,
43
+ lineHeight: t.body + s.xs,
44
+ },
45
+ textStyle,
46
+ ] }), keyword.length > 0 && (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: clearAccessibilityLabel, hitSlop: s.sm, onPress: () => {
47
+ changeText("");
48
+ onClear?.();
49
+ if (autoFocus)
50
+ inputRef.current?.focus();
51
+ }, style: clearIcon == null
52
+ ? [
53
+ styles.center,
54
+ {
55
+ width: t.body,
56
+ height: t.body,
57
+ borderRadius: r.full,
58
+ backgroundColor: c.gray600,
59
+ },
60
+ ]
61
+ : undefined, children: clearIcon ?? (_jsx(UIIcon, { name: "close", size: t.caption, color: c.background })) }))] })), filter && (_jsxs(Pressable, { testID: filter.testID, accessibilityRole: "button", accessibilityLabel: filter.accessibilityLabel ?? "Filter", accessibilityValue: hasFilters ? { text: String(filterCount) } : undefined, onPress: filter.onPress, style: [
62
+ styles.center,
63
+ {
64
+ width: height,
65
+ height,
66
+ borderRadius: r.full,
67
+ backgroundColor: c.base3,
68
+ },
69
+ ], children: [filter.icon ?? (_jsx(UIIcon, { name: "filter", size: s.xxl, color: hasFilters ? c.primary500 : c.content1 })), hasFilters && (_jsx(View, { pointerEvents: "none", style: [
70
+ styles.center,
71
+ {
72
+ position: "absolute",
73
+ top: badgeCenterInset - badgeHeight / 2,
74
+ right: badgeCenterInset - badgeWidth / 2,
75
+ width: badgeWidth,
76
+ height: badgeHeight,
77
+ borderRadius: r.full,
78
+ backgroundColor: c.danger,
79
+ },
80
+ ], children: _jsx(UIText, { color: "textPrimary", variant: "caption", weight: "600", children: badgeLabel }) }))] }))] }));
81
+ }
82
+ const styles = StyleSheet.create({
83
+ row: { flexDirection: "row", alignItems: "center", minWidth: 0 },
84
+ field: { flex: 1, minWidth: 0, flexDirection: "row", alignItems: "center" },
85
+ pressed: { opacity: 0.8 },
86
+ input: { flex: 1, minWidth: 0, padding: 0 },
87
+ center: { alignItems: "center", justifyContent: "center" },
88
+ });
@@ -0,0 +1,62 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ function withDefined(base, overrides) {
4
+ const output = { ...base };
5
+ if (overrides)
6
+ for (const key of Object.keys(overrides)) {
7
+ if (overrides[key] !== undefined)
8
+ output[key] = overrides[key];
9
+ }
10
+ return output;
11
+ }
12
+ /** Returns a fresh, frozen value. It never configures a global native theme. */
13
+ export function createUITheme(options) {
14
+ if (!options?.colors) {
15
+ throw new Error('UI360 requires an app-owned palette in createUITheme({ colors }).');
16
+ }
17
+ const scale = options.scale ?? 1;
18
+ if (!Number.isFinite(scale) || scale <= 0)
19
+ throw new RangeError("UI theme scale must be positive and finite");
20
+ const mode = options.mode ?? "light";
21
+ return Object.freeze({
22
+ mode,
23
+ colors: Object.freeze({ ...options.colors }),
24
+ spacing: Object.freeze(withDefined({
25
+ xs: 4 * scale,
26
+ sm: 8 * scale,
27
+ md: 12 * scale,
28
+ lg: 16 * scale,
29
+ xl: 20 * scale,
30
+ xxl: 24 * scale,
31
+ }, options.spacing)),
32
+ radius: Object.freeze(withDefined({
33
+ sm: 4 * scale,
34
+ md: 8 * scale,
35
+ lg: 12 * scale,
36
+ sheet: 24 * scale,
37
+ full: 999,
38
+ }, options.radius)),
39
+ typography: Object.freeze(withDefined({
40
+ caption: 10 * scale,
41
+ label: 12 * scale,
42
+ body: 14 * scale,
43
+ subtitle: 16 * scale,
44
+ title: 18 * scale,
45
+ }, options.typography)),
46
+ });
47
+ }
48
+ /** Pure theme value usable by Unistyles. Configuration belongs to app entries. */
49
+ export function create360Theme(options) {
50
+ const theme = createUITheme(options);
51
+ return { ...theme, type: theme.mode, color: theme.colors };
52
+ }
53
+ const UIThemeContext = createContext(null);
54
+ export function UIThemeProvider({ theme, children }) {
55
+ return (_jsx(UIThemeContext.Provider, { value: theme, children: children }));
56
+ }
57
+ export function useUITheme() {
58
+ const theme = useContext(UIThemeContext);
59
+ if (!theme)
60
+ throw new Error('UIThemeProvider with an app-owned palette is required.');
61
+ return theme;
62
+ }
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { StyleSheet, useWindowDimensions } from "react-native";
4
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
5
+ import Toast, { BaseToast, } from "react-native-toast-message";
6
+ function MultilineToast({ variant, ...props }) {
7
+ const { width } = useWindowDimensions();
8
+ return (_jsx(BaseToast, { ...props, text1NumberOfLines: 0, text2NumberOfLines: 0, style: [
9
+ styles.container,
10
+ styles[variant],
11
+ { width: Math.min(width - 32, 420) },
12
+ ], contentContainerStyle: styles.content, text1Style: [styles.message, props.text1Style], text2Style: [styles.description, props.text2Style] }));
13
+ }
14
+ const defaults = {
15
+ multilineSuccess: (props) => _jsx(MultilineToast, { ...props, variant: "success" }),
16
+ multilineError: (props) => _jsx(MultilineToast, { ...props, variant: "error" }),
17
+ };
18
+ export function AppToast({ config, topOffset, ...props }) {
19
+ const insets = useSafeAreaInsets();
20
+ const resolvedConfig = React.useMemo(() => (config ? { ...defaults, ...config } : defaults), [config]);
21
+ return (_jsx(Toast, { ...props, config: resolvedConfig, topOffset: topOffset ?? insets.top }));
22
+ }
23
+ const styles = StyleSheet.create({
24
+ container: { height: "auto", minHeight: 60 },
25
+ success: { borderLeftColor: "#69C779" },
26
+ error: { borderLeftColor: "#FE6301" },
27
+ content: { paddingHorizontal: 20, paddingVertical: 14 },
28
+ message: { fontSize: 14, lineHeight: 20, fontWeight: "500" },
29
+ description: { fontSize: 12, lineHeight: 18 },
30
+ });
@@ -0,0 +1,145 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { AccessibilityInfo, Animated, Easing, KeyboardAvoidingView, Modal, Platform, Pressable, StyleSheet, View, } from "react-native";
4
+ import { useUITheme } from "./theme.js";
5
+ export function UIModal({ visible, onClose, onOpened, onClosed, position = "center", animationType = "slide", statusBarTranslucent, keyboardAvoiding = false, backdropColor, contentStyle, containerStyle, children, }) {
6
+ const { colors } = useUITheme();
7
+ const Root = keyboardAvoiding && Platform.OS === "ios" ? KeyboardAvoidingView : View;
8
+ const backgroundColor = backdropColor ?? colors.backdrop;
9
+ const renderContent = (motion) => {
10
+ const Panel = motion ? Animated.View : View;
11
+ return (_jsxs(Root, { behavior: Root === KeyboardAvoidingView ? "padding" : undefined, style: [
12
+ styles.root,
13
+ position === "bottom" && styles.bottom,
14
+ containerStyle,
15
+ !motion && { backgroundColor },
16
+ ], pointerEvents: visible ? "auto" : "none", children: [motion && (_jsx(Animated.View, { pointerEvents: "none", style: [
17
+ StyleSheet.absoluteFill,
18
+ { backgroundColor, opacity: motion.progress },
19
+ ] })), onClose && (_jsx(Pressable, { style: StyleSheet.absoluteFill, onPress: onClose, accessible: false })), _jsx(Panel, { accessibilityViewIsModal: true, onLayout: motion?.onLayout, style: [
20
+ styles.panel,
21
+ position === "fullScreen" && styles.fullScreen,
22
+ contentStyle,
23
+ motion && {
24
+ opacity: motion.progress,
25
+ transform: [
26
+ {
27
+ translateY: motion.progress.interpolate({
28
+ inputRange: [0, 1],
29
+ outputRange: [motion.offset, 0],
30
+ }),
31
+ },
32
+ ],
33
+ },
34
+ ], children: children })] }));
35
+ };
36
+ if (onOpened || onClosed)
37
+ return (_jsx(ModalTransition, { visible: visible, onClose: onClose, onOpened: onOpened, onClosed: onClosed, animationType: animationType, statusBarTranslucent: statusBarTranslucent, children: renderContent }));
38
+ return (_jsx(Modal, { visible: visible, transparent: true, animationType: animationType, onRequestClose: onClose ?? ignoreModalClose, statusBarTranslucent: statusBarTranslucent, children: renderContent() }));
39
+ }
40
+ // Modal.onDismiss is iOS-only. Animate the panel and backdrop when callbacks
41
+ // are requested so Android can finish the exit before removing the modal.
42
+ function ModalTransition({ visible, onClose, statusBarTranslucent, onOpened, onClosed, animationType, children, }) {
43
+ const [presented, setPresented] = React.useState(visible);
44
+ const [shown, setShown] = React.useState(false);
45
+ const [panelHeight, setPanelHeight] = React.useState(0);
46
+ const [reduceMotion, setReduceMotion] = React.useState(false);
47
+ const [progress] = React.useState(() => new Animated.Value(0));
48
+ const request = React.useRef({ visible, onOpened, onClosed });
49
+ const dismissing = React.useRef(false);
50
+ const didOpen = React.useRef(false);
51
+ const entranceReady = shown && (animationType !== "slide" || panelHeight > 0);
52
+ const animate = animationType !== "none" && !reduceMotion;
53
+ React.useEffect(() => {
54
+ if (!presented)
55
+ return;
56
+ let active = true;
57
+ AccessibilityInfo.isReduceMotionEnabled().then((value) => {
58
+ if (active)
59
+ setReduceMotion(value);
60
+ });
61
+ const subscription = AccessibilityInfo.addEventListener("reduceMotionChanged", setReduceMotion);
62
+ return () => {
63
+ active = false;
64
+ subscription.remove();
65
+ };
66
+ }, [presented]);
67
+ React.useLayoutEffect(() => {
68
+ request.current = { visible, onOpened, onClosed };
69
+ }, [visible, onOpened, onClosed]);
70
+ const didDismiss = React.useCallback(() => {
71
+ if (!dismissing.current)
72
+ return;
73
+ dismissing.current = false;
74
+ setShown(false);
75
+ setPanelHeight(0);
76
+ if (request.current.visible)
77
+ setPresented(true);
78
+ else
79
+ request.current.onClosed?.();
80
+ }, []);
81
+ React.useEffect(() => {
82
+ if (Platform.OS !== "ios" && !presented)
83
+ didDismiss();
84
+ }, [didDismiss, presented]);
85
+ React.useEffect(() => {
86
+ if (dismissing.current)
87
+ return;
88
+ if (!presented) {
89
+ if (visible)
90
+ setPresented(true);
91
+ return;
92
+ }
93
+ if (visible && !entranceReady && animate)
94
+ return;
95
+ if (visible && !shown)
96
+ return;
97
+ if (!visible)
98
+ didOpen.current = false;
99
+ const complete = () => {
100
+ if (visible !== request.current.visible)
101
+ return;
102
+ if (visible) {
103
+ if (didOpen.current)
104
+ return;
105
+ didOpen.current = true;
106
+ request.current.onOpened?.();
107
+ }
108
+ else {
109
+ dismissing.current = true;
110
+ setPresented(false);
111
+ }
112
+ };
113
+ const target = visible ? 1 : 0;
114
+ if (!animate || !shown) {
115
+ progress.setValue(target);
116
+ complete();
117
+ return;
118
+ }
119
+ const animation = Animated.timing(progress, {
120
+ toValue: target,
121
+ duration: visible ? 220 : 200,
122
+ easing: Easing.out(Easing.cubic),
123
+ useNativeDriver: true,
124
+ });
125
+ animation.start(({ finished }) => {
126
+ if (finished)
127
+ complete();
128
+ });
129
+ return () => animation.stop();
130
+ }, [animate, entranceReady, presented, progress, shown, visible]);
131
+ return (_jsx(Modal, { visible: presented, transparent: true, animationType: "none", onRequestClose: visible ? onClose ?? ignoreModalClose : ignoreModalClose, onShow: () => setShown(true), onDismiss: didDismiss, statusBarTranslucent: statusBarTranslucent, children: children(animate
132
+ ? {
133
+ progress,
134
+ offset: animationType === "slide" ? panelHeight : 0,
135
+ onLayout: (event) => setPanelHeight(event.nativeEvent.layout.height),
136
+ }
137
+ : undefined) }));
138
+ }
139
+ const ignoreModalClose = () => { };
140
+ const styles = StyleSheet.create({
141
+ root: { flex: 1, justifyContent: "center" },
142
+ bottom: { justifyContent: "flex-end" },
143
+ panel: { flexShrink: 1 },
144
+ fullScreen: { flex: 1 },
145
+ });
@@ -0,0 +1,72 @@
1
+ import React from "react";
2
+ import { StyleProp, ViewStyle } from "react-native";
3
+ export interface SheetProps {
4
+ visible: boolean;
5
+ onClose: () => void;
6
+ /** Runs after the entrance animation finishes. */
7
+ onOpened?: () => void;
8
+ /** Runs after dismissing the sheet and completing its exit animation. */
9
+ onClosed?: () => void;
10
+ title?: string;
11
+ description?: string;
12
+ titleNumberOfLines?: number;
13
+ closeAccessibilityLabel?: string;
14
+ children?: React.ReactNode;
15
+ style?: StyleProp<ViewStyle>;
16
+ headerStyle?: StyleProp<ViewStyle>;
17
+ headerStart?: React.ReactNode;
18
+ headerEnd?: React.ReactNode;
19
+ showHandle?: boolean;
20
+ /** Desired height as a fraction of the window, between 0 and 1. */
21
+ heightRatio?: number;
22
+ animationType?: "none" | "slide" | "fade";
23
+ keyboardAvoiding?: boolean;
24
+ }
25
+ type SheetHeaderProps = Pick<SheetProps, "title" | "titleNumberOfLines" | "headerStart" | "headerEnd" | "headerStyle" | "showHandle" | "closeAccessibilityLabel"> & {
26
+ onClose?: () => void;
27
+ closeDisabled?: boolean;
28
+ closeTestID?: string;
29
+ titleStyle?: StyleProp<import("react-native").TextStyle>;
30
+ };
31
+ export declare function SheetHeader({ title, titleNumberOfLines, headerStart, headerEnd, headerStyle, showHandle, closeAccessibilityLabel, onClose, closeDisabled, closeTestID, titleStyle, }: SheetHeaderProps): React.JSX.Element;
32
+ /** Native Modal children retain the provider of the app that rendered them. */
33
+ export declare function Sheet({ visible, onClose, onOpened, onClosed, title, description, titleNumberOfLines, closeAccessibilityLabel, children, style, headerStyle, headerStart, headerEnd, showHandle, heightRatio, animationType, keyboardAvoiding, }: SheetProps): React.JSX.Element;
34
+ export interface ActionSheetItem {
35
+ id: string;
36
+ label: string;
37
+ icon?: React.ReactNode;
38
+ destructive?: boolean;
39
+ disabled?: boolean;
40
+ }
41
+ export interface ActionSheetProps extends Omit<SheetProps, "children"> {
42
+ items: readonly ActionSheetItem[];
43
+ onSelect: (item: ActionSheetItem) => void;
44
+ cancelText?: string;
45
+ }
46
+ export declare function ActionSheet({ items, onSelect, cancelText, ...props }: ActionSheetProps): React.JSX.Element;
47
+ export interface ConfirmDialogProps {
48
+ visible: boolean;
49
+ title?: string;
50
+ message?: React.ReactNode;
51
+ confirmText: string;
52
+ cancelText?: string;
53
+ destructive?: boolean;
54
+ loading?: boolean;
55
+ onConfirm: () => void;
56
+ onClose: () => void;
57
+ illustration?: React.ReactNode;
58
+ }
59
+ export declare function ConfirmDialog({ visible, title, message, confirmText, cancelText, destructive, loading, onConfirm, onClose, illustration, }: ConfirmDialogProps): React.JSX.Element;
60
+ export interface ResultDialogProps extends Omit<ConfirmDialogProps, "confirmText" | "cancelText" | "onConfirm" | "destructive" | "loading"> {
61
+ buttonText: string;
62
+ }
63
+ export declare function ResultDialog({ buttonText, ...props }: ResultDialogProps): React.JSX.Element;
64
+ export interface LoadingOverlayProps {
65
+ visible: boolean;
66
+ label?: string;
67
+ /** Inline is useful inside an app-owned FullWindowOverlay or portal. */
68
+ presentation?: "modal" | "inline";
69
+ testID?: string;
70
+ }
71
+ export declare function LoadingOverlay({ visible, label, presentation, testID, }: LoadingOverlayProps): React.JSX.Element | null;
72
+ export {};
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SheetHeader = SheetHeader;
4
+ exports.Sheet = Sheet;
5
+ exports.ActionSheet = ActionSheet;
6
+ exports.ConfirmDialog = ConfirmDialog;
7
+ exports.ResultDialog = ResultDialog;
8
+ exports.LoadingOverlay = LoadingOverlay;
9
+ const jsx_runtime_1 = require("react/jsx-runtime");
10
+ const react_native_1 = require("react-native");
11
+ const react_native_safe_area_context_1 = require("react-native-safe-area-context");
12
+ const theme_1 = require("./theme");
13
+ const primitives_1 = require("./primitives");
14
+ const icons_1 = require("./icons");
15
+ const ui_modal_1 = require("./ui-modal");
16
+ function SheetHeader({ title, titleNumberOfLines = 1, headerStart, headerEnd, headerStyle, showHandle = false, closeAccessibilityLabel = "Close", onClose, closeDisabled, closeTestID, titleStyle, }) {
17
+ const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
18
+ const showClose = headerEnd === undefined && !!onClose;
19
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { children: [showHandle && ((0, jsx_runtime_1.jsx)(react_native_1.View, { accessible: false, pointerEvents: "none", style: [
20
+ styles.handle,
21
+ {
22
+ width: s.xxl + s.md,
23
+ height: s.xs,
24
+ marginTop: s.md,
25
+ borderRadius: r.full,
26
+ backgroundColor: c.content3,
27
+ },
28
+ ] })), (title != null ||
29
+ showClose ||
30
+ headerStart != null ||
31
+ headerEnd != null) && ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
32
+ styles.sheetHeader,
33
+ { paddingHorizontal: s.lg, paddingVertical: s.md },
34
+ showClose && {
35
+ paddingHorizontal: s.xxl * 2,
36
+ paddingTop: showHandle ? s.md : s.xxl + s.xs,
37
+ },
38
+ headerStyle,
39
+ ], children: [headerStart === undefined && !showClose ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.headerSide })) : (headerStart), (0, jsx_runtime_1.jsx)(primitives_1.UIText, { accessibilityRole: "header", variant: "subtitle", weight: "600", numberOfLines: titleNumberOfLines, style: [styles.sheetTitle, titleStyle], children: title }), headerEnd === undefined && !showClose ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.headerSide })) : (headerEnd)] })), showClose && ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { testID: closeTestID, onPress: onClose, disabled: closeDisabled, accessibilityState: { disabled: !!closeDisabled }, hitSlop: s.sm, accessibilityRole: "button", accessibilityLabel: closeAccessibilityLabel, style: [
40
+ styles.closeCorner,
41
+ { top: s.xs, right: s.md, opacity: closeDisabled ? 0.5 : 1 },
42
+ ], children: (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "close", size: 22, color: c.content1 }) }))] }));
43
+ }
44
+ /** Native Modal children retain the provider of the app that rendered them. */
45
+ function Sheet({ visible, onClose, onOpened, onClosed, title, description, titleNumberOfLines, closeAccessibilityLabel, children, style, headerStyle, headerStart, headerEnd, showHandle = true, heightRatio, animationType = "slide", keyboardAvoiding = false, }) {
46
+ const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
47
+ const insets = (0, react_native_safe_area_context_1.useSafeAreaInsets)();
48
+ const { height } = (0, react_native_1.useWindowDimensions)();
49
+ const panelHeight = heightRatio == null
50
+ ? undefined
51
+ : Math.max(0, Math.min(height * heightRatio, height - insets.top));
52
+ return ((0, jsx_runtime_1.jsxs)(ui_modal_1.UIModal, { visible: visible, onClose: onClose, onOpened: onOpened, onClosed: onClosed, position: "bottom", animationType: animationType, keyboardAvoiding: keyboardAvoiding, statusBarTranslucent: true, containerStyle: { paddingTop: insets.top }, contentStyle: [
53
+ {
54
+ height: panelHeight,
55
+ maxHeight: panelHeight ?? "90%",
56
+ flexShrink: keyboardAvoiding || panelHeight != null ? 1 : undefined,
57
+ overflow: panelHeight != null ? "hidden" : undefined,
58
+ backgroundColor: c.background,
59
+ borderTopLeftRadius: r.sheet,
60
+ borderTopRightRadius: r.sheet,
61
+ paddingBottom: Math.max(s.xxl, insets.bottom),
62
+ },
63
+ style,
64
+ ], children: [(0, jsx_runtime_1.jsx)(SheetHeader, { title: title, titleNumberOfLines: titleNumberOfLines, closeAccessibilityLabel: closeAccessibilityLabel, headerStart: headerStart, headerEnd: headerEnd, headerStyle: headerStyle, showHandle: showHandle, onClose: onClose }), !!description && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "caption", color: "content3", style: {
65
+ textAlign: "center",
66
+ paddingHorizontal: s.lg,
67
+ marginBottom: s.md,
68
+ }, children: description })), children] }));
69
+ }
70
+ function ActionSheet({ items, onSelect, cancelText, ...props }) {
71
+ const { colors: c, spacing: s } = (0, theme_1.useUITheme)();
72
+ return ((0, jsx_runtime_1.jsx)(Sheet, { ...props, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { paddingHorizontal: s.lg }, children: [items.map((item) => ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { disabled: item.disabled, onPress: () => {
73
+ onSelect(item);
74
+ props.onClose();
75
+ }, accessibilityRole: "button", accessibilityState: { disabled: !!item.disabled }, style: [
76
+ styles.actionItem,
77
+ {
78
+ paddingVertical: s.lg,
79
+ gap: s.md,
80
+ borderBottomColor: c.divider,
81
+ opacity: item.disabled ? 0.5 : 1,
82
+ },
83
+ ], children: [item.icon, (0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: item.destructive ? "danger" : "content1", children: item.label })] }, item.id))), cancelText != null && ((0, jsx_runtime_1.jsx)(primitives_1.Button, { label: cancelText, variant: "ghost", onPress: props.onClose, style: { marginTop: s.sm } }))] }) }));
84
+ }
85
+ function ConfirmDialog({ visible, title, message, confirmText, cancelText, destructive, loading, onConfirm, onClose, illustration, }) {
86
+ const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
87
+ return ((0, jsx_runtime_1.jsxs)(ui_modal_1.UIModal, { visible: visible, animationType: "fade", onClose: loading ? undefined : onClose, statusBarTranslucent: true, containerStyle: { padding: s.xxl }, contentStyle: [
88
+ styles.dialog,
89
+ {
90
+ padding: s.xl,
91
+ gap: s.lg,
92
+ backgroundColor: c.background,
93
+ borderRadius: r.lg,
94
+ },
95
+ ], children: [illustration, title != null && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "subtitle", weight: "600", style: styles.center, children: title })), typeof message === "string" ? ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "content2", style: styles.center, children: message })) : (message), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.dialogActions, { gap: s.md }], children: [cancelText != null && ((0, jsx_runtime_1.jsx)(primitives_1.Button, { label: cancelText, variant: "outline", disabled: loading, onPress: onClose, style: styles.flex })), (0, jsx_runtime_1.jsx)(primitives_1.Button, { label: confirmText, variant: destructive ? "danger" : "primary", loading: loading, onPress: onConfirm, style: styles.flex })] })] }));
96
+ }
97
+ function ResultDialog({ buttonText, ...props }) {
98
+ return ((0, jsx_runtime_1.jsx)(ConfirmDialog, { ...props, confirmText: buttonText, onConfirm: props.onClose }));
99
+ }
100
+ function LoadingOverlay({ visible, label, presentation = "modal", testID, }) {
101
+ const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
102
+ if (!visible)
103
+ return null;
104
+ const content = ((0, jsx_runtime_1.jsx)(react_native_1.View, { testID: testID, accessibilityViewIsModal: true, accessibilityLiveRegion: "polite", style: [
105
+ styles.dialogRoot,
106
+ { backgroundColor: c.backdrop },
107
+ presentation === "inline" && {
108
+ ...react_native_1.StyleSheet.absoluteFillObject,
109
+ zIndex: 10000,
110
+ elevation: 10000,
111
+ },
112
+ ], children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: {
113
+ padding: s.xxl,
114
+ gap: s.md,
115
+ backgroundColor: c.background,
116
+ borderRadius: r.lg,
117
+ alignItems: "center",
118
+ }, children: [(0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "large", color: c.primary500 }), label != null && (0, jsx_runtime_1.jsx)(primitives_1.UIText, { children: label })] }) }));
119
+ if (presentation === "inline")
120
+ return content;
121
+ return ((0, jsx_runtime_1.jsx)(ui_modal_1.UIModal, { visible: true, position: "fullScreen", animationType: "fade", backdropColor: "transparent", statusBarTranslucent: true, children: content }));
122
+ }
123
+ const styles = react_native_1.StyleSheet.create({
124
+ handle: { alignSelf: "center" },
125
+ closeCorner: {
126
+ position: "absolute",
127
+ width: 32,
128
+ height: 32,
129
+ alignItems: "center",
130
+ justifyContent: "center",
131
+ zIndex: 1,
132
+ },
133
+ sheetHeader: { flexDirection: "row", alignItems: "center" },
134
+ headerSide: { width: 18 },
135
+ sheetTitle: { flex: 1, textAlign: "center" },
136
+ actionItem: {
137
+ flexDirection: "row",
138
+ alignItems: "center",
139
+ borderBottomWidth: 1,
140
+ },
141
+ dialogRoot: { flex: 1, alignItems: "center", justifyContent: "center" },
142
+ dialog: { width: "100%", maxWidth: 420, alignItems: "center" },
143
+ dialogActions: { flexDirection: "row", alignSelf: "stretch" },
144
+ center: { textAlign: "center" },
145
+ flex: { flex: 1 },
146
+ });