@flipova/foundation 1.14.0 → 2.0.4
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/CHANGELOG.md +175 -0
- package/README.md +53 -178
- package/components/ui/accordion/ANIMATION_CUSTOMIZATION.md +162 -0
- package/components/ui/accordion/AccordionAnimatedHeight.tsx +56 -0
- package/components/ui/accordion/AccordionAnimatedIcon.tsx +41 -0
- package/components/ui/accordion/AnimatedHeight.tsx +56 -0
- package/components/ui/accordion/AnimatedIcon.tsx +41 -0
- package/components/ui/accordion/MIGRATION_SUMMARY.md +250 -0
- package/components/ui/accordion/USAGE_EXAMPLE.tsx +179 -0
- package/components/ui/accordion/animation-config.ts +32 -0
- package/components/ui/accordion/index.tsx +253 -0
- package/components/ui/actionsheet/index.tsx +511 -0
- package/components/ui/alert/index.tsx +158 -0
- package/components/ui/alert-dialog/index.tsx +254 -0
- package/components/ui/avatar/index.tsx +139 -0
- package/components/ui/badge/index.tsx +163 -0
- package/components/ui/bottomsheet/index.tsx +477 -0
- package/components/ui/box/index.tsx +19 -0
- package/components/ui/box/index.web.tsx +19 -0
- package/components/ui/box/styles.tsx +10 -0
- package/components/ui/button/index.tsx +264 -0
- package/components/ui/calendar/creator.tsx +366 -0
- package/components/ui/calendar/index.tsx +462 -0
- package/components/ui/calendar/styles.tsx +140 -0
- package/components/ui/card/index.tsx +23 -0
- package/components/ui/card/index.web.tsx +26 -0
- package/components/ui/card/styles.tsx +16 -0
- package/components/ui/center/index.tsx +22 -0
- package/components/ui/center/index.web.tsx +20 -0
- package/components/ui/center/styles.tsx +8 -0
- package/components/ui/checkbox/index.tsx +184 -0
- package/components/ui/date-time-picker/creator.tsx +109 -0
- package/components/ui/date-time-picker/index.tsx +585 -0
- package/components/ui/date-time-picker/index.web.tsx +217 -0
- package/components/ui/date-time-picker/styles.tsx +56 -0
- package/components/ui/divider/index.tsx +40 -0
- package/components/ui/drawer/index.tsx +362 -0
- package/components/ui/fab/index.tsx +215 -0
- package/components/ui/flat-list/index.tsx +21 -0
- package/components/ui/form-control/index.tsx +352 -0
- package/components/ui/gluestack-ui-provider/config.ts +72 -0
- package/components/ui/gluestack-ui-provider/index.tsx +47 -0
- package/components/ui/gluestack-ui-provider/index.web.tsx +96 -0
- package/components/ui/gluestack-ui-provider/script.ts +19 -0
- package/components/ui/gluestack-ui-provider/tokens.d.ts +17 -0
- package/components/ui/gluestack-ui-provider/tokens.js +188 -0
- package/components/ui/gluestack-ui-provider/useGluestackColors.ts +82 -0
- package/components/ui/grid/index.tsx +283 -0
- package/components/ui/grid/index.web.tsx +66 -0
- package/components/ui/grid/styles.tsx +15 -0
- package/components/ui/heading/index.tsx +220 -0
- package/components/ui/heading/index.web.tsx +202 -0
- package/components/ui/heading/styles.tsx +43 -0
- package/components/ui/hstack/index.tsx +27 -0
- package/components/ui/hstack/index.web.tsx +26 -0
- package/components/ui/hstack/styles.tsx +25 -0
- package/components/ui/icon/index.tsx +1588 -0
- package/components/ui/icon/index.web.tsx +1573 -0
- package/components/ui/image/index.tsx +48 -0
- package/components/ui/image-background/index.tsx +25 -0
- package/components/ui/image-viewer/index.tsx +743 -0
- package/components/ui/image-viewer/index.web.tsx +302 -0
- package/components/ui/index.ts +58 -0
- package/components/ui/input/index.tsx +125 -0
- package/components/ui/input-accessory-view/index.tsx +2 -0
- package/components/ui/keyboard-avoiding-view/index.tsx +2 -0
- package/components/ui/link/index.tsx +102 -0
- package/components/ui/liquid-glass/index.tsx +74 -0
- package/components/ui/menu/index.tsx +186 -0
- package/components/ui/modal/index.tsx +237 -0
- package/components/ui/popover/index.tsx +272 -0
- package/components/ui/portal/index.tsx +17 -0
- package/components/ui/pressable/index.tsx +39 -0
- package/components/ui/progress/index.tsx +83 -0
- package/components/ui/radio/index.tsx +217 -0
- package/components/ui/refresh-control/index.tsx +2 -0
- package/components/ui/safe-area-view/index.tsx +2 -0
- package/components/ui/scroll-view/index.tsx +2 -0
- package/components/ui/section-list/index.tsx +2 -0
- package/components/ui/select/index.tsx +277 -0
- package/components/ui/select/select-actionsheet.tsx +562 -0
- package/components/ui/skeleton/index.tsx +105 -0
- package/components/ui/skeleton/index.web.tsx +103 -0
- package/components/ui/skeleton/styles.tsx +35 -0
- package/components/ui/slider/index.tsx +181 -0
- package/components/ui/spinner/index.tsx +40 -0
- package/components/ui/status-bar/index.tsx +2 -0
- package/components/ui/switch/index.tsx +41 -0
- package/components/ui/table/index.tsx +210 -0
- package/components/ui/table/index.web.tsx +157 -0
- package/components/ui/table/styles.tsx +44 -0
- package/components/ui/tabs/TabsAnimatedIndicator.tsx +160 -0
- package/components/ui/tabs/animation-config.ts +3 -0
- package/components/ui/tabs/creator.tsx +206 -0
- package/components/ui/tabs/index.tsx +484 -0
- package/components/ui/text/index.tsx +48 -0
- package/components/ui/text/index.web.tsx +45 -0
- package/components/ui/text/styles.tsx +47 -0
- package/components/ui/textarea/index.tsx +94 -0
- package/components/ui/toast/index.tsx +252 -0
- package/components/ui/tooltip/index.tsx +131 -0
- package/components/ui/view/index.tsx +2 -0
- package/components/ui/virtualized-list/index.tsx +2 -0
- package/components/ui/vstack/index.tsx +28 -0
- package/components/ui/vstack/index.web.tsx +27 -0
- package/components/ui/vstack/styles.tsx +25 -0
- package/design/canonical.index.txt +53 -0
- package/design/documentation.xml +519 -0
- package/design/manifest.xml +90 -0
- package/design/schema.xsd +639 -0
- package/design/themes.xml +204 -0
- package/design/tokens.xml +510 -0
- package/design/tools/design.js +165 -0
- package/design/tools/npm.js +65 -0
- package/design/tools/requirements.txt +35 -0
- package/design/tools/sources/.checker/__init__.py +81 -0
- package/design/tools/sources/.checker/checks.py +198 -0
- package/design/tools/sources/.checker/cli.py +154 -0
- package/design/tools/sources/.checker/io.py +242 -0
- package/design/tools/sources/.checker/model.py +144 -0
- package/design/tools/sources/.checker/registry.py +115 -0
- package/design/tools/sources/.checker/report.py +21 -0
- package/design/tools/sources/.docgen/__init__.py +45 -0
- package/design/tools/sources/.docgen/cli.py +101 -0
- package/design/tools/sources/.docgen/model.py +147 -0
- package/design/tools/sources/.docgen/reference.py +97 -0
- package/design/tools/sources/.docgen/site.py +145 -0
- package/design/tools/sources/.docgen/xsddoc.py +329 -0
- package/design/tools/sources/.generate/__init__.py +35 -0
- package/design/tools/sources/.generate/cli.py +76 -0
- package/design/tools/sources/.generate/common.py +33 -0
- package/design/tools/sources/.generate/config.py +119 -0
- package/design/tools/sources/.generate/model.py +51 -0
- package/design/tools/sources/.generate/tokens.py +141 -0
- package/design/tools/sources/.linter/__init__.py +9 -0
- package/design/tools/sources/.linter/cli.py +44 -0
- package/design/tools/sources/.linter/discovery.py +30 -0
- package/design/tools/sources/.linter/errors.py +45 -0
- package/design/tools/sources/.linter/linter.py +68 -0
- package/design/tools/sources/.xmleditor/__init__.py +74 -0
- package/design/tools/sources/.xmleditor/blocks.py +185 -0
- package/design/tools/sources/.xmleditor/cli.py +141 -0
- package/design/tools/sources/.xmleditor/editor.py +906 -0
- package/design/tools/sources/.xmleditor/model.py +708 -0
- package/design/tools/sources/.xmleditor/widgets.py +1832 -0
- package/design/tools/sources/.xmleditor/xsdmodel.py +753 -0
- package/design/tools/sources/checker.py +55 -0
- package/design/tools/sources/docgen.py +66 -0
- package/design/tools/sources/generate.py +48 -0
- package/design/tools/sources/linter.py +54 -0
- package/design/tools/sources/ruff.toml +12 -0
- package/design/tools/sources/xmleditor.py +62 -0
- package/design/tools/unix/_venv_python.sh +16 -0
- package/design/tools/unix/check.sh +13 -0
- package/design/tools/unix/doc.sh +14 -0
- package/design/tools/unix/gen.sh +14 -0
- package/design/tools/unix/lint.sh +10 -0
- package/design/tools/unix/run.sh +20 -0
- package/design/tools/unix/verify.sh +12 -0
- package/design/tools/unix/xmledit.sh +12 -0
- package/design/tools/windows/check.cmd +12 -0
- package/design/tools/windows/doc.cmd +12 -0
- package/design/tools/windows/gen.cmd +11 -0
- package/design/tools/windows/lint.cmd +9 -0
- package/design/tools/windows/run.cmd +26 -0
- package/design/tools/windows/verify.cmd +10 -0
- package/design/tools/windows/xmledit.cmd +10 -0
- package/dist/chunk-LV4UIEQN.js +9730 -0
- package/dist/chunk-LV4UIEQN.js.map +1 -0
- package/dist/chunk-WNVU3BM2.mjs +9401 -0
- package/dist/chunk-WNVU3BM2.mjs.map +1 -0
- package/dist/index.d.mts +40 -10
- package/dist/index.d.ts +40 -10
- package/dist/index.js +726 -414
- package/dist/index.mjs +1 -5
- package/dist/ui/index.d.mts +6931 -3070
- package/dist/ui/index.d.ts +6931 -3070
- package/dist/ui/index.js +779 -352
- package/dist/ui/index.mjs +1 -2
- package/package.json +66 -149
- package/dist/chunk-2XORADW6.js +0 -24552
- package/dist/chunk-2XORADW6.js.map +0 -1
- package/dist/chunk-52BHHF5M.js +0 -46
- package/dist/chunk-52BHHF5M.js.map +0 -1
- package/dist/chunk-5647JY7Z.mjs +0 -100
- package/dist/chunk-5647JY7Z.mjs.map +0 -1
- package/dist/chunk-5N5HC4ZA.mjs +0 -3
- package/dist/chunk-5N5HC4ZA.mjs.map +0 -1
- package/dist/chunk-7QFZMGL6.js +0 -8583
- package/dist/chunk-7QFZMGL6.js.map +0 -1
- package/dist/chunk-ASZEP37D.js +0 -423
- package/dist/chunk-ASZEP37D.js.map +0 -1
- package/dist/chunk-BH5SU2JQ.mjs +0 -8282
- package/dist/chunk-BH5SU2JQ.mjs.map +0 -1
- package/dist/chunk-BO65GO53.mjs +0 -422
- package/dist/chunk-BO65GO53.mjs.map +0 -1
- package/dist/chunk-BSVXX52E.mjs +0 -413
- package/dist/chunk-BSVXX52E.mjs.map +0 -1
- package/dist/chunk-DNV5UBNF.mjs +0 -3
- package/dist/chunk-DNV5UBNF.mjs.map +0 -1
- package/dist/chunk-EDTAMUO2.js +0 -8310
- package/dist/chunk-EDTAMUO2.js.map +0 -1
- package/dist/chunk-IJTI6EX4.js +0 -4
- package/dist/chunk-IJTI6EX4.js.map +0 -1
- package/dist/chunk-M3YLASM2.js +0 -428
- package/dist/chunk-M3YLASM2.js.map +0 -1
- package/dist/chunk-OXKOGLXE.js +0 -4
- package/dist/chunk-OXKOGLXE.js.map +0 -1
- package/dist/chunk-RQXQK3ZO.mjs +0 -8486
- package/dist/chunk-RQXQK3ZO.mjs.map +0 -1
- package/dist/chunk-SR25V4EA.mjs +0 -40
- package/dist/chunk-SR25V4EA.mjs.map +0 -1
- package/dist/chunk-UB34WFEQ.js +0 -106
- package/dist/chunk-UB34WFEQ.js.map +0 -1
- package/dist/chunk-ZBRWXKDF.mjs +0 -24431
- package/dist/chunk-ZBRWXKDF.mjs.map +0 -1
- package/dist/cli/ds.d.mts +0 -1
- package/dist/cli/ds.d.ts +0 -1
- package/dist/cli/ds.js +0 -602
- package/dist/cli/ds.js.map +0 -1
- package/dist/cli/ds.mjs +0 -579
- package/dist/cli/ds.mjs.map +0 -1
- package/dist/cli/flipova.d.mts +0 -1
- package/dist/cli/flipova.d.ts +0 -1
- package/dist/cli/flipova.js +0 -161
- package/dist/cli/flipova.js.map +0 -1
- package/dist/cli/flipova.mjs +0 -154
- package/dist/cli/flipova.mjs.map +0 -1
- package/dist/config/index.d.mts +0 -123
- package/dist/config/index.d.ts +0 -123
- package/dist/config/index.js +0 -28
- package/dist/config/index.js.map +0 -1
- package/dist/config/index.mjs +0 -3
- package/dist/config/index.mjs.map +0 -1
- package/dist/createTheme-DQeX3s0I.d.mts +0 -78
- package/dist/createTheme-Y4jfz4-u.d.ts +0 -78
- package/dist/index-CuaJA3gM.d.mts +0 -78
- package/dist/index-CuaJA3gM.d.ts +0 -78
- package/dist/registry/index.d.mts +0 -10160
- package/dist/registry/index.d.ts +0 -10160
- package/dist/registry/index.js +0 -392
- package/dist/registry/index.js.map +0 -1
- package/dist/registry/index.mjs +0 -3
- package/dist/registry/index.mjs.map +0 -1
- package/dist/theme/index.d.mts +0 -35
- package/dist/theme/index.d.ts +0 -35
- package/dist/theme/index.js +0 -28
- package/dist/theme/index.js.map +0 -1
- package/dist/theme/index.mjs +0 -3
- package/dist/theme/index.mjs.map +0 -1
- package/dist/tokens/index.d.mts +0 -423
- package/dist/tokens/index.d.ts +0 -423
- package/dist/tokens/index.js +0 -44
- package/dist/tokens/index.js.map +0 -1
- package/dist/tokens/index.mjs +0 -3
- package/dist/tokens/index.mjs.map +0 -1
- package/dist/types/index.d.mts +0 -202
- package/dist/types/index.d.ts +0 -202
- package/dist/types/index.js +0 -4
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -3
- package/dist/types/index.mjs.map +0 -1
- package/dist/web/index.d.mts +0 -316
- package/dist/web/index.d.ts +0 -316
- package/dist/web/index.js +0 -1500
- package/dist/web/index.js.map +0 -1
- package/dist/web/index.mjs +0 -1396
- package/dist/web/index.mjs.map +0 -1
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { useCallback, useMemo } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
View,
|
|
6
|
+
Pressable,
|
|
7
|
+
TextInput,
|
|
8
|
+
Text,
|
|
9
|
+
Platform,
|
|
10
|
+
Modal,
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
import DateTimePickerNative from '@react-native-community/datetimepicker';
|
|
13
|
+
import { tva } from '@gluestack-ui/utils/nativewind-utils';
|
|
14
|
+
import {
|
|
15
|
+
withStyleContext,
|
|
16
|
+
useStyleContext,
|
|
17
|
+
} from '@gluestack-ui/utils/nativewind-utils';
|
|
18
|
+
import type { VariantProps } from '@gluestack-ui/utils/nativewind-utils';
|
|
19
|
+
import {
|
|
20
|
+
createDateTimePicker,
|
|
21
|
+
DateTimePickerProvider,
|
|
22
|
+
useDateTimePicker,
|
|
23
|
+
} from './creator';
|
|
24
|
+
import { cssInterop } from 'nativewind';
|
|
25
|
+
import { PrimitiveIcon, UIIcon } from '@gluestack-ui/core/icon/creator';
|
|
26
|
+
import {
|
|
27
|
+
dateTimePickerStyle,
|
|
28
|
+
dateTimePickerTriggerStyle,
|
|
29
|
+
dateTimePickerInputStyle,
|
|
30
|
+
dateTimePickerIconStyle,
|
|
31
|
+
} from './styles';
|
|
32
|
+
|
|
33
|
+
const SCOPE = 'DATE_TIME_PICKER';
|
|
34
|
+
|
|
35
|
+
export type DateTimePickerMode = 'date' | 'time' | 'datetime';
|
|
36
|
+
|
|
37
|
+
export interface DateTimePickerProps {
|
|
38
|
+
value?: Date;
|
|
39
|
+
onChange?: (date: Date | undefined) => void;
|
|
40
|
+
mode?: DateTimePickerMode;
|
|
41
|
+
minimumDate?: Date;
|
|
42
|
+
maximumDate?: Date;
|
|
43
|
+
locale?: string;
|
|
44
|
+
timeZoneOffsetInMinutes?: number;
|
|
45
|
+
is24Hour?: boolean;
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
placeholder?: string;
|
|
48
|
+
format?: string;
|
|
49
|
+
display?: 'modal' | 'inline'; // iOS only: 'modal' shows picker in modal with backdrop, 'inline' shows picker directly
|
|
50
|
+
children?: React.ReactNode;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const DateTimePickerTriggerWrapper = React.forwardRef<
|
|
54
|
+
React.ComponentRef<typeof Pressable>,
|
|
55
|
+
React.ComponentProps<typeof Pressable>
|
|
56
|
+
>(function DateTimePickerTriggerWrapper({ ...props }, ref) {
|
|
57
|
+
return <Pressable {...props} ref={ref} />;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const UIDateTimePicker = createDateTimePicker({
|
|
61
|
+
Root: withStyleContext(View, SCOPE),
|
|
62
|
+
Trigger: withStyleContext(DateTimePickerTriggerWrapper, SCOPE),
|
|
63
|
+
Input: TextInput,
|
|
64
|
+
Icon: UIIcon,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
cssInterop(UIDateTimePicker, { className: 'style' });
|
|
68
|
+
cssInterop(UIDateTimePicker.Input, {
|
|
69
|
+
className: { target: 'style', nativeStyleToProp: { textAlign: true } },
|
|
70
|
+
});
|
|
71
|
+
cssInterop(DateTimePickerTriggerWrapper, { className: 'style' });
|
|
72
|
+
|
|
73
|
+
cssInterop(PrimitiveIcon, {
|
|
74
|
+
className: {
|
|
75
|
+
target: 'style',
|
|
76
|
+
nativeStyleToProp: {
|
|
77
|
+
height: true,
|
|
78
|
+
width: true,
|
|
79
|
+
fill: true,
|
|
80
|
+
color: 'classNameColor',
|
|
81
|
+
stroke: true,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
type IDateTimePickerProps = VariantProps<typeof dateTimePickerStyle> &
|
|
87
|
+
DateTimePickerProps & { className?: string };
|
|
88
|
+
|
|
89
|
+
const DateTimePicker = React.forwardRef<
|
|
90
|
+
React.ComponentRef<typeof UIDateTimePicker>,
|
|
91
|
+
IDateTimePickerProps
|
|
92
|
+
>(function DateTimePicker(
|
|
93
|
+
{
|
|
94
|
+
className,
|
|
95
|
+
value,
|
|
96
|
+
onChange,
|
|
97
|
+
mode = 'datetime',
|
|
98
|
+
minimumDate,
|
|
99
|
+
maximumDate,
|
|
100
|
+
locale,
|
|
101
|
+
timeZoneOffsetInMinutes,
|
|
102
|
+
is24Hour,
|
|
103
|
+
disabled,
|
|
104
|
+
placeholder,
|
|
105
|
+
format,
|
|
106
|
+
display = 'modal', // Default to modal for iOS
|
|
107
|
+
children,
|
|
108
|
+
...props
|
|
109
|
+
},
|
|
110
|
+
ref
|
|
111
|
+
) {
|
|
112
|
+
const handleNativeChange = useCallback(
|
|
113
|
+
(event: any, selectedDate?: Date) => {
|
|
114
|
+
// The native picker handles its own close
|
|
115
|
+
if (selectedDate) {
|
|
116
|
+
onChange?.(selectedDate);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
[onChange]
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
// On iOS, use custom trigger + spinner in modal or inline
|
|
123
|
+
if (Platform.OS === 'ios') {
|
|
124
|
+
return (
|
|
125
|
+
<DateTimePickerProvider
|
|
126
|
+
value={value}
|
|
127
|
+
onChange={onChange}
|
|
128
|
+
mode={mode}
|
|
129
|
+
minimumDate={minimumDate}
|
|
130
|
+
maximumDate={maximumDate}
|
|
131
|
+
locale={locale}
|
|
132
|
+
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
|
|
133
|
+
is24Hour={is24Hour}
|
|
134
|
+
disabled={disabled}
|
|
135
|
+
placeholder={placeholder}
|
|
136
|
+
format={format}
|
|
137
|
+
>
|
|
138
|
+
<UIDateTimePicker
|
|
139
|
+
className={dateTimePickerStyle({ class: className })}
|
|
140
|
+
ref={ref}
|
|
141
|
+
{...props}
|
|
142
|
+
>
|
|
143
|
+
{children}
|
|
144
|
+
</UIDateTimePicker>
|
|
145
|
+
{/* iOS spinner picker shown in modal or inline based on display prop */}
|
|
146
|
+
<IOSDateTimePicker
|
|
147
|
+
value={value}
|
|
148
|
+
mode={mode}
|
|
149
|
+
minimumDate={minimumDate}
|
|
150
|
+
maximumDate={maximumDate}
|
|
151
|
+
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
|
|
152
|
+
is24Hour={is24Hour}
|
|
153
|
+
display={display}
|
|
154
|
+
onChange={handleNativeChange}
|
|
155
|
+
/>
|
|
156
|
+
</DateTimePickerProvider>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<DateTimePickerProvider
|
|
162
|
+
value={value}
|
|
163
|
+
onChange={onChange}
|
|
164
|
+
mode={mode}
|
|
165
|
+
minimumDate={minimumDate}
|
|
166
|
+
maximumDate={maximumDate}
|
|
167
|
+
locale={locale}
|
|
168
|
+
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
|
|
169
|
+
is24Hour={is24Hour}
|
|
170
|
+
disabled={disabled}
|
|
171
|
+
placeholder={placeholder}
|
|
172
|
+
format={format}
|
|
173
|
+
>
|
|
174
|
+
<UIDateTimePicker
|
|
175
|
+
className={dateTimePickerStyle({ class: className })}
|
|
176
|
+
ref={ref}
|
|
177
|
+
{...props}
|
|
178
|
+
>
|
|
179
|
+
{children}
|
|
180
|
+
</UIDateTimePicker>
|
|
181
|
+
{/* Native picker is rendered directly on Android */}
|
|
182
|
+
<DateTimePickerNativeWrapper
|
|
183
|
+
value={value}
|
|
184
|
+
mode={mode}
|
|
185
|
+
minimumDate={minimumDate}
|
|
186
|
+
maximumDate={maximumDate}
|
|
187
|
+
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
|
|
188
|
+
is24Hour={is24Hour}
|
|
189
|
+
onChange={handleNativeChange}
|
|
190
|
+
/>
|
|
191
|
+
</DateTimePickerProvider>
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Separate component to handle the native picker display (Android only)
|
|
196
|
+
function DateTimePickerNativeWrapper({
|
|
197
|
+
value,
|
|
198
|
+
mode,
|
|
199
|
+
minimumDate,
|
|
200
|
+
maximumDate,
|
|
201
|
+
timeZoneOffsetInMinutes,
|
|
202
|
+
is24Hour,
|
|
203
|
+
onChange,
|
|
204
|
+
}: {
|
|
205
|
+
value?: Date;
|
|
206
|
+
mode: DateTimePickerMode;
|
|
207
|
+
minimumDate?: Date;
|
|
208
|
+
maximumDate?: Date;
|
|
209
|
+
timeZoneOffsetInMinutes?: number;
|
|
210
|
+
is24Hour?: boolean;
|
|
211
|
+
onChange: (event: any, date?: Date) => void;
|
|
212
|
+
}) {
|
|
213
|
+
const { isOpen, setIsOpen } = useDateTimePicker();
|
|
214
|
+
|
|
215
|
+
const handleChange = useCallback(
|
|
216
|
+
(event: any, selectedDate?: Date) => {
|
|
217
|
+
setIsOpen(false);
|
|
218
|
+
onChange(event, selectedDate);
|
|
219
|
+
},
|
|
220
|
+
[onChange, setIsOpen]
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
// Android doesn't support 'datetime' mode - use two-step picker
|
|
224
|
+
if (mode === 'datetime') {
|
|
225
|
+
return (
|
|
226
|
+
<AndroidDateTimePicker
|
|
227
|
+
value={value}
|
|
228
|
+
minimumDate={minimumDate}
|
|
229
|
+
maximumDate={maximumDate}
|
|
230
|
+
is24Hour={is24Hour}
|
|
231
|
+
isOpen={isOpen}
|
|
232
|
+
onChange={onChange}
|
|
233
|
+
setIsOpen={setIsOpen}
|
|
234
|
+
/>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Android: Use display="default" which opens system dialogs for date/time
|
|
239
|
+
if (!isOpen) return null;
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<DateTimePickerNative
|
|
243
|
+
key={`picker-${mode}`}
|
|
244
|
+
value={value || new Date()}
|
|
245
|
+
mode={mode}
|
|
246
|
+
display="default"
|
|
247
|
+
minimumDate={minimumDate}
|
|
248
|
+
maximumDate={maximumDate}
|
|
249
|
+
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
|
|
250
|
+
is24Hour={is24Hour}
|
|
251
|
+
onChange={handleChange}
|
|
252
|
+
/>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Android-specific datetime picker (uses two separate pickers)
|
|
257
|
+
function AndroidDateTimePicker({
|
|
258
|
+
value,
|
|
259
|
+
minimumDate,
|
|
260
|
+
maximumDate,
|
|
261
|
+
is24Hour,
|
|
262
|
+
isOpen,
|
|
263
|
+
onChange,
|
|
264
|
+
setIsOpen,
|
|
265
|
+
}: {
|
|
266
|
+
value?: Date;
|
|
267
|
+
minimumDate?: Date;
|
|
268
|
+
maximumDate?: Date;
|
|
269
|
+
is24Hour?: boolean;
|
|
270
|
+
isOpen: boolean;
|
|
271
|
+
onChange: (event: any, date?: Date) => void;
|
|
272
|
+
setIsOpen: (open: boolean) => void;
|
|
273
|
+
}) {
|
|
274
|
+
const [step, setStep] = React.useState<'date' | 'time' | null>(null);
|
|
275
|
+
const [tempDate, setTempDate] = React.useState<Date | undefined>(value);
|
|
276
|
+
|
|
277
|
+
React.useEffect(() => {
|
|
278
|
+
if (isOpen) {
|
|
279
|
+
setStep('date');
|
|
280
|
+
setTempDate(value || new Date());
|
|
281
|
+
} else {
|
|
282
|
+
setStep(null);
|
|
283
|
+
}
|
|
284
|
+
}, [isOpen, value]);
|
|
285
|
+
|
|
286
|
+
const handleDateChange = React.useCallback(
|
|
287
|
+
(event: any, selectedDate?: Date) => {
|
|
288
|
+
if (selectedDate) {
|
|
289
|
+
setTempDate(selectedDate);
|
|
290
|
+
setStep('time');
|
|
291
|
+
} else {
|
|
292
|
+
setIsOpen(false);
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
[setIsOpen]
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const handleTimeChange = React.useCallback(
|
|
299
|
+
(event: any, selectedTime?: Date) => {
|
|
300
|
+
setIsOpen(false);
|
|
301
|
+
setStep(null);
|
|
302
|
+
if (selectedTime && tempDate) {
|
|
303
|
+
// Combine date and time
|
|
304
|
+
const combinedDate = new Date(tempDate);
|
|
305
|
+
combinedDate.setHours(selectedTime.getHours());
|
|
306
|
+
combinedDate.setMinutes(selectedTime.getMinutes());
|
|
307
|
+
onChange(event, combinedDate);
|
|
308
|
+
} else if (selectedTime) {
|
|
309
|
+
onChange(event, selectedTime);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
[tempDate, onChange, setIsOpen]
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
if (!isOpen || !step) return null;
|
|
316
|
+
|
|
317
|
+
if (step === 'date') {
|
|
318
|
+
return (
|
|
319
|
+
<DateTimePickerNative
|
|
320
|
+
key="android-date"
|
|
321
|
+
value={tempDate || new Date()}
|
|
322
|
+
mode="date"
|
|
323
|
+
display="default"
|
|
324
|
+
minimumDate={minimumDate}
|
|
325
|
+
maximumDate={maximumDate}
|
|
326
|
+
onChange={handleDateChange}
|
|
327
|
+
/>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return (
|
|
332
|
+
<DateTimePickerNative
|
|
333
|
+
key="android-time"
|
|
334
|
+
value={tempDate || new Date()}
|
|
335
|
+
mode="time"
|
|
336
|
+
display="default"
|
|
337
|
+
is24Hour={is24Hour}
|
|
338
|
+
onChange={handleTimeChange}
|
|
339
|
+
/>
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// iOS-specific picker with spinner in modal or inline
|
|
344
|
+
function IOSDateTimePicker({
|
|
345
|
+
value,
|
|
346
|
+
mode,
|
|
347
|
+
minimumDate,
|
|
348
|
+
maximumDate,
|
|
349
|
+
timeZoneOffsetInMinutes,
|
|
350
|
+
is24Hour,
|
|
351
|
+
display,
|
|
352
|
+
onChange,
|
|
353
|
+
}: {
|
|
354
|
+
value?: Date;
|
|
355
|
+
mode: DateTimePickerMode;
|
|
356
|
+
minimumDate?: Date;
|
|
357
|
+
maximumDate?: Date;
|
|
358
|
+
timeZoneOffsetInMinutes?: number;
|
|
359
|
+
is24Hour?: boolean;
|
|
360
|
+
display: 'modal' | 'inline';
|
|
361
|
+
onChange: (event: any, date?: Date) => void;
|
|
362
|
+
}) {
|
|
363
|
+
const { isOpen, setIsOpen } = useDateTimePicker();
|
|
364
|
+
const [tempValue, setTempValue] = React.useState(value || new Date());
|
|
365
|
+
|
|
366
|
+
// Update temp value when picker opens
|
|
367
|
+
React.useEffect(() => {
|
|
368
|
+
if (isOpen) {
|
|
369
|
+
setTempValue(value || new Date());
|
|
370
|
+
}
|
|
371
|
+
}, [isOpen, value]);
|
|
372
|
+
|
|
373
|
+
const handleChange = React.useCallback(
|
|
374
|
+
(event: any, selectedDate?: Date) => {
|
|
375
|
+
if (selectedDate) {
|
|
376
|
+
setTempValue(selectedDate);
|
|
377
|
+
// Update the parent immediately for live feedback
|
|
378
|
+
onChange(event, selectedDate);
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
[onChange]
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
const handleDone = React.useCallback(() => {
|
|
385
|
+
setIsOpen(false);
|
|
386
|
+
}, [setIsOpen]);
|
|
387
|
+
|
|
388
|
+
const handleCancel = React.useCallback(() => {
|
|
389
|
+
setIsOpen(false);
|
|
390
|
+
// Revert to original value
|
|
391
|
+
if (value) {
|
|
392
|
+
onChange({ type: 'dismissed' }, value);
|
|
393
|
+
}
|
|
394
|
+
}, [setIsOpen, onChange, value]);
|
|
395
|
+
|
|
396
|
+
if (!isOpen) return null;
|
|
397
|
+
|
|
398
|
+
// Inline mode: show picker directly without modal
|
|
399
|
+
if (display === 'inline') {
|
|
400
|
+
return (
|
|
401
|
+
<View className="w-full">
|
|
402
|
+
<DateTimePickerNative
|
|
403
|
+
value={tempValue}
|
|
404
|
+
mode={mode}
|
|
405
|
+
display="spinner"
|
|
406
|
+
minimumDate={minimumDate}
|
|
407
|
+
maximumDate={maximumDate}
|
|
408
|
+
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
|
|
409
|
+
is24Hour={is24Hour}
|
|
410
|
+
onChange={handleChange}
|
|
411
|
+
/>
|
|
412
|
+
</View>
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Modal mode: show picker in modal with backdrop
|
|
417
|
+
return (
|
|
418
|
+
<Modal
|
|
419
|
+
visible={isOpen}
|
|
420
|
+
transparent={true}
|
|
421
|
+
animationType="slide"
|
|
422
|
+
onRequestClose={handleCancel}
|
|
423
|
+
>
|
|
424
|
+
<View className="flex-1 justify-end">
|
|
425
|
+
{/* Backdrop - separate touchable area */}
|
|
426
|
+
<Pressable
|
|
427
|
+
className="absolute inset-0 bg-black/50"
|
|
428
|
+
onPress={handleCancel}
|
|
429
|
+
/>
|
|
430
|
+
{/* Picker container */}
|
|
431
|
+
<View className="bg-background rounded-t-lg p-4 relative">
|
|
432
|
+
<View className="flex-row justify-between items-center mb-4 border-b border-border pb-2">
|
|
433
|
+
<Pressable onPress={handleCancel}>
|
|
434
|
+
<Text className="text-primary font-semibold text-base">
|
|
435
|
+
Cancel
|
|
436
|
+
</Text>
|
|
437
|
+
</Pressable>
|
|
438
|
+
<Text className="text-foreground font-semibold text-base">
|
|
439
|
+
{mode === 'date'
|
|
440
|
+
? 'Select Date'
|
|
441
|
+
: mode === 'time'
|
|
442
|
+
? 'Select Time'
|
|
443
|
+
: 'Select Date & Time'}
|
|
444
|
+
</Text>
|
|
445
|
+
<Pressable onPress={handleDone}>
|
|
446
|
+
<Text className="text-primary font-semibold text-base">Done</Text>
|
|
447
|
+
</Pressable>
|
|
448
|
+
</View>
|
|
449
|
+
<DateTimePickerNative
|
|
450
|
+
value={tempValue}
|
|
451
|
+
mode={mode}
|
|
452
|
+
display="spinner"
|
|
453
|
+
minimumDate={minimumDate}
|
|
454
|
+
maximumDate={maximumDate}
|
|
455
|
+
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
|
|
456
|
+
is24Hour={is24Hour}
|
|
457
|
+
onChange={handleChange}
|
|
458
|
+
/>
|
|
459
|
+
</View>
|
|
460
|
+
</View>
|
|
461
|
+
</Modal>
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
type IDateTimePickerTriggerProps = VariantProps<
|
|
466
|
+
typeof dateTimePickerTriggerStyle
|
|
467
|
+
> &
|
|
468
|
+
React.ComponentProps<typeof UIDateTimePicker.Trigger> & {
|
|
469
|
+
className?: string;
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
const DateTimePickerTrigger = React.forwardRef<
|
|
473
|
+
React.ComponentRef<typeof UIDateTimePicker.Trigger>,
|
|
474
|
+
IDateTimePickerTriggerProps
|
|
475
|
+
>(function DateTimePickerTrigger(
|
|
476
|
+
{ className, size = 'md', variant = 'outline', ...props },
|
|
477
|
+
ref
|
|
478
|
+
) {
|
|
479
|
+
const { disabled, setIsOpen } = useDateTimePicker();
|
|
480
|
+
|
|
481
|
+
return (
|
|
482
|
+
<UIDateTimePicker.Trigger
|
|
483
|
+
className={dateTimePickerTriggerStyle({
|
|
484
|
+
class: className,
|
|
485
|
+
size,
|
|
486
|
+
variant,
|
|
487
|
+
})}
|
|
488
|
+
ref={ref}
|
|
489
|
+
context={{ size, variant }}
|
|
490
|
+
disabled={disabled}
|
|
491
|
+
onPress={() => !disabled && setIsOpen(true)}
|
|
492
|
+
{...props}
|
|
493
|
+
/>
|
|
494
|
+
);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
type IDateTimePickerInputProps = VariantProps<typeof dateTimePickerInputStyle> &
|
|
498
|
+
React.ComponentProps<typeof UIDateTimePicker.Input> & { className?: string };
|
|
499
|
+
|
|
500
|
+
const DateTimePickerInput = React.forwardRef<
|
|
501
|
+
React.ComponentRef<typeof UIDateTimePicker.Input>,
|
|
502
|
+
IDateTimePickerInputProps
|
|
503
|
+
>(function DateTimePickerInput({ className, ...props }, ref) {
|
|
504
|
+
const { size: parentSize, variant: parentVariant } = useStyleContext(SCOPE);
|
|
505
|
+
const { value, placeholder, format } = useDateTimePicker();
|
|
506
|
+
|
|
507
|
+
const displayValue = useMemo(() => {
|
|
508
|
+
if (!value) return '';
|
|
509
|
+
if (format) {
|
|
510
|
+
return formatDate(value, format);
|
|
511
|
+
}
|
|
512
|
+
return value.toLocaleString();
|
|
513
|
+
}, [value, format]);
|
|
514
|
+
|
|
515
|
+
return (
|
|
516
|
+
<UIDateTimePicker.Input
|
|
517
|
+
className={dateTimePickerInputStyle({
|
|
518
|
+
class: className,
|
|
519
|
+
parentVariants: {
|
|
520
|
+
size: parentSize,
|
|
521
|
+
variant: parentVariant,
|
|
522
|
+
},
|
|
523
|
+
})}
|
|
524
|
+
ref={ref}
|
|
525
|
+
value={displayValue}
|
|
526
|
+
placeholder={placeholder}
|
|
527
|
+
editable={false}
|
|
528
|
+
style={{ pointerEvents: 'none' }}
|
|
529
|
+
{...props}
|
|
530
|
+
/>
|
|
531
|
+
);
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
type IDateTimePickerIconProps = VariantProps<typeof dateTimePickerIconStyle> &
|
|
535
|
+
React.ComponentProps<typeof UIDateTimePicker.Icon> & { className?: string };
|
|
536
|
+
|
|
537
|
+
const DateTimePickerIcon = React.forwardRef<
|
|
538
|
+
React.ComponentRef<typeof UIDateTimePicker.Icon>,
|
|
539
|
+
IDateTimePickerIconProps
|
|
540
|
+
>(function DateTimePickerIcon({ className, size, ...props }, ref) {
|
|
541
|
+
const { size: parentSize } = useStyleContext(SCOPE);
|
|
542
|
+
|
|
543
|
+
if (typeof size === 'number') {
|
|
544
|
+
return (
|
|
545
|
+
<UIDateTimePicker.Icon
|
|
546
|
+
ref={ref}
|
|
547
|
+
{...props}
|
|
548
|
+
className={dateTimePickerIconStyle({ class: className })}
|
|
549
|
+
size={size}
|
|
550
|
+
/>
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
return (
|
|
555
|
+
<UIDateTimePicker.Icon
|
|
556
|
+
className={dateTimePickerIconStyle({
|
|
557
|
+
class: className,
|
|
558
|
+
size,
|
|
559
|
+
parentVariants: {
|
|
560
|
+
size: parentSize,
|
|
561
|
+
},
|
|
562
|
+
})}
|
|
563
|
+
ref={ref}
|
|
564
|
+
{...props}
|
|
565
|
+
/>
|
|
566
|
+
);
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
function formatDate(date: Date, format: string): string {
|
|
570
|
+
const pad = (n: number) => n.toString().padStart(2, '0');
|
|
571
|
+
return format
|
|
572
|
+
.replace('YYYY', date.getFullYear().toString())
|
|
573
|
+
.replace('MM', pad(date.getMonth() + 1))
|
|
574
|
+
.replace('DD', pad(date.getDate()))
|
|
575
|
+
.replace('HH', pad(date.getHours()))
|
|
576
|
+
.replace('mm', pad(date.getMinutes()))
|
|
577
|
+
.replace('ss', pad(date.getSeconds()));
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
export {
|
|
581
|
+
DateTimePicker,
|
|
582
|
+
DateTimePickerTrigger,
|
|
583
|
+
DateTimePickerInput,
|
|
584
|
+
DateTimePickerIcon,
|
|
585
|
+
};
|