@cdx-ui/components 0.0.1-beta.140 → 0.0.1-beta.142
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/lib/commonjs/components/BottomSheet/index.js +8 -2
- package/lib/commonjs/components/BottomSheet/index.js.map +1 -1
- package/lib/commonjs/components/Calendar/CalendarMonthHeader.js +96 -0
- package/lib/commonjs/components/Calendar/CalendarMonthHeader.js.map +1 -0
- package/lib/commonjs/components/Calendar/CalendarYearPickerGrid.js +74 -0
- package/lib/commonjs/components/Calendar/CalendarYearPickerGrid.js.map +1 -0
- package/lib/commonjs/components/Calendar/flashCalendarAdapter.js +298 -0
- package/lib/commonjs/components/Calendar/flashCalendarAdapter.js.map +1 -0
- package/lib/commonjs/components/Calendar/index.js +149 -0
- package/lib/commonjs/components/Calendar/index.js.map +1 -0
- package/lib/commonjs/components/Calendar/styles.js +70 -0
- package/lib/commonjs/components/Calendar/styles.js.map +1 -0
- package/lib/commonjs/components/DateField/index.js +147 -0
- package/lib/commonjs/components/DateField/index.js.map +1 -0
- package/lib/commonjs/components/DateField/styles.js +34 -0
- package/lib/commonjs/components/DateField/styles.js.map +1 -0
- package/lib/commonjs/components/DatePicker/index.js +163 -0
- package/lib/commonjs/components/DatePicker/index.js.map +1 -0
- package/lib/commonjs/components/DateRangePicker/index.js +177 -0
- package/lib/commonjs/components/DateRangePicker/index.js.map +1 -0
- package/lib/commonjs/components/DateTimeField/index.js +96 -0
- package/lib/commonjs/components/DateTimeField/index.js.map +1 -0
- package/lib/commonjs/components/DateTimeList/index.js +180 -0
- package/lib/commonjs/components/DateTimeList/index.js.map +1 -0
- package/lib/commonjs/components/DateTimeList/styles.js +55 -0
- package/lib/commonjs/components/DateTimeList/styles.js.map +1 -0
- package/lib/commonjs/components/DateTimePicker/index.js +187 -0
- package/lib/commonjs/components/DateTimePicker/index.js.map +1 -0
- package/lib/commonjs/components/MonthCalendar/index.js +229 -0
- package/lib/commonjs/components/MonthCalendar/index.js.map +1 -0
- package/lib/commonjs/components/MonthPicker/index.js +163 -0
- package/lib/commonjs/components/MonthPicker/index.js.map +1 -0
- package/lib/commonjs/components/RangeCalendar/index.js +165 -0
- package/lib/commonjs/components/RangeCalendar/index.js.map +1 -0
- package/lib/commonjs/components/index.js +120 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/components/picker/PickerTrigger.js +49 -0
- package/lib/commonjs/components/picker/PickerTrigger.js.map +1 -0
- package/lib/commonjs/components/picker/styles.js +15 -0
- package/lib/commonjs/components/picker/styles.js.map +1 -0
- package/lib/commonjs/components/picker/surfaces.js +141 -0
- package/lib/commonjs/components/picker/surfaces.js.map +1 -0
- package/lib/module/components/BottomSheet/index.js +8 -2
- package/lib/module/components/BottomSheet/index.js.map +1 -1
- package/lib/module/components/Calendar/CalendarMonthHeader.js +92 -0
- package/lib/module/components/Calendar/CalendarMonthHeader.js.map +1 -0
- package/lib/module/components/Calendar/CalendarYearPickerGrid.js +70 -0
- package/lib/module/components/Calendar/CalendarYearPickerGrid.js.map +1 -0
- package/lib/module/components/Calendar/flashCalendarAdapter.js +290 -0
- package/lib/module/components/Calendar/flashCalendarAdapter.js.map +1 -0
- package/lib/module/components/Calendar/index.js +145 -0
- package/lib/module/components/Calendar/index.js.map +1 -0
- package/lib/module/components/Calendar/styles.js +66 -0
- package/lib/module/components/Calendar/styles.js.map +1 -0
- package/lib/module/components/DateField/index.js +143 -0
- package/lib/module/components/DateField/index.js.map +1 -0
- package/lib/module/components/DateField/styles.js +30 -0
- package/lib/module/components/DateField/styles.js.map +1 -0
- package/lib/module/components/DatePicker/index.js +159 -0
- package/lib/module/components/DatePicker/index.js.map +1 -0
- package/lib/module/components/DateRangePicker/index.js +173 -0
- package/lib/module/components/DateRangePicker/index.js.map +1 -0
- package/lib/module/components/DateTimeField/index.js +92 -0
- package/lib/module/components/DateTimeField/index.js.map +1 -0
- package/lib/module/components/DateTimeList/index.js +176 -0
- package/lib/module/components/DateTimeList/index.js.map +1 -0
- package/lib/module/components/DateTimeList/styles.js +52 -0
- package/lib/module/components/DateTimeList/styles.js.map +1 -0
- package/lib/module/components/DateTimePicker/index.js +183 -0
- package/lib/module/components/DateTimePicker/index.js.map +1 -0
- package/lib/module/components/MonthCalendar/index.js +225 -0
- package/lib/module/components/MonthCalendar/index.js.map +1 -0
- package/lib/module/components/MonthPicker/index.js +159 -0
- package/lib/module/components/MonthPicker/index.js.map +1 -0
- package/lib/module/components/RangeCalendar/index.js +161 -0
- package/lib/module/components/RangeCalendar/index.js.map +1 -0
- package/lib/module/components/index.js +10 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/picker/PickerTrigger.js +45 -0
- package/lib/module/components/picker/PickerTrigger.js.map +1 -0
- package/lib/module/components/picker/styles.js +12 -0
- package/lib/module/components/picker/styles.js.map +1 -0
- package/lib/module/components/picker/surfaces.js +135 -0
- package/lib/module/components/picker/surfaces.js.map +1 -0
- package/lib/typescript/components/BottomSheet/index.d.ts +2 -2
- package/lib/typescript/components/BottomSheet/index.d.ts.map +1 -1
- package/lib/typescript/components/Calendar/CalendarMonthHeader.d.ts +14 -0
- package/lib/typescript/components/Calendar/CalendarMonthHeader.d.ts.map +1 -0
- package/lib/typescript/components/Calendar/CalendarYearPickerGrid.d.ts +12 -0
- package/lib/typescript/components/Calendar/CalendarYearPickerGrid.d.ts.map +1 -0
- package/lib/typescript/components/Calendar/flashCalendarAdapter.d.ts +18 -0
- package/lib/typescript/components/Calendar/flashCalendarAdapter.d.ts.map +1 -0
- package/lib/typescript/components/Calendar/index.d.ts +19 -0
- package/lib/typescript/components/Calendar/index.d.ts.map +1 -0
- package/lib/typescript/components/Calendar/styles.d.ts +23 -0
- package/lib/typescript/components/Calendar/styles.d.ts.map +1 -0
- package/lib/typescript/components/DateField/index.d.ts +43 -0
- package/lib/typescript/components/DateField/index.d.ts.map +1 -0
- package/lib/typescript/components/DateField/styles.d.ts +15 -0
- package/lib/typescript/components/DateField/styles.d.ts.map +1 -0
- package/lib/typescript/components/DatePicker/index.d.ts +40 -0
- package/lib/typescript/components/DatePicker/index.d.ts.map +1 -0
- package/lib/typescript/components/DateRangePicker/index.d.ts +45 -0
- package/lib/typescript/components/DateRangePicker/index.d.ts.map +1 -0
- package/lib/typescript/components/DateTimeField/index.d.ts +29 -0
- package/lib/typescript/components/DateTimeField/index.d.ts.map +1 -0
- package/lib/typescript/components/DateTimeList/index.d.ts +19 -0
- package/lib/typescript/components/DateTimeList/index.d.ts.map +1 -0
- package/lib/typescript/components/DateTimeList/styles.d.ts +17 -0
- package/lib/typescript/components/DateTimeList/styles.d.ts.map +1 -0
- package/lib/typescript/components/DateTimePicker/index.d.ts +40 -0
- package/lib/typescript/components/DateTimePicker/index.d.ts.map +1 -0
- package/lib/typescript/components/MonthCalendar/index.d.ts +29 -0
- package/lib/typescript/components/MonthCalendar/index.d.ts.map +1 -0
- package/lib/typescript/components/MonthPicker/index.d.ts +40 -0
- package/lib/typescript/components/MonthPicker/index.d.ts.map +1 -0
- package/lib/typescript/components/RangeCalendar/index.d.ts +19 -0
- package/lib/typescript/components/RangeCalendar/index.d.ts.map +1 -0
- package/lib/typescript/components/index.d.ts +10 -0
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/components/picker/PickerTrigger.d.ts +25 -0
- package/lib/typescript/components/picker/PickerTrigger.d.ts.map +1 -0
- package/lib/typescript/components/picker/styles.d.ts +4 -0
- package/lib/typescript/components/picker/styles.d.ts.map +1 -0
- package/lib/typescript/components/picker/surfaces.d.ts +28 -0
- package/lib/typescript/components/picker/surfaces.d.ts.map +1 -0
- package/package.json +6 -4
- package/src/components/BottomSheet/index.tsx +7 -1
- package/src/components/Calendar/CalendarMonthHeader.tsx +124 -0
- package/src/components/Calendar/CalendarYearPickerGrid.tsx +101 -0
- package/src/components/Calendar/flashCalendarAdapter.ts +362 -0
- package/src/components/Calendar/index.tsx +151 -0
- package/src/components/Calendar/styles.ts +80 -0
- package/src/components/DateField/index.tsx +196 -0
- package/src/components/DateField/styles.ts +51 -0
- package/src/components/DatePicker/index.tsx +187 -0
- package/src/components/DateRangePicker/index.tsx +202 -0
- package/src/components/DateTimeField/index.tsx +128 -0
- package/src/components/DateTimeList/index.tsx +187 -0
- package/src/components/DateTimeList/styles.ts +59 -0
- package/src/components/DateTimePicker/index.tsx +233 -0
- package/src/components/MonthCalendar/index.tsx +252 -0
- package/src/components/MonthPicker/index.tsx +188 -0
- package/src/components/RangeCalendar/index.tsx +162 -0
- package/src/components/index.ts +10 -0
- package/src/components/picker/PickerTrigger.tsx +65 -0
- package/src/components/picker/styles.ts +17 -0
- package/src/components/picker/surfaces.tsx +174 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState, type ReactNode, type RefObject } from 'react';
|
|
2
|
+
import { ScrollView, View } from 'react-native';
|
|
3
|
+
import { FadeIn, FadeOut } from 'react-native-reanimated';
|
|
4
|
+
import {
|
|
5
|
+
OverlayContainer,
|
|
6
|
+
useAnchorPosition,
|
|
7
|
+
useDismissOverlay,
|
|
8
|
+
useEscapeKey,
|
|
9
|
+
useOverlayPosition,
|
|
10
|
+
} from '@cdx-ui/primitives';
|
|
11
|
+
import { cn } from '@cdx-ui/utils';
|
|
12
|
+
import { Dialog } from '../Dialog';
|
|
13
|
+
import { BottomSheet, useBottomSheet, type BottomSheetModalProps } from '../BottomSheet';
|
|
14
|
+
import { PICKER_POPOVER_Z_INDEX, pickerPopoverContentVariants } from './styles';
|
|
15
|
+
|
|
16
|
+
// Shared surface wiring for picker compound components.
|
|
17
|
+
|
|
18
|
+
export function PickerDialogSurface({
|
|
19
|
+
open,
|
|
20
|
+
setOpen,
|
|
21
|
+
registerSurface,
|
|
22
|
+
children,
|
|
23
|
+
}: {
|
|
24
|
+
open: boolean;
|
|
25
|
+
setOpen: (open: boolean) => void;
|
|
26
|
+
registerSurface: (type: 'dialog') => void;
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
}) {
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
registerSurface('dialog');
|
|
31
|
+
}, [registerSurface]);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Dialog isOpen={open} onOpenChange={setOpen}>
|
|
35
|
+
{children}
|
|
36
|
+
</Dialog>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type PickerBottomSheetSurfaceProps = {
|
|
41
|
+
open: boolean;
|
|
42
|
+
setOpen: (open: boolean) => void;
|
|
43
|
+
registerSurface: (type: 'bottomSheet') => void;
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
} & Pick<BottomSheetModalProps, 'snapPoints' | 'enableDynamicSizing'>;
|
|
46
|
+
|
|
47
|
+
export function PickerBottomSheetSurface({
|
|
48
|
+
open,
|
|
49
|
+
setOpen,
|
|
50
|
+
registerSurface,
|
|
51
|
+
children,
|
|
52
|
+
snapPoints = ['70%', '90%'],
|
|
53
|
+
enableDynamicSizing = false,
|
|
54
|
+
}: PickerBottomSheetSurfaceProps) {
|
|
55
|
+
const { ref, dismiss } = useBottomSheet();
|
|
56
|
+
const isPresentedRef = useRef(false);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
registerSurface('bottomSheet');
|
|
60
|
+
}, [registerSurface]);
|
|
61
|
+
|
|
62
|
+
const handleDismiss = useCallback(() => {
|
|
63
|
+
isPresentedRef.current = false;
|
|
64
|
+
setOpen(false);
|
|
65
|
+
}, [setOpen]);
|
|
66
|
+
|
|
67
|
+
const tryPresent = useCallback(() => {
|
|
68
|
+
if (!open || isPresentedRef.current) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
ref.current?.present();
|
|
72
|
+
isPresentedRef.current = true;
|
|
73
|
+
}, [open, ref]);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!open) {
|
|
77
|
+
if (isPresentedRef.current) {
|
|
78
|
+
dismiss();
|
|
79
|
+
isPresentedRef.current = false;
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const frame = requestAnimationFrame(() => {
|
|
85
|
+
tryPresent();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return () => cancelAnimationFrame(frame);
|
|
89
|
+
}, [dismiss, open, tryPresent]);
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<BottomSheet.Modal
|
|
93
|
+
ref={ref}
|
|
94
|
+
onDismiss={handleDismiss}
|
|
95
|
+
snapPoints={snapPoints}
|
|
96
|
+
enableDynamicSizing={enableDynamicSizing}
|
|
97
|
+
>
|
|
98
|
+
<BottomSheet.View onLayout={tryPresent}>{children}</BottomSheet.View>
|
|
99
|
+
</BottomSheet.Modal>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface PickerPopoverSurfaceProps {
|
|
104
|
+
open: boolean;
|
|
105
|
+
setOpen: (open: boolean) => void;
|
|
106
|
+
registerSurface: (type: 'popover') => void;
|
|
107
|
+
anchorRef: RefObject<View | null>;
|
|
108
|
+
triggerRef?: RefObject<View | null>;
|
|
109
|
+
children: ReactNode;
|
|
110
|
+
className?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function PickerPopoverSurface({
|
|
114
|
+
open,
|
|
115
|
+
setOpen,
|
|
116
|
+
registerSurface,
|
|
117
|
+
anchorRef,
|
|
118
|
+
triggerRef,
|
|
119
|
+
children,
|
|
120
|
+
className,
|
|
121
|
+
}: PickerPopoverSurfaceProps) {
|
|
122
|
+
const contentRef = useRef<View>(null);
|
|
123
|
+
const [dismissEnabled, setDismissEnabled] = useState(false);
|
|
124
|
+
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
registerSurface('popover');
|
|
127
|
+
}, [registerSurface]);
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (!open) {
|
|
131
|
+
setDismissEnabled(false);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const frame = requestAnimationFrame(() => {
|
|
136
|
+
setDismissEnabled(true);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return () => cancelAnimationFrame(frame);
|
|
140
|
+
}, [open]);
|
|
141
|
+
|
|
142
|
+
const dismiss = useCallback(() => setOpen(false), [setOpen]);
|
|
143
|
+
|
|
144
|
+
const anchorLayout = useAnchorPosition(anchorRef, open);
|
|
145
|
+
const position = useOverlayPosition(anchorLayout);
|
|
146
|
+
|
|
147
|
+
const excludeRefs = triggerRef ? [anchorRef, triggerRef] : [anchorRef];
|
|
148
|
+
useDismissOverlay(dismissEnabled, contentRef, excludeRefs, dismiss);
|
|
149
|
+
useEscapeKey(open, dismiss);
|
|
150
|
+
|
|
151
|
+
if (!open || !position) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<OverlayContainer
|
|
157
|
+
onDismiss={dismiss}
|
|
158
|
+
entering={FadeIn.duration(150)}
|
|
159
|
+
exiting={FadeOut.duration(100)}
|
|
160
|
+
style={[position.style, { zIndex: PICKER_POPOVER_Z_INDEX }]}
|
|
161
|
+
>
|
|
162
|
+
<View
|
|
163
|
+
ref={contentRef}
|
|
164
|
+
className={cn(pickerPopoverContentVariants(), className)}
|
|
165
|
+
style={{ maxHeight: position.maxHeight }}
|
|
166
|
+
accessibilityViewIsModal
|
|
167
|
+
>
|
|
168
|
+
<ScrollView scrollEventThrottle={16} showsVerticalScrollIndicator={false}>
|
|
169
|
+
{children}
|
|
170
|
+
</ScrollView>
|
|
171
|
+
</View>
|
|
172
|
+
</OverlayContainer>
|
|
173
|
+
);
|
|
174
|
+
}
|