react-native-molecules 0.5.0-beta.12 → 0.5.0-beta.14
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.
|
@@ -27,15 +27,15 @@ export type Props = Omit<TextInputProps, OmitProp> &
|
|
|
27
27
|
/**
|
|
28
28
|
* Default value for uncontrolled usage
|
|
29
29
|
*/
|
|
30
|
-
defaultValue?: DocumentResult
|
|
30
|
+
defaultValue?: DocumentResult[];
|
|
31
31
|
/**
|
|
32
32
|
* To Control the value
|
|
33
33
|
*/
|
|
34
|
-
value?: DocumentResult
|
|
34
|
+
value?: DocumentResult[];
|
|
35
35
|
/**
|
|
36
36
|
* The Callback function to return the selected files as an array or object
|
|
37
37
|
*/
|
|
38
|
-
onChange?: (result: DocumentResult
|
|
38
|
+
onChange?: (result: DocumentResult[] | undefined) => any;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
const FilePicker = ({
|
|
@@ -53,9 +53,7 @@ const FilePicker = ({
|
|
|
53
53
|
children,
|
|
54
54
|
...rest
|
|
55
55
|
}: Props) => {
|
|
56
|
-
const [value, onValueChange] = useControlledValue<
|
|
57
|
-
DocumentResult | DocumentResult[] | undefined
|
|
58
|
-
>({
|
|
56
|
+
const [value, onValueChange] = useControlledValue<DocumentResult[] | undefined>({
|
|
59
57
|
value: valueProp,
|
|
60
58
|
defaultValue,
|
|
61
59
|
onChange,
|
|
@@ -74,14 +72,10 @@ const FilePicker = ({
|
|
|
74
72
|
const displayText = useMemo(() => {
|
|
75
73
|
if (!value) return '';
|
|
76
74
|
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
return `${value.length} files`;
|
|
80
|
-
}
|
|
81
|
-
return value[0]?.name || '';
|
|
75
|
+
if (value.length > 1) {
|
|
76
|
+
return `${value.length} files`;
|
|
82
77
|
}
|
|
83
|
-
|
|
84
|
-
return value.name || '';
|
|
78
|
+
return value[0]?.name || '';
|
|
85
79
|
}, [value]);
|
|
86
80
|
|
|
87
81
|
const onPress = useCallback(() => {
|
|
@@ -30,14 +30,6 @@ const TooltipTrigger = memo(({ children }: { children: ReactElement }) => {
|
|
|
30
30
|
() => triggerRef?.current,
|
|
31
31
|
);
|
|
32
32
|
|
|
33
|
-
const onPress = useCallback(
|
|
34
|
-
(e: unknown) => {
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
children?.props?.onPress?.(e);
|
|
37
|
-
},
|
|
38
|
-
[children?.props],
|
|
39
|
-
);
|
|
40
|
-
|
|
41
33
|
const onLongPress = useCallback(
|
|
42
34
|
(e: unknown) => {
|
|
43
35
|
// @ts-ignore
|
|
@@ -93,9 +85,8 @@ const TooltipTrigger = memo(({ children }: { children: ReactElement }) => {
|
|
|
93
85
|
ref: actionsRef,
|
|
94
86
|
onLongPress,
|
|
95
87
|
onPressOut,
|
|
96
|
-
onPress,
|
|
97
88
|
}),
|
|
98
|
-
[children, onLongPress,
|
|
89
|
+
[children, onLongPress, onPressOut, actionsRef],
|
|
99
90
|
);
|
|
100
91
|
});
|
|
101
92
|
|
package/package.json
CHANGED
|
@@ -49,43 +49,69 @@ const getDocumentAsyncWeb = async ({
|
|
|
49
49
|
throw error;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
try {
|
|
54
|
+
const input = document.createElement('input');
|
|
55
|
+
input.style.display = 'none';
|
|
56
|
+
input.setAttribute('type', 'file');
|
|
57
|
+
// @ts-expect-error
|
|
58
|
+
input.setAttribute('accept', Array.isArray(type) ? type.join(',') : type);
|
|
59
|
+
|
|
60
|
+
if (multiple) {
|
|
61
|
+
input.setAttribute('multiple', 'multiple');
|
|
62
|
+
}
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
document.body.appendChild(input);
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
const cleanup = () => {
|
|
67
|
+
try {
|
|
68
|
+
document.body.removeChild(input);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
// Input already removed, ignore
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
input.addEventListener('change', async () => {
|
|
75
|
+
try {
|
|
76
|
+
if (input.files && input.files.length > 0) {
|
|
77
|
+
const response: Promise<DocumentResult>[] = [];
|
|
78
|
+
|
|
79
|
+
Array.from(input.files).forEach(file =>
|
|
80
|
+
response.push(resolveFileData(file)),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const results = await Promise.all(response);
|
|
84
|
+
resolve(results);
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
onError?.(error);
|
|
77
88
|
reject(error);
|
|
89
|
+
} finally {
|
|
90
|
+
cleanup();
|
|
78
91
|
}
|
|
79
|
-
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
input.addEventListener('cancel', () => {
|
|
95
|
+
const error = new OperationCanceledError();
|
|
96
|
+
onCancel?.();
|
|
97
|
+
cleanup();
|
|
98
|
+
reject(error);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
input.addEventListener('error', () => {
|
|
102
|
+
const error = new Error('File picker error occurred');
|
|
80
103
|
onError?.(error);
|
|
104
|
+
cleanup();
|
|
81
105
|
reject(error);
|
|
82
|
-
}
|
|
83
|
-
document.body.removeChild(input);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
106
|
+
});
|
|
86
107
|
|
|
87
|
-
|
|
88
|
-
|
|
108
|
+
const event = new MouseEvent('click');
|
|
109
|
+
input.dispatchEvent(event);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
// Handle errors from file picker setup or opening
|
|
112
|
+
onError?.(error);
|
|
113
|
+
reject(error);
|
|
114
|
+
}
|
|
89
115
|
});
|
|
90
116
|
};
|
|
91
117
|
|