@thanhphi/unistyles-ui 0.2.6 → 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.
@@ -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,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
+ });
@@ -3,15 +3,34 @@ import { StyleProp, ViewStyle } from "react-native";
3
3
  export interface SheetProps {
4
4
  visible: boolean;
5
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;
6
10
  title?: string;
11
+ description?: string;
12
+ titleNumberOfLines?: number;
7
13
  closeAccessibilityLabel?: string;
8
14
  children?: React.ReactNode;
9
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;
10
22
  animationType?: "none" | "slide" | "fade";
11
23
  keyboardAvoiding?: boolean;
12
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;
13
32
  /** Native Modal children retain the provider of the app that rendered them. */
14
- export declare function Sheet({ visible, onClose, title, closeAccessibilityLabel, children, style, animationType, keyboardAvoiding, }: SheetProps): React.JSX.Element;
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;
15
34
  export interface ActionSheetItem {
16
35
  id: string;
17
36
  label: string;
@@ -50,3 +69,4 @@ export interface LoadingOverlayProps {
50
69
  testID?: string;
51
70
  }
52
71
  export declare function LoadingOverlay({ visible, label, presentation, testID, }: LoadingOverlayProps): React.JSX.Element | null;
72
+ export {};
package/dist/overlays.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SheetHeader = SheetHeader;
3
4
  exports.Sheet = Sheet;
4
5
  exports.ActionSheet = ActionSheet;
5
6
  exports.ConfirmDialog = ConfirmDialog;
@@ -11,29 +12,60 @@ const react_native_safe_area_context_1 = require("react-native-safe-area-context
11
12
  const theme_1 = require("./theme");
12
13
  const primitives_1 = require("./primitives");
13
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
+ }
14
44
  /** Native Modal children retain the provider of the app that rendered them. */
15
- function Sheet({ visible, onClose, title, closeAccessibilityLabel = "Close", children, style, animationType = "slide", keyboardAvoiding = false, }) {
45
+ function Sheet({ visible, onClose, onOpened, onClosed, title, description, titleNumberOfLines, closeAccessibilityLabel, children, style, headerStyle, headerStart, headerEnd, showHandle = true, heightRatio, animationType = "slide", keyboardAvoiding = false, }) {
16
46
  const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
17
47
  const insets = (0, react_native_safe_area_context_1.useSafeAreaInsets)();
18
- const Root = keyboardAvoiding ? react_native_1.KeyboardAvoidingView : react_native_1.View;
19
- return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { visible: visible, transparent: true, animationType: animationType, onRequestClose: onClose, statusBarTranslucent: true, children: (0, jsx_runtime_1.jsxs)(Root, { behavior: keyboardAvoiding && react_native_1.Platform.OS === "ios" ? "padding" : undefined, style: [
20
- styles.modalRoot,
21
- { backgroundColor: c.backdrop, paddingTop: insets.top },
22
- ], children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { style: react_native_1.StyleSheet.absoluteFill, onPress: onClose, accessible: false }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { accessibilityViewIsModal: true, style: [
23
- {
24
- maxHeight: "90%",
25
- // The panel must yield to the keyboard instead of moving its header off-screen.
26
- flexShrink: keyboardAvoiding ? 1 : undefined,
27
- backgroundColor: c.background,
28
- borderTopLeftRadius: r.sheet,
29
- borderTopRightRadius: r.sheet,
30
- paddingBottom: Math.max(s.xxl, insets.bottom),
31
- },
32
- style,
33
- ], children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
34
- styles.sheetHeader,
35
- { paddingHorizontal: s.lg, paddingVertical: s.md },
36
- ], children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.headerSide }), (0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "subtitle", weight: "600", numberOfLines: 1, style: styles.sheetTitle, children: title }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: onClose, hitSlop: 12, accessibilityRole: "button", accessibilityLabel: closeAccessibilityLabel, children: (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "close", size: 18, color: c.content2 }) })] }), children] })] }) }));
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] }));
37
69
  }
