react-native-molecules 0.5.0-beta.2 → 0.5.0-beta.20
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/README.md +1 -1
- package/components/Accordion/Accordion.tsx +2 -6
- package/components/Accordion/AccordionItem.tsx +16 -12
- package/components/Accordion/AccordionItemContent.tsx +6 -1
- package/components/Accordion/AccordionItemHeader.tsx +1 -1
- package/components/Accordion/utils.ts +6 -0
- package/components/ActivityIndicator/ActivityIndicator.tsx +6 -15
- package/components/Appbar/AppbarBase.tsx +18 -13
- package/components/Button/Button.tsx +209 -264
- package/components/Button/index.tsx +9 -3
- package/components/Button/types.ts +16 -2
- package/components/Button/utils.ts +230 -208
- package/components/Checkbox/CheckboxBase.tsx +23 -128
- package/components/Checkbox/utils.ts +0 -25
- package/components/Chip/Chip.tsx +40 -52
- package/components/Chip/utils.ts +3 -7
- package/components/DateField/DateField.tsx +110 -0
- package/components/DateField/index.tsx +6 -0
- package/components/{DatePickerInput/inputUtils.ts → DateField/useDateFieldState.ts} +17 -49
- package/components/DatePicker/DateCalendar.tsx +83 -0
- package/components/DatePicker/DatePickerActions.tsx +73 -0
- package/components/DatePicker/DatePickerModal.tsx +234 -0
- package/components/DatePicker/DatePickerPopover.tsx +79 -0
- package/components/DatePicker/DatePickerProvider.tsx +152 -0
- package/components/DatePicker/DatePickerTrigger.tsx +23 -0
- package/components/DatePicker/context.tsx +82 -0
- package/components/DatePicker/index.tsx +44 -0
- package/components/DatePicker/utils.ts +293 -0
- package/components/DatePickerInline/DatePickerContext.tsx +1 -0
- package/components/DatePickerInline/DatePickerDockedHeader.tsx +113 -0
- package/components/DatePickerInline/DatePickerInline.tsx +16 -15
- package/components/DatePickerInline/DatePickerInlineBase.tsx +7 -1
- package/components/DatePickerInline/Day.tsx +25 -1
- package/components/DatePickerInline/DayRange.tsx +2 -4
- package/components/DatePickerInline/HeaderItem.tsx +42 -27
- package/components/DatePickerInline/Month.tsx +45 -65
- package/components/DatePickerInline/MonthPicker.tsx +25 -41
- package/components/DatePickerInline/Swiper.native.tsx +21 -4
- package/components/DatePickerInline/Swiper.tsx +168 -13
- package/components/DatePickerInline/Week.tsx +6 -1
- package/components/DatePickerInline/YearPicker.tsx +206 -53
- package/components/DatePickerInline/dateUtils.tsx +17 -12
- package/components/DatePickerInline/types.ts +3 -0
- package/components/DatePickerInline/utils.ts +66 -29
- package/components/Drawer/Drawer.tsx +17 -6
- package/components/ElementGroup/ElementGroup.tsx +16 -14
- package/components/FilePicker/FilePicker.tsx +48 -78
- package/components/FilePicker/index.tsx +2 -1
- package/components/FilePicker/utils.ts +9 -0
- package/components/HelperText/HelperText.tsx +0 -35
- package/components/Icon/iconFactory.tsx +3 -3
- package/components/Icon/index.tsx +1 -1
- package/components/Icon/types.ts +17 -6
- package/components/IconButton/IconButton.tsx +42 -57
- package/components/IconButton/utils.ts +142 -33
- package/components/ListItem/ListItem.tsx +3 -1
- package/components/ListItem/utils.ts +1 -1
- package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
- package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
- package/components/LoadingIndicator/index.tsx +13 -0
- package/components/LoadingIndicator/utils.ts +117 -0
- package/components/Menu/Menu.tsx +3 -18
- package/components/NavigationRail/NavigationRail.tsx +15 -9
- package/components/Popover/Popover.tsx +122 -145
- package/components/Popover/PopoverRoot.tsx +74 -0
- package/components/Popover/common.ts +50 -34
- package/components/Popover/index.ts +18 -1
- package/components/Popover/usePlatformMeasure.native.ts +90 -0
- package/components/Popover/usePlatformMeasure.ts +118 -0
- package/components/Popover/utils.ts +34 -0
- package/components/Select/Select.tsx +368 -507
- package/components/Select/context.tsx +72 -0
- package/components/Select/index.ts +8 -14
- package/components/Select/types.ts +2 -4
- package/components/Select/utils.ts +144 -0
- package/components/Slot/Slot.tsx +244 -0
- package/components/Slot/compose-refs.tsx +62 -0
- package/components/Slot/index.tsx +8 -0
- package/components/Surface/Surface.android.tsx +34 -8
- package/components/Surface/Surface.ios.tsx +36 -29
- package/components/Surface/Surface.tsx +31 -4
- package/components/Surface/utils.ts +44 -30
- package/components/Switch/Switch.tsx +8 -2
- package/components/Tabs/TabItem.tsx +35 -58
- package/components/Tabs/TabLabel.tsx +5 -9
- package/components/Tabs/Tabs.tsx +154 -148
- package/components/Tabs/utils.ts +15 -2
- package/components/TextInput/TextInput.tsx +658 -575
- package/components/TextInput/index.tsx +19 -3
- package/components/TextInput/types.ts +76 -27
- package/components/TextInput/utils.ts +225 -145
- package/components/TimeField/TimeField.tsx +75 -0
- package/components/TimeField/index.tsx +6 -0
- package/components/TimeField/useTimeFieldState.ts +70 -0
- package/components/{TimePickerField/sanitizeTime.ts → TimeField/utils.ts} +77 -10
- package/components/TimePicker/TimeInput.tsx +87 -37
- package/components/TimePicker/TimeInputs.tsx +137 -49
- package/components/TimePicker/TimePicker.tsx +73 -10
- package/components/TimePicker/TimePickerModal.tsx +186 -0
- package/components/TimePicker/context.tsx +17 -0
- package/components/TimePicker/index.tsx +15 -3
- package/components/TimePicker/utils.ts +93 -0
- package/components/Tooltip/Tooltip.tsx +42 -67
- package/components/Tooltip/TooltipContent.tsx +32 -5
- package/components/Tooltip/TooltipTrigger.tsx +20 -20
- package/components/Tooltip/index.tsx +1 -1
- package/components/TouchableRipple/TouchableRipple.native.tsx +50 -14
- package/components/TouchableRipple/TouchableRipple.tsx +137 -47
- package/hocs/withPortal.tsx +1 -1
- package/hooks/index.tsx +0 -6
- package/hooks/useActionState.tsx +19 -8
- package/hooks/useControlledValue.tsx +20 -4
- package/hooks/useFilePicker.tsx +6 -16
- package/hooks/useWhatHasUpdated.tsx +48 -0
- package/package.json +17 -13
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +5 -2
- package/styles/shadow.ts +2 -1
- package/styles/themes/LightTheme.tsx +1 -1
- package/utils/DocumentPicker/documentPicker.ts +78 -27
- package/utils/DocumentPicker/types.ts +0 -1
- package/utils/extractPropertiesFromStyles.ts +25 -0
- package/utils/extractSubcomponents.ts +89 -0
- package/utils/lodash.ts +77 -5
- package/components/DatePickerDocked/DatePickerDocked.tsx +0 -30
- package/components/DatePickerDocked/DatePickerDockedHeader.tsx +0 -129
- package/components/DatePickerDocked/index.tsx +0 -17
- package/components/DatePickerDocked/types.ts +0 -11
- package/components/DatePickerDocked/utils.ts +0 -157
- package/components/DatePickerInput/DatePickerInput.tsx +0 -139
- package/components/DatePickerInput/DatePickerInputModal.tsx +0 -48
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +0 -77
- package/components/DatePickerInput/DateRangeInput.tsx +0 -88
- package/components/DatePickerInput/index.tsx +0 -10
- package/components/DatePickerInput/types.ts +0 -28
- package/components/DatePickerInput/utils.ts +0 -15
- package/components/DatePickerModal/AnimatedCrossView.tsx +0 -94
- package/components/DatePickerModal/CalendarEdit.tsx +0 -139
- package/components/DatePickerModal/DatePickerModal.tsx +0 -85
- package/components/DatePickerModal/DatePickerModalContent.tsx +0 -155
- package/components/DatePickerModal/DatePickerModalContentHeader.tsx +0 -213
- package/components/DatePickerModal/DatePickerModalHeader.tsx +0 -74
- package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +0 -13
- package/components/DatePickerModal/index.tsx +0 -16
- package/components/DatePickerModal/types.ts +0 -92
- package/components/DatePickerModal/utils.ts +0 -122
- package/components/DateTimePicker/DateTimePicker.tsx +0 -172
- package/components/DateTimePicker/index.tsx +0 -10
- package/components/DateTimePicker/utils.ts +0 -12
- package/components/Popover/Popover.native.tsx +0 -185
- package/components/TimePickerField/TimePickerField.tsx +0 -152
- package/components/TimePickerField/index.tsx +0 -10
- package/components/TimePickerField/utils.ts +0 -94
- package/components/TimePickerModal/TimePickerModal.tsx +0 -115
- package/components/TimePickerModal/index.tsx +0 -10
- package/components/TimePickerModal/utils.ts +0 -47
- package/hooks/useSearchable.tsx +0 -74
- package/hooks/useSubcomponents.tsx +0 -59
|
@@ -2,6 +2,14 @@ import { Platform } from 'react-native';
|
|
|
2
2
|
|
|
3
3
|
import type { DocumentPickerOptions, DocumentResult } from './types';
|
|
4
4
|
|
|
5
|
+
class OperationCanceledError extends Error {
|
|
6
|
+
code = 'OPERATION_CANCELED';
|
|
7
|
+
constructor() {
|
|
8
|
+
super('user canceled the document picker');
|
|
9
|
+
this.name = 'OperationCanceledError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
const resolveFileData = (file: File): Promise<DocumentResult> => {
|
|
6
14
|
return new Promise((resolve, reject) => {
|
|
7
15
|
const mimeType = file.type;
|
|
@@ -31,46 +39,89 @@ const resolveFileData = (file: File): Promise<DocumentResult> => {
|
|
|
31
39
|
const getDocumentAsyncWeb = async ({
|
|
32
40
|
type = '*/*',
|
|
33
41
|
multiple = false,
|
|
34
|
-
|
|
42
|
+
onCancel,
|
|
43
|
+
onError,
|
|
44
|
+
}: DocumentPickerOptions): Promise<DocumentResult[]> => {
|
|
35
45
|
// SSR guard
|
|
36
46
|
if (Platform.OS !== 'web') {
|
|
37
|
-
|
|
47
|
+
const error = new OperationCanceledError();
|
|
48
|
+
onCancel?.();
|
|
49
|
+
throw error;
|
|
38
50
|
}
|
|
39
51
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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);
|
|
45
59
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
if (multiple) {
|
|
61
|
+
input.setAttribute('multiple', 'multiple');
|
|
62
|
+
}
|
|
49
63
|
|
|
50
|
-
|
|
64
|
+
document.body.appendChild(input);
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
const cleanup = () => {
|
|
67
|
+
try {
|
|
68
|
+
document.body.removeChild(input);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
// Input already removed, ignore
|
|
71
|
+
}
|
|
72
|
+
};
|
|
56
73
|
|
|
57
|
-
|
|
74
|
+
input.addEventListener('change', async () => {
|
|
75
|
+
try {
|
|
76
|
+
if (input.files && input.files.length > 0) {
|
|
77
|
+
const response: Promise<DocumentResult>[] = [];
|
|
58
78
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
79
|
+
Array.from(input.files).forEach(file =>
|
|
80
|
+
response.push(resolveFileData(file)),
|
|
81
|
+
);
|
|
63
82
|
|
|
64
|
-
|
|
65
|
-
|
|
83
|
+
const results = await Promise.all(response);
|
|
84
|
+
resolve(results);
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
onError?.(error);
|
|
88
|
+
reject(error);
|
|
89
|
+
} finally {
|
|
90
|
+
cleanup();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
66
93
|
|
|
67
|
-
|
|
68
|
-
|
|
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');
|
|
103
|
+
onError?.(error);
|
|
104
|
+
cleanup();
|
|
105
|
+
reject(error);
|
|
106
|
+
});
|
|
107
|
+
|
|
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
|
+
}
|
|
69
115
|
});
|
|
70
116
|
};
|
|
71
117
|
|
|
118
|
+
const pickSingle = (options: DocumentPickerOptions = {}) =>
|
|
119
|
+
getDocumentAsyncWeb({ ...options, multiple: false });
|
|
120
|
+
|
|
121
|
+
const pickMultiple = (options: DocumentPickerOptions = {}) =>
|
|
122
|
+
getDocumentAsyncWeb({ ...options, multiple: true });
|
|
123
|
+
|
|
72
124
|
export default {
|
|
73
|
-
pickSingle
|
|
74
|
-
pickMultiple
|
|
75
|
-
getDocumentAsyncWeb({ type, multiple: true }),
|
|
125
|
+
pickSingle,
|
|
126
|
+
pickMultiple,
|
|
76
127
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
// TODO - abstract this
|
|
4
|
+
export function extractPropertiesFromStyles(
|
|
5
|
+
_objectsArray: Record<string, any>,
|
|
6
|
+
propertiesToExtract: string[],
|
|
7
|
+
) {
|
|
8
|
+
const extracted: Record<string, any> = {};
|
|
9
|
+
|
|
10
|
+
const objectsArray = StyleSheet.flatten(_objectsArray);
|
|
11
|
+
|
|
12
|
+
for (let i = objectsArray.length - 1; i >= 0; i--) {
|
|
13
|
+
const obj = objectsArray[i];
|
|
14
|
+
|
|
15
|
+
for (const prop of propertiesToExtract) {
|
|
16
|
+
if (!obj) continue;
|
|
17
|
+
if (prop in obj) {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
extracted[prop] = obj[prop];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return extracted;
|
|
25
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Children, type FC, isValidElement } from 'react';
|
|
3
|
+
|
|
4
|
+
export type ExtractSubcomponentsArgs<T extends string> = {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
/**
|
|
7
|
+
* array of displayName as string
|
|
8
|
+
* */
|
|
9
|
+
allowedChildren: (T | { name: T; allowMultiple?: boolean })[];
|
|
10
|
+
/**
|
|
11
|
+
* If true, also returns the remaining children that don't match any of the allowedChildren
|
|
12
|
+
* in a `rest` property
|
|
13
|
+
*/
|
|
14
|
+
includeRest?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ExtractSubcomponentsResult<T extends string, IncludeRest extends boolean = false> = {
|
|
18
|
+
[key in T]: ReactElement[];
|
|
19
|
+
} & (IncludeRest extends true ? { rest: ReactNode[] } : {});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This will return an object with the displayNames as the property names
|
|
23
|
+
* eg. allowedChildren: ['Drawer_Header', 'Drawer_Content', 'Drawer_Footer', 'DrawerItem'];
|
|
24
|
+
*
|
|
25
|
+
* return value -> {
|
|
26
|
+
* Drawer_Header: [],
|
|
27
|
+
* Drawer_Content: [],
|
|
28
|
+
* Drawer_Footer: [],
|
|
29
|
+
* DrawerItem: [],
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* If includeRest is true, also returns:
|
|
33
|
+
* {
|
|
34
|
+
* ...above,
|
|
35
|
+
* rest: [remaining children that don't match allowedChildren]
|
|
36
|
+
* }
|
|
37
|
+
* */
|
|
38
|
+
export function extractSubcomponents<
|
|
39
|
+
T extends string = string,
|
|
40
|
+
IncludeRest extends boolean = false,
|
|
41
|
+
>({
|
|
42
|
+
children,
|
|
43
|
+
allowedChildren,
|
|
44
|
+
includeRest,
|
|
45
|
+
}: ExtractSubcomponentsArgs<T> & { includeRest?: IncludeRest }): ExtractSubcomponentsResult<
|
|
46
|
+
T,
|
|
47
|
+
IncludeRest
|
|
48
|
+
> {
|
|
49
|
+
// Single map: name → allowMultiple
|
|
50
|
+
const allowedMap = new Map<T, boolean>();
|
|
51
|
+
for (const entry of allowedChildren) {
|
|
52
|
+
if (typeof entry === 'string') {
|
|
53
|
+
allowedMap.set(entry as T, true);
|
|
54
|
+
} else {
|
|
55
|
+
allowedMap.set(entry.name, entry.allowMultiple ?? true);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const result = (includeRest ? { rest: [] } : {}) as ExtractSubcomponentsResult<T, IncludeRest>;
|
|
60
|
+
for (const name of allowedMap.keys()) {
|
|
61
|
+
(result as any)[name] = [];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Children.forEach(children, child => {
|
|
65
|
+
if (!isValidElement(child)) {
|
|
66
|
+
if (includeRest) (result as any).rest.push(child);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const displayName = (child.type as FC)?.displayName as T | undefined;
|
|
71
|
+
if (!displayName) {
|
|
72
|
+
if (includeRest) (result as any).rest.push(child);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const allowMultiple = allowedMap.get(displayName);
|
|
77
|
+
if (allowMultiple !== undefined) {
|
|
78
|
+
if (allowMultiple) {
|
|
79
|
+
(result as any)[displayName].push(child);
|
|
80
|
+
} else {
|
|
81
|
+
(result as any)[displayName] = [child];
|
|
82
|
+
}
|
|
83
|
+
} else if (includeRest) {
|
|
84
|
+
(result as any).rest.push(child);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return result;
|
|
89
|
+
}
|
package/utils/lodash.ts
CHANGED
|
@@ -1,8 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
type MemoizeCache<K = any, V = any> = {
|
|
2
|
+
has(key: K): boolean;
|
|
3
|
+
get(key: K): V | undefined;
|
|
4
|
+
set(key: K, value: V): unknown;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
type MemoizeFn = {
|
|
8
|
+
<T extends (...args: any[]) => any>(
|
|
9
|
+
func: T,
|
|
10
|
+
resolver?: (...args: Parameters<T>) => any,
|
|
11
|
+
): MemoizedFunction<T>;
|
|
12
|
+
Cache: { new (): MemoizeCache<any, any> };
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export interface MemoizedFunction<T extends (...args: any[]) => any> {
|
|
16
|
+
(...args: Parameters<T>): ReturnType<T>;
|
|
17
|
+
cache: MemoizeCache<any, ReturnType<T>>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const memoize: MemoizeFn = ((
|
|
21
|
+
func: (...args: any[]) => any,
|
|
22
|
+
resolver?: (...args: any[]) => any,
|
|
23
|
+
) => {
|
|
24
|
+
if (typeof func !== 'function') {
|
|
25
|
+
throw new TypeError('Expected a function');
|
|
26
|
+
}
|
|
27
|
+
const memoized = function (this: unknown, ...args: any[]) {
|
|
28
|
+
const key = resolver ? resolver.apply(this, args) : args[0];
|
|
29
|
+
const { cache } = memoized as MemoizedFunction<typeof func>;
|
|
30
|
+
if (cache.has(key)) {
|
|
31
|
+
return cache.get(key);
|
|
32
|
+
}
|
|
33
|
+
const result = func.apply(this, args);
|
|
34
|
+
cache.set(key, result);
|
|
35
|
+
return result;
|
|
36
|
+
} as MemoizedFunction<typeof func>;
|
|
37
|
+
|
|
38
|
+
(memoized as MemoizedFunction<typeof func>).cache = new memoize.Cache();
|
|
39
|
+
return memoized;
|
|
40
|
+
}) as MemoizeFn;
|
|
41
|
+
|
|
42
|
+
memoize.Cache = Map;
|
|
43
|
+
|
|
44
|
+
type Iteratee<T> = ((item: T) => string | number | symbol) | keyof T;
|
|
45
|
+
|
|
46
|
+
export const keyBy = <T extends Record<string, any>>(
|
|
47
|
+
collection: T[],
|
|
48
|
+
iteratee: Iteratee<T>,
|
|
49
|
+
): Record<string, T> => {
|
|
50
|
+
const result: Record<string, T> = {};
|
|
51
|
+
if (!Array.isArray(collection)) return result;
|
|
52
|
+
|
|
53
|
+
const getter = typeof iteratee === 'function' ? iteratee : (item: T) => item[iteratee];
|
|
54
|
+
for (const item of collection) {
|
|
55
|
+
const key = getter(item);
|
|
56
|
+
if (key != null) {
|
|
57
|
+
result[String(key)] = item;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
type Predicate = (value: any, key: string) => boolean;
|
|
64
|
+
|
|
65
|
+
export const omitBy = <T extends Record<string, any>>(
|
|
66
|
+
object: T,
|
|
67
|
+
predicate: Predicate,
|
|
68
|
+
): Partial<T> => {
|
|
69
|
+
if (object == null) return {};
|
|
70
|
+
const result: Partial<T> = {};
|
|
71
|
+
for (const [key, value] of Object.entries(object)) {
|
|
72
|
+
if (!predicate(value, key)) {
|
|
73
|
+
result[key as keyof T] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
6
78
|
|
|
7
79
|
export const isNil = (value: unknown): value is null | undefined => value == null;
|
|
8
80
|
export const noop = () => {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { memo } from 'react';
|
|
2
|
-
|
|
3
|
-
import DatePickerInlineBase from '../DatePickerInline/DatePickerInlineBase';
|
|
4
|
-
import { Popover } from '../Popover';
|
|
5
|
-
import DatePickerDockedHeader from './DatePickerDockedHeader';
|
|
6
|
-
import type { DatePickerDockedProps } from './types';
|
|
7
|
-
import { datePickerDockedMonthStyles } from './utils';
|
|
8
|
-
|
|
9
|
-
const DatePickerDocked = (props: DatePickerDockedProps) => {
|
|
10
|
-
const { triggerRef, isOpen, onToggle, onClose } = props;
|
|
11
|
-
|
|
12
|
-
return (
|
|
13
|
-
<Popover
|
|
14
|
-
triggerRef={triggerRef}
|
|
15
|
-
isOpen={isOpen}
|
|
16
|
-
onClose={onClose}
|
|
17
|
-
{...props.popoverContentProps}>
|
|
18
|
-
<DatePickerInlineBase
|
|
19
|
-
{...props}
|
|
20
|
-
// TODO - fix ts issues
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
HeaderComponent={DatePickerDockedHeader}
|
|
23
|
-
onToggle={onToggle}
|
|
24
|
-
monthStyle={datePickerDockedMonthStyles}
|
|
25
|
-
/>
|
|
26
|
-
</Popover>
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default memo(DatePickerDocked);
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { add, format } from 'date-fns';
|
|
2
|
-
import { memo, useCallback, useMemo } from 'react';
|
|
3
|
-
import { View, type ViewStyle } from 'react-native';
|
|
4
|
-
|
|
5
|
-
import { useDatePickerStore } from '../DatePickerInline/DatePickerContext';
|
|
6
|
-
import type { DisableWeekDaysType } from '../DatePickerInline/dateUtils';
|
|
7
|
-
import DayNames from '../DatePickerInline/DayNames';
|
|
8
|
-
import HeaderItem from '../DatePickerInline/HeaderItem';
|
|
9
|
-
import { dayNamesHeight } from '../DatePickerInline/utils';
|
|
10
|
-
import { datePickerDockedHeaderStyles } from './utils';
|
|
11
|
-
|
|
12
|
-
const buttonContainerHeight = 56;
|
|
13
|
-
const buttonContainerMarginTop = 4;
|
|
14
|
-
const buttonContainerMarginBottom = 8;
|
|
15
|
-
|
|
16
|
-
export type CalendarHeaderProps = {
|
|
17
|
-
locale?: string;
|
|
18
|
-
disableWeekDays?: DisableWeekDaysType;
|
|
19
|
-
style?: ViewStyle;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function DatePickerDockedHeader({
|
|
23
|
-
locale = 'en',
|
|
24
|
-
disableWeekDays,
|
|
25
|
-
style: styleProp,
|
|
26
|
-
}: CalendarHeaderProps) {
|
|
27
|
-
const [{ localDate, pickerType, startDateYear, endDateYear }, setStore] = useDatePickerStore(
|
|
28
|
-
state => ({
|
|
29
|
-
localDate: state.localDate,
|
|
30
|
-
pickerType: state.pickerType,
|
|
31
|
-
startDateYear: state.startDateYear,
|
|
32
|
-
endDateYear: state.endDateYear,
|
|
33
|
-
}),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
// const componentStyles = useComponentStyles('DatePickerDocked_Header', styleProp);
|
|
37
|
-
|
|
38
|
-
const monthName = useMemo(() => {
|
|
39
|
-
return format(localDate, 'MMM');
|
|
40
|
-
}, [localDate]);
|
|
41
|
-
|
|
42
|
-
const { containerStyle, daysWrapperStyle } = useMemo(() => {
|
|
43
|
-
return {
|
|
44
|
-
containerStyle: [datePickerDockedHeaderStyles.datePickerHeader, styleProp],
|
|
45
|
-
daysWrapperStyle: datePickerDockedHeaderStyles.daysWrapperStyle,
|
|
46
|
-
};
|
|
47
|
-
}, [styleProp]);
|
|
48
|
-
|
|
49
|
-
const handlePressDropDown = useCallback(
|
|
50
|
-
(type: 'month' | 'year') => {
|
|
51
|
-
setStore(prev => ({
|
|
52
|
-
pickerType: prev.pickerType ? undefined : type,
|
|
53
|
-
}));
|
|
54
|
-
},
|
|
55
|
-
[setStore],
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const isNotInRange = useCallback(
|
|
59
|
-
(date: Date) => {
|
|
60
|
-
const year = date.getFullYear();
|
|
61
|
-
const month = date.getMonth();
|
|
62
|
-
if (year < startDateYear || year > endDateYear || month > 11 || month < 0) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
},
|
|
67
|
-
[startDateYear, endDateYear],
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
const handleChange = useCallback(
|
|
71
|
-
(offset: number, type?: 'month' | 'year') => {
|
|
72
|
-
let newDate = localDate;
|
|
73
|
-
const prop = type === 'month' ? 'months' : 'years';
|
|
74
|
-
newDate = add(newDate, { [prop]: offset });
|
|
75
|
-
|
|
76
|
-
if (isNotInRange(newDate)) return;
|
|
77
|
-
|
|
78
|
-
setStore(() => ({
|
|
79
|
-
localDate: newDate,
|
|
80
|
-
}));
|
|
81
|
-
},
|
|
82
|
-
[isNotInRange, localDate, setStore],
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const handleChangePrevious = useMemo(() => handleChange.bind(null, -1), [handleChange]);
|
|
86
|
-
const handleChangeNext = useMemo(() => handleChange.bind(null, 1), [handleChange]);
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<View>
|
|
90
|
-
<View style={containerStyle} pointerEvents={'box-none'}>
|
|
91
|
-
<HeaderItem
|
|
92
|
-
selecting={!!pickerType}
|
|
93
|
-
type="month"
|
|
94
|
-
value={monthName}
|
|
95
|
-
onNext={handleChangeNext}
|
|
96
|
-
onPrev={handleChangePrevious}
|
|
97
|
-
onPressDropdown={handlePressDropDown}
|
|
98
|
-
pickerType={pickerType}
|
|
99
|
-
/>
|
|
100
|
-
<HeaderItem
|
|
101
|
-
selecting={!!pickerType}
|
|
102
|
-
type="year"
|
|
103
|
-
value={localDate.getFullYear()}
|
|
104
|
-
onNext={handleChangeNext}
|
|
105
|
-
onPrev={handleChangePrevious}
|
|
106
|
-
onPressDropdown={handlePressDropDown}
|
|
107
|
-
pickerType={pickerType}
|
|
108
|
-
/>
|
|
109
|
-
</View>
|
|
110
|
-
<View style={daysWrapperStyle}>
|
|
111
|
-
<DayNames disableWeekDays={disableWeekDays} locale={locale} />
|
|
112
|
-
</View>
|
|
113
|
-
</View>
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function getCalendarHeaderHeight(scrollMode: 'horizontal' | 'vertical') {
|
|
118
|
-
if (scrollMode === 'horizontal') {
|
|
119
|
-
return (
|
|
120
|
-
buttonContainerHeight +
|
|
121
|
-
buttonContainerMarginTop +
|
|
122
|
-
buttonContainerMarginBottom +
|
|
123
|
-
dayNamesHeight
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
return dayNamesHeight;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export default memo(DatePickerDockedHeader);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
|
-
import DatePickerDockedDefault from './DatePickerDocked';
|
|
3
|
-
|
|
4
|
-
export const DatePickerDocked = getRegisteredComponentWithFallback(
|
|
5
|
-
'DatePickerDocked',
|
|
6
|
-
DatePickerDockedDefault,
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
export type { DatePickerDockedProps } from './types';
|
|
10
|
-
export {
|
|
11
|
-
datePickerDockedHeaderStyles,
|
|
12
|
-
datePickerDockedMonthItemStyles,
|
|
13
|
-
datePickerDockedMonthStyles,
|
|
14
|
-
datePickerDockedStyles,
|
|
15
|
-
datePickerHeaderItemStyles,
|
|
16
|
-
datePickerMonthPickerStyles,
|
|
17
|
-
} from './utils';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ViewProps } from 'react-native';
|
|
2
|
-
|
|
3
|
-
import type { DatePickerSingleProps } from '../DatePickerInline';
|
|
4
|
-
|
|
5
|
-
export type DatePickerDockedProps = DatePickerSingleProps & {
|
|
6
|
-
triggerRef: any;
|
|
7
|
-
onToggle: () => void;
|
|
8
|
-
onClose: () => void;
|
|
9
|
-
isOpen: boolean;
|
|
10
|
-
popoverContentProps?: ViewProps;
|
|
11
|
-
};
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
-
|
|
3
|
-
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
4
|
-
|
|
5
|
-
const datePickerDockedStylesDefault = StyleSheet.create(theme => ({
|
|
6
|
-
root: {
|
|
7
|
-
roundness: theme.shapes.corner.extraSmall,
|
|
8
|
-
headerBackgroundColor: theme.colors.surface,
|
|
9
|
-
} as any,
|
|
10
|
-
|
|
11
|
-
container: {
|
|
12
|
-
minHeight: 360,
|
|
13
|
-
minWidth: 360,
|
|
14
|
-
},
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
const datePickerDockedHeaderStylesDefault = StyleSheet.create(theme => ({
|
|
18
|
-
datePickerHeader: {
|
|
19
|
-
position: 'relative',
|
|
20
|
-
flexDirection: 'row',
|
|
21
|
-
alignItems: 'center',
|
|
22
|
-
justifyContent: 'space-evenly',
|
|
23
|
-
},
|
|
24
|
-
daysWrapperStyle: {
|
|
25
|
-
marginHorizontal: theme.spacings['3'],
|
|
26
|
-
},
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
const datePickerHeaderItemStylesDefault = StyleSheet.create(theme => ({
|
|
30
|
-
buttonContainer: {
|
|
31
|
-
height: 46,
|
|
32
|
-
width: '50%',
|
|
33
|
-
flexDirection: 'row',
|
|
34
|
-
alignItems: 'center',
|
|
35
|
-
},
|
|
36
|
-
buttonWrapper: {},
|
|
37
|
-
spacer: { flex: 1 },
|
|
38
|
-
labelStyle: {
|
|
39
|
-
...theme.typescale.bodyMedium,
|
|
40
|
-
opacity: 0.7,
|
|
41
|
-
},
|
|
42
|
-
buttonStyle: {
|
|
43
|
-
alignSelf: 'center',
|
|
44
|
-
borderRadius: theme.shapes.corner.extraSmall,
|
|
45
|
-
},
|
|
46
|
-
innerStyle: {
|
|
47
|
-
paddingLeft: theme.spacings['0'],
|
|
48
|
-
flexDirection: 'row',
|
|
49
|
-
alignItems: 'center',
|
|
50
|
-
borderRadius: theme.shapes.corner.extraSmall,
|
|
51
|
-
},
|
|
52
|
-
emtpyView: {
|
|
53
|
-
width: 30,
|
|
54
|
-
},
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
const datePickerMonthPickerStylesDefault = StyleSheet.create(theme => ({
|
|
58
|
-
root: {
|
|
59
|
-
backgroundColor: theme.colors.surface,
|
|
60
|
-
},
|
|
61
|
-
month: {
|
|
62
|
-
flex: 1,
|
|
63
|
-
justifyContent: 'center',
|
|
64
|
-
alignItems: 'flex-start',
|
|
65
|
-
},
|
|
66
|
-
selectedMonth: { color: theme.colors.onSurface },
|
|
67
|
-
monthButton: {
|
|
68
|
-
width: '100%',
|
|
69
|
-
overflow: 'hidden',
|
|
70
|
-
},
|
|
71
|
-
monthInner: {
|
|
72
|
-
height: 46,
|
|
73
|
-
alignItems: 'center',
|
|
74
|
-
justifyContent: 'flex-start',
|
|
75
|
-
flexDirection: 'row',
|
|
76
|
-
},
|
|
77
|
-
selectedMonthInner: { backgroundColor: theme.colors.surfaceVariant },
|
|
78
|
-
monthLabel: {
|
|
79
|
-
fontSize: 16,
|
|
80
|
-
},
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
const datePickerDockedMonthItemStylesDefault = StyleSheet.create(theme => ({
|
|
84
|
-
root: {
|
|
85
|
-
backgroundColor: theme.colors.surface,
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
monthButton: {
|
|
89
|
-
width: '100%',
|
|
90
|
-
overflow: 'hidden',
|
|
91
|
-
padding: theme.spacings['0'],
|
|
92
|
-
|
|
93
|
-
variants: {
|
|
94
|
-
state: {
|
|
95
|
-
selected: {
|
|
96
|
-
backgroundColor: theme.colors.surfaceVariant,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
monthInner: {
|
|
102
|
-
height: 46,
|
|
103
|
-
alignItems: 'center',
|
|
104
|
-
justifyContent: 'flex-start',
|
|
105
|
-
flexDirection: 'row',
|
|
106
|
-
padding: theme.spacings['0'],
|
|
107
|
-
},
|
|
108
|
-
monthLabel: {
|
|
109
|
-
fontSize: 16,
|
|
110
|
-
|
|
111
|
-
variants: {
|
|
112
|
-
state: {
|
|
113
|
-
selected: {
|
|
114
|
-
color: theme.colors.onSurface,
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
}));
|
|
120
|
-
|
|
121
|
-
const datePickerDockedMonthStylesDefault = StyleSheet.create(theme => ({
|
|
122
|
-
dockedHeaderStyle: {
|
|
123
|
-
alignItems: 'flex-start',
|
|
124
|
-
marginLeft: theme.spacings['4'],
|
|
125
|
-
},
|
|
126
|
-
weekContainerStyle: {
|
|
127
|
-
marginHorizontal: theme.spacings['3'],
|
|
128
|
-
},
|
|
129
|
-
backDropStyle: {
|
|
130
|
-
backgroundColor: 'transparent',
|
|
131
|
-
},
|
|
132
|
-
}));
|
|
133
|
-
|
|
134
|
-
export const datePickerDockedStyles = getRegisteredComponentStylesWithFallback(
|
|
135
|
-
'DatePickerDocked',
|
|
136
|
-
datePickerDockedStylesDefault,
|
|
137
|
-
);
|
|
138
|
-
export const datePickerDockedHeaderStyles = getRegisteredComponentStylesWithFallback(
|
|
139
|
-
'DatePickerDocked_Header',
|
|
140
|
-
datePickerDockedHeaderStylesDefault,
|
|
141
|
-
);
|
|
142
|
-
export const datePickerHeaderItemStyles = getRegisteredComponentStylesWithFallback(
|
|
143
|
-
'DatePicker_HeaderItem',
|
|
144
|
-
datePickerHeaderItemStylesDefault,
|
|
145
|
-
);
|
|
146
|
-
export const datePickerMonthPickerStyles = getRegisteredComponentStylesWithFallback(
|
|
147
|
-
'DatePickerDocked_MonthPicker',
|
|
148
|
-
datePickerMonthPickerStylesDefault,
|
|
149
|
-
);
|
|
150
|
-
export const datePickerDockedMonthItemStyles = getRegisteredComponentStylesWithFallback(
|
|
151
|
-
'DatePickerDocked_MonthItem',
|
|
152
|
-
datePickerDockedMonthItemStylesDefault,
|
|
153
|
-
);
|
|
154
|
-
export const datePickerDockedMonthStyles = getRegisteredComponentStylesWithFallback(
|
|
155
|
-
'DatePickerDocked_Month',
|
|
156
|
-
datePickerDockedMonthStylesDefault,
|
|
157
|
-
);
|