@thanhphi/unistyles-ui 0.0.0-stage → 0.2.6

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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +374 -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 +138 -0
  10. package/dist/fields.js +240 -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 +51 -0
  15. package/dist/image.d.ts +20 -0
  16. package/dist/image.js +34 -0
  17. package/dist/index.d.ts +12 -0
  18. package/dist/index.js +30 -0
  19. package/dist/module/choices.js +135 -0
  20. package/dist/module/colors/index.js +1 -0
  21. package/dist/module/colors/package.json +1 -0
  22. package/dist/module/date.js +145 -0
  23. package/dist/module/fields.js +232 -0
  24. package/dist/module/form/index.js +62 -0
  25. package/dist/module/form/package.json +1 -0
  26. package/dist/module/icons.js +15 -0
  27. package/dist/module/image.js +31 -0
  28. package/dist/module/index.js +10 -0
  29. package/dist/module/overlays.js +102 -0
  30. package/dist/module/package.json +1 -0
  31. package/dist/module/primitives.js +432 -0
  32. package/dist/module/process-graph.js +125 -0
  33. package/dist/module/rich-html/html-styles.js +55 -0
  34. package/dist/module/rich-html/image-renderers.js +141 -0
  35. package/dist/module/rich-html/index.js +54 -0
  36. package/dist/module/rich-html/normalize-inline-colors.js +93 -0
  37. package/dist/module/rich-html/package.json +1 -0
  38. package/dist/module/rich-html/rich-html.js +118 -0
  39. package/dist/module/theme.js +62 -0
  40. package/dist/module/toast.js +30 -0
  41. package/dist/overlays.d.ts +52 -0
  42. package/dist/overlays.js +109 -0
  43. package/dist/primitives.d.ts +157 -0
  44. package/dist/primitives.js +480 -0
  45. package/dist/process-graph.d.ts +33 -0
  46. package/dist/process-graph.js +161 -0
  47. package/dist/rich-html/html-styles.d.ts +23 -0
  48. package/dist/rich-html/html-styles.js +63 -0
  49. package/dist/rich-html/image-renderers.d.ts +12 -0
  50. package/dist/rich-html/image-renderers.js +144 -0
  51. package/dist/rich-html/index.d.ts +18 -0
  52. package/dist/rich-html/index.js +92 -0
  53. package/dist/rich-html/normalize-inline-colors.d.ts +8 -0
  54. package/dist/rich-html/normalize-inline-colors.js +99 -0
  55. package/dist/rich-html/rich-html.d.ts +7 -0
  56. package/dist/rich-html/rich-html.js +123 -0
  57. package/dist/theme.d.ts +67 -0
  58. package/dist/theme.js +68 -0
  59. package/dist/toast.d.ts +3 -0
  60. package/dist/toast.js +69 -0
  61. package/package.json +35 -4