38
70
  function ActionSheet({ items, onSelect, cancelText, ...props }) {
39
71
  const { colors: c, spacing: s } = (0, theme_1.useUITheme)();
@@ -52,18 +84,15 @@ function ActionSheet({ items, onSelect, cancelText, ...props }) {
52
84
  }
53
85
  function ConfirmDialog({ visible, title, message, confirmText, cancelText, destructive, loading, onConfirm, onClose, illustration, }) {
54
86
  const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
55
- return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { visible: visible, transparent: true, animationType: "fade", onRequestClose: loading ? () => undefined : onClose, statusBarTranslucent: true, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
56
- styles.dialogRoot,
57
- { backgroundColor: c.backdrop, padding: s.xxl },
58
- ], children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { style: react_native_1.StyleSheet.absoluteFill, onPress: loading ? undefined : onClose, accessible: false }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { accessibilityViewIsModal: true, style: [
59
- styles.dialog,
60
- {
61
- padding: s.xl,
62
- gap: s.lg,
63
- backgroundColor: c.background,
64
- borderRadius: r.lg,
65
- },
66
- ], 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 })] })] })] }) }));
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 })] })] }));
67
96
  }
68
97
  function ResultDialog({ buttonText, ...props }) {
69
98
  return ((0, jsx_runtime_1.jsx)(ConfirmDialog, { ...props, confirmText: buttonText, onConfirm: props.onClose }));
@@ -89,10 +118,18 @@ function LoadingOverlay({ visible, label, presentation = "modal", testID, }) {
89
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 })] }) }));
90
119
  if (presentation === "inline")
91
120
  return content;
92
- return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { visible: true, transparent: true, animationType: "fade", onRequestClose: () => undefined, statusBarTranslucent: true, children: content }));
121
+ return ((0, jsx_runtime_1.jsx)(ui_modal_1.UIModal, { visible: true, position: "fullScreen", animationType: "fade", backdropColor: "transparent", statusBarTranslucent: true, children: content }));
93
122
  }
