@avenue-ticketing/native 0.1.4 → 0.1.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.
- package/dist/combobox.d.ts +37 -0
- package/dist/combobox.js +584 -0
- package/dist/combobox.js.map +1 -0
- package/dist/input.d.ts +3 -31
- package/dist/input.js +6 -4
- package/dist/input.js.map +1 -1
- package/dist/multi-select.d.ts +54 -0
- package/dist/multi-select.js +1251 -0
- package/dist/multi-select.js.map +1 -0
- package/dist/popover.d.ts +21 -0
- package/dist/popover.js +231 -0
- package/dist/popover.js.map +1 -0
- package/dist/select-BJtrES5I.d.ts +23 -0
- package/dist/select-item.d.ts +17 -0
- package/dist/select-item.js +465 -0
- package/dist/select-item.js.map +1 -0
- package/dist/select-native-C3ctbnUG.d.ts +33 -0
- package/dist/select-native.d.ts +2 -0
- package/dist/select-native.js +406 -0
- package/dist/select-native.js.map +1 -0
- package/dist/select-shared-Ah_SqhzA.d.ts +24 -0
- package/dist/select.d.ts +26 -0
- package/dist/select.js +1063 -0
- package/dist/select.js.map +1 -0
- package/dist/tag-select.d.ts +37 -0
- package/dist/tag-select.js +905 -0
- package/dist/tag-select.js.map +1 -0
- package/dist/textarea.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ReactNode, FC } from 'react';
|
|
2
|
+
import { TextInputProps } from 'react-native';
|
|
3
|
+
import { C as CommonProps, S as SelectItemType } from './select-shared-Ah_SqhzA.js';
|
|
4
|
+
import './select-BJtrES5I.js';
|
|
5
|
+
|
|
6
|
+
interface ComboBoxProps extends CommonProps {
|
|
7
|
+
icon?: SelectItemType["icon"];
|
|
8
|
+
items?: SelectItemType[];
|
|
9
|
+
inputValue?: string;
|
|
10
|
+
/** Accepted for API parity. The web shortcut is hidden below the `md` breakpoint. */
|
|
11
|
+
shortcut?: boolean;
|
|
12
|
+
allowsCustomValue?: boolean;
|
|
13
|
+
isDisabled?: boolean;
|
|
14
|
+
isInvalid?: boolean;
|
|
15
|
+
isRequired?: boolean;
|
|
16
|
+
autoComplete?: TextInputProps["autoComplete"];
|
|
17
|
+
textContentType?: TextInputProps["textContentType"];
|
|
18
|
+
inputClassName?: string;
|
|
19
|
+
popoverClassName?: string;
|
|
20
|
+
/**
|
|
21
|
+
* When omitted, rows whose label or supporting text contain the query stay visible.
|
|
22
|
+
* Pass a function that always returns true when the parent already filtered (Places).
|
|
23
|
+
*/
|
|
24
|
+
defaultFilter?: (textValue: string, inputValue: string) => boolean;
|
|
25
|
+
onInputChange?: (value: string) => void;
|
|
26
|
+
onSelectionChange?: (key: string | number | null) => void;
|
|
27
|
+
onFocus?: () => void;
|
|
28
|
+
onBlur?: () => void;
|
|
29
|
+
children: (item: SelectItemType) => ReactNode;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Native `Select.ComboBox`. `sheet: false` is the floating search field (address).
|
|
33
|
+
* The default sheet matches the web combo box on a phone: a closed trigger, then search inside the sheet.
|
|
34
|
+
*/
|
|
35
|
+
declare const ComboBox: FC<ComboBoxProps>;
|
|
36
|
+
|
|
37
|
+
export { ComboBox, type ComboBoxProps };
|
package/dist/combobox.js
ADDED
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
import { createContext, useRef, useState, useMemo, isValidElement, useEffect } from 'react';
|
|
2
|
+
import { View, TextInput, Pressable, Text, ScrollView } from 'react-native-css/components';
|
|
3
|
+
import { useNativeVariable } from 'react-native-css';
|
|
4
|
+
import { CaretDownIcon } from 'phosphor-react-native/src/icons/CaretDown';
|
|
5
|
+
import { MagnifyingGlassIcon } from 'phosphor-react-native/src/icons/MagnifyingGlass';
|
|
6
|
+
import { extendTailwindMerge } from 'tailwind-merge';
|
|
7
|
+
import 'phosphor-react-native/src/icons/Eye';
|
|
8
|
+
import 'phosphor-react-native/src/icons/EyeSlash';
|
|
9
|
+
import 'phosphor-react-native/src/icons/Info';
|
|
10
|
+
import 'phosphor-react-native/src/icons/Question';
|
|
11
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
12
|
+
import { useWindowDimensions, Modal } from 'react-native';
|
|
13
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
14
|
+
import Animated, { Easing, FadeIn, FadeOut, FadeInDown, FadeOutDown } from 'react-native-reanimated';
|
|
15
|
+
import { XIcon } from 'phosphor-react-native/src/icons/X';
|
|
16
|
+
|
|
17
|
+
// ../../native/components/base/select/combobox.tsx
|
|
18
|
+
var twMerge = extendTailwindMerge({
|
|
19
|
+
extend: {
|
|
20
|
+
theme: {
|
|
21
|
+
text: ["display-xs", "display-sm", "display-md", "display-lg", "display-xl", "display-2xl"]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
var cx = twMerge;
|
|
26
|
+
function sortCx(classes) {
|
|
27
|
+
return classes;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ../core/src/input.ts
|
|
31
|
+
var inputFocusRingShadow = "border-brand ring-1 ring-inset ring-brand";
|
|
32
|
+
var inputErrorFocusRingShadow = "border-error ring-1 ring-inset ring-error";
|
|
33
|
+
var inputStyles = sortCx({
|
|
34
|
+
stack: "w-full flex-col items-start justify-start gap-1.5",
|
|
35
|
+
labelRow: "flex-row items-center gap-0.5",
|
|
36
|
+
label: "text-sm font-medium text-secondary",
|
|
37
|
+
required: "text-brand-tertiary",
|
|
38
|
+
requiredInvalid: "text-error-primary",
|
|
39
|
+
hint: "text-sm text-tertiary",
|
|
40
|
+
hintSm: "text-xs",
|
|
41
|
+
hintInvalid: "text-error-primary",
|
|
42
|
+
field: {
|
|
43
|
+
root: "relative isolate w-full flex-row items-center rounded-lg border border-solid border-primary bg-primary shadow-xs",
|
|
44
|
+
/** Web: focus-within:border-brand + inset ring-1 ring-brand (2px visual, no layout shift). */
|
|
45
|
+
focus: inputFocusRingShadow,
|
|
46
|
+
invalid: "border-error_subtle",
|
|
47
|
+
invalidFocus: inputErrorFocusRingShadow,
|
|
48
|
+
disabled: "opacity-50"
|
|
49
|
+
},
|
|
50
|
+
input: "m-0 min-w-0 flex-1 bg-transparent text-primary placeholder:text-placeholder",
|
|
51
|
+
iconLeading: "absolute inset-y-0 items-center justify-center text-fg-quaternary",
|
|
52
|
+
iconTrailing: "absolute inset-y-0 items-center justify-center text-fg-quaternary",
|
|
53
|
+
iconInvalid: "absolute inset-y-0 items-center justify-center text-fg-error-secondary",
|
|
54
|
+
sizes: {
|
|
55
|
+
sm: {
|
|
56
|
+
field: "min-h-9",
|
|
57
|
+
input: "px-3 py-2 text-sm",
|
|
58
|
+
inputLeading: "pl-9",
|
|
59
|
+
inputTrailing: "pr-9",
|
|
60
|
+
iconLeading: "left-3 w-4",
|
|
61
|
+
iconTrailing: "right-3 w-4",
|
|
62
|
+
iconPx: 16,
|
|
63
|
+
shortcut: "pr-1.5"
|
|
64
|
+
},
|
|
65
|
+
md: {
|
|
66
|
+
field: "min-h-10",
|
|
67
|
+
input: "px-3 py-2 text-md",
|
|
68
|
+
inputLeading: "pl-10",
|
|
69
|
+
inputTrailing: "pr-9",
|
|
70
|
+
iconLeading: "left-3 w-5",
|
|
71
|
+
iconTrailing: "right-3 w-4",
|
|
72
|
+
iconPx: 20,
|
|
73
|
+
shortcut: "pr-2"
|
|
74
|
+
},
|
|
75
|
+
lg: {
|
|
76
|
+
field: "min-h-11",
|
|
77
|
+
input: "px-3.5 py-2.5 text-md",
|
|
78
|
+
inputLeading: "pl-10.5",
|
|
79
|
+
inputTrailing: "pr-9.5",
|
|
80
|
+
iconLeading: "left-3.5 w-5",
|
|
81
|
+
iconTrailing: "right-3.5 w-4",
|
|
82
|
+
iconPx: 20,
|
|
83
|
+
shortcut: "pr-2.5"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
createContext(null);
|
|
88
|
+
createContext(null);
|
|
89
|
+
var Label = ({ children, isRequired, isInvalid, className }) => {
|
|
90
|
+
return /* @__PURE__ */ jsxs(View, { className: cx(inputStyles.labelRow, className), children: [
|
|
91
|
+
/* @__PURE__ */ jsx(Text, { className: inputStyles.label, children }),
|
|
92
|
+
isRequired && /* @__PURE__ */ jsx(Text, { className: isInvalid ? inputStyles.requiredInvalid : inputStyles.required, children: "*" })
|
|
93
|
+
] });
|
|
94
|
+
};
|
|
95
|
+
var HintText = ({ children, isInvalid, size, className }) => {
|
|
96
|
+
if (children == null || children === false) return null;
|
|
97
|
+
if (typeof children !== "string" && typeof children !== "number") {
|
|
98
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
99
|
+
}
|
|
100
|
+
return /* @__PURE__ */ jsx(
|
|
101
|
+
Text,
|
|
102
|
+
{
|
|
103
|
+
className: cx(
|
|
104
|
+
inputStyles.hint,
|
|
105
|
+
size === "sm" && inputStyles.hintSm,
|
|
106
|
+
isInvalid && inputStyles.hintInvalid,
|
|
107
|
+
className
|
|
108
|
+
),
|
|
109
|
+
children
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// ../core/src/dialog.ts
|
|
115
|
+
var DIALOG_SHEET_MOTION_MS = 175;
|
|
116
|
+
var DIALOG_SLIDE_OFFSET_PX = 120;
|
|
117
|
+
var DIALOG_ENTRY_EASING_BEZIER = [0.85, 0, 0.15, 1];
|
|
118
|
+
var DIALOG_EXIT_EASING_BEZIER = [0.85, 0, 1, 0.15];
|
|
119
|
+
var DIALOG_SHEET_RADIUS_PX = 16;
|
|
120
|
+
var dialogStyles = sortCx({
|
|
121
|
+
root: "flex",
|
|
122
|
+
rootFull: "h-full w-full flex-col bg-primary",
|
|
123
|
+
rootSheet: "flex-col justify-end",
|
|
124
|
+
rootModal: "flex-col items-center justify-center p-4",
|
|
125
|
+
overlay: "absolute inset-0 bg-overlay/70",
|
|
126
|
+
panel: "relative z-10 w-full overflow-hidden bg-primary",
|
|
127
|
+
panelElevated: "shadow-xl",
|
|
128
|
+
panelFull: "flex min-h-0 flex-1 flex-col",
|
|
129
|
+
/**
|
|
130
|
+
* Web sheet chrome (≤1024). Native pins the same chrome with RN layout styles
|
|
131
|
+
* (`DIALOG_SHEET_RADIUS_PX` + token colors) because NativeWind border/radius
|
|
132
|
+
* on sheets leave side gaps and bottom transparency.
|
|
133
|
+
*/
|
|
134
|
+
panelSheet: "w-full max-h-[90%] rounded-t-2xl rounded-b-none border border-solid border-secondary border-x-0 border-b-0 border-t",
|
|
135
|
+
panelModal: "w-full rounded-2xl border border-solid border-secondary",
|
|
136
|
+
sizes: {
|
|
137
|
+
sm: "max-w-sm",
|
|
138
|
+
md: "max-w-md",
|
|
139
|
+
lg: "max-w-lg",
|
|
140
|
+
xl: "max-w-xl"
|
|
141
|
+
},
|
|
142
|
+
sizesLgOnly: {
|
|
143
|
+
sm: "lg:max-w-sm",
|
|
144
|
+
md: "lg:max-w-md",
|
|
145
|
+
lg: "lg:max-w-lg",
|
|
146
|
+
xl: "lg:max-w-xl"
|
|
147
|
+
},
|
|
148
|
+
sizesSmUp: {
|
|
149
|
+
sm: "sm:max-w-sm",
|
|
150
|
+
md: "sm:max-w-md",
|
|
151
|
+
lg: "sm:max-w-lg",
|
|
152
|
+
xl: "sm:max-w-xl"
|
|
153
|
+
},
|
|
154
|
+
header: "flex-col gap-1.5 p-6 pr-14",
|
|
155
|
+
headerFixed: "border-b border-solid border-secondary bg-primary",
|
|
156
|
+
footer: "flex-col-reverse gap-2 p-6",
|
|
157
|
+
footerFixed: "border-t border-solid border-secondary bg-primary",
|
|
158
|
+
title: "text-xl font-semibold text-primary",
|
|
159
|
+
description: "text-sm text-tertiary",
|
|
160
|
+
close: "size-12 items-center justify-center rounded-full bg-primary active:scale-[0.96] active:bg-primary_hover",
|
|
161
|
+
closePosition: "absolute top-4 right-4 z-20"
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// ../core/src/select.ts
|
|
165
|
+
var sizes = {
|
|
166
|
+
sm: { root: "gap-2 py-2 pr-2.5 pl-3", text: "text-sm", icon: 16, textGap: "gap-x-1.5" },
|
|
167
|
+
md: { root: "gap-2 px-3 py-2", text: "text-md", icon: 20, textGap: "gap-x-1.5" },
|
|
168
|
+
lg: { root: "gap-2 px-3.5 py-2.5", text: "text-md", icon: 20, textGap: "gap-x-1.5" }
|
|
169
|
+
};
|
|
170
|
+
var searchSizes = {
|
|
171
|
+
sm: { wrapper: "py-1", root: "gap-2 px-3 py-2", text: "text-sm" },
|
|
172
|
+
md: { wrapper: "py-0.5", root: "gap-2 px-3 py-2", text: "text-md" },
|
|
173
|
+
lg: { wrapper: "py-0.5", root: "gap-2 px-3.5 py-2.5", text: "text-md" }
|
|
174
|
+
};
|
|
175
|
+
var menuMaxHeight = {
|
|
176
|
+
sm: "max-h-56",
|
|
177
|
+
md: "max-h-64",
|
|
178
|
+
lg: "max-h-80"
|
|
179
|
+
};
|
|
180
|
+
function resolveSelectMobileOptions(mobileOptions) {
|
|
181
|
+
const fullScreen = mobileOptions?.fullScreen ?? false;
|
|
182
|
+
return {
|
|
183
|
+
sheet: mobileOptions?.sheet ?? true,
|
|
184
|
+
fullScreen,
|
|
185
|
+
overlay: fullScreen ? false : mobileOptions?.overlay ?? true,
|
|
186
|
+
title: mobileOptions?.title,
|
|
187
|
+
sheetClassName: mobileOptions?.className,
|
|
188
|
+
contentClassName: mobileOptions?.contentClassName
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function selectIdKey(id) {
|
|
192
|
+
return String(id);
|
|
193
|
+
}
|
|
194
|
+
function itemText(item) {
|
|
195
|
+
return item.supportingText ? `${item.label ?? ""} ${item.supportingText}` : item.label ?? "";
|
|
196
|
+
}
|
|
197
|
+
function itemMatches(item, query) {
|
|
198
|
+
const needle = query.trim().toLowerCase();
|
|
199
|
+
if (!needle) return true;
|
|
200
|
+
return itemText(item).toLowerCase().includes(needle);
|
|
201
|
+
}
|
|
202
|
+
function selectFieldClassName(options) {
|
|
203
|
+
return cx(
|
|
204
|
+
"bg-primary w-full flex-row items-center rounded-lg border border-solid shadow-xs",
|
|
205
|
+
sizes[options.size].root,
|
|
206
|
+
options.isDisabled && "opacity-50",
|
|
207
|
+
options.isInvalid && options.focused && inputErrorFocusRingShadow,
|
|
208
|
+
options.isInvalid && !options.focused && "border-error_subtle",
|
|
209
|
+
!options.isInvalid && options.focused && inputFocusRingShadow,
|
|
210
|
+
!options.isInvalid && !options.focused && "border-primary",
|
|
211
|
+
options.className
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ../core/src/is-react-component.ts
|
|
216
|
+
var isFunctionComponent = (component) => {
|
|
217
|
+
return typeof component === "function";
|
|
218
|
+
};
|
|
219
|
+
var isClassComponent = (component) => {
|
|
220
|
+
return typeof component === "function" && component.prototype && (!!component.prototype.isReactComponent || !!component.prototype.render);
|
|
221
|
+
};
|
|
222
|
+
var isForwardRefComponent = (component) => {
|
|
223
|
+
return typeof component === "object" && component !== null && component.$$typeof.toString() === "Symbol(react.forward_ref)";
|
|
224
|
+
};
|
|
225
|
+
var isReactComponent = (component) => {
|
|
226
|
+
return isFunctionComponent(component) || isForwardRefComponent(component) || isClassComponent(component);
|
|
227
|
+
};
|
|
228
|
+
var SelectMenuContext = createContext(null);
|
|
229
|
+
var SelectContext = createContext({ size: "md" });
|
|
230
|
+
var SelectGlyph = ({ icon, size, color }) => {
|
|
231
|
+
if (isReactComponent(icon)) {
|
|
232
|
+
const Icon = icon;
|
|
233
|
+
return /* @__PURE__ */ jsx(Icon, { size, color });
|
|
234
|
+
}
|
|
235
|
+
if (isValidElement(icon)) return icon;
|
|
236
|
+
return null;
|
|
237
|
+
};
|
|
238
|
+
var ENTRY = Easing.bezier(...DIALOG_ENTRY_EASING_BEZIER);
|
|
239
|
+
var EXIT = Easing.bezier(...DIALOG_EXIT_EASING_BEZIER);
|
|
240
|
+
var overlayEntering = FadeIn.duration(DIALOG_SHEET_MOTION_MS).easing(ENTRY);
|
|
241
|
+
var overlayExiting = FadeOut.duration(DIALOG_SHEET_MOTION_MS).easing(EXIT);
|
|
242
|
+
var panelEntering = FadeInDown.duration(DIALOG_SHEET_MOTION_MS).easing(ENTRY).withInitialValues({ opacity: 0, transform: [{ translateY: DIALOG_SLIDE_OFFSET_PX }] });
|
|
243
|
+
var panelExiting = FadeOutDown.duration(DIALOG_SHEET_MOTION_MS).easing(EXIT).withTargetValues({ opacity: 0, transform: [{ translateY: DIALOG_SLIDE_OFFSET_PX }] });
|
|
244
|
+
function useSheetPresence(open) {
|
|
245
|
+
const [shouldRender, setShouldRender] = useState(open);
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
if (open) {
|
|
248
|
+
setShouldRender(true);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const hide = setTimeout(() => setShouldRender(false), DIALOG_SHEET_MOTION_MS);
|
|
252
|
+
return () => clearTimeout(hide);
|
|
253
|
+
}, [open]);
|
|
254
|
+
return shouldRender;
|
|
255
|
+
}
|
|
256
|
+
function overlayFill(color) {
|
|
257
|
+
const hex = /^#([\da-f]{6})$/i.exec(color);
|
|
258
|
+
if (!hex) return "rgba(10, 13, 18, 0.7)";
|
|
259
|
+
const value = parseInt(hex[1], 16);
|
|
260
|
+
return `rgba(${value >> 16 & 255}, ${value >> 8 & 255}, ${value & 255}, 0.7)`;
|
|
261
|
+
}
|
|
262
|
+
var HEADER_HEIGHT = 56;
|
|
263
|
+
var Popover = ({
|
|
264
|
+
open,
|
|
265
|
+
onClose,
|
|
266
|
+
size = "md",
|
|
267
|
+
mobileOptions,
|
|
268
|
+
compound = false,
|
|
269
|
+
className,
|
|
270
|
+
children
|
|
271
|
+
}) => {
|
|
272
|
+
const resolved = resolveSelectMobileOptions(mobileOptions);
|
|
273
|
+
if (!resolved.sheet) {
|
|
274
|
+
if (!open) return null;
|
|
275
|
+
return /* @__PURE__ */ jsx(
|
|
276
|
+
View,
|
|
277
|
+
{
|
|
278
|
+
className: cx(
|
|
279
|
+
"bg-primary overflow-hidden rounded-lg shadow-lg ring-1 ring-secondary_alt",
|
|
280
|
+
!compound && "py-1",
|
|
281
|
+
!compound && menuMaxHeight[size],
|
|
282
|
+
className
|
|
283
|
+
),
|
|
284
|
+
children: compound ? children : /* @__PURE__ */ jsx(ScrollView, { keyboardShouldPersistTaps: "handled", nestedScrollEnabled: true, children })
|
|
285
|
+
}
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
return /* @__PURE__ */ jsx(
|
|
289
|
+
SelectSheet,
|
|
290
|
+
{
|
|
291
|
+
open,
|
|
292
|
+
onClose,
|
|
293
|
+
title: resolved.title,
|
|
294
|
+
fullScreen: resolved.fullScreen,
|
|
295
|
+
overlay: resolved.overlay,
|
|
296
|
+
className: cx(resolved.sheetClassName, resolved.contentClassName, className),
|
|
297
|
+
children
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
};
|
|
301
|
+
var SelectSheet = ({ open, onClose, title, fullScreen, overlay, className, children }) => {
|
|
302
|
+
const insets = useSafeAreaInsets();
|
|
303
|
+
const { width: windowWidth, height: windowHeight } = useWindowDimensions();
|
|
304
|
+
const shouldRender = useSheetPresence(open);
|
|
305
|
+
const fgPrimary = useNativeVariable("--color-fg-primary") ?? "#181d27";
|
|
306
|
+
const bgPrimary = useNativeVariable("--color-bg-primary") ?? "#ffffff";
|
|
307
|
+
const borderSecondary = useNativeVariable("--color-border-secondary") ?? "#e9eaeb";
|
|
308
|
+
const overlayColor = useNativeVariable("--color-bg-overlay") ?? "#0a0d12";
|
|
309
|
+
const sheetMax = fullScreen ? windowHeight : Math.round(windowHeight * 0.9);
|
|
310
|
+
const listMax = Math.max(0, sheetMax - HEADER_HEIGHT - (fullScreen ? insets.top : insets.bottom));
|
|
311
|
+
return /* @__PURE__ */ jsx(Modal, { visible: shouldRender, transparent: true, animationType: "none", presentationStyle: "overFullScreen", statusBarTranslucent: true, onRequestClose: onClose, children: /* @__PURE__ */ jsxs(View, { className: cx(dialogStyles.root, "h-full w-full flex-1", fullScreen ? dialogStyles.rootFull : dialogStyles.rootSheet), children: [
|
|
312
|
+
open && overlay ? /* @__PURE__ */ jsx(View, { className: dialogStyles.overlay, children: /* @__PURE__ */ jsx(Animated.View, { entering: overlayEntering, exiting: overlayExiting, style: { flex: 1, backgroundColor: overlayFill(overlayColor) }, children: /* @__PURE__ */ jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: "Dismiss", onPress: onClose, className: "flex-1" }) }) }) : null,
|
|
313
|
+
open ? /* @__PURE__ */ jsxs(
|
|
314
|
+
Animated.View,
|
|
315
|
+
{
|
|
316
|
+
collapsable: false,
|
|
317
|
+
entering: panelEntering,
|
|
318
|
+
exiting: panelExiting,
|
|
319
|
+
style: fullScreen ? {
|
|
320
|
+
flex: 1,
|
|
321
|
+
width: windowWidth,
|
|
322
|
+
backgroundColor: bgPrimary,
|
|
323
|
+
paddingBottom: 12
|
|
324
|
+
} : {
|
|
325
|
+
position: "absolute",
|
|
326
|
+
left: 0,
|
|
327
|
+
right: 0,
|
|
328
|
+
bottom: 0,
|
|
329
|
+
width: windowWidth,
|
|
330
|
+
maxHeight: sheetMax,
|
|
331
|
+
zIndex: 10,
|
|
332
|
+
overflow: "hidden",
|
|
333
|
+
backgroundColor: bgPrimary,
|
|
334
|
+
borderTopLeftRadius: DIALOG_SHEET_RADIUS_PX,
|
|
335
|
+
borderTopRightRadius: DIALOG_SHEET_RADIUS_PX,
|
|
336
|
+
borderBottomLeftRadius: 0,
|
|
337
|
+
borderBottomRightRadius: 0,
|
|
338
|
+
borderTopWidth: 1,
|
|
339
|
+
borderLeftWidth: 0,
|
|
340
|
+
borderRightWidth: 0,
|
|
341
|
+
borderBottomWidth: 0,
|
|
342
|
+
borderTopColor: borderSecondary,
|
|
343
|
+
paddingBottom: insets.bottom
|
|
344
|
+
},
|
|
345
|
+
children: [
|
|
346
|
+
fullScreen ? /* @__PURE__ */ jsx(View, { style: { height: insets.top } }) : null,
|
|
347
|
+
/* @__PURE__ */ jsxs(View, { className: cx("w-full flex-row items-center pr-2 pl-4", title ? "justify-between" : "justify-end"), style: { height: HEADER_HEIGHT }, children: [
|
|
348
|
+
title ? /* @__PURE__ */ jsx(Text, { numberOfLines: 1, className: "text-primary min-w-0 flex-1 text-base font-semibold", children: title }) : null,
|
|
349
|
+
/* @__PURE__ */ jsx(
|
|
350
|
+
Pressable,
|
|
351
|
+
{
|
|
352
|
+
accessibilityRole: "button",
|
|
353
|
+
accessibilityLabel: "Close",
|
|
354
|
+
onPress: onClose,
|
|
355
|
+
className: "size-12 items-center justify-center rounded-full active:bg-primary_hover",
|
|
356
|
+
children: /* @__PURE__ */ jsx(XIcon, { size: 20, color: fgPrimary })
|
|
357
|
+
}
|
|
358
|
+
)
|
|
359
|
+
] }),
|
|
360
|
+
/* @__PURE__ */ jsx(
|
|
361
|
+
ScrollView,
|
|
362
|
+
{
|
|
363
|
+
keyboardShouldPersistTaps: "handled",
|
|
364
|
+
style: fullScreen ? { flex: 1 } : { flexGrow: 0, flexShrink: 0, maxHeight: listMax },
|
|
365
|
+
children: /* @__PURE__ */ jsx(View, { className: cx("py-1", className), children })
|
|
366
|
+
}
|
|
367
|
+
)
|
|
368
|
+
]
|
|
369
|
+
}
|
|
370
|
+
) : null
|
|
371
|
+
] }) });
|
|
372
|
+
};
|
|
373
|
+
function visibleItems(items, query, defaultFilter) {
|
|
374
|
+
if (!defaultFilter) return items.filter((item) => itemMatches(item, query));
|
|
375
|
+
return items.filter((item) => defaultFilter(itemText(item), query));
|
|
376
|
+
}
|
|
377
|
+
var ComboBox = ({
|
|
378
|
+
size = "md",
|
|
379
|
+
label,
|
|
380
|
+
placeholder = "Search",
|
|
381
|
+
hint,
|
|
382
|
+
icon,
|
|
383
|
+
items = [],
|
|
384
|
+
inputValue = "",
|
|
385
|
+
allowsCustomValue = false,
|
|
386
|
+
isDisabled,
|
|
387
|
+
isInvalid,
|
|
388
|
+
isRequired,
|
|
389
|
+
hideRequiredIndicator,
|
|
390
|
+
autoComplete,
|
|
391
|
+
textContentType,
|
|
392
|
+
inputClassName,
|
|
393
|
+
popoverClassName,
|
|
394
|
+
mobileOptions,
|
|
395
|
+
defaultFilter,
|
|
396
|
+
onInputChange,
|
|
397
|
+
onSelectionChange,
|
|
398
|
+
onFocus,
|
|
399
|
+
onBlur,
|
|
400
|
+
children
|
|
401
|
+
}) => {
|
|
402
|
+
const fgQuaternary = useNativeVariable("--color-fg-quaternary") ?? "#a4a7ae";
|
|
403
|
+
const resolved = resolveSelectMobileOptions({ title: label, ...mobileOptions });
|
|
404
|
+
const blurTimer = useRef(null);
|
|
405
|
+
const [focused, setFocused] = useState(false);
|
|
406
|
+
const [open, setOpen] = useState(false);
|
|
407
|
+
const [pickedId, setPickedId] = useState(null);
|
|
408
|
+
const [pickedValue, setPickedValue] = useState(null);
|
|
409
|
+
const [sheetQuery, setSheetQuery] = useState(inputValue);
|
|
410
|
+
const query = resolved.sheet ? sheetQuery : inputValue;
|
|
411
|
+
const rows = useMemo(() => visibleItems(items, query, defaultFilter), [items, query, defaultFilter]);
|
|
412
|
+
const picked = items.find((item) => item.id === pickedId) ?? null;
|
|
413
|
+
const showFloating = !resolved.sheet && open && focused && rows.length > 0 && inputValue.trim() !== pickedValue;
|
|
414
|
+
const selectItem = (id) => {
|
|
415
|
+
const item = items.find((entry) => selectIdKey(entry.id) === selectIdKey(id));
|
|
416
|
+
const next = item?.label ?? query;
|
|
417
|
+
setPickedId(id);
|
|
418
|
+
setPickedValue(next.trim());
|
|
419
|
+
setOpen(false);
|
|
420
|
+
setFocused(false);
|
|
421
|
+
if (resolved.sheet) setSheetQuery(next);
|
|
422
|
+
if (next !== inputValue) onInputChange?.(next);
|
|
423
|
+
onSelectionChange?.(id);
|
|
424
|
+
};
|
|
425
|
+
const menuValue = {
|
|
426
|
+
size,
|
|
427
|
+
isSelected: (id) => pickedId != null && selectIdKey(pickedId) === selectIdKey(id),
|
|
428
|
+
onSelect: selectItem,
|
|
429
|
+
selectOnPressIn: !resolved.sheet
|
|
430
|
+
};
|
|
431
|
+
const list = rows.map((item) => /* @__PURE__ */ jsx(View, { children: children(item) }, selectIdKey(item.id)));
|
|
432
|
+
return /* @__PURE__ */ jsx(SelectContext.Provider, { value: { size }, children: /* @__PURE__ */ jsx(SelectMenuContext.Provider, { value: menuValue, children: /* @__PURE__ */ jsxs(View, { className: "w-full gap-1.5", children: [
|
|
433
|
+
label ? /* @__PURE__ */ jsx(Label, { isRequired: Boolean(isRequired && !hideRequiredIndicator), isInvalid, children: label }) : null,
|
|
434
|
+
resolved.sheet ? /* @__PURE__ */ jsx(
|
|
435
|
+
SheetTrigger,
|
|
436
|
+
{
|
|
437
|
+
size,
|
|
438
|
+
placeholder,
|
|
439
|
+
icon,
|
|
440
|
+
item: picked,
|
|
441
|
+
customValue: allowsCustomValue ? inputValue : "",
|
|
442
|
+
isDisabled,
|
|
443
|
+
isInvalid,
|
|
444
|
+
focused: open,
|
|
445
|
+
color: fgQuaternary,
|
|
446
|
+
onPress: () => {
|
|
447
|
+
if (isDisabled) return;
|
|
448
|
+
setSheetQuery(inputValue);
|
|
449
|
+
setOpen(true);
|
|
450
|
+
onFocus?.();
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
) : /* @__PURE__ */ jsx(
|
|
454
|
+
FloatingField,
|
|
455
|
+
{
|
|
456
|
+
size,
|
|
457
|
+
placeholder,
|
|
458
|
+
icon,
|
|
459
|
+
value: inputValue,
|
|
460
|
+
isDisabled,
|
|
461
|
+
isInvalid,
|
|
462
|
+
focused,
|
|
463
|
+
autoComplete,
|
|
464
|
+
textContentType,
|
|
465
|
+
inputClassName,
|
|
466
|
+
color: fgQuaternary,
|
|
467
|
+
onChangeText: (next) => {
|
|
468
|
+
if (next.trim() !== pickedValue) {
|
|
469
|
+
setPickedValue(null);
|
|
470
|
+
setPickedId(null);
|
|
471
|
+
}
|
|
472
|
+
setOpen(true);
|
|
473
|
+
onInputChange?.(next);
|
|
474
|
+
},
|
|
475
|
+
onFocus: () => {
|
|
476
|
+
if (blurTimer.current) clearTimeout(blurTimer.current);
|
|
477
|
+
setFocused(true);
|
|
478
|
+
setOpen(true);
|
|
479
|
+
onFocus?.();
|
|
480
|
+
},
|
|
481
|
+
onBlur: () => {
|
|
482
|
+
onBlur?.();
|
|
483
|
+
blurTimer.current = setTimeout(() => {
|
|
484
|
+
setFocused(false);
|
|
485
|
+
setOpen(false);
|
|
486
|
+
if (!allowsCustomValue && pickedValue != null && inputValue.trim() !== pickedValue) {
|
|
487
|
+
onInputChange?.(pickedValue);
|
|
488
|
+
}
|
|
489
|
+
}, 300);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
),
|
|
493
|
+
/* @__PURE__ */ jsx(
|
|
494
|
+
Popover,
|
|
495
|
+
{
|
|
496
|
+
open: resolved.sheet ? open : showFloating,
|
|
497
|
+
onClose: () => {
|
|
498
|
+
setOpen(false);
|
|
499
|
+
onBlur?.();
|
|
500
|
+
},
|
|
501
|
+
size,
|
|
502
|
+
mobileOptions: { title: label, ...mobileOptions, sheet: resolved.sheet },
|
|
503
|
+
className: popoverClassName,
|
|
504
|
+
compound: resolved.sheet,
|
|
505
|
+
children: resolved.sheet ? /* @__PURE__ */ jsxs(View, { children: [
|
|
506
|
+
/* @__PURE__ */ jsx(View, { className: cx("border-secondary border-b", searchSizes[size].wrapper), children: /* @__PURE__ */ jsxs(View, { className: cx("flex-row items-center", searchSizes[size].root), children: [
|
|
507
|
+
/* @__PURE__ */ jsx(SelectGlyph, { icon: icon ?? MagnifyingGlassIcon, size: sizes[size].icon, color: fgQuaternary }),
|
|
508
|
+
/* @__PURE__ */ jsx(
|
|
509
|
+
TextInput,
|
|
510
|
+
{
|
|
511
|
+
value: sheetQuery,
|
|
512
|
+
placeholder,
|
|
513
|
+
onChangeText: (next) => {
|
|
514
|
+
setSheetQuery(next);
|
|
515
|
+
onInputChange?.(next);
|
|
516
|
+
},
|
|
517
|
+
placeholderTextColor: "#737373",
|
|
518
|
+
className: cx("text-primary min-w-0 flex-1", inputStyles.input, searchSizes[size].text),
|
|
519
|
+
style: { includeFontPadding: false, paddingVertical: 0 }
|
|
520
|
+
}
|
|
521
|
+
)
|
|
522
|
+
] }) }),
|
|
523
|
+
list
|
|
524
|
+
] }) : list
|
|
525
|
+
}
|
|
526
|
+
),
|
|
527
|
+
hint ? /* @__PURE__ */ jsx(HintText, { isInvalid, size, children: hint }) : null
|
|
528
|
+
] }) }) });
|
|
529
|
+
};
|
|
530
|
+
var FloatingField = ({
|
|
531
|
+
size,
|
|
532
|
+
placeholder,
|
|
533
|
+
icon,
|
|
534
|
+
value,
|
|
535
|
+
isDisabled,
|
|
536
|
+
isInvalid,
|
|
537
|
+
focused,
|
|
538
|
+
autoComplete,
|
|
539
|
+
textContentType,
|
|
540
|
+
inputClassName,
|
|
541
|
+
color,
|
|
542
|
+
onChangeText,
|
|
543
|
+
onFocus,
|
|
544
|
+
onBlur
|
|
545
|
+
}) => /* @__PURE__ */ jsxs(View, { className: selectFieldClassName({ size, focused, isInvalid, isDisabled }), children: [
|
|
546
|
+
/* @__PURE__ */ jsx(SelectGlyph, { icon: icon ?? MagnifyingGlassIcon, size: sizes[size].icon, color }),
|
|
547
|
+
/* @__PURE__ */ jsx(
|
|
548
|
+
TextInput,
|
|
549
|
+
{
|
|
550
|
+
editable: !isDisabled,
|
|
551
|
+
value,
|
|
552
|
+
placeholder,
|
|
553
|
+
autoComplete,
|
|
554
|
+
textContentType,
|
|
555
|
+
onChangeText,
|
|
556
|
+
onFocus,
|
|
557
|
+
onBlur,
|
|
558
|
+
placeholderTextColor: "#737373",
|
|
559
|
+
className: cx("text-primary min-w-0 flex-1 font-medium", inputStyles.input, sizes[size].text, inputClassName),
|
|
560
|
+
style: { includeFontPadding: false, paddingVertical: 0 }
|
|
561
|
+
}
|
|
562
|
+
)
|
|
563
|
+
] });
|
|
564
|
+
var SheetTrigger = ({ size, placeholder, icon, item, customValue, isDisabled, isInvalid, focused, color, onPress }) => /* @__PURE__ */ jsxs(
|
|
565
|
+
Pressable,
|
|
566
|
+
{
|
|
567
|
+
accessibilityRole: "button",
|
|
568
|
+
disabled: isDisabled,
|
|
569
|
+
onPress,
|
|
570
|
+
className: selectFieldClassName({ size, focused, isInvalid, isDisabled }),
|
|
571
|
+
children: [
|
|
572
|
+
/* @__PURE__ */ jsx(SelectGlyph, { icon: item?.icon ?? icon ?? MagnifyingGlassIcon, size: sizes[size].icon, color }),
|
|
573
|
+
/* @__PURE__ */ jsx(View, { className: cx("min-w-0 flex-1 flex-row flex-wrap", sizes[size].textGap), children: item?.label || customValue ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
574
|
+
/* @__PURE__ */ jsx(Text, { numberOfLines: 1, className: cx("text-primary font-medium", sizes[size].text), children: item?.label || customValue }),
|
|
575
|
+
item?.supportingText ? /* @__PURE__ */ jsx(Text, { numberOfLines: 1, className: cx("text-tertiary", sizes[size].text), children: item.supportingText }) : null
|
|
576
|
+
] }) : /* @__PURE__ */ jsx(Text, { numberOfLines: 1, className: cx("text-placeholder", sizes[size].text), children: placeholder }) }),
|
|
577
|
+
/* @__PURE__ */ jsx(CaretDownIcon, { size: size === "lg" ? 20 : 16, color })
|
|
578
|
+
]
|
|
579
|
+
}
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
export { ComboBox };
|
|
583
|
+
//# sourceMappingURL=combobox.js.map
|
|
584
|
+
//# sourceMappingURL=combobox.js.map
|