@@ -0,0 +1,79 @@
1
+ /** Names and meaning follow the 360 guideline. Hex values belong to each app. */
2
+ export interface PaletteColors {
3
+ background: string;
4
+ base2: string;
5
+ base3: string;
6
+ divider: string;
7
+ focus: string;
8
+ content1: string;
9
+ content2: string;
10
+ content3: string;
11
+ content4: string;
12
+ textPrimary: string;
13
+ default: string;
14
+ primary: string;
15
+ secondary: string;
16
+ success: string;
17
+ warning: string;
18
+ danger: string;
19
+ gray50: string;
20
+ gray100: string;
21
+ gray200: string;
22
+ gray300: string;
23
+ gray400: string;
24
+ gray500: string;
25
+ gray600: string;
26
+ gray700: string;
27
+ gray800: string;
28
+ gray900: string;
29
+ primary50: string;
30
+ primary100: string;
31
+ primary200: string;
32
+ primary300: string;
33
+ primary400: string;
34
+ primary500: string;
35
+ primary600: string;
36
+ primary700: string;
37
+ primary800: string;
38
+ primary900: string;
39
+ secondary50: string;
40
+ secondary100: string;
41
+ secondary200: string;
42
+ secondary300: string;
43
+ secondary400: string;
44
+ secondary500: string;
45
+ secondary600: string;
46
+ secondary700: string;
47
+ secondary800: string;
48
+ secondary900: string;
49
+ success50: string;
50
+ success100: string;
51
+ success200: string;
52
+ success300: string;
53
+ success400: string;
54
+ success500: string;
55
+ success600: string;
56
+ success700: string;
57
+ success800: string;
58
+ success900: string;
59
+ warning50: string;
60
+ warning100: string;
61
+ warning200: string;
62
+ warning300: string;
63
+ warning400: string;
64
+ warning500: string;
65
+ warning600: string;
66
+ warning700: string;
67
+ warning800: string;
68
+ warning900: string;
69
+ danger50: string;
70
+ danger100: string;
71
+ danger200: string;
72
+ danger300: string;
73
+ danger400: string;
74
+ danger500: string;
75
+ danger600: string;
76
+ danger700: string;
77
+ danger800: string;
78
+ danger900: string;
79
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/date.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import React from "react";
2
+ import { ImageSourcePropType, StyleProp, ViewStyle } from "react-native";
3
+ /** Validates date-only values without parsing through UTC or applying a timezone. */
4
+ export declare function isDateOnly(value: string): boolean;
5
+ export declare function isDateInRange(value: string, minDate?: string, maxDate?: string): boolean;
6
+ export declare function todayDateOnly(): string;
7
+ export declare function formatDateOnly(value: string): string;
8
+ export declare function addDateMonths(value: string, amount: number): string;
9
+ export interface DatePickerRenderProps {
10
+ selectedDate: string | null;
11
+ currentMonth: string;
12
+ onSelect: (date: string) => void;
13
+ onMonthChange: (date: string) => void;
14
+ minDate?: string;
15
+ maxDate?: string;
16
+ }
17
+ export interface DateFieldProps {
18
+ variant?: "default" | "form";
19
+ label?: string;
20
+ required?: boolean;
21
+ placeholder?: string;
22
+ confirmText: string;
23
+ clearText?: string;
24
+ value: string | null;
25
+ minDate?: string;
26
+ maxDate?: string;
27
+ disabled?: boolean;
28
+ error?: string;
29
+ onChange: (date: string) => void;
30
+ onClear?: () => void;
31
+ formatValue?: (date: string) => string;
32
+ formatMonth?: (date: string) => string;
33
+ renderPicker?: (props: DatePickerRenderProps) => React.ReactNode;
34
+ icon?: React.ReactNode;
35
+ iconSource?: ImageSourcePropType;
36
+ closeAccessibilityLabel?: string;
37
+ style?: StyleProp<ViewStyle>;
38
+ fieldStyle?: StyleProp<ViewStyle>;
39
+ }
40
+ export declare function DateField({ variant, label, required, placeholder, confirmText, clearText, value, minDate, maxDate, disabled, error, onChange, onClear, formatValue, formatMonth, renderPicker, icon, iconSource, closeAccessibilityLabel, style, fieldStyle, }: DateFieldProps): React.JSX.Element;
package/dist/date.js ADDED
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDateOnly = isDateOnly;
4
+ exports.isDateInRange = isDateInRange;
5
+ exports.todayDateOnly = todayDateOnly;
6
+ exports.formatDateOnly = formatDateOnly;
7
+ exports.addDateMonths = addDateMonths;
8
+ exports.DateField = DateField;
9
+ const jsx_runtime_1 = require("react/jsx-runtime");
10
+ const react_1 = require("react");
11
+ const react_native_1 = require("react-native");
12
+ const react_native_calendars_1 = require("react-native-calendars");
13
+ const theme_1 = require("./theme");
14
+ const primitives_1 = require("./primitives");
15
+ const fields_1 = require("./fields");
16
+ const overlays_1 = require("./overlays");
17
+ const icons_1 = require("./icons");
18
+ /** Validates date-only values without parsing through UTC or applying a timezone. */
19
+ function isDateOnly(value) {
20
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
21
+ if (!match)
22
+ return false;
23
+ const year = Number(match[1]), month = Number(match[2]), day = Number(match[3]);
24
+ if (year < 1 || month < 1 || month > 12 || day < 1)
25
+ return false;
26
+ const days = month === 2
27
+ ? year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)
28
+ ? 29
29
+ : 28
30
+ : [4, 6, 9, 11].includes(month)
31
+ ? 30
32
+ : 31;
33
+ return day <= days;
34
+ }
35
+ function isDateInRange(value, minDate, maxDate) {
36
+ return (isDateOnly(value) &&
37
+ (!minDate || value >= minDate) &&
38
+ (!maxDate || value <= maxDate));
39
+ }
40
+ function todayDateOnly() {
41
+ const now = new Date();
42
+ return `${String(now.getFullYear()).padStart(4, "0")}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
43
+ }
44
+ function formatDateOnly(value) {
45
+ return isDateOnly(value) ? value.split("-").reverse().join("/") : value;
46
+ }
47
+ function addDateMonths(value, amount) {
48
+ const [year, month] = value.split("-").map(Number);
49
+ const index = year * 12 + month - 1 + amount;
50
+ return `${String(Math.floor(index / 12)).padStart(4, "0")}-${String((((index % 12) + 12) % 12) + 1).padStart(2, "0")}-01`;
51
+ }
52
+ function DateField({ variant = "default", label, required, placeholder, confirmText, clearText, value, minDate, maxDate, disabled = false, error, onChange, onClear, formatValue = formatDateOnly, formatMonth, renderPicker, icon, iconSource, closeAccessibilityLabel, style, fieldStyle, }) {
53
+ const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
54
+ const [visible, setVisible] = (0, react_1.useState)(false);
55
+ const [selectedDate, setSelectedDate] = (0, react_1.useState)(null);
56
+ const [currentMonth, setCurrentMonth] = (0, react_1.useState)(todayDateOnly);
57
+ const validSelection = !!selectedDate && isDateInRange(selectedDate, minDate, maxDate);
58
+ const open = () => {
59
+ const selected = value && isDateOnly(value) ? value : null;
60
+ let month = selected ?? todayDateOnly();
61
+ if (minDate && month < minDate)
62
+ month = minDate;
63
+ if (maxDate && month > maxDate)
64
+ month = maxDate;
65
+ setSelectedDate(selected);
66
+ setCurrentMonth(month);
67
+ setVisible(true);
68
+ };
69
+ const select = (date) => {
70
+ if (isDateInRange(date, minDate, maxDate))
71
+ setSelectedDate(date);
72
+ };
73
+ const confirm = () => {
74
+ if (validSelection && selectedDate) {
75
+ onChange(selectedDate);
76
+ setVisible(false);
77
+ }
78
+ };
79
+ const calendarTheme = (0, react_1.useMemo)(() => ({
80
+ backgroundColor: c.background,
81
+ calendarBackground: c.background,
82
+ dayTextColor: c.content1,
83
+ textDisabledColor: c.content4,
84
+ monthTextColor: c.content1,
85
+ textMonthFontWeight: "600",
86
+ todayTextColor: c.primary500,
87
+ arrowColor: c.primary500,
88
+ textSectionTitleColor: c.content2,
89
+ }), [c]);
90
+ // Calendar caches theme styles at mount, including weekday/disabled text.
91
+ const calendarPaletteKey = `${JSON.stringify(calendarTheme)}:${c.textPrimary}`;
92
+ const monthLabel = formatMonth?.(currentMonth) ??
93
+ `${currentMonth.slice(5, 7)}/${currentMonth.slice(0, 4)}`;
94
+ const calendarHeader = () => ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
95
+ styles.calendarHeader,
96
+ { paddingHorizontal: s.sm, paddingVertical: s.sm },
97
+ ], children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.arrows, { gap: s.lg }], children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: "Previous year", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, -12)), children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "title", color: "content3", children: "\u00AB" }) }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: "Previous month", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, -1)), children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "title", color: "content3", children: "\u2039" }) })] }), (0, jsx_runtime_1.jsx)(primitives_1.UIText, { weight: "600", style: styles.monthLabel, children: monthLabel }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.arrows, { gap: s.lg }], children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: "Next month", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, 1)), children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "title", color: "content3", children: "\u203A" }) }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: "Next year", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, 12)), children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "title", color: "content3", children: "\u00BB" }) })] })] }));
98
+ return ((0, jsx_runtime_1.jsxs)(fields_1.Field, { label: label, required: required, error: error, style: [variant === "form" && { marginBottom: s.lg, gap: s.sm }, style], children: [(0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { disabled: disabled, onPress: open, accessibilityRole: "button", accessibilityLabel: label ?? placeholder, accessibilityState: { disabled, expanded: visible }, style: [
99
+ styles.field,
100
+ {
101
+ minHeight: variant === "form" ? s.xxl * 2 : s.xxl + s.xl,
102
+ ...(variant === "form" ? { height: s.xxl * 2 } : {}),
103
+ gap: s.sm,
104
+ paddingHorizontal: variant === "form" ? s.lg : s.md,
105
+ borderColor: error ? c.danger : c.gray200,
106
+ borderRadius: variant === "form" ? r.lg : r.md,
107
+ backgroundColor: disabled ? c.gray50 : c.background,
108
+ opacity: disabled && variant === "form" ? 0.5 : 1,
109
+ },
110
+ fieldStyle,
111
+ ], children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: value ? "content1" : "content3", style: styles.flex, children: value ? formatValue(value) : placeholder }), icon ??
112
+ (iconSource ? ((0, jsx_runtime_1.jsx)(react_native_1.Image, { source: iconSource, resizeMode: "contain", style: { width: s.xl, height: s.xl, tintColor: c.content2 } })) : ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "calendar", size: 20, color: c.content2 })))] }), (0, jsx_runtime_1.jsxs)(overlays_1.Sheet, { visible: visible, onClose: () => setVisible(false), title: label, closeAccessibilityLabel: closeAccessibilityLabel, children: [visible &&
113
+ (renderPicker ? (renderPicker({
114
+ selectedDate,
115
+ currentMonth,
116
+ onSelect: select,
117
+ onMonthChange: setCurrentMonth,
118
+ minDate,
119
+ maxDate,
120
+ })) : ((0, jsx_runtime_1.jsx)(react_native_calendars_1.Calendar, { current: currentMonth, theme: calendarTheme, minDate: minDate, maxDate: maxDate, markedDates: selectedDate
121
+ ? {
122
+ [selectedDate]: {
123
+ selected: true,
124
+ selectedColor: c.primary500,
125
+ selectedTextColor: c.textPrimary,
126
+ },
127
+ }
128
+ : {}, onDayPress: (day) => select(day.dateString), onMonthChange: (month) => setCurrentMonth(month.dateString), hideArrows: true, renderHeader: calendarHeader, enableSwipeMonths: true }, `${currentMonth}:${calendarPaletteKey}`))), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
129
+ styles.footer,
130
+ { gap: s.md, paddingHorizontal: s.xl, paddingTop: s.lg },
131
+ ], children: [onClear && ((0, jsx_runtime_1.jsx)(primitives_1.Button, { label: clearText ?? "", variant: "outline", disabled: !selectedDate && !value, onPress: () => {
132
+ setSelectedDate(null);
133
+ onClear();
134
+ setVisible(false);
135
+ }, style: styles.flex })), (0, jsx_runtime_1.jsx)(primitives_1.Button, { label: confirmText, disabled: !validSelection, onPress: confirm, style: styles.flex })] })] })] }));
136
+ }
137
+ const styles = react_native_1.StyleSheet.create({
138
+ field: {
139
+ borderWidth: 1,
140
+ flexDirection: "row",
141
+ alignItems: "center",
142
+ justifyContent: "space-between",
143
+ },
144
+ flex: { flex: 1 },
145
+ footer: { flexDirection: "row" },
146
+ calendarHeader: {
147
+ flexDirection: "row",
148
+ alignItems: "center",
149
+ justifyContent: "space-between",
150
+ },
151
+ arrows: { flexDirection: "row", alignItems: "center" },
152
+ monthLabel: { flex: 1, textAlign: "center" },
153
+ });
@@ -0,0 +1,138 @@
1
+ import React from "react";
2
+ import { PressableProps, StyleProp, TextInputProps, TextStyle, ViewStyle } from "react-native";
3
+ export interface FieldProps {
4
+ label?: React.ReactNode;
5
+ required?: boolean;
6
+ error?: string;
7
+ hint?: React.ReactNode;
8
+ children?: React.ReactNode;
9
+ style?: StyleProp<ViewStyle>;
10
+ labelStyle?: StyleProp<TextStyle>;
11
+ }
12
+ export declare function Field({ label, required, error, hint, children, style, labelStyle, }: FieldProps): React.JSX.Element;
13
+ export interface TextFieldProps extends TextInputProps {
14
+ label?: string;
15
+ required?: boolean;
16
+ error?: string;
17
+ hint?: React.ReactNode;
18
+ containerStyle?: StyleProp<ViewStyle>;
19
+ showCount?: boolean;
20
+ countLabel?: string;
21
+ labelStyle?: StyleProp<TextStyle>;
22
+ }
23
+ export declare function TextField({ label, required, error, hint, containerStyle, showCount, countLabel, labelStyle, style, multiline, editable, placeholderTextColor, ...props }: TextFieldProps): React.JSX.Element;
24
+ /** Display-only trigger for an app-owned picker or modal. No picker state is stored here. */
25
+ export interface PressableFieldProps extends Omit<PressableProps, "children" | "style"> {
26
+ variant?: "default" | "form" | "filter";
27
+ label?: React.ReactNode;
28
+ value?: React.ReactNode;
29
+ placeholder?: string;
30
+ required?: boolean;
31
+ error?: string;
32
+ hint?: React.ReactNode;
33
+ loading?: boolean;
34
+ icon?: React.ReactNode;
35
+ trailing?: React.ReactNode;
36
+ style?: StyleProp<ViewStyle>;
37
+ labelStyle?: StyleProp<TextStyle>;
38
+ fieldStyle?: StyleProp<ViewStyle>;
39
+ valueStyle?: StyleProp<TextStyle>;
40
+ placeholderStyle?: StyleProp<TextStyle>;
41
+ }
42
+ export declare function PressableField({ variant, label, value, placeholder, required, error, hint, loading, disabled, icon, trailing, style, labelStyle, fieldStyle, valueStyle, placeholderStyle, ...props }: PressableFieldProps): React.JSX.Element;
43
+ export interface TimePickerRenderProps {
44
+ visible: boolean;
45
+ value: string;
46
+ onClose: () => void;
47
+ onConfirm: (time: string) => void;
48
+ }
49
+ export interface TimeFieldProps {
50
+ label?: string;
51
+ value: string;
52
+ onChange: (time: string) => void;
53
+ renderPicker: (props: TimePickerRenderProps) => React.ReactNode;
54
+ placeholder?: string;
55
+ required?: boolean;
56
+ error?: string;
57
+ clearable?: boolean;
58
+ disabled?: boolean;
59
+ clearAccessibilityLabel?: string;
60
+ icon?: React.ReactNode;
61
+ clearIcon?: React.ReactNode;
62
+ style?: StyleProp<ViewStyle>;
63
+ labelStyle?: StyleProp<TextStyle>;
64
+ fieldStyle?: StyleProp<ViewStyle>;
65
+ valueStyle?: StyleProp<TextStyle>;
66
+ }
67
+ /** Complete time field UI; the app supplies its native picker implementation. */
68
+ export declare function TimeField({ label, value, onChange, renderPicker, placeholder, required, error, clearable, disabled, clearAccessibilityLabel, icon, clearIcon, style, labelStyle, fieldStyle, valueStyle, }: TimeFieldProps): React.JSX.Element;
69
+ export interface SelectOption<Value = unknown> {
70
+ label: string;
71
+ value: Value;
72
+ [key: string]: unknown;
73
+ }
74
+ export interface SelectFieldProps<T extends {
75
+ label: string;
76
+ value: unknown;
77
+ }> {
78
+ variant?: "default" | "form";
79
+ options: readonly T[];
80
+ value?: T | null;
81
+ onChange: (option: T) => void;
82
+ label?: string;
83
+ placeholder?: string;
84
+ required?: boolean;
85
+ error?: string;
86
+ disabled?: boolean;
87
+ loading?: boolean;
88
+ searchable?: boolean;
89
+ /** Keep the sheet at its maximum height as the option list changes. */
90
+ fixedSheetHeight?: boolean;
91
+ keyboardAvoiding?: boolean;
92
+ localSearch?: boolean;
93
+ searchKey?: keyof T;
94
+ searchFilter?: (option: T, query: string) => boolean;
95
+ onSearch?: (query: string) => void;
96
+ searchDelay?: number;
97
+ searchPlaceholder?: string;
98
+ autoFocus?: boolean;
99
+ emptyText?: string;
100
+ noResultsText?: string;
101
+ renderSelected?: (option: T) => React.ReactNode;
102
+ icon?: React.ReactNode;
103
+ closeAccessibilityLabel?: string;
104
+ style?: StyleProp<ViewStyle>;
105
+ fieldStyle?: StyleProp<ViewStyle>;
106
+ }
107
+ export declare function SelectField<T extends {
108
+ label: string;
109
+ value: unknown;
110
+ }>({ variant, options, value, onChange, label, placeholder, required, error, disabled, loading, searchable, fixedSheetHeight, keyboardAvoiding, localSearch, searchKey, searchFilter, onSearch, searchDelay, searchPlaceholder, autoFocus, emptyText, noResultsText, renderSelected, icon, closeAccessibilityLabel, style, fieldStyle, }: SelectFieldProps<T>): React.JSX.Element;
111
+ export interface Attachment {
112
+ id?: string;
113
+ name: string;
114
+ [key: string]: unknown;
115
+ }
116
+ export interface AttachmentFieldProps<T extends {
117
+ name: string;
118
+ }> {
119
+ title?: string;
120
+ description?: string;
121
+ buttonText: string;
122
+ files: readonly T[];
123
+ loading?: boolean;
124
+ disabled?: boolean;
125
+ openingId?: string | null;
126
+ getId?: (file: T, index: number) => string;
127
+ onPick: () => void;
128
+ onOpen?: (file: T, index: number) => void;
129
+ onRemove?: (file: T, index: number) => void;
130
+ illustration?: React.ReactNode;
131
+ pickIcon?: React.ReactNode;
132
+ removeIcon?: React.ReactNode;
133
+ removeAccessibilityLabel?: string;
134
+ style?: StyleProp<ViewStyle>;
135
+ }
136
+ export declare function AttachmentField<T extends {
137
+ name: string;
138
+ }>({ title, description, buttonText, files, loading, disabled, openingId, getId, onPick, onOpen, onRemove, illustration, pickIcon, removeIcon, removeAccessibilityLabel, style, }: AttachmentFieldProps<T>): React.JSX.Element;
package/dist/fields.js ADDED
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Field = Field;
4
+ exports.TextField = TextField;
5
+ exports.PressableField = PressableField;
6
+ exports.TimeField = TimeField;
7
+ exports.SelectField = SelectField;
8
+ exports.AttachmentField = AttachmentField;
9
+ const jsx_runtime_1 = require("react/jsx-runtime");
10
+ const react_1 = require("react");
11
+ const react_native_1 = require("react-native");
12
+ const theme_1 = require("./theme");
13
+ const primitives_1 = require("./primitives");
14
+ const icons_1 = require("./icons");
15
+ const overlays_1 = require("./overlays");
16
+ function Field({ label, required, error, hint, children, style, labelStyle, }) {
17
+ const { spacing: s } = (0, theme_1.useUITheme)();
18
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [{ gap: s.xs }, style], children: [label != null && ((0, jsx_runtime_1.jsxs)(primitives_1.UIText, { variant: "label", color: "content2", style: labelStyle, children: [label, required && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "label", color: "danger", children: "*" }))] })), children, hint != null &&
19
+ (typeof hint === "string" ? ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "caption", color: "content2", children: hint })) : (hint)), !!error && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "caption", color: "danger", accessibilityLiveRegion: "polite", children: error }))] }));
20
+ }
21
+ function TextField({ label, required, error, hint, containerStyle, showCount = false, countLabel, labelStyle, style, multiline, editable, placeholderTextColor, ...props }) {
22
+ const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
23
+ return ((0, jsx_runtime_1.jsxs)(Field, { label: label, required: required, error: error, hint: hint, style: containerStyle, labelStyle: labelStyle, children: [(0, jsx_runtime_1.jsx)(react_native_1.TextInput, { ...props, editable: editable, multiline: multiline, placeholderTextColor: placeholderTextColor ?? c.content3, textAlignVertical: multiline ? "top" : "center", accessibilityLabel: props.accessibilityLabel ?? label, style: [
24
+ {
25
+ minHeight: multiline ? s.xxl * 4 : s.xxl + s.xl,
26
+ borderWidth: 1,
27
+ borderColor: error ? c.danger : c.gray200,
28
+ borderRadius: r.md,
29
+ paddingHorizontal: s.md,
30
+ paddingVertical: multiline ? s.md : s.sm,
31
+ backgroundColor: editable === false ? c.gray50 : c.background,
32
+ color: c.content1,
33
+ fontSize: t.body,
34
+ fontFamily: t.fontFamily,
35
+ },
36
+ style,
37
+ ] }), showCount && ((0, jsx_runtime_1.jsxs)(primitives_1.UIText, { variant: "caption", color: "content2", style: styles.count, children: [props.value?.length ?? 0, props.maxLength != null ? `/${props.maxLength}` : "", countLabel ? ` ${countLabel}` : ""] }))] }));
38
+ }
39
+ function PressableField({ variant = "default", label, value, placeholder, required, error, hint, loading = false, disabled = false, icon, trailing, style, labelStyle, fieldStyle, valueStyle, placeholderStyle, ...props }) {
40
+ const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
41
+ const filter = variant === "filter";
42
+ const largeField = variant !== "default";
43
+ const hasValue = value !== undefined && value !== null && value !== "";
44
+ const textValue = !hasValue || typeof value === "string" || typeof value === "number";
45
+ return ((0, jsx_runtime_1.jsx)(Field, { label: label, required: required, error: error, hint: hint, labelStyle: [
46
+ filter && { fontSize: t.body, fontWeight: "500", color: c.content1 },
47
+ labelStyle,
48
+ ], style: [
49
+ variant === "form" && { marginBottom: s.lg, gap: s.sm },
50
+ filter && { gap: s.sm },
51
+ style,
52
+ ], children: (0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { ...props, disabled: disabled || loading, accessibilityRole: props.accessibilityRole ?? "button", accessibilityLabel: props.accessibilityLabel ??
53
+ (typeof label === "string" ? label : placeholder), accessibilityState: {
54
+ ...props.accessibilityState,
55
+ disabled: disabled || loading,
56
+ busy: loading,
57
+ }, style: [
58
+ styles.selector,
59
+ {
60
+ minHeight: largeField ? s.xxl * 2 : s.xxl + s.xl,
61
+ ...(largeField ? { height: s.xxl * 2 } : {}),
62
+ gap: s.sm,
63
+ paddingHorizontal: filter
64
+ ? (s.md + s.lg) / 2
65
+ : variant === "form"
66
+ ? s.lg
67
+ : s.md,
68
+ borderColor: error ? c.danger : c.gray200,
69
+ borderRadius: largeField ? r.lg : r.md,
70
+ backgroundColor: disabled ? c.gray50 : c.background,
71
+ opacity: disabled ? (variant === "form" ? 0.5 : 0.6) : 1,
72
+ },
73
+ fieldStyle,
74
+ ], children: [loading ? ((0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "small", color: c.primary500 })) : textValue ? ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: hasValue ? "content1" : filter ? "content2" : "content3", style: [styles.flex, hasValue ? valueStyle : placeholderStyle], children: hasValue ? value : placeholder })) : ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.flex, children: value })), trailing ?? icon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "chevron", size: 16, color: disabled ? c.content4 : c.content2 }))] }) }));
75
+ }
76
+ /** Complete time field UI; the app supplies its native picker implementation. */
77
+ function TimeField({ label, value, onChange, renderPicker, placeholder, required, error, clearable = false, disabled = false, clearAccessibilityLabel = "Clear time", icon, clearIcon, style, labelStyle, fieldStyle, valueStyle, }) {
78
+ const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
79
+ const [visible, setVisible] = (0, react_1.useState)(false);
80
+ const hasValue = !!value;
81
+ const iconSize = s.lg + s.xs / 2;
82
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [{ flex: 1, marginBottom: s.lg }, style], children: [label != null && ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { flexDirection: "row", marginBottom: s.sm }, children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: "content2", style: [{ fontSize: t.body }, labelStyle], children: label }), required && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "danger", style: { fontSize: t.body, marginLeft: s.xs / 2 }, children: "*" }))] })), (0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { disabled: disabled, onPress: () => setVisible(true), accessibilityRole: "button", accessibilityLabel: label ?? placeholder, accessibilityState: { disabled, expanded: visible }, style: ({ pressed }) => [
83
+ styles.selector,
84
+ {
85
+ height: s.xxl * 2,
86
+ paddingHorizontal: s.lg,
87
+ borderColor: error ? c.danger : c.gray200,
88
+ borderRadius: r.lg,
89
+ backgroundColor: c.gray50,
90
+ opacity: disabled ? 0.5 : pressed ? 0.2 : 1,
91
+ },
92
+ fieldStyle,
93
+ ], children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, style: [
94
+ styles.flex,
95
+ {
96
+ fontSize: (t.body + t.subtitle) / 2,
97
+ color: hasValue ? c.content1 : c.content4,
98
+ },
99
+ valueStyle,
100
+ ], children: hasValue ? value : placeholder }), clearable && hasValue ? ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { disabled: disabled, hitSlop: 8, accessibilityRole: "button", accessibilityLabel: clearAccessibilityLabel, onPress: (event) => {
101
+ event.stopPropagation();
102
+ onChange("");
103
+ }, children: clearIcon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "close", size: iconSize, color: c.content3 })) })) : ((icon ?? (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "clock", size: iconSize, color: c.content3 })))] }), !!error && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "label", color: "danger", accessibilityLiveRegion: "polite", style: { marginTop: s.xs }, children: error })), visible &&
104
+ renderPicker({
105
+ visible,
106
+ value,
107
+ onClose: () => setVisible(false),
108
+ onConfirm: (time) => {
109
+ onChange(time);
110
+ setVisible(false);
111
+ },
112
+ })] }));
113
+ }
114
+ function SelectField({ variant = "default", options, value, onChange, label, placeholder, required, error, disabled = false, loading = false, searchable = true, fixedSheetHeight = false, keyboardAvoiding = false, localSearch = true, searchKey, searchFilter, onSearch, searchDelay = 500, searchPlaceholder, autoFocus = false, emptyText, noResultsText, renderSelected, icon, closeAccessibilityLabel, style, fieldStyle, }) {
115
+ const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
116
+ const { height } = (0, react_native_1.useWindowDimensions)();
117
+ const sheetHeight = height * 0.7;
118
+ const [visible, setVisible] = (0, react_1.useState)(false);
119
+ const [query, setQuery] = (0, react_1.useState)("");
120
+ const searchCallback = (0, react_1.useRef)(onSearch);
121
+ searchCallback.current = onSearch;
122
+ (0, react_1.useEffect)(() => {
123
+ if (!visible || !searchable || localSearch)
124
+ return;
125
+ const timer = setTimeout(() => searchCallback.current?.(query), searchDelay);
126
+ return () => clearTimeout(timer);
127
+ }, [query, searchDelay, visible, searchable, localSearch]);
128
+ const filtered = (0, react_1.useMemo)(() => {
129
+ if (!searchable || !localSearch || !query.trim())
130
+ return options;
131
+ const normalized = query.trim().toLocaleLowerCase();
132
+ return options.filter((option) => searchFilter
133
+ ? searchFilter(option, query)
134
+ : String(searchKey ? (option[searchKey] ?? "") : option.label)
135
+ .toLocaleLowerCase()
136
+ .includes(normalized));
137
+ }, [options, searchable, localSearch, query, searchKey, searchFilter]);
138
+ const open = () => {
139
+ if (disabled || loading)
140
+ return;
141
+ if (keyboardAvoiding && searchable)
142
+ react_native_1.Keyboard.dismiss();
143
+ setQuery("");
144
+ setVisible(true);
145
+ };
146
+ return ((0, jsx_runtime_1.jsxs)(Field, { label: label, required: required, error: error, style: [variant === "form" && { marginBottom: s.lg, gap: s.sm }, style], children: [(0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { onPress: open, disabled: disabled || loading, accessibilityRole: "button", accessibilityLabel: label ?? placeholder, accessibilityState: {
147
+ disabled: disabled || loading,
148
+ expanded: visible,
149
+ busy: loading,
150
+ }, style: [
151
+ styles.selector,
152
+ {
153
+ minHeight: variant === "form" ? s.xxl * 2 : s.xxl + s.xl,
154
+ ...(variant === "form" ? { height: s.xxl * 2 } : {}),
155
+ gap: s.sm,
156
+ paddingHorizontal: variant === "form" ? s.lg : s.md,
157
+ borderColor: error ? c.danger : c.gray200,
158
+ borderRadius: variant === "form" ? r.lg : r.md,
159
+ backgroundColor: disabled ? c.gray50 : c.background,
160
+ opacity: disabled ? (variant === "form" ? 0.5 : 0.6) : 1,
161
+ },
162
+ fieldStyle,
163
+ ], children: [loading ? ((0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "small", color: c.primary500 })) : value ? (renderSelected ? (renderSelected(value)) : ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, style: styles.flex, children: value.label }))) : ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: "content3", style: styles.flex, children: placeholder })), icon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "chevron", size: 16, color: disabled ? c.content4 : c.content2 }))] }), (0, jsx_runtime_1.jsxs)(overlays_1.Sheet, { visible: visible, onClose: () => setVisible(false), keyboardAvoiding: keyboardAvoiding && searchable, title: label ?? placeholder, closeAccessibilityLabel: closeAccessibilityLabel, style: {
164
+ maxHeight: sheetHeight,
165
+ height: fixedSheetHeight ? sheetHeight : undefined,
166
+ }, children: [searchable && ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
167
+ styles.search,
168
+ {
169
+ marginHorizontal: s.lg,
170
+ marginBottom: s.md,
171
+ gap: s.sm,
172
+ paddingHorizontal: s.md,
173
+ minHeight: s.xl * 2,
174
+ borderRadius: r.md,
175
+ backgroundColor: c.gray50,
176
+ },
177
+ ], children: [(0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "search", size: 16, color: c.content3 }), visible && ((0, jsx_runtime_1.jsx)(react_native_1.TextInput, { placeholder: searchPlaceholder, placeholderTextColor: c.content3, value: query, onChangeText: setQuery, autoFocus: autoFocus, autoCorrect: false, autoComplete: "off", importantForAutofill: "no", style: {
178
+ flex: 1,
179
+ color: c.content1,
180
+ fontSize: t.body,
181
+ fontFamily: t.fontFamily,
182
+ } }))] })), loading && (0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { color: c.primary500 }), (0, jsx_runtime_1.jsx)(react_native_1.FlatList, { data: filtered, keyboardShouldPersistTaps: "handled", keyExtractor: (option, index) => `${String(option.value)}_${index}`, contentContainerStyle: { paddingHorizontal: s.lg }, ItemSeparatorComponent: () => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: { height: 1, backgroundColor: c.divider } })), renderItem: ({ item }) => {
183
+ const selected = Object.is(item.value, value?.value);
184
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { accessibilityRole: "radio", accessibilityState: { selected }, onPress: () => {
185
+ onChange(item);
186
+ setVisible(false);
187
+ }, style: [
188
+ styles.selectItem,
189
+ { paddingVertical: s.md + 2, gap: s.sm },
190
+ ], children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: selected ? "primary500" : "content1", weight: selected ? "600" : "400", style: styles.flex, children: item.label }), selected && (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "check", size: 18, color: c.primary500 })] }));
191
+ }, ListEmptyComponent: !loading ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: { paddingVertical: s.xxl + s.sm }, children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "content3", style: styles.center, children: query ? (noResultsText ?? emptyText) : emptyText }) })) : null })] })] }));
192
+ }
193
+ function AttachmentField({ title, description, buttonText, files, loading, disabled, openingId, getId, onPick, onOpen, onRemove, illustration, pickIcon, removeIcon, removeAccessibilityLabel = "Remove file", style, }) {
194
+ const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
195
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [{ gap: s.sm }, style], children: [title != null && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "label", color: "content2", children: title })), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: {
196
+ borderWidth: 1,
197
+ borderStyle: "dashed",
198
+ borderColor: c.gray200,
199
+ borderRadius: r.md,
200
+ paddingVertical: s.xl,
201
+ paddingHorizontal: s.lg,
202
+ alignItems: "center",
203
+ gap: s.sm,
204
+ }, children: [illustration ?? (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "folder", color: c.primary500, size: 24 }), description != null && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "label", color: "content3", style: styles.center, children: description })), (0, jsx_runtime_1.jsx)(primitives_1.Button, { label: buttonText, size: "small", onPress: onPick, loading: loading, disabled: disabled, leading: pickIcon ?? (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "upload", color: c.textPrimary, size: 14 }), style: { borderRadius: r.md, marginTop: s.xs }, textStyle: { fontSize: 13 } })] }), files.map((file, index) => {
205
+ const id = getId?.(file, index) ?? String(file.id ?? index);
206
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
207
+ styles.attachment,
208
+ {
209
+ gap: s.sm,
210
+ paddingVertical: s.sm,
211
+ paddingHorizontal: s.md,
212
+ borderWidth: 1,
213
+ borderColor: c.gray200,
214
+ borderRadius: r.md,
215
+ },
216
+ ], children: [(0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { onPress: () => onOpen?.(file, index), disabled: !onOpen || openingId === id, accessibilityRole: "button", accessibilityLabel: file.name, style: [styles.selectItem, styles.flex, { gap: s.sm }], children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, style: {
217
+ flex: 1,
218
+ fontSize: 13,
219
+ textDecorationLine: onOpen ? "underline" : "none",
220
+ }, children: file.name }), openingId === id && ((0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { color: c.content2, size: "small" }))] }), onRemove && ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { hitSlop: 8, disabled: disabled, onPress: () => onRemove(file, index), accessibilityRole: "button", accessibilityLabel: `${removeAccessibilityLabel}: ${file.name}`, children: removeIcon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "close", color: c.content2, size: 14 })) }))] }, id));
221
+ })] }));
222
+ }
223
+ const styles = react_native_1.StyleSheet.create({
224
+ count: { alignSelf: "flex-end" },
225
+ selector: {
226
+ borderWidth: 1,
227
+ flexDirection: "row",
228
+ alignItems: "center",
229
+ justifyContent: "space-between",
230
+ },
231
+ flex: { flex: 1 },
232
+ center: { textAlign: "center" },
233
+ search: { flexDirection: "row", alignItems: "center" },
234
+ selectItem: {
235
+ flexDirection: "row",
236
+ alignItems: "center",
237
+ justifyContent: "space-between",
238
+ },
239
+ attachment: { flexDirection: "row", alignItems: "center" },
240
+ });