@momo-kits/date-picker 0.92.8-beta.1 → 0.92.8-beta.11
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/WheelPicker.tsx +1 -7
- package/index.tsx +44 -24
- package/package.json +1 -1
- package/styles.ts +3 -2
- package/types.ts +6 -1
package/WheelPicker.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import React, {
|
|
|
6
6
|
useEffect,
|
|
7
7
|
useRef,
|
|
8
8
|
} from 'react';
|
|
9
|
-
import {Animated,
|
|
9
|
+
import {Animated, View} from 'react-native';
|
|
10
10
|
import {FlatList} from 'react-native-gesture-handler';
|
|
11
11
|
import styles from './styles';
|
|
12
12
|
import {ApplicationContext, scaleSize} from '@momo-kits/foundation';
|
|
@@ -46,12 +46,6 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
46
46
|
};
|
|
47
47
|
}, [data.length]);
|
|
48
48
|
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
if (Platform.OS === 'android') {
|
|
51
|
-
onMomentumScrollEnd();
|
|
52
|
-
}
|
|
53
|
-
}, []);
|
|
54
|
-
|
|
55
49
|
const findClosestIndex = (array: string[], value: string) => {
|
|
56
50
|
let closest = array.reduce((a, b) => {
|
|
57
51
|
let aDiff = Math.abs(Number(a) - Number(value));
|
package/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, {FC,
|
|
2
|
-
import {Dimensions, LayoutChangeEvent, View} from 'react-native';
|
|
3
|
-
import {Spacing} from '@momo-kits/foundation';
|
|
1
|
+
import React, { FC, useEffect, useState } from 'react';
|
|
2
|
+
import { Dimensions, LayoutChangeEvent, Platform, View } from 'react-native';
|
|
3
|
+
import { Spacing, Text } from '@momo-kits/foundation';
|
|
4
4
|
import WheelPicker from './WheelPicker';
|
|
5
5
|
import {
|
|
6
6
|
getDaysInMonth,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
getYears,
|
|
11
11
|
timeMode,
|
|
12
12
|
} from './utils';
|
|
13
|
-
import {DateObject, DateTimePickerProps, PickerDataObject} from './types';
|
|
13
|
+
import { DateObject, DateTimePickerProps, PickerDataObject } from './types';
|
|
14
14
|
import styles from './styles';
|
|
15
15
|
|
|
16
16
|
const date = new Date();
|
|
@@ -28,6 +28,7 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
28
28
|
selectedValue = date,
|
|
29
29
|
minDate = minDateDefault,
|
|
30
30
|
maxDate = maxDateDefault,
|
|
31
|
+
arrayLabelTime = []
|
|
31
32
|
}) => {
|
|
32
33
|
const [data, setData] = useState<DateObject[]>([]);
|
|
33
34
|
let [currentDate, setCurrentDate] = useState<PickerDataObject>({
|
|
@@ -41,14 +42,20 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
41
42
|
|
|
42
43
|
useEffect(() => {
|
|
43
44
|
setupData();
|
|
44
|
-
return () => {};
|
|
45
|
+
return () => { };
|
|
46
|
+
}, [selectedValue, currentDate]);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (Platform.OS === 'android') {
|
|
50
|
+
onChange?.(selectedValue);
|
|
51
|
+
}
|
|
45
52
|
}, []);
|
|
46
53
|
|
|
47
|
-
const setupData =
|
|
54
|
+
const setupData = () => {
|
|
48
55
|
const formatParts = format.split(/[^A-Za-z]+/);
|
|
49
56
|
const isOnlyHour = formatParts.length === 1 && formatParts[0] === 'HH';
|
|
50
57
|
|
|
51
|
-
const componentData: {[key: string]: DateObject} = {
|
|
58
|
+
const componentData: { [key: string]: DateObject } = {
|
|
52
59
|
DD: {
|
|
53
60
|
name: 'day',
|
|
54
61
|
data: getDaysInMonth(
|
|
@@ -66,8 +73,8 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
66
73
|
name: 'year',
|
|
67
74
|
data: getYears(minDate, maxDate),
|
|
68
75
|
},
|
|
69
|
-
HH: {name: 'hour', data: getHours(isOnlyHour ? 12 : 24)},
|
|
70
|
-
mm: {name: 'min', data: getMinutes(minuteInterval)},
|
|
76
|
+
HH: { name: 'hour', data: getHours(isOnlyHour ? 12 : 24) },
|
|
77
|
+
mm: { name: 'min', data: getMinutes(minuteInterval) },
|
|
71
78
|
};
|
|
72
79
|
|
|
73
80
|
const initialData = formatParts.map(part => {
|
|
@@ -81,11 +88,11 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
81
88
|
});
|
|
82
89
|
|
|
83
90
|
if (isOnlyHour) {
|
|
84
|
-
initialData.push({name: 'timeMode', data: timeMode});
|
|
91
|
+
initialData.push({ name: 'timeMode', data: timeMode });
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
setData(initialData);
|
|
88
|
-
}
|
|
95
|
+
};
|
|
89
96
|
|
|
90
97
|
const numOfColumns = data.length;
|
|
91
98
|
|
|
@@ -113,6 +120,7 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
113
120
|
if (changedDate <= maxDate && changedDate >= minDate) {
|
|
114
121
|
onChange?.(changedDate);
|
|
115
122
|
}
|
|
123
|
+
|
|
116
124
|
setCurrentDate(newDate);
|
|
117
125
|
};
|
|
118
126
|
|
|
@@ -128,22 +136,34 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
128
136
|
<View onLayout={onLayout} style={styles.datePicker}>
|
|
129
137
|
{data.map((dataItem, index) => {
|
|
130
138
|
return (
|
|
131
|
-
<
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
<View>
|
|
140
|
+
{arrayLabelTime[index] && (
|
|
141
|
+
<View style={{ alignItems: 'center', marginBottom: Spacing.M }}>
|
|
142
|
+
<Text typography="header_default_bold">
|
|
143
|
+
{arrayLabelTime[index]}
|
|
144
|
+
</Text>
|
|
145
|
+
</View>
|
|
146
|
+
)}
|
|
147
|
+
<WheelPicker
|
|
148
|
+
key={`${dataItem.name}_${index}`}
|
|
149
|
+
selectedData={String(currentDate[dataItem.name])}
|
|
150
|
+
onChange={onPickerChange}
|
|
151
|
+
data={[...paddingArray, ...dataItem.data, ...paddingArray]}
|
|
152
|
+
name={dataItem.name}
|
|
153
|
+
style={{
|
|
154
|
+
width:
|
|
155
|
+
(containerWidth -
|
|
156
|
+
Spacing.M * 2 -
|
|
157
|
+
(numOfColumns - 1) * Spacing.M) /
|
|
158
|
+
numOfColumns,
|
|
159
|
+
}}
|
|
160
|
+
/>
|
|
161
|
+
</View>
|
|
162
|
+
)
|
|
144
163
|
})}
|
|
145
164
|
</View>
|
|
146
165
|
);
|
|
147
166
|
};
|
|
148
167
|
|
|
168
|
+
export type {DateTimePickerProps};
|
|
149
169
|
export {DateTimePicker};
|
package/package.json
CHANGED
package/styles.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {StyleSheet} from 'react-native';
|
|
2
|
-
import {Colors, Radius} from '@momo-kits/foundation';
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors, Radius, Spacing } from '@momo-kits/foundation';
|
|
3
3
|
|
|
4
4
|
export default StyleSheet.create({
|
|
5
5
|
wheelItem: {
|
|
@@ -30,5 +30,6 @@ export default StyleSheet.create({
|
|
|
30
30
|
overflow: 'hidden',
|
|
31
31
|
flexDirection: 'row',
|
|
32
32
|
justifyContent: 'space-evenly',
|
|
33
|
+
marginBottom: Spacing.XL,
|
|
33
34
|
},
|
|
34
35
|
});
|
package/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ViewStyle} from 'react-native';
|
|
1
|
+
import { ViewStyle } from 'react-native';
|
|
2
2
|
|
|
3
3
|
export type DateTimePickerProps = {
|
|
4
4
|
/**
|
|
@@ -30,6 +30,11 @@ export type DateTimePickerProps = {
|
|
|
30
30
|
* Optional. The maximum date that can be selected.
|
|
31
31
|
*/
|
|
32
32
|
maxDate?: Date;
|
|
33
|
+
/**
|
|
34
|
+
* Optional. Label for Time
|
|
35
|
+
*/
|
|
36
|
+
arrayLabelTime?: string[];
|
|
37
|
+
|
|
33
38
|
};
|
|
34
39
|
|
|
35
40
|
/**
|