@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,14 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type ScrollViewProps, type ViewProps } from 'react-native';
3
+ export declare const useScrollToFormError: () => {
4
+ validationAttempt: number;
5
+ onValidationError: () => void;
6
+ };
7
+ export type FormScrollViewProps = Omit<ScrollViewProps, 'horizontal' | 'innerViewRef'> & {
8
+ validationAttempt: number;
9
+ footer?: ReactNode;
10
+ };
11
+ export declare const FormScrollView: ({ validationAttempt, footer, style, keyboardShouldPersistTaps, ...props }: FormScrollViewProps) => import("react").JSX.Element;
12
+ export declare const FormErrorAnchor: ({ error, ...props }: ViewProps & {
13
+ error?: string;
14
+ }) => import("react").JSX.Element;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FormErrorAnchor = exports.FormScrollView = exports.useScrollToFormError = void 0;
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 react_native_keyboard_controller_1 = require("react-native-keyboard-controller");
8
+ const FormErrorContext = (0, react_1.createContext)(null);
9
+ const useScrollToFormError = () => {
10
+ const [validationAttempt, setValidationAttempt] = (0, react_1.useState)(0);
11
+ const onValidationError = (0, react_1.useCallback)(() => setValidationAttempt(count => count + 1), []);
12
+ return { validationAttempt, onValidationError };
13
+ };
14
+ exports.useScrollToFormError = useScrollToFormError;
15
+ const FormScrollView = ({ validationAttempt, footer, style, keyboardShouldPersistTaps = 'handled', ...props }) => {
16
+ const scroll = (0, react_1.useRef)(null);
17
+ const content = (0, react_1.useRef)(null);
18
+ const invalidFields = (0, react_1.useRef)(new Set());
19
+ const [footerHeight, setFooterHeight] = (0, react_1.useState)(0);
20
+ const register = (0, react_1.useCallback)((field) => {
21
+ invalidFields.current.add(field);
22
+ return () => {
23
+ invalidFields.current.delete(field);
24
+ };
25
+ }, []);
26
+ (0, react_1.useEffect)(() => {
27
+ if (!validationAttempt)
28
+ return;
29
+ let cancelled = false;
30
+ let frame;
31
+ // Let the keyboard and its scroll adjustments finish before measuring the errors.
32
+ void react_native_keyboard_controller_1.KeyboardController.dismiss().then(() => {
33
+ if (cancelled)
34
+ return;
35
+ frame = requestAnimationFrame(async () => {
36
+ const parent = content.current;
37
+ if (!parent)
38
+ return;
39
+ const positions = await Promise.all([...invalidFields.current].map(field => new Promise(resolve => {
40
+ field.measureLayout(parent, (_x, y) => resolve(y), () => resolve(Infinity));
41
+ })));
42
+ const first = Math.min(...positions.filter(Number.isFinite));
43
+ if (!cancelled && Number.isFinite(first)) {
44
+ scroll.current?.scrollTo({ y: Math.max(0, first - 16), animated: true });
45
+ }
46
+ });
47
+ });
48
+ return () => {
49
+ cancelled = true;
50
+ if (frame !== undefined)
51
+ cancelAnimationFrame(frame);
52
+ };
53
+ }, [validationAttempt]);
54
+ return ((0, jsx_runtime_1.jsx)(FormErrorContext.Provider, { value: register, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.fill, style], children: [(0, jsx_runtime_1.jsx)(react_native_keyboard_controller_1.KeyboardAwareScrollView, { ...props, ref: scroll, style: styles.fill, innerViewRef: content, keyboardShouldPersistTaps: keyboardShouldPersistTaps, bottomOffset: (footer == null ? 0 : footerHeight) + 16 }), footer != null && ((0, jsx_runtime_1.jsx)(react_native_keyboard_controller_1.KeyboardStickyView, { onLayout: event => setFooterHeight(event.nativeEvent.layout.height), children: footer }))] }) }));
55
+ };
56
+ exports.FormScrollView = FormScrollView;
57
+ const FormErrorAnchor = ({ error, ...props }) => {
58
+ const register = (0, react_1.useContext)(FormErrorContext);
59
+ const field = (0, react_1.useRef)(null);
60
+ const invalid = !!error;
61
+ (0, react_1.useLayoutEffect)(() => {
62
+ if (invalid && field.current)
63
+ return register?.(field.current);
64
+ }, [invalid, register]);
65
+ return (0, jsx_runtime_1.jsx)(react_native_1.View, { ...props, ref: field, collapsable: false });
66
+ };
67
+ exports.FormErrorAnchor = FormErrorAnchor;
68
+ const styles = react_native_1.StyleSheet.create({ fill: { flex: 1 } });
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ export interface UIIconProps {
3
+ color: string;
4
+ size?: number;
5
+ }
6
+ type Name = "back" | "close" | "chevron" | "check" | "calendar" | "clock" | "search" | "filter" | "folder" | "upload" | "file";
7
+ export declare function UIIcon({ name, color, size, }: UIIconProps & {
8
+ name: Name;
9
+ }): React.JSX.Element;
10
+ export {};
package/dist/icons.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.UIIcon = UIIcon;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_native_svg_1 = __importStar(require("react-native-svg"));
39
+ function UIIcon({ name, color, size = 20, }) {
40
+ const paths = {
41
+ back: "M15 5l-7 7 7 7",
42
+ close: "M6 6l12 12M18 6L6 18",
43
+ chevron: "M6 9l6 6 6-6",
44
+ check: "M5 12l4 4L19 6",
45
+ search: "M21 11.5C21 16.7467 16.7467 21 11.5 21C6.25329 21 2 16.7467 2 11.5C2 6.25329 6.25329 2 11.5 2C16.7467 2 21 6.25329 21 11.5ZM22 22L20 20",
46
+ filter: "M3 7h18M6 12h12M10 17h4",
47
+ folder: "M3 7V5h7l2 2h9v13H3V7zm9 4v6m-3-3h6",
48
+ upload: "M12 16V3m-5 5 5-5 5 5M4 15v6h16v-6",
49
+ file: "M14 3H5v18h14V8l-5-5zm0 0v5h5M8 12h8M8 16h6",
50
+ };
51
+ return ((0, jsx_runtime_1.jsx)(react_native_svg_1.default, { width: size, height: size, viewBox: "0 0 24 24", fill: "none", children: name === "calendar" ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_svg_1.Rect, { x: 3, y: 5, width: 18, height: 16, rx: 2, stroke: color, strokeWidth: 1.7 }), (0, jsx_runtime_1.jsx)(react_native_svg_1.Path, { d: "M3 10h18M7 3v4M17 3v4M7 14h2M12 14h2M7 17h2M12 17h2", stroke: color, strokeWidth: 1.7, strokeLinecap: "round" })] })) : name === "clock" ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_svg_1.Circle, { cx: 12, cy: 12, r: 9, stroke: color, strokeWidth: 1.7 }), (0, jsx_runtime_1.jsx)(react_native_svg_1.Path, { d: "M12 7v5l3 2", stroke: color, strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round" })] })) : ((0, jsx_runtime_1.jsx)(react_native_svg_1.Path, { d: paths[name], stroke: color, strokeWidth: name === "search" ? 1.5 : 1.7, strokeLinecap: "round", strokeLinejoin: "round" })) }));
52
+ }
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ import { ImageProps, ImageSource } from "expo-image";
3
+ import { StyleProp, ViewStyle } from "react-native";
4
+ import { SkeletonProps } from "./primitives";
5
+ export type ImageWithSkeletonSource = ImageSource | string | number;
6
+ export interface ImageWithSkeletonProps extends Omit<ImageProps, "source" | "style" | "loading"> {
7
+ source?: ImageWithSkeletonSource;
8
+ fallbackSource?: ImageWithSkeletonSource;
9
+ /** Wait for the caller to resolve a source before showing the fallback. */
10
+ loading?: boolean;
11
+ /** Keep the skeleton until the image is displayed instead of when it loads. */
12
+ waitForDisplay?: boolean;
13
+ /** Container geometry, including width/height or aspectRatio and borderRadius. */
14
+ style?: StyleProp<ViewStyle>;
15
+ imageStyle?: ImageProps["style"];
16
+ fallbackContentFit?: ImageProps["contentFit"];
17
+ skeletonProps?: SkeletonProps;
18
+ }
19
+ /** Image loading state is local; source resolution, credentials and fallbacks belong to the app. */
20
+ export declare function ImageWithSkeleton(props: ImageWithSkeletonProps): React.JSX.Element;
package/dist/image.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImageWithSkeleton = ImageWithSkeleton;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const expo_image_1 = require("expo-image");
7
+ const react_native_1 = require("react-native");
8
+ const primitives_1 = require("./primitives");
9
+ function ImagePresentation({ source, fallbackSource, loading = false, waitForDisplay = false, style, imageStyle, contentFit = "cover", fallbackContentFit = "contain", skeletonProps, testID = "image", onLoad, onDisplay, onError, ...imageProps }) {
10
+ const [loaded, setLoaded] = (0, react_1.useState)(false);
11
+ const [displayed, setDisplayed] = (0, react_1.useState)(false);
12
+ const [failed, setFailed] = (0, react_1.useState)(false);
13
+ const ready = waitForDisplay ? displayed : loaded;
14
+ const showSkeleton = source ? !failed && !ready : loading;
15
+ const useFallback = failed || !source;
16
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [{ overflow: "hidden" }, style], testID: `${testID}-container`, children: [(0, jsx_runtime_1.jsx)(expo_image_1.Image, { ...imageProps, source: useFallback ? fallbackSource : source, contentFit: useFallback ? fallbackContentFit : contentFit, style: [react_native_1.StyleSheet.absoluteFill, imageStyle], testID: testID, onLoad: (event) => {
17
+ setLoaded(true);
18
+ onLoad?.(event);
19
+ }, onDisplay: () => {
20
+ setDisplayed(true);
21
+ onDisplay?.();
22
+ }, onError: (event) => {
23
+ setFailed(true);
24
+ onError?.(event);
25
+ } }), showSkeleton && ((0, jsx_runtime_1.jsx)(primitives_1.Skeleton, { ...skeletonProps, style: [
26
+ react_native_1.StyleSheet.absoluteFill,
27
+ { width: "100%", height: "100%" },
28
+ skeletonProps?.style,
29
+ ], testID: `${testID}-skeleton` }))] }));
30
+ }
31
+ /** Image loading state is local; source resolution, credentials and fallbacks belong to the app. */
32
+ function ImageWithSkeleton(props) {
33
+ return ((0, jsx_runtime_1.jsx)(ImagePresentation, { ...props }, JSON.stringify(props.source ?? null)));
34
+ }
@@ -0,0 +1,15 @@
1
+ export type { PaletteColors } from "./colors";
2
+ export * from "./theme";
3
+ export * from "./primitives";
4
+ export * from "./image";
5
+ export * from "./fields";
6
+ export * from "./search";
7
+ export * from "./date";
8
+ export * from "./overlays";
9
+ export * from "./ui-modal";
10
+ export * from "./choices";
11
+ export * from "./process-graph";
12
+ export { UIIcon } from "./icons";
13
+ export type { UIIconProps } from "./icons";
14
+ export { ScreenHeader as Header, CollapsibleSection as CollapsibleCard, } from "./primitives";
15
+ export * from "./list-picker";
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.CollapsibleCard = exports.Header = exports.UIIcon = void 0;
18
+ __exportStar(require("./theme"), exports);
19
+ __exportStar(require("./primitives"), exports);
20
+ __exportStar(require("./image"), exports);
21
+ __exportStar(require("./fields"), exports);
22
+ __exportStar(require("./search"), exports);
23
+ __exportStar(require("./date"), exports);
24
+ __exportStar(require("./overlays"), exports);
25
+ __exportStar(require("./ui-modal"), exports);
26
+ __exportStar(require("./choices"), exports);
27
+ __exportStar(require("./process-graph"), exports);
28
+ var icons_1 = require("./icons");
29
+ Object.defineProperty(exports, "UIIcon", { enumerable: true, get: function () { return icons_1.UIIcon; } });
30
+ var primitives_1 = require("./primitives");
31
+ Object.defineProperty(exports, "Header", { enumerable: true, get: function () { return primitives_1.ScreenHeader; } });
32
+ Object.defineProperty(exports, "CollapsibleCard", { enumerable: true, get: function () { return primitives_1.CollapsibleSection; } });
33
+ __exportStar(require("./list-picker"), exports);
@@ -0,0 +1,45 @@
1
+ import React from "react";
2
+ import { type FlatListProps, type StyleProp, type ViewStyle } from "react-native";
3
+ export type ListPickerListProps<T> = Pick<FlatListProps<T>, "style" | "keyExtractor" | "extraData" | "contentContainerStyle" | "ListEmptyComponent" | "ListFooterComponent" | "onEndReached" | "onEndReachedThreshold" | "refreshControl" | "showsVerticalScrollIndicator" | "keyboardShouldPersistTaps"> & {
4
+ data: readonly T[];
5
+ renderItem: (info: {
6
+ item: T;
7
+ }) => React.ReactElement | null;
8
+ ItemSeparatorComponent: React.ComponentType;
9
+ };
10
+ type Selection<T> = {
11
+ multiple?: false;
12
+ value?: T | null;
13
+ onChange: (value: T) => void;
14
+ } | {
15
+ multiple: true;
16
+ value?: readonly T[] | null;
17
+ onChange: (value: T[]) => void;
18
+ };
19
+ export type ListPickerProps<T> = Selection<T> & {
20
+ items: readonly T[];
21
+ getKey: (item: T) => unknown;
22
+ getLabel: (item: T) => string;
23
+ loading?: boolean;
24
+ loadingMore?: boolean;
25
+ refreshing?: boolean;
26
+ onRefresh?: () => void;
27
+ onLoadMore?: () => void;
28
+ onSearch?: (keyword: string) => void;
29
+ errorText?: string;
30
+ emptyText?: string;
31
+ onRetry?: () => void;
32
+ retryText?: string;
33
+ confirmText?: string;
34
+ searchPlaceholder?: string;
35
+ clearSearchAccessibilityLabel?: string;
36
+ search?: React.ReactNode;
37
+ loadingContent?: React.ReactNode;
38
+ listStyle?: StyleProp<ViewStyle>;
39
+ contentContainerStyle?: StyleProp<ViewStyle>;
40
+ footerStyle?: StyleProp<ViewStyle>;
41
+ renderList?: (props: ListPickerListProps<T>) => React.ReactNode;
42
+ renderItem?: (item: T, selected: boolean, onSelect: () => void) => React.ReactElement;
43
+ };
44
+ export declare function ListPicker<T>(props: ListPickerProps<T>): React.JSX.Element;
45
+ export {};
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ListPicker = ListPicker;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = __importDefault(require("react"));
9
+ const react_native_1 = require("react-native");
10
+ const icons_1 = require("./icons");
11
+ const primitives_1 = require("./primitives");
12
+ const search_1 = require("./search");
13
+ const theme_1 = require("./theme");
14
+ function ListPicker(props) {
15
+ const { colors: c, spacing: s } = (0, theme_1.useUITheme)();
16
+ const { items, getKey, getLabel, loading, loadingMore, refreshing, onRefresh, onLoadMore, onSearch, errorText, emptyText, onRetry, retryText = "Retry", confirmText = "Confirm", searchPlaceholder, clearSearchAccessibilityLabel, search, loadingContent, listStyle, contentContainerStyle, footerStyle, renderList, renderItem, } = props;
17
+ const [keyword, setKeyword] = react_1.default.useState("");
18
+ const [draft, setDraft] = react_1.default.useState(null);
19
+ const selected = props.multiple ? draft ?? props.value ?? [] : undefined;
20
+ const selectedKeys = react_1.default.useMemo(() => selected && new Set(selected.map(getKey)), [getKey, selected]);
21
+ const singleKey = !props.multiple && props.value != null ? getKey(props.value) : undefined;
22
+ const normalized = keyword.trim().toLocaleLowerCase();
23
+ const data = react_1.default.useMemo(() => searchPlaceholder && !onSearch && normalized
24
+ ? items.filter((item) => getLabel(item).toLocaleLowerCase().includes(normalized))
25
+ : items, [getLabel, items, normalized, onSearch, searchPlaceholder]);
26
+ const select = (item) => {
27
+ if (!props.multiple) {
28
+ props.onChange(item);
29
+ return;
30
+ }
31
+ const key = getKey(item);
32
+ setDraft((previous) => {
33
+ const current = previous ?? props.value ?? [];
34
+ return current.some((option) => Object.is(getKey(option), key))
35
+ ? current.filter((option) => !Object.is(getKey(option), key))
36
+ : [...current, item];
37
+ });
38
+ };
39
+ const listProps = {
40
+ style: listStyle,
41
+ data,
42
+ extraData: selectedKeys ?? singleKey,
43
+ renderItem: ({ item }) => {
44
+ const key = getKey(item);
45
+ const isSelected = props.multiple
46
+ ? !!selectedKeys?.has(key)
47
+ : props.value != null && Object.is(singleKey, key);
48
+ return renderItem ? (renderItem(item, isSelected, () => select(item))) : ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { accessibilityRole: props.multiple ? "checkbox" : "radio", accessibilityState: props.multiple ? { checked: isSelected } : { selected: isSelected }, style: [styles.row, { paddingVertical: s.md + 2, gap: s.sm }], onPress: () => select(item), children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: isSelected ? "primary500" : "content1", weight: isSelected ? "600" : "400", style: styles.label, children: getLabel(item) }), isSelected && (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "check", size: 18, color: c.primary500 })] }));
49
+ },
50
+ contentContainerStyle: contentContainerStyle ?? { paddingHorizontal: s.lg },
51
+ keyExtractor: (item, index) => `${String(getKey(item))}_${index}`,
52
+ keyboardShouldPersistTaps: "handled",
53
+ showsVerticalScrollIndicator: false,
54
+ onEndReached: loading || loadingMore ? undefined : onLoadMore,
55
+ onEndReachedThreshold: 0.3,
56
+ refreshControl: onRefresh && ((0, jsx_runtime_1.jsx)(react_native_1.RefreshControl, { refreshing: !!refreshing, onRefresh: onRefresh, colors: [c.primary500], tintColor: c.primary500 })),
57
+ ItemSeparatorComponent: () => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: { height: 1, backgroundColor: c.divider } })),
58
+ ListFooterComponent: loadingMore ? ((0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { color: c.primary500 })) : null,
59
+ ListEmptyComponent: errorText || emptyText ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.empty, { paddingVertical: s.xxl + s.sm }], children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "content3", style: styles.emptyText, children: errorText || emptyText }), !!errorText && onRetry && ((0, jsx_runtime_1.jsx)(primitives_1.Button, { variant: "ghost", label: retryText, onPress: onRetry }))] })) : null,
60
+ };
61
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [search ??
62
+ (searchPlaceholder && ((0, jsx_runtime_1.jsx)(search_1.SearchBar, { style: { marginHorizontal: s.lg, marginBottom: s.xs }, placeholder: searchPlaceholder, clearAccessibilityLabel: clearSearchAccessibilityLabel, onChangeText: (text) => {
63
+ setKeyword(text);
64
+ onSearch?.(text.trim());
65
+ } }))), loading ? (loadingContent ?? (0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { color: c.primary500 })) : renderList ? (renderList(listProps)) : ((0, jsx_runtime_1.jsx)(react_native_1.FlatList, { ...listProps })), props.multiple && ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [{ paddingHorizontal: s.lg, paddingTop: s.md }, footerStyle], children: (0, jsx_runtime_1.jsx)(primitives_1.Button, { label: confirmText, onPress: () => props.onChange([...(selected ?? [])]) }) }))] }));
66
+ }
67
+ const styles = react_native_1.StyleSheet.create({
68
+ row: {
69
+ flexDirection: "row",
70
+ alignItems: "center",
71
+ justifyContent: "space-between",
72
+ },
73
+ label: { flex: 1 },
74
+ empty: { alignItems: "center" },
75
+ emptyText: { textAlign: "center" },
76
+ });
@@ -0,0 +1,135 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { Animated, I18nManager, Platform, Pressable, StyleSheet, View, } from "react-native";
4
+ import { useUITheme } from "./theme.js";
5
+ import { UIText } from "./primitives.js";
6
+ import { UIIcon } from "./icons.js";
7
+ const switchDimensions = {
8
+ small: { width: 40, padding: 10, thumb: 15, onOffset: 18 },
9
+ medium: { width: 46, padding: 12, thumb: 18, onOffset: 20 },
10
+ large: { width: 70, padding: 20, thumb: 30, onOffset: 32 },
11
+ };
12
+ /** Controlled switch. Animation belongs to the component; state belongs to the app. */
13
+ export function ToggleSwitch({ checked, onChange, size = "medium", disabled = false, style, onColor, offColor, thumbColor, hitSlop, testID, accessibilityLabel, }) {
14
+ const { colors: c } = useUITheme();
15
+ const dimensions = switchDimensions[size];
16
+ const offset = useRef(new Animated.Value(0)).current;
17
+ const isRTL = I18nManager.isRTL;
18
+ const desktop = ["windows", "macos"].includes(Platform.OS);
19
+ useEffect(() => {
20
+ const animation = Animated.timing(offset, {
21
+ toValue: checked
22
+ ? isRTL
23
+ ? -dimensions.onOffset
24
+ : dimensions.onOffset
25
+ : -1,
26
+ duration: 300,
27
+ useNativeDriver: true,
28
+ });
29
+ animation.start();
30
+ return () => animation.stop();
31
+ }, [checked, isRTL, dimensions.onOffset, offset]);
32
+ return (_jsx(View, { style: [styles.row, style], children: _jsx(Pressable, { testID: testID, hitSlop: hitSlop, disabled: disabled, onPress: () => onChange(!checked), accessibilityRole: "switch", accessibilityLabel: accessibilityLabel, accessibilityState: { checked, disabled }, style: ({ pressed }) => ({
33
+ justifyContent: "center",
34
+ width: dimensions.width,
35
+ borderRadius: desktop ? 10 : 20,
36
+ padding: dimensions.padding,
37
+ paddingBottom: dimensions.padding + (desktop ? 2 : 0),
38
+ backgroundColor: checked ? onColor ?? c.primary500 : offColor ?? c.gray200,
39
+ opacity: pressed ? 0.8 : 1,
40
+ }), children: _jsx(Animated.View, { pointerEvents: "none", style: {
41
+ position: "absolute",
42
+ alignItems: "center",
43
+ justifyContent: "center",
44
+ margin: Platform.OS === "web" ? 0 : 4,
45
+ left: Platform.OS === "web" ? 4 : 0,
46
+ width: dimensions.thumb,
47
+ height: dimensions.thumb,
48
+ borderRadius: dimensions.thumb / 2,
49
+ backgroundColor: thumbColor ?? c.textPrimary,
50
+ transform: [{ translateX: offset }],
51
+ shadowColor: "#000",
52
+ shadowOffset: { width: 0, height: 2 },
53
+ shadowOpacity: 0.2,
54
+ shadowRadius: 2.5,
55
+ elevation: 1.5,
56
+ } }) }) }));
57
+ }
58
+ /** Use an indicator inside an app-owned Pressable to avoid nested touch targets. */
59
+ export function RadioIndicator({ selected, disabled, size = 20, style, }) {
60
+ const { colors: c } = useUITheme();
61
+ return (_jsx(View, { style: [
62
+ styles.choice,
63
+ {
64
+ width: size,
65
+ height: size,
66
+ borderRadius: 99,
67
+ borderColor: selected ? c.primary500 : c.gray200,
68
+ backgroundColor: c.background,
69
+ opacity: disabled ? 0.5 : 1,
70
+ },
71
+ style,
72
+ ], children: selected && (_jsx(View, { style: {
73
+ width: size / 2,
74
+ height: size / 2,
75
+ borderRadius: 99,
76
+ backgroundColor: c.primary500,
77
+ } })) }));
78
+ }
79
+ export function CheckboxIndicator({ selected, disabled, size = 20, style, }) {
80
+ const { colors: c, radius: r } = useUITheme();
81
+ return (_jsx(View, { style: [
82
+ styles.choice,
83
+ {
84
+ width: size,
85
+ height: size,
86
+ borderColor: selected ? c.primary500 : c.gray200,
87
+ backgroundColor: selected ? c.primary500 : c.background,
88
+ borderRadius: r.sm,
89
+ opacity: disabled ? 0.5 : 1,
90
+ },
91
+ style,
92
+ ], children: selected && _jsx(UIIcon, { name: "check", color: c.textPrimary, size: size * 0.8 }) }));
93
+ }
94
+ export function Checkbox({ checked, onChange, label, disabled, style, labelStyle, }) {
95
+ const { spacing: s } = useUITheme();
96
+ return (_jsxs(Pressable, { onPress: () => onChange(!checked), disabled: disabled, accessibilityRole: "checkbox", accessibilityState: { checked, disabled: !!disabled }, style: [styles.row, { gap: s.sm, opacity: disabled ? 0.5 : 1 }, style], children: [_jsx(CheckboxIndicator, { selected: checked }), typeof label === "string" ? (_jsx(UIText, { style: labelStyle, children: label })) : (label)] }));
97
+ }
98
+ export function Radio({ selected, onPress, label, disabled, style, labelStyle, }) {
99
+ const { spacing: s } = useUITheme();
100
+ return (_jsxs(Pressable, { onPress: onPress, disabled: disabled, accessibilityRole: "radio", accessibilityState: { selected, disabled: !!disabled }, style: [styles.row, { gap: s.sm, opacity: disabled ? 0.5 : 1 }, style], children: [_jsx(RadioIndicator, { selected: selected }), typeof label === "string" ? (_jsx(UIText, { style: labelStyle, children: label })) : (label)] }));
101
+ }
102
+ export function SegmentedTabs({ tabs, value, onChange, style, }) {
103
+ const { colors: c, spacing: s, radius: r } = useUITheme();
104
+ return (_jsx(View, { accessibilityRole: "tablist", style: [
105
+ styles.row,
106
+ {
107
+ backgroundColor: c.gray50,
108
+ padding: s.xs,
109
+ borderRadius: r.md,
110
+ gap: s.xs,
111
+ },
112
+ style,
113
+ ], children: tabs.map((tab, index) => {
114
+ const selected = Object.is(tab.value, value);
115
+ return (_jsx(Pressable, { accessibilityRole: "tab", accessibilityState: { selected, disabled: !!tab.disabled }, disabled: tab.disabled, onPress: () => onChange(tab.value), style: {
116
+ flex: 1,
117
+ paddingVertical: s.sm,
118
+ paddingHorizontal: s.sm,
119
+ alignItems: "center",
120
+ borderRadius: r.sm,
121
+ backgroundColor: selected ? c.background : "transparent",
122
+ opacity: tab.disabled ? 0.5 : 1,
123
+ }, children: _jsx(UIText, { weight: selected ? "600" : "400", color: selected ? "primary500" : "content2", children: tab.label }) }, index));
124
+ }) }));
125
+ }
126
+ const styles = StyleSheet.create({
127
+ row: { flexDirection: "row", alignItems: "center" },
128
+ choice: {
129
+ width: 20,
130
+ height: 20,
131
+ borderWidth: 1.5,
132
+ alignItems: "center",
133
+ justifyContent: "center",
134
+ },
135
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ {"type":"module"}