94
123
  const styles = react_native_1.StyleSheet.create({
95
- modalRoot: { flex: 1, justifyContent: "flex-end" },
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
+ },
96
133
  sheetHeader: { flexDirection: "row", alignItems: "center" },
97
134
  headerSide: { width: 18 },
98
135
  sheetTitle: { flex: 1, textAlign: "center" },
@@ -0,0 +1,27 @@
1
+ import React from "react";
2
+ import { StyleProp, TextStyle, ViewStyle } from "react-native";
3
+ export interface SearchBarFilter {
4
+ onPress: () => void;
5
+ count?: number;
6
+ accessibilityLabel?: string;
7
+ icon?: React.ReactNode;
8
+ testID?: string;
9
+ }
10
+ export interface SearchBarProps {
11
+ value?: string;
12
+ onChangeText?: (value: string) => void;
13
+ onSubmit?: (value: string) => void;
14
+ onClear?: () => void;
15
+ /** Opens a dedicated search screen when the field is pressed. */
16
+ onPress?: () => void;
17
+ autoFocus?: boolean;
18
+ placeholder?: string;
19
+ clearAccessibilityLabel?: string;
20
+ searchIcon?: React.ReactNode;
21
+ clearIcon?: React.ReactNode;
22
+ filter?: SearchBarFilter;
23
+ style?: StyleProp<ViewStyle>;
24
+ fieldStyle?: StyleProp<ViewStyle>;
25
+ textStyle?: StyleProp<TextStyle>;
26
+ }
27
+ export declare function SearchBar({ value, onChangeText, onSubmit, onClear, onPress, autoFocus, placeholder, clearAccessibilityLabel, searchIcon, clearIcon, filter, style, fieldStyle, textStyle, }: SearchBarProps): React.JSX.Element;
package/dist/search.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchBar = SearchBar;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const icons_1 = require("./icons");
8
+ const primitives_1 = require("./primitives");
9
+ const theme_1 = require("./theme");
10
+ function SearchBar({ value, onChangeText, onSubmit, onClear, onPress, autoFocus, placeholder = "Search", clearAccessibilityLabel = "Clear search", searchIcon, clearIcon, filter, style, fieldStyle, textStyle, }) {
11
+ const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
12
+ const [input, setInput] = (0, react_1.useState)("");
13
+ const inputRef = (0, react_1.useRef)(null);
14
+ const keyword = value ?? input;
15
+ const height = s.xxl + s.xl;
16
+ const filterCount = filter?.count ?? 0;
17
+ const hasFilters = filterCount > 0;
18
+ const badgeLabel = filterCount > 99 ? "99+" : String(filterCount);
19
+ const badgeHeight = s.lg;
20
+ const badgeWidth = badgeHeight + (badgeLabel.length - 1) * s.sm;
21
+ // Keep the badge center on the button's top-right arc at 45 degrees.
22
+ const badgeCenterInset = (height / 2) * (1 - Math.SQRT1_2);
23
+ const changeText = (text) => {
24
+ if (value === undefined)
25
+ setInput(text);
26
+ onChangeText?.(text);
27
+ };
28
+ const field = [
29
+ styles.field,
30
+ {
31
+ height,
32
+ paddingHorizontal: s.md,
33
+ gap: s.sm,
34
+ borderRadius: r.full,
35
+ backgroundColor: c.base3,
36
+ },
37
+ fieldStyle,
38
+ ];
39
+ const icon = searchIcon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "search", size: s.xxl, color: c.content2 }));
40
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.row, { gap: s.md }, style], children: [onPress ? ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { accessibilityRole: "button", onPress: onPress, style: ({ pressed }) => [field, pressed && styles.pressed], children: [icon, (0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "content2", numberOfLines: 1, style: [styles.input, textStyle], children: placeholder })] })) : ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: field, children: [icon, (0, jsx_runtime_1.jsx)(react_native_1.TextInput, { ref: inputRef, autoFocus: autoFocus, value: keyword, placeholder: placeholder, placeholderTextColor: c.content2, onChangeText: changeText, onSubmitEditing: () => onSubmit?.(keyword), returnKeyType: "search", style: [
41
+ styles.input,
42
+ {
43
+ color: c.content1,
44
+ fontFamily: t.fontFamily,
45
+ fontSize: t.body,
46
+ lineHeight: t.body + s.xs,
47
+ },
48
+ textStyle,
49
+ ] }), keyword.length > 0 && ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: clearAccessibilityLabel, hitSlop: s.sm, onPress: () => {
50
+ changeText("");
51
+ onClear?.();
52
+ if (autoFocus)
53
+ inputRef.current?.focus();
54
+ }, style: clearIcon == null
55
+ ? [
56
+ styles.center,
57
+ {
58
+ width: t.body,
59
+ height: t.body,
60
+ borderRadius: r.full,
61
+ backgroundColor: c.gray600,
62
+ },
63
+ ]
64
+ : undefined, children: clearIcon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "close", size: t.caption, color: c.background })) }))] })), filter && ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { testID: filter.testID, accessibilityRole: "button", accessibilityLabel: filter.accessibilityLabel ?? "Filter", accessibilityValue: hasFilters ? { text: String(filterCount) } : undefined, onPress: filter.onPress, style: [
65
+ styles.center,
66
+ {
67
+ width: height,
68
+ height,
69
+ borderRadius: r.full,
70
+ backgroundColor: c.base3,
71
+ },
72
+ ], children: [filter.icon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "filter", size: s.xxl, color: hasFilters ? c.primary500 : c.content1 })), hasFilters && ((0, jsx_runtime_1.jsx)(react_native_1.View, { pointerEvents: "none", style: [
73
+ styles.center,
74
+ {
75
+ position: "absolute",
76
+ top: badgeCenterInset - badgeHeight / 2,
77
+ right: badgeCenterInset - badgeWidth / 2,
78
+ width: badgeWidth,
79
+ height: badgeHeight,
80
+ borderRadius: r.full,
81
+ backgroundColor: c.danger,
82
+ },
83
+ ], children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "textPrimary", variant: "caption", weight: "600", children: badgeLabel }) }))] }))] }));
84
+ }
85
+ const styles = react_native_1.StyleSheet.create({
86
+ row: { flexDirection: "row", alignItems: "center", minWidth: 0 },
87
+ field: { flex: 1, minWidth: 0, flexDirection: "row", alignItems: "center" },
88
+ pressed: { opacity: 0.8 },
89
+ input: { flex: 1, minWidth: 0, padding: 0 },
90
+ center: { alignItems: "center", justifyContent: "center" },
91
+ });
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { type ColorValue, type ModalProps, type StyleProp, type ViewStyle } from "react-native";
3
+ export interface UIModalProps {
4
+ visible: boolean;
5
+ onClose?: () => void;
6
+ onOpened?: () => void;
7
+ onClosed?: () => void;
8
+ position?: "center" | "bottom" | "fullScreen";
9
+ animationType?: ModalProps["animationType"];
10
+ statusBarTranslucent?: boolean;
11
+ keyboardAvoiding?: boolean;
12
+ backdropColor?: ColorValue;
13
+ contentStyle?: StyleProp<ViewStyle>;
14
+ containerStyle?: StyleProp<ViewStyle>;
15
+ children?: React.ReactNode;
16
+ }
17
+ export declare function UIModal({ visible, onClose, onOpened, onClosed, position, animationType, statusBarTranslucent, keyboardAvoiding, backdropColor, contentStyle, containerStyle, children, }: UIModalProps): React.JSX.Element;