daliry-mobile-date-picker 1.0.0 → 1.0.2
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/.editorconfig +10 -10
- package/.gitattributes +4 -4
- package/.yarnrc.yml +1 -1
- package/README.md +138 -26
- package/build.js +15 -15
- package/daliry-mobile-date-picker-1.0.2.tgz +0 -0
- package/dist/MobileDatePicker.d.ts +11 -7
- package/dist/MobileDatePicker.d.ts.map +1 -0
- package/dist/MobileDatePicker.js +105 -0
- package/dist/index.css +34 -15
- package/dist/index.d.ts +3 -3
- package/dist/index.js +155 -127
- package/dist/src/MobileDatePicker.d.ts +21 -0
- package/package.json +17 -7
- package/src/MobileDatePicker.tsx +144 -92
- package/src/assets/images/daliry-mobile-date-picker102.PNG +0 -0
- package/src/global.d.ts +1 -0
- package/src/mobileDatePicker.css +36 -15
- package/tsconfig.json +18 -18
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -813
- package/src/index.tsx +0 -12
package/dist/index.js
CHANGED
|
@@ -211,7 +211,7 @@ var require_moment = __commonJS({
|
|
|
211
211
|
}
|
|
212
212
|
return to2;
|
|
213
213
|
}
|
|
214
|
-
function
|
|
214
|
+
function Moment(config) {
|
|
215
215
|
copyConfig(this, config);
|
|
216
216
|
this._d = new Date(config._d != null ? config._d.getTime() : NaN);
|
|
217
217
|
if (!this.isValid()) {
|
|
@@ -224,7 +224,7 @@ var require_moment = __commonJS({
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
function isMoment(obj) {
|
|
227
|
-
return obj instanceof
|
|
227
|
+
return obj instanceof Moment || obj != null && obj._isAMomentObject != null;
|
|
228
228
|
}
|
|
229
229
|
function warn(msg) {
|
|
230
230
|
if (hooks.suppressDeprecationWarnings === false && typeof console !== "undefined" && console.warn) {
|
|
@@ -2129,7 +2129,7 @@ var require_moment = __commonJS({
|
|
|
2129
2129
|
configFromArray(config);
|
|
2130
2130
|
}
|
|
2131
2131
|
function createFromConfig(config) {
|
|
2132
|
-
var res = new
|
|
2132
|
+
var res = new Moment(checkOverflow(prepareConfig(config)));
|
|
2133
2133
|
if (res._nextDay) {
|
|
2134
2134
|
res.add(1, "d");
|
|
2135
2135
|
res._nextDay = void 0;
|
|
@@ -2146,7 +2146,7 @@ var require_moment = __commonJS({
|
|
|
2146
2146
|
config._i = input = config._locale.preparse(input);
|
|
2147
2147
|
}
|
|
2148
2148
|
if (isMoment(input)) {
|
|
2149
|
-
return new
|
|
2149
|
+
return new Moment(checkOverflow(input));
|
|
2150
2150
|
} else if (isDate(input)) {
|
|
2151
2151
|
config._d = input;
|
|
2152
2152
|
} else if (isArray(format2)) {
|
|
@@ -2291,13 +2291,13 @@ var require_moment = __commonJS({
|
|
|
2291
2291
|
return createDuration(NaN);
|
|
2292
2292
|
}
|
|
2293
2293
|
function Duration(duration) {
|
|
2294
|
-
var normalizedInput = normalizeObjectUnits(duration),
|
|
2294
|
+
var normalizedInput = normalizeObjectUnits(duration), years2 = normalizedInput.year || 0, quarters = normalizedInput.quarter || 0, months2 = normalizedInput.month || 0, weeks2 = normalizedInput.week || normalizedInput.isoWeek || 0, days2 = normalizedInput.day || 0, hours2 = normalizedInput.hour || 0, minutes2 = normalizedInput.minute || 0, seconds2 = normalizedInput.second || 0, milliseconds2 = normalizedInput.millisecond || 0;
|
|
2295
2295
|
this._isValid = isDurationValid(normalizedInput);
|
|
2296
2296
|
this._milliseconds = +milliseconds2 + seconds2 * 1e3 + // 1000
|
|
2297
2297
|
minutes2 * 6e4 + // 1000 * 60
|
|
2298
2298
|
hours2 * 1e3 * 60 * 60;
|
|
2299
|
-
this._days = +
|
|
2300
|
-
this._months = +months2 + quarters * 3 +
|
|
2299
|
+
this._days = +days2 + weeks2 * 7;
|
|
2300
|
+
this._months = +months2 + quarters * 3 + years2 * 12;
|
|
2301
2301
|
this._data = {};
|
|
2302
2302
|
this._locale = getLocale();
|
|
2303
2303
|
this._bubble();
|
|
@@ -2585,7 +2585,7 @@ var require_moment = __commonJS({
|
|
|
2585
2585
|
};
|
|
2586
2586
|
}
|
|
2587
2587
|
function addSubtract(mom, duration, isAdding, updateOffset) {
|
|
2588
|
-
var milliseconds2 = duration._milliseconds,
|
|
2588
|
+
var milliseconds2 = duration._milliseconds, days2 = absRound(duration._days), months2 = absRound(duration._months);
|
|
2589
2589
|
if (!mom.isValid()) {
|
|
2590
2590
|
return;
|
|
2591
2591
|
}
|
|
@@ -2593,14 +2593,14 @@ var require_moment = __commonJS({
|
|
|
2593
2593
|
if (months2) {
|
|
2594
2594
|
setMonth(mom, get(mom, "Month") + months2 * isAdding);
|
|
2595
2595
|
}
|
|
2596
|
-
if (
|
|
2597
|
-
set$1(mom, "Date", get(mom, "Date") +
|
|
2596
|
+
if (days2) {
|
|
2597
|
+
set$1(mom, "Date", get(mom, "Date") + days2 * isAdding);
|
|
2598
2598
|
}
|
|
2599
2599
|
if (milliseconds2) {
|
|
2600
2600
|
mom._d.setTime(mom._d.valueOf() + milliseconds2 * isAdding);
|
|
2601
2601
|
}
|
|
2602
2602
|
if (updateOffset) {
|
|
2603
|
-
hooks.updateOffset(mom,
|
|
2603
|
+
hooks.updateOffset(mom, days2 || months2);
|
|
2604
2604
|
}
|
|
2605
2605
|
}
|
|
2606
2606
|
var add = createAdder(1, "add"), subtract = createAdder(-1, "subtract");
|
|
@@ -2690,7 +2690,7 @@ var require_moment = __commonJS({
|
|
|
2690
2690
|
);
|
|
2691
2691
|
}
|
|
2692
2692
|
function clone() {
|
|
2693
|
-
return new
|
|
2693
|
+
return new Moment(this);
|
|
2694
2694
|
}
|
|
2695
2695
|
function isAfter(input, units) {
|
|
2696
2696
|
var localInput = isMoment(input) ? input : createLocal(input);
|
|
@@ -3463,7 +3463,7 @@ var require_moment = __commonJS({
|
|
|
3463
3463
|
function getZoneName() {
|
|
3464
3464
|
return this._isUTC ? "Coordinated Universal Time" : "";
|
|
3465
3465
|
}
|
|
3466
|
-
var proto =
|
|
3466
|
+
var proto = Moment.prototype;
|
|
3467
3467
|
proto.add = add;
|
|
3468
3468
|
proto.calendar = calendar$1;
|
|
3469
3469
|
proto.clone = clone;
|
|
@@ -3735,10 +3735,10 @@ var require_moment = __commonJS({
|
|
|
3735
3735
|
}
|
|
3736
3736
|
}
|
|
3737
3737
|
function bubble() {
|
|
3738
|
-
var milliseconds2 = this._milliseconds,
|
|
3739
|
-
if (!(milliseconds2 >= 0 &&
|
|
3740
|
-
milliseconds2 += absCeil(monthsToDays(months2) +
|
|
3741
|
-
|
|
3738
|
+
var milliseconds2 = this._milliseconds, days2 = this._days, months2 = this._months, data = this._data, seconds2, minutes2, hours2, years2, monthsFromDays;
|
|
3739
|
+
if (!(milliseconds2 >= 0 && days2 >= 0 && months2 >= 0 || milliseconds2 <= 0 && days2 <= 0 && months2 <= 0)) {
|
|
3740
|
+
milliseconds2 += absCeil(monthsToDays(months2) + days2) * 864e5;
|
|
3741
|
+
days2 = 0;
|
|
3742
3742
|
months2 = 0;
|
|
3743
3743
|
}
|
|
3744
3744
|
data.milliseconds = milliseconds2 % 1e3;
|
|
@@ -3748,19 +3748,19 @@ var require_moment = __commonJS({
|
|
|
3748
3748
|
data.minutes = minutes2 % 60;
|
|
3749
3749
|
hours2 = absFloor(minutes2 / 60);
|
|
3750
3750
|
data.hours = hours2 % 24;
|
|
3751
|
-
|
|
3752
|
-
monthsFromDays = absFloor(daysToMonths(
|
|
3751
|
+
days2 += absFloor(hours2 / 24);
|
|
3752
|
+
monthsFromDays = absFloor(daysToMonths(days2));
|
|
3753
3753
|
months2 += monthsFromDays;
|
|
3754
|
-
|
|
3755
|
-
|
|
3754
|
+
days2 -= absCeil(monthsToDays(monthsFromDays));
|
|
3755
|
+
years2 = absFloor(months2 / 12);
|
|
3756
3756
|
months2 %= 12;
|
|
3757
|
-
data.days =
|
|
3757
|
+
data.days = days2;
|
|
3758
3758
|
data.months = months2;
|
|
3759
|
-
data.years =
|
|
3759
|
+
data.years = years2;
|
|
3760
3760
|
return this;
|
|
3761
3761
|
}
|
|
3762
|
-
function daysToMonths(
|
|
3763
|
-
return
|
|
3762
|
+
function daysToMonths(days2) {
|
|
3763
|
+
return days2 * 4800 / 146097;
|
|
3764
3764
|
}
|
|
3765
3765
|
function monthsToDays(months2) {
|
|
3766
3766
|
return months2 * 146097 / 4800;
|
|
@@ -3769,11 +3769,11 @@ var require_moment = __commonJS({
|
|
|
3769
3769
|
if (!this.isValid()) {
|
|
3770
3770
|
return NaN;
|
|
3771
3771
|
}
|
|
3772
|
-
var
|
|
3772
|
+
var days2, months2, milliseconds2 = this._milliseconds;
|
|
3773
3773
|
units = normalizeUnits(units);
|
|
3774
3774
|
if (units === "month" || units === "quarter" || units === "year") {
|
|
3775
|
-
|
|
3776
|
-
months2 = this._months + daysToMonths(
|
|
3775
|
+
days2 = this._days + milliseconds2 / 864e5;
|
|
3776
|
+
months2 = this._months + daysToMonths(days2);
|
|
3777
3777
|
switch (units) {
|
|
3778
3778
|
case "month":
|
|
3779
3779
|
return months2;
|
|
@@ -3783,21 +3783,21 @@ var require_moment = __commonJS({
|
|
|
3783
3783
|
return months2 / 12;
|
|
3784
3784
|
}
|
|
3785
3785
|
} else {
|
|
3786
|
-
|
|
3786
|
+
days2 = this._days + Math.round(monthsToDays(this._months));
|
|
3787
3787
|
switch (units) {
|
|
3788
3788
|
case "week":
|
|
3789
|
-
return
|
|
3789
|
+
return days2 / 7 + milliseconds2 / 6048e5;
|
|
3790
3790
|
case "day":
|
|
3791
|
-
return
|
|
3791
|
+
return days2 + milliseconds2 / 864e5;
|
|
3792
3792
|
case "hour":
|
|
3793
|
-
return
|
|
3793
|
+
return days2 * 24 + milliseconds2 / 36e5;
|
|
3794
3794
|
case "minute":
|
|
3795
|
-
return
|
|
3795
|
+
return days2 * 1440 + milliseconds2 / 6e4;
|
|
3796
3796
|
case "second":
|
|
3797
|
-
return
|
|
3797
|
+
return days2 * 86400 + milliseconds2 / 1e3;
|
|
3798
3798
|
// Math.floor prevents floating point math errors here
|
|
3799
3799
|
case "millisecond":
|
|
3800
|
-
return Math.floor(
|
|
3800
|
+
return Math.floor(days2 * 864e5) + milliseconds2;
|
|
3801
3801
|
default:
|
|
3802
3802
|
throw new Error("Unknown unit " + units);
|
|
3803
3803
|
}
|
|
@@ -3821,7 +3821,7 @@ var require_moment = __commonJS({
|
|
|
3821
3821
|
return this.isValid() ? this._data[name] : NaN;
|
|
3822
3822
|
};
|
|
3823
3823
|
}
|
|
3824
|
-
var milliseconds = makeGetter("milliseconds"), seconds = makeGetter("seconds"), minutes = makeGetter("minutes"), hours = makeGetter("hours"),
|
|
3824
|
+
var milliseconds = makeGetter("milliseconds"), seconds = makeGetter("seconds"), minutes = makeGetter("minutes"), hours = makeGetter("hours"), days = makeGetter("days"), months = makeGetter("months"), years = makeGetter("years");
|
|
3825
3825
|
function weeks() {
|
|
3826
3826
|
return absFloor(this.days() / 7);
|
|
3827
3827
|
}
|
|
@@ -3845,11 +3845,11 @@ var require_moment = __commonJS({
|
|
|
3845
3845
|
return locale2.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
|
|
3846
3846
|
}
|
|
3847
3847
|
function relativeTime$1(posNegDuration, withoutSuffix, thresholds2, locale2) {
|
|
3848
|
-
var duration = createDuration(posNegDuration).abs(), seconds2 = round(duration.as("s")), minutes2 = round(duration.as("m")), hours2 = round(duration.as("h")),
|
|
3848
|
+
var duration = createDuration(posNegDuration).abs(), seconds2 = round(duration.as("s")), minutes2 = round(duration.as("m")), hours2 = round(duration.as("h")), days2 = round(duration.as("d")), months2 = round(duration.as("M")), weeks2 = round(duration.as("w")), years2 = round(duration.as("y")), a = seconds2 <= thresholds2.ss && ["s", seconds2] || seconds2 < thresholds2.s && ["ss", seconds2] || minutes2 <= 1 && ["m"] || minutes2 < thresholds2.m && ["mm", minutes2] || hours2 <= 1 && ["h"] || hours2 < thresholds2.h && ["hh", hours2] || days2 <= 1 && ["d"] || days2 < thresholds2.d && ["dd", days2];
|
|
3849
3849
|
if (thresholds2.w != null) {
|
|
3850
3850
|
a = a || weeks2 <= 1 && ["w"] || weeks2 < thresholds2.w && ["ww", weeks2];
|
|
3851
3851
|
}
|
|
3852
|
-
a = a || months2 <= 1 && ["M"] || months2 < thresholds2.M && ["MM", months2] ||
|
|
3852
|
+
a = a || months2 <= 1 && ["M"] || months2 < thresholds2.M && ["MM", months2] || years2 <= 1 && ["y"] || ["yy", years2];
|
|
3853
3853
|
a[2] = withoutSuffix;
|
|
3854
3854
|
a[3] = +posNegDuration > 0;
|
|
3855
3855
|
a[4] = locale2;
|
|
@@ -3911,7 +3911,7 @@ var require_moment = __commonJS({
|
|
|
3911
3911
|
if (!this.isValid()) {
|
|
3912
3912
|
return this.localeData().invalidDate();
|
|
3913
3913
|
}
|
|
3914
|
-
var seconds2 = abs$1(this._milliseconds) / 1e3,
|
|
3914
|
+
var seconds2 = abs$1(this._milliseconds) / 1e3, days2 = abs$1(this._days), months2 = abs$1(this._months), minutes2, hours2, years2, s, total = this.asSeconds(), totalSign, ymSign, daysSign, hmsSign;
|
|
3915
3915
|
if (!total) {
|
|
3916
3916
|
return "P0D";
|
|
3917
3917
|
}
|
|
@@ -3919,14 +3919,14 @@ var require_moment = __commonJS({
|
|
|
3919
3919
|
hours2 = absFloor(minutes2 / 60);
|
|
3920
3920
|
seconds2 %= 60;
|
|
3921
3921
|
minutes2 %= 60;
|
|
3922
|
-
|
|
3922
|
+
years2 = absFloor(months2 / 12);
|
|
3923
3923
|
months2 %= 12;
|
|
3924
3924
|
s = seconds2 ? seconds2.toFixed(3).replace(/\.?0+$/, "") : "";
|
|
3925
3925
|
totalSign = total < 0 ? "-" : "";
|
|
3926
3926
|
ymSign = sign(this._months) !== sign(total) ? "-" : "";
|
|
3927
3927
|
daysSign = sign(this._days) !== sign(total) ? "-" : "";
|
|
3928
3928
|
hmsSign = sign(this._milliseconds) !== sign(total) ? "-" : "";
|
|
3929
|
-
return totalSign + "P" + (
|
|
3929
|
+
return totalSign + "P" + (years2 ? ymSign + years2 + "Y" : "") + (months2 ? ymSign + months2 + "M" : "") + (days2 ? daysSign + days2 + "D" : "") + (hours2 || minutes2 || seconds2 ? "T" : "") + (hours2 ? hmsSign + hours2 + "H" : "") + (minutes2 ? hmsSign + minutes2 + "M" : "") + (seconds2 ? hmsSign + s + "S" : "");
|
|
3930
3930
|
}
|
|
3931
3931
|
var proto$2 = Duration.prototype;
|
|
3932
3932
|
proto$2.isValid = isValid$1;
|
|
@@ -3951,10 +3951,10 @@ var require_moment = __commonJS({
|
|
|
3951
3951
|
proto$2.seconds = seconds;
|
|
3952
3952
|
proto$2.minutes = minutes;
|
|
3953
3953
|
proto$2.hours = hours;
|
|
3954
|
-
proto$2.days =
|
|
3954
|
+
proto$2.days = days;
|
|
3955
3955
|
proto$2.weeks = weeks;
|
|
3956
3956
|
proto$2.months = months;
|
|
3957
|
-
proto$2.years =
|
|
3957
|
+
proto$2.years = years;
|
|
3958
3958
|
proto$2.humanize = humanize;
|
|
3959
3959
|
proto$2.toISOString = toISOString$1;
|
|
3960
3960
|
proto$2.toString = toISOString$1;
|
|
@@ -5177,97 +5177,125 @@ var require_moment_jalaali = __commonJS({
|
|
|
5177
5177
|
|
|
5178
5178
|
// src/MobileDatePicker.tsx
|
|
5179
5179
|
var import_moment_jalaali = __toESM(require_moment_jalaali());
|
|
5180
|
-
import {
|
|
5180
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
5181
5181
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5182
|
-
var
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
"
|
|
5190
|
-
"
|
|
5191
|
-
"
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
];
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
const
|
|
5202
|
-
const [
|
|
5203
|
-
const
|
|
5204
|
-
const
|
|
5205
|
-
const
|
|
5206
|
-
const
|
|
5207
|
-
const
|
|
5208
|
-
|
|
5209
|
-
const
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5182
|
+
var JALALI_MONTHS = ["\u0641\u0631\u0648\u0631\u062F\u06CC\u0646", "\u0627\u0631\u062F\u06CC\u0628\u0647\u0634\u062A", "\u062E\u0631\u062F\u0627\u062F", "\u062A\u06CC\u0631", "\u0645\u0631\u062F\u0627\u062F", "\u0634\u0647\u0631\u06CC\u0648\u0631", "\u0645\u0647\u0631", "\u0622\u0628\u0627\u0646", "\u0622\u0630\u0631", "\u062F\u06CC", "\u0628\u0647\u0645\u0646", "\u0627\u0633\u0641\u0646\u062F"];
|
|
5183
|
+
var GREGORIAN_MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
5184
|
+
var ITEM_HEIGHT = 45;
|
|
5185
|
+
var DaliryMobileDatePicker = ({
|
|
5186
|
+
onDateChange,
|
|
5187
|
+
isBirthdate = false,
|
|
5188
|
+
isGregorian = false,
|
|
5189
|
+
backgroundColor = "#f5f5f5",
|
|
5190
|
+
textColor = "#bbb",
|
|
5191
|
+
selectedColor = "#333"
|
|
5192
|
+
}) => {
|
|
5193
|
+
const now = (0, import_moment_jalaali.default)();
|
|
5194
|
+
const initialYear = useMemo(() => {
|
|
5195
|
+
const currentYear = isGregorian ? now.year() : now.jYear();
|
|
5196
|
+
return isBirthdate ? currentYear - 18 : currentYear;
|
|
5197
|
+
}, [isGregorian, isBirthdate]);
|
|
5198
|
+
const initialMonth = isGregorian ? now.month() + 1 : now.jMonth() + 1;
|
|
5199
|
+
const initialDay = isGregorian ? now.date() : now.jDate();
|
|
5200
|
+
const [selectedYear, setSelectedYear] = useState(initialYear);
|
|
5201
|
+
const [selectedMonth, setSelectedMonth] = useState(initialMonth);
|
|
5202
|
+
const [selectedDay, setSelectedDay] = useState(initialDay);
|
|
5203
|
+
const yearRef = useRef(null);
|
|
5204
|
+
const monthRef = useRef(null);
|
|
5205
|
+
const dayRef = useRef(null);
|
|
5206
|
+
const months = isGregorian ? GREGORIAN_MONTHS : JALALI_MONTHS;
|
|
5207
|
+
const years = useMemo(() => {
|
|
5208
|
+
const start = isGregorian ? 1930 : 1300;
|
|
5209
|
+
const end = (isGregorian ? now.year() : now.jYear()) + 20;
|
|
5210
|
+
return Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
|
5211
|
+
}, [isGregorian, now]);
|
|
5212
|
+
const daysInMonth = useMemo(() => {
|
|
5213
|
+
if (isGregorian) {
|
|
5214
|
+
return (0, import_moment_jalaali.default)(`${selectedYear}-${selectedMonth}-01`, "YYYY-M-DD").daysInMonth();
|
|
5215
|
+
}
|
|
5216
|
+
return import_moment_jalaali.default.jDaysInMonth(selectedYear, selectedMonth - 1);
|
|
5217
|
+
}, [isGregorian, selectedYear, selectedMonth]);
|
|
5218
|
+
const days = useMemo(() => {
|
|
5219
|
+
return Array.from({ length: daysInMonth }, (_, i) => i + 1);
|
|
5220
|
+
}, [daysInMonth]);
|
|
5220
5221
|
useEffect(() => {
|
|
5221
|
-
if (
|
|
5222
|
-
|
|
5222
|
+
if (selectedDay > daysInMonth) {
|
|
5223
|
+
setSelectedDay(daysInMonth);
|
|
5224
|
+
}
|
|
5225
|
+
}, [selectedDay, daysInMonth]);
|
|
5226
|
+
const buildDateObject = (year, month, day) => {
|
|
5227
|
+
const m = isGregorian ? (0, import_moment_jalaali.default)(`${year}-${month}-${day}`, "YYYY-M-D") : (0, import_moment_jalaali.default)(`${year}-${month}-${day}`, "jYYYY-jM-jD");
|
|
5228
|
+
return {
|
|
5229
|
+
year,
|
|
5230
|
+
month,
|
|
5231
|
+
day,
|
|
5232
|
+
formatted: isGregorian ? m.format("YYYY/MM/DD") : m.format("jYYYY/jMM/jDD"),
|
|
5233
|
+
date: m.format("YYYY-MM-DD"),
|
|
5234
|
+
gDate: m.format("YYYY-MM-DD"),
|
|
5235
|
+
moment: m
|
|
5236
|
+
};
|
|
5237
|
+
};
|
|
5223
5238
|
useEffect(() => {
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5239
|
+
const timer = setTimeout(() => {
|
|
5240
|
+
onDateChange(buildDateObject(selectedYear, selectedMonth, selectedDay));
|
|
5241
|
+
}, 500);
|
|
5242
|
+
return () => clearTimeout(timer);
|
|
5243
|
+
}, [selectedYear, selectedMonth, selectedDay, isGregorian]);
|
|
5244
|
+
const scrollToIndex = (ref, index) => {
|
|
5245
|
+
if (ref.current) {
|
|
5246
|
+
ref.current.scrollTop = index * ITEM_HEIGHT;
|
|
5247
|
+
}
|
|
5231
5248
|
};
|
|
5232
|
-
|
|
5233
|
-
const
|
|
5234
|
-
|
|
5249
|
+
useEffect(() => {
|
|
5250
|
+
const monthIndex = Math.max(0, selectedMonth - 1);
|
|
5251
|
+
const dayIndex = Math.max(0, selectedDay - 1);
|
|
5252
|
+
const yearIndex = Math.max(0, years.indexOf(selectedYear));
|
|
5253
|
+
const timer = window.setTimeout(() => {
|
|
5254
|
+
scrollToIndex(dayRef, dayIndex);
|
|
5255
|
+
scrollToIndex(monthRef, monthIndex);
|
|
5256
|
+
scrollToIndex(yearRef, yearIndex);
|
|
5257
|
+
}, 0);
|
|
5258
|
+
return () => window.clearTimeout(timer);
|
|
5259
|
+
}, [years]);
|
|
5260
|
+
const handleScroll = (e, type) => {
|
|
5261
|
+
const index = Math.round(e.currentTarget.scrollTop / ITEM_HEIGHT);
|
|
5262
|
+
if (type === "day") {
|
|
5263
|
+
const nextDay = days[index];
|
|
5264
|
+
if (nextDay && nextDay !== selectedDay) setSelectedDay(nextDay);
|
|
5265
|
+
} else if (type === "month") {
|
|
5266
|
+
const nextMonth = index + 1;
|
|
5267
|
+
if (nextMonth >= 1 && nextMonth <= 12 && nextMonth !== selectedMonth) setSelectedMonth(nextMonth);
|
|
5268
|
+
} else {
|
|
5269
|
+
const nextYear = years[index];
|
|
5270
|
+
if (nextYear && nextYear !== selectedYear) setSelectedYear(nextYear);
|
|
5271
|
+
}
|
|
5235
5272
|
};
|
|
5236
|
-
const
|
|
5237
|
-
|
|
5238
|
-
|
|
5273
|
+
const renderList = (items, selectedValue, ref, type) => {
|
|
5274
|
+
return /* @__PURE__ */ jsxs("div", { className: "scroll-list", onScroll: (e) => handleScroll(e, type), ref, children: [
|
|
5275
|
+
/* @__PURE__ */ jsx("div", { style: { height: ITEM_HEIGHT } }),
|
|
5276
|
+
items.map((item, index) => {
|
|
5277
|
+
const isSelected = type === "month" ? index + 1 === selectedMonth : item === selectedValue;
|
|
5278
|
+
return /* @__PURE__ */ jsx(
|
|
5279
|
+
"div",
|
|
5280
|
+
{
|
|
5281
|
+
className: `scroll-item ${isSelected ? "selected" : ""}`,
|
|
5282
|
+
style: { color: isSelected ? selectedColor : textColor },
|
|
5283
|
+
children: item
|
|
5284
|
+
},
|
|
5285
|
+
`${type}-${item}`
|
|
5286
|
+
);
|
|
5287
|
+
}),
|
|
5288
|
+
/* @__PURE__ */ jsx("div", { style: { height: ITEM_HEIGHT } })
|
|
5289
|
+
] });
|
|
5239
5290
|
};
|
|
5240
|
-
return /* @__PURE__ */
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
children: day
|
|
5247
|
-
},
|
|
5248
|
-
i
|
|
5249
|
-
)) }),
|
|
5250
|
-
/* @__PURE__ */ jsx("div", { className: "scroll-list", onScroll: handleScrollMonths, ref: listRefMonths, children: jalaliMonths.map((month, i) => /* @__PURE__ */ jsx(
|
|
5251
|
-
"div",
|
|
5252
|
-
{
|
|
5253
|
-
className: `scroll-item ${i === selectedMonth ? "selected" : ""}`,
|
|
5254
|
-
children: month
|
|
5255
|
-
},
|
|
5256
|
-
i
|
|
5257
|
-
)) }),
|
|
5258
|
-
/* @__PURE__ */ jsx("div", { className: "scroll-list", onScroll: handleScroll, ref: listRef, children: years.map((year) => /* @__PURE__ */ jsx(
|
|
5259
|
-
"div",
|
|
5260
|
-
{
|
|
5261
|
-
className: `scroll-item ${year === selectedYear ? "selected" : ""}`,
|
|
5262
|
-
children: year
|
|
5263
|
-
},
|
|
5264
|
-
year
|
|
5265
|
-
)) })
|
|
5266
|
-
] }),
|
|
5267
|
-
!isBirthdate && /* @__PURE__ */ jsx("button", { className: "apply-button", onClick: selectDateFunction, children: "\u0627\u0639\u0645\u0627\u0644 \u062A\u0627\u0631\u06CC\u062E" })
|
|
5268
|
-
] });
|
|
5291
|
+
return /* @__PURE__ */ jsx("div", { className: "datepicker-container", children: /* @__PURE__ */ jsxs("div", { className: "scroll-lists", style: { backgroundColor }, children: [
|
|
5292
|
+
renderList(days, selectedDay, dayRef, "day"),
|
|
5293
|
+
renderList(months, months[selectedMonth - 1], monthRef, "month"),
|
|
5294
|
+
renderList(years, selectedYear, yearRef, "year"),
|
|
5295
|
+
/* @__PURE__ */ jsx("div", { className: "selection-highlight", style: { top: ITEM_HEIGHT, height: ITEM_HEIGHT } })
|
|
5296
|
+
] }) });
|
|
5269
5297
|
};
|
|
5270
|
-
var MobileDatePicker_default =
|
|
5298
|
+
var MobileDatePicker_default = DaliryMobileDatePicker;
|
|
5271
5299
|
export {
|
|
5272
5300
|
MobileDatePicker_default as default
|
|
5273
5301
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Moment } from "moment";
|
|
2
|
+
import "./mobileDatePicker.css";
|
|
3
|
+
export interface IDate {
|
|
4
|
+
year: number;
|
|
5
|
+
month: number;
|
|
6
|
+
day: number;
|
|
7
|
+
formatted: string;
|
|
8
|
+
date: string;
|
|
9
|
+
gDate: string;
|
|
10
|
+
moment: Moment;
|
|
11
|
+
}
|
|
12
|
+
interface IMobileDatePicker {
|
|
13
|
+
onDateChange: (date: IDate) => void;
|
|
14
|
+
isBirthdate?: boolean;
|
|
15
|
+
isGregorian?: boolean;
|
|
16
|
+
backgroundColor?: string;
|
|
17
|
+
textColor?: string;
|
|
18
|
+
selectedColor?: string;
|
|
19
|
+
}
|
|
20
|
+
declare const DaliryMobileDatePicker: ({ onDateChange, isBirthdate, isGregorian, backgroundColor, textColor, selectedColor, }: IMobileDatePicker) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export default DaliryMobileDatePicker;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "daliry-mobile-date-picker",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"packageManager": "yarn@4.
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"packageManager": "yarn@4.10.3",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/MobileDatePicker.d.ts",
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
"build": "node build.js && tsc"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"react": "^
|
|
13
|
-
"react-dom": "^
|
|
12
|
+
"react": "^19.2.1",
|
|
13
|
+
"react-dom": "^19.2.1"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@alwatr/nano-build": "^5.5.0",
|
|
17
17
|
"moment-jalaali": "^0.10.4",
|
|
18
|
-
"react": "^
|
|
19
|
-
"react-dom": "^
|
|
18
|
+
"react": "^19.2.1",
|
|
19
|
+
"react-dom": "^19.2.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/moment-jalaali": "^0.7.9",
|
|
@@ -24,7 +24,17 @@
|
|
|
24
24
|
"@types/react-dom": "^19.0.4",
|
|
25
25
|
"esbuild": "^0.25.1"
|
|
26
26
|
},
|
|
27
|
-
"keywords": [
|
|
27
|
+
"keywords": [
|
|
28
|
+
"react",
|
|
29
|
+
"mobile date picker",
|
|
30
|
+
"jalali date picker",
|
|
31
|
+
"shamsi calendar",
|
|
32
|
+
"persian date picker",
|
|
33
|
+
"gregorian date picker",
|
|
34
|
+
"react component",
|
|
35
|
+
"birthdate picker",
|
|
36
|
+
"moment.js"
|
|
37
|
+
],
|
|
28
38
|
"author": "Mahdi Daliry",
|
|
29
39
|
"license": "MIT"
|
|
30
40
|
}
|